1414#include " DXILShaderFlags.h"
1515#include " DirectX.h"
1616#include " llvm/ADT/STLExtras.h"
17+ #include " llvm/Analysis/DXILResource.h"
1718#include " llvm/IR/Instruction.h"
19+ #include " llvm/IR/IntrinsicInst.h"
20+ #include " llvm/IR/Intrinsics.h"
21+ #include " llvm/IR/IntrinsicsDirectX.h"
1822#include " llvm/IR/Module.h"
23+ #include " llvm/InitializePasses.h"
1924#include " llvm/Support/FormatVariadic.h"
2025#include " llvm/Support/raw_ostream.h"
2126
2227using namespace llvm ;
2328using namespace llvm ::dxil;
2429
25- static void updateFunctionFlags (ComputedShaderFlags &CSF,
26- const Instruction &I ) {
30+ static void updateFunctionFlags (ComputedShaderFlags &CSF, const Instruction &I,
31+ DXILResourceTypeMap &DRTM ) {
2732 if (!CSF.Doubles )
2833 CSF.Doubles = I.getType ()->isDoubleTy ();
2934
@@ -44,9 +49,23 @@ static void updateFunctionFlags(ComputedShaderFlags &CSF,
4449 break ;
4550 }
4651 }
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+ }
4765}
4866
49- void ModuleShaderFlags::initialize (const Module &M) {
67+ void ModuleShaderFlags::initialize (const Module &M, DXILResourceTypeMap &DRTM) {
68+
5069 // Collect shader flags for each of the functions
5170 for (const auto &F : M.getFunctionList ()) {
5271 if (F.isDeclaration ()) {
@@ -57,7 +76,7 @@ void ModuleShaderFlags::initialize(const Module &M) {
5776 ComputedShaderFlags CSF;
5877 for (const auto &BB : F)
5978 for (const auto &I : BB)
60- updateFunctionFlags (CSF, I);
79+ updateFunctionFlags (CSF, I, DRTM );
6180 // Insert shader flag mask for function F
6281 FunctionFlags.push_back ({&F, CSF});
6382 // Update combined shader flags mask
@@ -104,8 +123,11 @@ AnalysisKey ShaderFlagsAnalysis::Key;
104123
105124ModuleShaderFlags ShaderFlagsAnalysis::run (Module &M,
106125 ModuleAnalysisManager &AM) {
126+ DXILResourceTypeMap &DRTM = AM.getResult <DXILResourceTypeAnalysis>(M);
127+
107128 ModuleShaderFlags MSFI;
108- MSFI.initialize (M);
129+ MSFI.initialize (M, DRTM);
130+
109131 return MSFI;
110132}
111133
@@ -132,11 +154,22 @@ PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M,
132154// ShaderFlagsAnalysis and ShaderFlagsAnalysisPrinterPass
133155
134156bool ShaderFlagsAnalysisWrapper::runOnModule (Module &M) {
135- MSFI.initialize (M);
157+ DXILResourceTypeMap &DRTM =
158+ getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
159+
160+ MSFI.initialize (M, DRTM);
136161 return false ;
137162}
138163
164+ void ShaderFlagsAnalysisWrapper::getAnalysisUsage (AnalysisUsage &AU) const {
165+ AU.setPreservesAll ();
166+ AU.addRequiredTransitive <DXILResourceTypeWrapperPass>();
167+ }
168+
139169char ShaderFlagsAnalysisWrapper::ID = 0 ;
140170
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