@@ -68,6 +68,20 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
6868 DXILValMD->addOperand (Val);
6969}
7070
71+ void addRootSignature (llvm::Function *Fn, llvm::Module &M) {
72+ auto &Ctx = M.getContext ();
73+ IRBuilder<> B (M.getContext ());
74+
75+ MDNode *ExampleRootSignature = MDNode::get (Ctx, {});
76+
77+ MDNode *ExamplePairing = MDNode::get (Ctx, {ValueAsMetadata::get (Fn),
78+ ExampleRootSignature});
79+
80+ StringRef RootSignatureValKey = " dx.rootsignatures" ;
81+ auto *RootSignatureValMD = M.getOrInsertNamedMetadata (RootSignatureValKey);
82+ RootSignatureValMD->addOperand (ExamplePairing);
83+ }
84+
7185} // namespace
7286
7387llvm::Type *
@@ -423,6 +437,13 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
423437 // FIXME: Handle codegen for return type semantics.
424438 // See: https://github.com/llvm/llvm-project/issues/57875
425439 B.CreateRetVoid ();
440+
441+ // Add and identify root signature to function, if applicable
442+ const AttrVec &Attrs = FD->getAttrs ();
443+ for (const Attr *Attr : Attrs) {
444+ if (isa<RootSignatureAttr>(Attr))
445+ addRootSignature (EntryFn, M);
446+ }
426447}
427448
428449void CGHLSLRuntime::setHLSLFunctionAttributes (const FunctionDecl *FD,
0 commit comments