14
14
#include " DXILShaderFlags.h"
15
15
#include " DirectX.h"
16
16
#include " llvm/ADT/STLExtras.h"
17
+ #include " llvm/Analysis/DXILResource.h"
17
18
#include " llvm/IR/Instruction.h"
19
+ #include " llvm/IR/IntrinsicInst.h"
20
+ #include " llvm/IR/Intrinsics.h"
21
+ #include " llvm/IR/IntrinsicsDirectX.h"
18
22
#include " llvm/IR/Module.h"
23
+ #include " llvm/InitializePasses.h"
19
24
#include " llvm/Support/FormatVariadic.h"
20
25
#include " llvm/Support/raw_ostream.h"
21
26
22
27
using namespace llvm ;
23
28
using namespace llvm ::dxil;
24
29
25
- static void updateFunctionFlags (ComputedShaderFlags &CSF,
26
- const Instruction &I ) {
30
+ static void updateFunctionFlags (ComputedShaderFlags &CSF, const Instruction &I,
31
+ DXILResourceTypeMap &DRTM ) {
27
32
if (!CSF.Doubles )
28
33
CSF.Doubles = I.getType ()->isDoubleTy ();
29
34
@@ -44,9 +49,23 @@ static void updateFunctionFlags(ComputedShaderFlags &CSF,
44
49
break ;
45
50
}
46
51
}
52
+
53
+ if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
54
+ switch (II->getIntrinsicID ()) {
55
+ default :
56
+ break ;
57
+ case Intrinsic::dx_typedBufferLoad: {
58
+ dxil::ResourceTypeInfo &RTI =
59
+ DRTM[cast<TargetExtType>(II->getArgOperand (0 )->getType ())];
60
+ if (RTI.isTyped ())
61
+ CSF.TypedUAVLoadAdditionalFormats |= RTI.getTyped ().ElementCount > 1 ;
62
+ }
63
+ }
64
+ }
47
65
}
48
66
49
- void ModuleShaderFlags::initialize (const Module &M) {
67
+ void ModuleShaderFlags::initialize (const Module &M, DXILResourceTypeMap &DRTM) {
68
+
50
69
// Collect shader flags for each of the functions
51
70
for (const auto &F : M.getFunctionList ()) {
52
71
if (F.isDeclaration ()) {
@@ -57,7 +76,7 @@ void ModuleShaderFlags::initialize(const Module &M) {
57
76
ComputedShaderFlags CSF;
58
77
for (const auto &BB : F)
59
78
for (const auto &I : BB)
60
- updateFunctionFlags (CSF, I);
79
+ updateFunctionFlags (CSF, I, DRTM );
61
80
// Insert shader flag mask for function F
62
81
FunctionFlags.push_back ({&F, CSF});
63
82
// Update combined shader flags mask
@@ -104,8 +123,11 @@ AnalysisKey ShaderFlagsAnalysis::Key;
104
123
105
124
ModuleShaderFlags ShaderFlagsAnalysis::run (Module &M,
106
125
ModuleAnalysisManager &AM) {
126
+ DXILResourceTypeMap &DRTM = AM.getResult <DXILResourceTypeAnalysis>(M);
127
+
107
128
ModuleShaderFlags MSFI;
108
- MSFI.initialize (M);
129
+ MSFI.initialize (M, DRTM);
130
+
109
131
return MSFI;
110
132
}
111
133
@@ -132,11 +154,22 @@ PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M,
132
154
// ShaderFlagsAnalysis and ShaderFlagsAnalysisPrinterPass
133
155
134
156
bool ShaderFlagsAnalysisWrapper::runOnModule (Module &M) {
135
- MSFI.initialize (M);
157
+ DXILResourceTypeMap &DRTM =
158
+ getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
159
+
160
+ MSFI.initialize (M, DRTM);
136
161
return false ;
137
162
}
138
163
164
+ void ShaderFlagsAnalysisWrapper::getAnalysisUsage (AnalysisUsage &AU) const {
165
+ AU.setPreservesAll ();
166
+ AU.addRequiredTransitive <DXILResourceTypeWrapperPass>();
167
+ }
168
+
139
169
char ShaderFlagsAnalysisWrapper::ID = 0 ;
140
170
141
- INITIALIZE_PASS (ShaderFlagsAnalysisWrapper, " dx-shader-flag-analysis" ,
142
- " DXIL Shader Flag Analysis" , true , true )
171
+ INITIALIZE_PASS_BEGIN (ShaderFlagsAnalysisWrapper, " dx-shader-flag-analysis" ,
172
+ " DXIL Shader Flag Analysis" , true , true )
173
+ INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
174
+ INITIALIZE_PASS_END(ShaderFlagsAnalysisWrapper, " dx-shader-flag-analysis" ,
175
+ " DXIL Shader Flag Analysis" , true , true )
0 commit comments