18
18
#include " llvm/CodeGen/Passes.h"
19
19
#include " llvm/IR/Constants.h"
20
20
#include " llvm/InitializePasses.h"
21
+ #include " llvm/MC/DXContainerPSVInfo.h"
21
22
#include " llvm/Pass.h"
22
23
#include " llvm/Support/MD5.h"
23
24
#include " llvm/Transforms/Utils/ModuleUtils.h"
24
25
25
26
using namespace llvm ;
26
27
using namespace llvm ::dxil;
28
+ using namespace llvm ::mcdxbc;
27
29
28
30
namespace {
29
31
class DXContainerGlobals : public llvm ::ModulePass {
30
32
33
+ GlobalVariable *buildContainerGlobal (Module &M, Constant *Content,
34
+ StringRef Name, StringRef SectionName);
31
35
GlobalVariable *getFeatureFlags (Module &M);
32
36
GlobalVariable *computeShaderHash (Module &M);
37
+ GlobalVariable *buildSignature (Module &M, Signature &Sig, StringRef Name,
38
+ StringRef SectionName);
39
+ void addSignature (Module &M, SmallVector<GlobalValue *> &Globals);
33
40
34
41
public:
35
42
static char ID; // Pass identification, replacement for typeid
@@ -55,7 +62,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
55
62
llvm::SmallVector<GlobalValue *> Globals;
56
63
Globals.push_back (getFeatureFlags (M));
57
64
Globals.push_back (computeShaderHash (M));
58
-
65
+ addSignature (M, Globals);
59
66
appendToCompilerUsed (M, Globals);
60
67
return true ;
61
68
}
@@ -68,12 +75,7 @@ GlobalVariable *DXContainerGlobals::getFeatureFlags(Module &M) {
68
75
69
76
Constant *FeatureFlagsConstant =
70
77
ConstantInt::get (M.getContext (), APInt (64 , FeatureFlags));
71
- auto *GV = new llvm::GlobalVariable (M, FeatureFlagsConstant->getType (), true ,
72
- GlobalValue::PrivateLinkage,
73
- FeatureFlagsConstant, " dx.sfi0" );
74
- GV->setSection (" SFI0" );
75
- GV->setAlignment (Align (4 ));
76
- return GV;
78
+ return buildContainerGlobal (M, FeatureFlagsConstant, " dx.sfi0" , " SFI0" );
77
79
}
78
80
79
81
GlobalVariable *DXContainerGlobals::computeShaderHash (Module &M) {
@@ -96,14 +98,41 @@ GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
96
98
97
99
Constant *ModuleConstant =
98
100
ConstantDataArray::get (M.getContext (), arrayRefFromStringRef (Data));
99
- auto *GV = new llvm::GlobalVariable (M, ModuleConstant->getType (), true ,
100
- GlobalValue::PrivateLinkage,
101
- ModuleConstant, " dx.hash" );
102
- GV->setSection (" HASH" );
101
+ return buildContainerGlobal (M, ModuleConstant, " dx.hash" , " HASH" );
102
+ }
103
+
104
+ GlobalVariable *DXContainerGlobals::buildContainerGlobal (
105
+ Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
106
+ auto *GV = new llvm::GlobalVariable (
107
+ M, Content->getType (), true , GlobalValue::PrivateLinkage, Content, Name);
108
+ GV->setSection (SectionName);
103
109
GV->setAlignment (Align (4 ));
104
110
return GV;
105
111
}
106
112
113
+ GlobalVariable *DXContainerGlobals::buildSignature (Module &M, Signature &Sig,
114
+ StringRef Name,
115
+ StringRef SectionName) {
116
+ SmallString<256 > Data;
117
+ raw_svector_ostream OS (Data);
118
+ Sig.write (OS);
119
+ Constant *Constant =
120
+ ConstantDataArray::getString (M.getContext (), Data, /* AddNull*/ false );
121
+ return buildContainerGlobal (M, Constant, Name, SectionName);
122
+ }
123
+
124
+ void DXContainerGlobals::addSignature (Module &M,
125
+ SmallVector<GlobalValue *> &Globals) {
126
+ // FIXME: support graphics shader.
127
+ // see issue https://github.com/llvm/llvm-project/issues/90504.
128
+
129
+ Signature InputSig;
130
+ Globals.emplace_back (buildSignature (M, InputSig, " dx.isg1" , " ISG1" ));
131
+
132
+ Signature OutputSig;
133
+ Globals.emplace_back (buildSignature (M, OutputSig, " dx.osg1" , " OSG1" ));
134
+ }
135
+
107
136
char DXContainerGlobals::ID = 0 ;
108
137
INITIALIZE_PASS_BEGIN (DXContainerGlobals, " dxil-globals" ,
109
138
" DXContainer Global Emitter" , false , true )
0 commit comments