Author: Finn Plummer
Date: 2026-08-12T09:47:34-07:00
New Revision: 8fda9eee8956d4ac5a393689ccbde16a0d3a72b3

URL: 
https://github.com/llvm/llvm-project/commit/8fda9eee8956d4ac5a393689ccbde16a0d3a72b3
DIFF: 
https://github.com/llvm/llvm-project/commit/8fda9eee8956d4ac5a393689ccbde16a0d3a72b3.diff

LOG: Revert "[HLSL] Generate semantic signature metadata" (#215844)

Reverts llvm/llvm-project#212892

Build dependency for `DXILResource.h` was not updated. I will reland
with the corrected dependency.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGHLSLRuntime.cpp
    clang/lib/CodeGen/CGHLSLRuntime.h
    clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl
    clang/test/CodeGenHLSL/semantics/semantic.input.hlsl
    clang/test/CodeGenHLSL/semantics/semantic.output.hlsl
    llvm/include/llvm/Analysis/DXILResource.h
    llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
    llvm/lib/Analysis/DXILResource.cpp
    llvm/unittests/Frontend/HLSLSemanticSignatureMetadataTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index f67f50aff79b1..814894ea14da7 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -31,12 +31,10 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Enum.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Analysis/DXILResource.h"
 #include "llvm/Frontend/HLSL/RootSignatureMetadata.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -104,33 +102,6 @@ void addRootSignatureMD(llvm::dxbc::RootSignatureVersion 
RootSigVer,
   RootSignatureValMD->addOperand(MDVals);
 }
 
-MDNode *buildSemanticSignatureMD(
-    ArrayRef<llvm::hlsl::SemanticSignatureElement> Elements, LLVMContext &Ctx) 
{
-  if (Elements.empty())
-    return nullptr;
-
-  SmallVector<Metadata *> ElementMD;
-  for (const llvm::hlsl::SemanticSignatureElement &Element : Elements)
-    ElementMD.push_back(Element.toMetadata(Ctx));
-  return MDNode::get(Ctx, ElementMD);
-}
-
-void addSemanticSignatureMD(
-    ArrayRef<llvm::hlsl::SemanticSignatureElement> InputElements,
-    ArrayRef<llvm::hlsl::SemanticSignatureElement> OutputElements,
-    llvm::Function *Fn, llvm::Module &M) {
-  if (InputElements.empty() && OutputElements.empty())
-    return;
-
-  LLVMContext &Ctx = M.getContext();
-  MDNode *InputSignature = buildSemanticSignatureMD(InputElements, Ctx);
-  MDNode *OutputSignature = buildSemanticSignatureMD(OutputElements, Ctx);
-  MDNode *MDVals = MDNode::get(
-      Ctx, {ValueAsMetadata::get(Fn), InputSignature, OutputSignature});
-
-  M.getOrInsertNamedMetadata("dx.semantic.signatures")->addOperand(MDVals);
-}
-
 static void copyGlobalResource(CodeGenFunction &CGF, const VarDecl *ResourceVD,
                                AggValueSlot &DestSlot) {
   GlobalVariable *ResGV =
@@ -1275,63 +1246,13 @@ static SemanticShape getSemanticShape(ASTContext &Ctx, 
QualType Ty) {
   return Shape;
 }
 
-static llvm::dxil::ElementType getSignatureComponentType(CodeGenModule &CGM,
-                                                         QualType Ty) {
-  if (const auto *VT = Ty->getAs<clang::VectorType>())
-    Ty = VT->getElementType();
-  else if (const auto *MT = Ty->getAs<clang::ConstantMatrixType>())
-    Ty = MT->getElementType();
-
-  llvm::Type *IRTy = CGM.getTypes().ConvertTypeForMem(Ty);
-  bool IsSigned = Ty->isSignedIntegerOrEnumerationType();
-  return llvm::dxil::toDXILElementType(IRTy, IsSigned);
-}
-
-static llvm::dxbc::PSV::SemanticKind
-getSignatureSemanticKind(StringRef SemanticName) {
-  if (!SemanticName.consume_front_insensitive("SV_"))
-    return llvm::dxbc::PSV::SemanticKind::Arbitrary;
-
-  for (const auto &Kind : llvm::dxbc::PSV::getSemanticKinds())
-    if (SemanticName.equals_insensitive(Kind.name()))
-      return Kind.value();
-
-  return llvm::dxbc::PSV::SemanticKind::Invalid;
-}
-
-static llvm::hlsl::SemanticSignatureElement createSemanticSignatureElement(
-    CodeGenModule &CGM, uint32_t SigId, HLSLAppliedSemanticAttr *Semantic,
-    std::optional<unsigned> Index, const SemanticShape &Shape) {
-  StringRef Name = Semantic->getAttrName()->getName();
-
-  // One semantic index per row, starting from the declared index.
-  SmallVector<uint32_t> SemanticIndices;
-  uint32_t FirstSemanticIndex = Index.value_or(0);
-  for (uint32_t I = 0, E = Shape.getNumRows(); I < E; ++I)
-    SemanticIndices.push_back(FirstSemanticIndex + I);
-
-  // The remaining members keep their default value and will be filled at a
-  // later stage, either during packing or analysis of usage
-  //
-  // FIXME #189762: Element.InterpMode is to be set
-  return llvm::hlsl::SemanticSignatureElement(
-      SigId, Name, getSignatureComponentType(CGM, Shape.RowType),
-      getSignatureSemanticKind(Name), SemanticIndices,
-      static_cast<uint8_t>(Shape.Cols));
-}
-
 llvm::Value *CGHLSLRuntime::emitDXILUserSemanticLoad(
     llvm::IRBuilder<> &B, llvm::Type *Type, const clang::DeclaratorDecl *Decl,
-    HLSLAppliedSemanticAttr *Semantic, std::optional<unsigned> Index,
-    SemanticSignatures &Signature) {
+    HLSLAppliedSemanticAttr *Semantic, std::optional<unsigned> Index) {
   StringRef Name = Semantic->getAttrName()->getName();
   SemanticShape Shape =
       getSemanticShape(CGM.getContext(), getSemanticLeafType(Decl));
 
-  uint32_t SigId = Signature.size();
-  Signature.push_back(
-      createSemanticSignatureElement(CGM, SigId, Semantic, Index, Shape));
-
   llvm::Type *RowTy = CGM.getTypes().ConvertTypeForMem(Shape.RowType);
 
   llvm::Function *IntrFn = llvm::Intrinsic::getOrInsertDeclaration(
@@ -1343,6 +1264,8 @@ llvm::Value *CGHLSLRuntime::emitDXILUserSemanticLoad(
     OB.emplace_back("convergencectrl", bundleArgs);
   }
 
+  unsigned SigId = DXILInputSemanticIndex++;
+
   llvm::Type *LeafTy = CGM.getTypes().ConvertType(Shape.RowType);
   llvm::Value *Result = llvm::PoisonValue::get(Type);
 
@@ -1376,15 +1299,9 @@ void 
CGHLSLRuntime::emitDXILUserSemanticStore(llvm::IRBuilder<> &B,
                                               llvm::Value *Source,
                                               const clang::DeclaratorDecl 
*Decl,
                                               HLSLAppliedSemanticAttr 
*Semantic,
-                                              std::optional<unsigned> Index,
-                                              SemanticSignatures &Signature) {
+                                              std::optional<unsigned> Index) {
   SemanticShape Shape =
       getSemanticShape(CGM.getContext(), getSemanticLeafType(Decl));
-
-  uint32_t SigId = Signature.size();
-  Signature.push_back(
-      createSemanticSignatureElement(CGM, SigId, Semantic, Index, Shape));
-
   llvm::Type *RowTy = CGM.getTypes().ConvertTypeForMem(Shape.RowType);
 
   llvm::Function *IntrFn = llvm::Intrinsic::getOrInsertDeclaration(
@@ -1397,6 +1314,8 @@ void 
CGHLSLRuntime::emitDXILUserSemanticStore(llvm::IRBuilder<> &B,
     OB.emplace_back("convergencectrl", bundleArgs);
   }
 
+  unsigned SigId = DXILOutputSemanticIndex++;
+
   const unsigned NumRows = Shape.getNumRows();
   for (unsigned Row = 0; Row < NumRows; ++Row) {
     SmallVector<unsigned> Indices = Shape.getArrayIndicesForRow(Row);
@@ -1421,12 +1340,12 @@ void 
CGHLSLRuntime::emitDXILUserSemanticStore(llvm::IRBuilder<> &B,
 llvm::Value *CGHLSLRuntime::emitUserSemanticLoad(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
     const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic,
-    std::optional<unsigned> Index, SemanticSignatures &Signature) {
+    std::optional<unsigned> Index) {
   if (CGM.getTarget().getTriple().isSPIRV())
     return emitSPIRVUserSemanticLoad(B, FD, Type, Decl, Semantic, Index);
 
   if (CGM.getTarget().getTriple().isDXIL())
-    return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index, Signature);
+    return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index);
 
   llvm_unreachable("Unsupported target for user-semantic load.");
 }
@@ -1434,14 +1353,12 @@ llvm::Value *CGHLSLRuntime::emitUserSemanticLoad(
 void CGHLSLRuntime::emitUserSemanticStore(IRBuilder<> &B, llvm::Value *Source,
                                           const clang::DeclaratorDecl *Decl,
                                           HLSLAppliedSemanticAttr *Semantic,
-                                          std::optional<unsigned> Index,
-                                          SemanticSignatures &Signature) {
+                                          std::optional<unsigned> Index) {
   if (CGM.getTarget().getTriple().isSPIRV())
     return emitSPIRVUserSemanticStore(B, Source, Decl, Semantic, Index);
 
   if (CGM.getTarget().getTriple().isDXIL())
-    return emitDXILUserSemanticStore(B, Source, Decl, Semantic, Index,
-                                     Signature);
+    return emitDXILUserSemanticStore(B, Source, Decl, Semantic, Index);
 
   llvm_unreachable("Unsupported target for user-semantic load.");
 }
@@ -1449,7 +1366,7 @@ void CGHLSLRuntime::emitUserSemanticStore(IRBuilder<> &B, 
llvm::Value *Source,
 llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
     const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic,
-    std::optional<unsigned> Index, SemanticSignatures &Signature) {
+    std::optional<unsigned> Index) {
 
   std::string SemanticName = Semantic->getAttrName()->getName().upper();
   if (SemanticName == "SV_GROUPINDEX") {
@@ -1496,13 +1413,11 @@ llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
                                       Semantic->getAttrName()->getName(),
                                       /* BuiltIn::FragCoord */ 15);
       if (CGM.getTarget().getTriple().isDXIL())
-        return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index,
-                                        Signature);
+        return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index);
     }
 
     if (ST == Triple::EnvironmentType::Vertex) {
-      return emitUserSemanticLoad(B, FD, Type, Decl, Semantic, Index,
-                                  Signature);
+      return emitUserSemanticLoad(B, FD, Type, Decl, Semantic, Index);
     }
   }
 
@@ -1513,8 +1428,7 @@ llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
                                       Semantic->getAttrName()->getName(),
                                       /* BuiltIn::VertexIndex */ 42);
       else
-        return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index,
-                                        Signature);
+        return emitDXILUserSemanticLoad(B, Type, Decl, Semantic, Index);
     }
   }
 
@@ -1539,13 +1453,12 @@ static void createSPIRVBuiltinStore(IRBuilder<> &B, 
llvm::Module &M,
 void CGHLSLRuntime::emitSystemSemanticStore(IRBuilder<> &B, llvm::Value 
*Source,
                                             const clang::DeclaratorDecl *Decl,
                                             HLSLAppliedSemanticAttr *Semantic,
-                                            std::optional<unsigned> Index,
-                                            SemanticSignatures &Signature) {
+                                            std::optional<unsigned> Index) {
 
   std::string SemanticName = Semantic->getAttrName()->getName().upper();
   if (SemanticName == "SV_POSITION") {
     if (CGM.getTarget().getTriple().isDXIL()) {
-      emitDXILUserSemanticStore(B, Source, Decl, Semantic, Index, Signature);
+      emitDXILUserSemanticStore(B, Source, Decl, Semantic, Index);
       return;
     }
 
@@ -1558,7 +1471,7 @@ void CGHLSLRuntime::emitSystemSemanticStore(IRBuilder<> 
&B, llvm::Value *Source,
   }
 
   if (SemanticName == "SV_TARGET") {
-    emitUserSemanticStore(B, Source, Decl, Semantic, Index, Signature);
+    emitUserSemanticStore(B, Source, Decl, Semantic, Index);
     return;
   }
 
@@ -1568,27 +1481,22 @@ void CGHLSLRuntime::emitSystemSemanticStore(IRBuilder<> 
&B, llvm::Value *Source,
 
 llvm::Value *CGHLSLRuntime::handleScalarSemanticLoad(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
-    const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic,
-    SemanticSignatures &Signature) {
+    const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic) {
 
   std::optional<unsigned> Index = Semantic->getSemanticIndex();
   if (Semantic->getAttrName()->getName().starts_with_insensitive("SV_"))
-    return emitSystemSemanticLoad(B, FD, Type, Decl, Semantic, Index,
-                                  Signature);
-  return emitUserSemanticLoad(B, FD, Type, Decl, Semantic, Index, Signature);
+    return emitSystemSemanticLoad(B, FD, Type, Decl, Semantic, Index);
+  return emitUserSemanticLoad(B, FD, Type, Decl, Semantic, Index);
 }
 
-void CGHLSLRuntime::handleScalarSemanticStore(IRBuilder<> &B,
-                                              const FunctionDecl *FD,
-                                              llvm::Value *Source,
-                                              const clang::DeclaratorDecl 
*Decl,
-                                              HLSLAppliedSemanticAttr 
*Semantic,
-                                              SemanticSignatures &Signature) {
+void CGHLSLRuntime::handleScalarSemanticStore(
+    IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source,
+    const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic) {
   std::optional<unsigned> Index = Semantic->getSemanticIndex();
   if (Semantic->getAttrName()->getName().starts_with_insensitive("SV_"))
-    emitSystemSemanticStore(B, Source, Decl, Semantic, Index, Signature);
+    emitSystemSemanticStore(B, Source, Decl, Semantic, Index);
   else
-    emitUserSemanticStore(B, Source, Decl, Semantic, Index, Signature);
+    emitUserSemanticStore(B, Source, Decl, Semantic, Index);
 }
 
 std::pair<llvm::Value *, specific_attr_iterator<HLSLAppliedSemanticAttr>>
@@ -1596,8 +1504,7 @@ CGHLSLRuntime::handleStructSemanticLoad(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
     const clang::DeclaratorDecl *Decl,
     specific_attr_iterator<HLSLAppliedSemanticAttr> AttrBegin,
-    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-    SemanticSignatures &Signature) {
+    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd) {
   const llvm::StructType *ST = cast<StructType>(Type);
   const clang::RecordDecl *RD = Decl->getType()->getAsRecordDecl();
 
@@ -1606,9 +1513,8 @@ CGHLSLRuntime::handleStructSemanticLoad(
   llvm::Value *Aggregate = llvm::PoisonValue::get(Type);
   auto FieldDecl = RD->field_begin();
   for (unsigned I = 0; I < ST->getNumElements(); ++I) {
-    auto [ChildValue, NextAttr] =
-        handleSemanticLoad(B, FD, ST->getElementType(I), *FieldDecl, AttrBegin,
-                           AttrEnd, Signature);
+    auto [ChildValue, NextAttr] = handleSemanticLoad(
+        B, FD, ST->getElementType(I), *FieldDecl, AttrBegin, AttrEnd);
     AttrBegin = NextAttr;
     assert(ChildValue);
     Aggregate = B.CreateInsertValue(Aggregate, ChildValue, I);
@@ -1623,8 +1529,7 @@ CGHLSLRuntime::handleStructSemanticStore(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source,
     const clang::DeclaratorDecl *Decl,
     specific_attr_iterator<HLSLAppliedSemanticAttr> AttrBegin,
-    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-    SemanticSignatures &Signature) {
+    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd) {
 
   const llvm::StructType *ST = cast<StructType>(Source->getType());
 
@@ -1640,8 +1545,8 @@ CGHLSLRuntime::handleStructSemanticStore(
   auto FieldDecl = RD->field_begin();
   for (unsigned I = 0; I < ST->getNumElements(); ++I, ++FieldDecl) {
     llvm::Value *Extract = B.CreateExtractValue(Source, I);
-    AttrBegin = handleSemanticStore(B, FD, Extract, *FieldDecl, AttrBegin,
-                                    AttrEnd, Signature);
+    AttrBegin =
+        handleSemanticStore(B, FD, Extract, *FieldDecl, AttrBegin, AttrEnd);
   }
 
   return AttrBegin;
@@ -1652,17 +1557,15 @@ CGHLSLRuntime::handleSemanticLoad(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
     const clang::DeclaratorDecl *Decl,
     specific_attr_iterator<HLSLAppliedSemanticAttr> AttrBegin,
-    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-    SemanticSignatures &Signature) {
+    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd) {
   assert(AttrBegin != AttrEnd);
   if (Type->isStructTy())
-    return handleStructSemanticLoad(B, FD, Type, Decl, AttrBegin, AttrEnd,
-                                    Signature);
+    return handleStructSemanticLoad(B, FD, Type, Decl, AttrBegin, AttrEnd);
 
   HLSLAppliedSemanticAttr *Attr = *AttrBegin;
   ++AttrBegin;
-  return std::make_pair(
-      handleScalarSemanticLoad(B, FD, Type, Decl, Attr, Signature), AttrBegin);
+  return std::make_pair(handleScalarSemanticLoad(B, FD, Type, Decl, Attr),
+                        AttrBegin);
 }
 
 specific_attr_iterator<HLSLAppliedSemanticAttr>
@@ -1670,23 +1573,21 @@ CGHLSLRuntime::handleSemanticStore(
     IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source,
     const clang::DeclaratorDecl *Decl,
     specific_attr_iterator<HLSLAppliedSemanticAttr> AttrBegin,
-    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-    SemanticSignatures &Signature) {
+    specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd) {
   assert(AttrBegin != AttrEnd);
   if (Source->getType()->isStructTy())
-    return handleStructSemanticStore(B, FD, Source, Decl, AttrBegin, AttrEnd,
-                                     Signature);
+    return handleStructSemanticStore(B, FD, Source, Decl, AttrBegin, AttrEnd);
 
   HLSLAppliedSemanticAttr *Attr = *AttrBegin;
   ++AttrBegin;
-  handleScalarSemanticStore(B, FD, Source, Decl, Attr, Signature);
+  handleScalarSemanticStore(B, FD, Source, Decl, Attr);
   return AttrBegin;
 }
 
 void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
                                       llvm::Function *Fn) {
-  SmallVector<llvm::hlsl::SemanticSignatureElement> InputSignature;
-  SmallVector<llvm::hlsl::SemanticSignatureElement> OutputSignature;
+  DXILInputSemanticIndex = 0;
+  DXILOutputSemanticIndex = 0;
 
   llvm::Module &M = CGM.getModule();
   llvm::LLVMContext &Ctx = M.getContext();
@@ -1750,8 +1651,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
 
       auto AttrBegin = PD->specific_attr_begin<HLSLAppliedSemanticAttr>();
       auto AttrEnd = PD->specific_attr_end<HLSLAppliedSemanticAttr>();
-      auto Result = handleSemanticLoad(B, FD, ParamType, PD, AttrBegin, 
AttrEnd,
-                                       InputSignature);
+      auto Result =
+          handleSemanticLoad(B, FD, ParamType, PD, AttrBegin, AttrEnd);
       SemanticValue = Result.first;
       if (!SemanticValue)
         return;
@@ -1784,8 +1685,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
 
     auto AttrBegin = FD->specific_attr_begin<HLSLAppliedSemanticAttr>();
     auto AttrEnd = FD->specific_attr_end<HLSLAppliedSemanticAttr>();
-    handleSemanticStore(B, FD, SourceValue, FD, AttrBegin, AttrEnd,
-                        OutputSignature);
+    handleSemanticStore(B, FD, SourceValue, FD, AttrBegin, AttrEnd);
   }
 
   B.CreateRetVoid();
@@ -1798,8 +1698,6 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl 
*FD,
                          EntryFn, M);
     }
   }
-
-  addSemanticSignatureMD(InputSignature, OutputSignature, EntryFn, M);
 }
 
 static void gatherFunctions(SmallVectorImpl<Function *> &Fns, llvm::Module &M,

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index ba8b2415a6275..f5674b64d0041 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -24,7 +24,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
-#include "llvm/Frontend/HLSL/SemanticSignatures.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicsDirectX.h"
@@ -220,65 +219,54 @@ class CGHLSLRuntime {
   
//===----------------------------------------------------------------------===//
 
 protected:
-  using SemanticSignatures =
-      llvm::SmallVectorImpl<llvm::hlsl::SemanticSignatureElement>;
-
   CodeGenModule &CGM;
 
   llvm::Value *emitSystemSemanticLoad(llvm::IRBuilder<> &B,
                                       const FunctionDecl *FD, llvm::Type *Type,
                                       const clang::DeclaratorDecl *Decl,
                                       HLSLAppliedSemanticAttr *Semantic,
-                                      std::optional<unsigned> Index,
-                                      SemanticSignatures &Signature);
+                                      std::optional<unsigned> Index);
 
   void emitSystemSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
                                const clang::DeclaratorDecl *Decl,
                                HLSLAppliedSemanticAttr *Semantic,
-                               std::optional<unsigned> Index,
-                               SemanticSignatures &Signature);
+                               std::optional<unsigned> Index);
 
   llvm::Value *handleScalarSemanticLoad(llvm::IRBuilder<> &B,
                                         const FunctionDecl *FD,
                                         llvm::Type *Type,
                                         const clang::DeclaratorDecl *Decl,
-                                        HLSLAppliedSemanticAttr *Semantic,
-                                        SemanticSignatures &Signature);
+                                        HLSLAppliedSemanticAttr *Semantic);
 
   void handleScalarSemanticStore(llvm::IRBuilder<> &B, const FunctionDecl *FD,
                                  llvm::Value *Source,
                                  const clang::DeclaratorDecl *Decl,
-                                 HLSLAppliedSemanticAttr *Semantic,
-                                 SemanticSignatures &Signature);
+                                 HLSLAppliedSemanticAttr *Semantic);
 
   std::pair<llvm::Value *, specific_attr_iterator<HLSLAppliedSemanticAttr>>
   handleStructSemanticLoad(
       llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
       const clang::DeclaratorDecl *Decl,
       specific_attr_iterator<HLSLAppliedSemanticAttr> begin,
-      specific_attr_iterator<HLSLAppliedSemanticAttr> end,
-      SemanticSignatures &Signature);
+      specific_attr_iterator<HLSLAppliedSemanticAttr> end);
 
   specific_attr_iterator<HLSLAppliedSemanticAttr> handleStructSemanticStore(
       llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source,
       const clang::DeclaratorDecl *Decl,
       specific_attr_iterator<HLSLAppliedSemanticAttr> AttrBegin,
-      specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-      SemanticSignatures &Signature);
+      specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd);
 
   std::pair<llvm::Value *, specific_attr_iterator<HLSLAppliedSemanticAttr>>
   handleSemanticLoad(llvm::IRBuilder<> &B, const FunctionDecl *FD,
                      llvm::Type *Type, const clang::DeclaratorDecl *Decl,
                      specific_attr_iterator<HLSLAppliedSemanticAttr> begin,
-                     specific_attr_iterator<HLSLAppliedSemanticAttr> end,
-                     SemanticSignatures &Signature);
+                     specific_attr_iterator<HLSLAppliedSemanticAttr> end);
 
   specific_attr_iterator<HLSLAppliedSemanticAttr>
   handleSemanticStore(llvm::IRBuilder<> &B, const FunctionDecl *FD,
                       llvm::Value *Source, const clang::DeclaratorDecl *Decl,
                       specific_attr_iterator<HLSLAppliedSemanticAttr> 
AttrBegin,
-                      specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd,
-                      SemanticSignatures &Signature);
+                      specific_attr_iterator<HLSLAppliedSemanticAttr> AttrEnd);
 
 public:
   CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
@@ -352,14 +340,12 @@ class CGHLSLRuntime {
   llvm::Value *emitDXILUserSemanticLoad(llvm::IRBuilder<> &B, llvm::Type *Type,
                                         const clang::DeclaratorDecl *Decl,
                                         HLSLAppliedSemanticAttr *Semantic,
-                                        std::optional<unsigned> Index,
-                                        SemanticSignatures &Signature);
+                                        std::optional<unsigned> Index);
   llvm::Value *emitUserSemanticLoad(llvm::IRBuilder<> &B,
                                     const FunctionDecl *FD, llvm::Type *Type,
                                     const clang::DeclaratorDecl *Decl,
                                     HLSLAppliedSemanticAttr *Semantic,
-                                    std::optional<unsigned> Index,
-                                    SemanticSignatures &Signature);
+                                    std::optional<unsigned> Index);
 
   void emitSPIRVUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
                                   const clang::DeclaratorDecl *Decl,
@@ -368,13 +354,11 @@ class CGHLSLRuntime {
   void emitDXILUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
                                  const clang::DeclaratorDecl *Decl,
                                  HLSLAppliedSemanticAttr *Semantic,
-                                 std::optional<unsigned> Index,
-                                 SemanticSignatures &Signature);
+                                 std::optional<unsigned> Index);
   void emitUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
                              const clang::DeclaratorDecl *Decl,
                              HLSLAppliedSemanticAttr *Semantic,
-                             std::optional<unsigned> Index,
-                             SemanticSignatures &Signature);
+                             std::optional<unsigned> Index);
 
   bool initializeGlobalResourceArray(CodeGenFunction &CGF,
                                      const VarDecl *ArrayDecl,
@@ -385,6 +369,12 @@ class CGHLSLRuntime {
   llvm::DenseMap<const clang::RecordType *, llvm::StructType *> LayoutTypes;
   unsigned SPIRVLastAssignedInputSemanticLocation = 0;
   unsigned SPIRVLastAssignedOutputSemanticLocation = 0;
+
+  // FIXME: #57928, storing these here and reseting them in the entry is not
+  // very nice and is a temporary until we accumulate the signatures as part of
+  // the mentioned issue.
+  unsigned DXILInputSemanticIndex = 0;
+  unsigned DXILOutputSemanticIndex = 0;
 };
 
 } // namespace CodeGen

diff  --git a/clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl 
b/clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl
index 5427a569e5eee..8c8fe6443183e 100644
--- a/clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl
@@ -34,11 +34,6 @@ S0 main1(float4 input : A) : B {
   return output;
 }
 
-// CHECK-DXIL: !dx.semantic.signatures = !{![[#ENTRY_SIG:]]}
-// CHECK-DXIL: ![[#ENTRY_SIG]] = !{ptr @main1, ![[#INPUT_SIG:]], 
![[#OUTPUT_SIG:]]}
-// CHECK-DXIL: ![[#INPUT_SIG]] = !{![[#INPUT_ELEMENT:]]}
-// CHECK-DXIL: ![[#OUTPUT_SIG]] = !{![[#OUTPUT_ELEMENT_0:]], 
![[#OUTPUT_ELEMENT_1:]]}
-
 // CHECK-SPIRV-DAG: ![[#METADATA_0]] = !{![[#METADATA_1:]]}
 // CHECK-SPIRV-DAG: ![[#METADATA_1]] = !{i32 30, i32 0}
 //                                            |      `- Location index

diff  --git a/clang/test/CodeGenHLSL/semantics/semantic.input.hlsl 
b/clang/test/CodeGenHLSL/semantics/semantic.input.hlsl
index 3bd77d783b435..3c46eace082ee 100644
--- a/clang/test/CodeGenHLSL/semantics/semantic.input.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/semantic.input.hlsl
@@ -51,14 +51,3 @@ void main(S s) {}
 // CHECK: %[[E5:.*]] = call <4 x float> @llvm.dx.load.input.v4f32(i32 3, i32 
5, i8 0, i32 poison)
 // CHECK: %[[E_ARRAY5:.*]] = insertvalue [2 x [3 x <4 x float>]] 
%[[E_ARRAY4]], <4 x float> %[[E5]], 1, 2
 // CHECK: %[[S3:.*]] = insertvalue %struct.S %[[S2]], [2 x [3 x <4 x float>]] 
%[[E_ARRAY5]], 3
-
-// CHECK: !dx.semantic.signatures = !{![[#ENTRY_SIG:]]}
-// CHECK: ![[#ENTRY_SIG]] = !{ptr @main, ![[#INPUT_SIG:]], null}
-// CHECK: ![[#INPUT_SIG]] = !{![[#A_SIG:]], ![[#B_SIG:]], ![[#D_SIG:]], 
![[#E_SIG:]]}
-// CHECK: ![[#A_SIG]] = !{i32 0, !"A", i32 9, i32 0, ![[#ZERO_INDEX:]], i32 0, 
i32 1, i8 1, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#ZERO_INDEX]] = !{i32 0}
-// CHECK: ![[#B_SIG]] = !{i32 1, !"B", i32 9, i32 0, ![[#ZERO_INDEX]], i32 0, 
i32 1, i8 4, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#D_SIG]] = !{i32 2, !"D", i32 9, i32 0, ![[#D_INDICES:]], i32 0, 
i32 5, i8 1, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#D_INDICES]] = !{i32 0, i32 1, i32 2, i32 3, i32 4}
-// CHECK: ![[#E_SIG]] = !{i32 3, !"E", i32 9, i32 0, ![[#E_INDICES:]], i32 0, 
i32 6, i8 4, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#E_INDICES]] = !{i32 0, i32 1, i32 2, i32 3, i32 4, i32 5}

diff  --git a/clang/test/CodeGenHLSL/semantics/semantic.output.hlsl 
b/clang/test/CodeGenHLSL/semantics/semantic.output.hlsl
index 54e9aa83cda0b..fdb195899ca97 100644
--- a/clang/test/CodeGenHLSL/semantics/semantic.output.hlsl
+++ b/clang/test/CodeGenHLSL/semantics/semantic.output.hlsl
@@ -54,14 +54,3 @@ S main() {
 // CHECK: call void @llvm.dx.store.output.v4f32(i32 3, i32 4, i8 0, <4 x 
float> %[[E11]])
 // CHECK: %[[E12:.*]] = extractvalue [2 x [3 x <4 x float>]] %[[E]], 1, 2
 // CHECK: call void @llvm.dx.store.output.v4f32(i32 3, i32 5, i8 0, <4 x 
float> %[[E12]])
-
-// CHECK: !dx.semantic.signatures = !{![[#ENTRY_SIG:]]}
-// CHECK: ![[#ENTRY_SIG]] = !{ptr @main, null, ![[#OUTPUT_SIG:]]}
-// CHECK: ![[#OUTPUT_SIG]] = !{![[#A_SIG:]], ![[#B_SIG:]], ![[#D_SIG:]], 
![[#E_SIG:]]}
-// CHECK: ![[#A_SIG]] = !{i32 0, !"A", i32 9, i32 0, ![[#ZERO_INDEX:]], i32 0, 
i32 1, i8 1, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#ZERO_INDEX]] = !{i32 0}
-// CHECK: ![[#B_SIG]] = !{i32 1, !"B", i32 9, i32 0, ![[#ZERO_INDEX]], i32 0, 
i32 1, i8 4, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#D_SIG]] = !{i32 2, !"D", i32 9, i32 0, ![[#D_INDICES:]], i32 0, 
i32 5, i8 1, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#D_INDICES]] = !{i32 0, i32 1, i32 2, i32 3, i32 4}
-// CHECK: ![[#E_SIG]] = !{i32 3, !"E", i32 9, i32 0, ![[#E_INDICES:]], i32 0, 
i32 6, i8 4, i32 -1, i8 -1, i8 0, i8 0, i32 0}
-// CHECK: ![[#E_INDICES]] = !{i32 0, i32 1, i32 2, i32 3, i32 4, i32 5}

diff  --git a/llvm/include/llvm/Analysis/DXILResource.h 
b/llvm/include/llvm/Analysis/DXILResource.h
index c996e79f2caee..1473a0f7d56c0 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -37,11 +37,6 @@ namespace dxil {
 // dx_resource_handlefromimplicitbinding call
 LLVM_ABI StringRef getResourceNameFromBindingCall(CallInst *CI);
 
-/// Converts a scalar or vector LLVM type to its DXIL element type. Integer
-/// signedness must be supplied separately because LLVM integer types are
-/// signless.
-LLVM_ABI ElementType toDXILElementType(Type *Ty, bool IsSigned);
-
 /// The dx.RawBuffer target extension type
 ///
 /// `target("dx.RawBuffer", Type, IsWriteable, IsROV)`

diff  --git a/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h 
b/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
index 76518f75a70ec..c5be2516a7364 100644
--- a/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
+++ b/llvm/include/llvm/Frontend/HLSL/SemanticSignatures.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_FRONTEND_HLSL_SEMANTICSIGNATURES_H
 #define LLVM_FRONTEND_HLSL_SEMANTICSIGNATURES_H
 
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/DXContainer.h"
@@ -54,15 +53,6 @@ struct SemanticSignatureElement {
   uint8_t DynIndexMask = 0;
   uint32_t GSStream = 0;
 
-  SemanticSignatureElement() = default;
-  SemanticSignatureElement(uint32_t SigId, StringRef SemanticName,
-                           dxil::ElementType CompType,
-                           dxbc::PSV::SemanticKind SemanticKind,
-                           ArrayRef<uint32_t> SemanticIndices, uint8_t Cols)
-      : SigId(SigId), SemanticName(SemanticName), CompType(CompType),
-        SemanticKind(SemanticKind), SemanticIndices(SemanticIndices),
-        Rows(static_cast<uint32_t>(SemanticIndices.size())), Cols(Cols) {}
-
   bool isAllocated() const {
     return StartRow != UnallocatedRow && StartCol != UnallocatedCol;
   }

diff  --git a/llvm/lib/Analysis/DXILResource.cpp 
b/llvm/lib/Analysis/DXILResource.cpp
index 6ed66dad3d317..767c33684da60 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -180,7 +180,7 @@ static StringRef 
getSamplerFeedbackTypeName(SamplerFeedbackType SFT) {
   llvm_unreachable("Unhandled SamplerFeedbackType");
 }
 
-dxil::ElementType dxil::toDXILElementType(Type *Ty, bool IsSigned) {
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
   // TODO: Handle unorm, snorm, and packed.
   Ty = Ty->getScalarType();
 

diff  --git a/llvm/unittests/Frontend/HLSLSemanticSignatureMetadataTest.cpp 
b/llvm/unittests/Frontend/HLSLSemanticSignatureMetadataTest.cpp
index 9813264bf1f85..0638cf0f49692 100644
--- a/llvm/unittests/Frontend/HLSLSemanticSignatureMetadataTest.cpp
+++ b/llvm/unittests/Frontend/HLSLSemanticSignatureMetadataTest.cpp
@@ -71,12 +71,14 @@ class HLSLSemanticSignatureMetadataTest : public 
testing::Test {
 
//===----------------------------------------------------------------------===//
 
 TEST_F(HLSLSemanticSignatureMetadataTest, StructHelpers) {
-  SemanticSignatureElement Elem(/*SigId=*/0, "TEXCOORD", 
dxil::ElementType::F32,
-                                dxbc::PSV::SemanticKind::Arbitrary,
-                                /*SemanticIndices=*/{0}, /*Cols=*/4);
-  EXPECT_EQ(Elem.Rows, 1u);
+  SemanticSignatureElement Elem;
+  Elem.SigId = 0;
+  Elem.CompType = dxil::ElementType::F32;
+  Elem.SemanticKind = dxbc::PSV::SemanticKind::Arbitrary;
+  Elem.Rows = 1;
   EXPECT_FALSE(Elem.isAllocated());
 
+  Elem.Cols = 4;
   Elem.StartRow = 0;
   Elem.StartCol = 0;
   EXPECT_TRUE(Elem.isAllocated());
@@ -387,11 +389,20 @@ TEST_F(HLSLSemanticSignatureMetadataTest, 
MetadataToElementIndicesRowMismatch) {
 
 // A fully populated element emits all 13 operands in order
 TEST_F(HLSLSemanticSignatureMetadataTest, ElementToMetadata) {
-  SemanticSignatureElement Elem(/*SigId=*/1, "TEXCOORD", 
dxil::ElementType::F32,
-                                dxbc::PSV::SemanticKind::Arbitrary,
-                                /*SemanticIndices=*/{0, 1}, /*Cols=*/4);
+  SemanticSignatureElement Elem;
+  Elem.SigId = 1;
+  Elem.SemanticName = "TEXCOORD";
+  Elem.CompType = dxil::ElementType::F32;
+  Elem.SemanticKind = dxbc::PSV::SemanticKind::Arbitrary;
+  Elem.SemanticIndices = {0, 1};
+  Elem.InterpMode = dxbc::PSV::InterpolationMode::Undefined;
+  Elem.Rows = 2;
+  Elem.Cols = 4;
   Elem.StartRow = 1;
   Elem.StartCol = 0;
+  Elem.UsageMask = 0;
+  Elem.DynIndexMask = 0;
+  Elem.GSStream = 0;
 
   MDNode *Node = Elem.toMetadata(Ctx);
   ASSERT_EQ(Node->getNumOperands(), 13u);
@@ -412,10 +423,14 @@ TEST_F(HLSLSemanticSignatureMetadataTest, 
ElementToMetadata) {
 
 // System value, non-zero masks and a non-zero stream index are emitted
 TEST_F(HLSLSemanticSignatureMetadataTest, ElementToMetadataSystemValue) {
-  SemanticSignatureElement Elem(/*SigId=*/1, "SV_Target",
-                                dxil::ElementType::F32,
-                                dxbc::PSV::SemanticKind::Target,
-                                /*SemanticIndices=*/{1}, /*Cols=*/4);
+  SemanticSignatureElement Elem;
+  Elem.SigId = 1;
+  Elem.SemanticName = "SV_Target";
+  Elem.CompType = dxil::ElementType::F32;
+  Elem.SemanticKind = dxbc::PSV::SemanticKind::Target;
+  Elem.SemanticIndices = {1};
+  Elem.Rows = 1;
+  Elem.Cols = 4;
   Elem.StartRow = 1;
   Elem.StartCol = 0;
   Elem.UsageMask = 0x7;
@@ -434,9 +449,14 @@ TEST_F(HLSLSemanticSignatureMetadataTest, 
ElementToMetadataSystemValue) {
 
 // An unallocated element emits the row/col sentinels
 TEST_F(HLSLSemanticSignatureMetadataTest, ElementToMetadataUnallocated) {
-  SemanticSignatureElement Elem(/*SigId=*/0, "POSITION", 
dxil::ElementType::F32,
-                                dxbc::PSV::SemanticKind::Arbitrary,
-                                /*SemanticIndices=*/{0}, /*Cols=*/4);
+  SemanticSignatureElement Elem;
+  Elem.SigId = 0;
+  Elem.SemanticName = "POSITION";
+  Elem.CompType = dxil::ElementType::F32;
+  Elem.SemanticKind = dxbc::PSV::SemanticKind::Arbitrary;
+  Elem.SemanticIndices = {0};
+  Elem.Rows = 0;
+  Elem.Cols = 0;
 
   MDNode *Node = Elem.toMetadata(Ctx);
   ASSERT_EQ(Node->getNumOperands(), 13u);
@@ -446,13 +466,20 @@ TEST_F(HLSLSemanticSignatureMetadataTest, 
ElementToMetadataUnallocated) {
 
 // Emitting then parsing yields an equivalent element
 TEST_F(HLSLSemanticSignatureMetadataTest, ElementRoundTrip) {
-  SemanticSignatureElement Elem(/*SigId=*/2, "TEXCOORD", 
dxil::ElementType::F32,
-                                dxbc::PSV::SemanticKind::Arbitrary,
-                                /*SemanticIndices=*/{1}, /*Cols=*/4);
+  SemanticSignatureElement Elem;
+  Elem.SigId = 2;
+  Elem.SemanticName = "TEXCOORD";
+  Elem.CompType = dxil::ElementType::F32;
+  Elem.SemanticKind = dxbc::PSV::SemanticKind::Arbitrary;
+  Elem.SemanticIndices = {1};
   Elem.InterpMode = dxbc::PSV::InterpolationMode::LinearNoperspective;
+  Elem.Rows = 1;
+  Elem.Cols = 4;
   Elem.StartRow = 2;
   Elem.StartCol = 0;
   Elem.UsageMask = 0x7;
+  Elem.DynIndexMask = 0;
+  Elem.GSStream = 0;
 
   Expected<SemanticSignatureElement> Parsed =
       SemanticSignatureElement::fromMetadata(Elem.toMetadata(Ctx));


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to