@@ -74,7 +74,8 @@ static bool checkWaveOps(Intrinsic::ID IID) {
7474// / \param I Instruction to check.
7575void ModuleShaderFlags::updateFunctionFlags (ComputedShaderFlags &CSF,
7676 const Instruction &I,
77- DXILResourceTypeMap &DRTM) {
77+ DXILResourceTypeMap &DRTM,
78+ const ModuleMetadataInfo &MMDI) {
7879 if (!CSF.Doubles )
7980 CSF.Doubles = I.getType ()->isDoubleTy ();
8081
@@ -116,8 +117,17 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
116117 switch (II->getIntrinsicID ()) {
117118 default :
118119 break ;
119- case Intrinsic::dx_resource_handlefrombinding:
120- switch (DRTM[cast<TargetExtType>(II->getType ())].getResourceKind ()) {
120+ case Intrinsic::dx_resource_handlefrombinding: {
121+ dxil::ResourceTypeInfo &RTI = DRTM[cast<TargetExtType>(II->getType ())];
122+
123+ // If -res-may-alias is NOT specified, and DXIL Ver > 1.7.
124+ // Then set ResMayNotAlias if function uses UAVs.
125+ if (!CSF.ResMayNotAlias && !ResMayAlias &&
126+ MMDI.DXILVersion > VersionTuple (1 , 7 ) && RTI.isUAV ()) {
127+ CSF.ResMayNotAlias = true ;
128+ }
129+
130+ switch (RTI.getResourceKind ()) {
121131 case dxil::ResourceKind::StructuredBuffer:
122132 case dxil::ResourceKind::RawBuffer:
123133 CSF.EnableRawAndStructuredBuffers = true ;
@@ -126,6 +136,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
126136 break ;
127137 }
128138 break ;
139+ }
129140 case Intrinsic::dx_resource_load_typedbuffer: {
130141 dxil::ResourceTypeInfo &RTI =
131142 DRTM[cast<TargetExtType>(II->getArgOperand (0 )->getType ())];
@@ -151,7 +162,17 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
151162
152163// / Construct ModuleShaderFlags for module Module M
153164void ModuleShaderFlags::initialize (Module &M, DXILResourceTypeMap &DRTM,
165+ DXILBindingMap &DBM,
154166 const ModuleMetadataInfo &MMDI) {
167+
168+ // Check if -res-may-alias was provided on the command line.
169+ // The command line option will set the dx.resmayalias module flag to 1.
170+ if (auto *RMA = mdconst::extract_or_null<ConstantInt>(
171+ M.getModuleFlag (" dx.resmayalias" ))) {
172+ if (RMA->getValue () != 0 )
173+ ResMayAlias = true ;
174+ }
175+
155176 CallGraph CG (M);
156177
157178 // Compute Shader Flags Mask for all functions using post-order visit of SCC
@@ -176,10 +197,16 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
176197 continue ;
177198 }
178199
200+ // If -res-may-alias is NOT specified, and DXIL Ver <= 1.7.
201+ // Then set ResMayNotAlias to true if there are UAVs present globally.
202+ if (!ResMayAlias && MMDI.DXILVersion <= VersionTuple (1 , 7 )) {
203+ SCCSF.ResMayNotAlias = !DBM.uavs ().empty ();
204+ }
205+
179206 ComputedShaderFlags CSF;
180207 for (const auto &BB : *F)
181208 for (const auto &I : BB)
182- updateFunctionFlags (CSF, I, DRTM);
209+ updateFunctionFlags (CSF, I, DRTM, MMDI );
183210 // Update combined shader flags mask for all functions in this SCC
184211 SCCSF.merge (CSF);
185212
@@ -249,10 +276,11 @@ AnalysisKey ShaderFlagsAnalysis::Key;
249276ModuleShaderFlags ShaderFlagsAnalysis::run (Module &M,
250277 ModuleAnalysisManager &AM) {
251278 DXILResourceTypeMap &DRTM = AM.getResult <DXILResourceTypeAnalysis>(M);
279+ DXILBindingMap &DBM = AM.getResult <DXILResourceBindingAnalysis>(M);
252280 const ModuleMetadataInfo MMDI = AM.getResult <DXILMetadataAnalysis>(M);
253281
254282 ModuleShaderFlags MSFI;
255- MSFI.initialize (M, DRTM, MMDI);
283+ MSFI.initialize (M, DRTM, DBM, MMDI);
256284
257285 return MSFI;
258286}
@@ -282,16 +310,19 @@ PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M,
282310bool ShaderFlagsAnalysisWrapper::runOnModule (Module &M) {
283311 DXILResourceTypeMap &DRTM =
284312 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap ();
313+ DXILBindingMap &DBM =
314+ getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap ();
285315 const ModuleMetadataInfo MMDI =
286316 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
287317
288- MSFI.initialize (M, DRTM, MMDI);
318+ MSFI.initialize (M, DRTM, DBM, MMDI);
289319 return false ;
290320}
291321
292322void ShaderFlagsAnalysisWrapper::getAnalysisUsage (AnalysisUsage &AU) const {
293323 AU.setPreservesAll ();
294324 AU.addRequiredTransitive <DXILResourceTypeWrapperPass>();
325+ AU.addRequiredTransitive <DXILResourceBindingWrapperPass>();
295326 AU.addRequired <DXILMetadataAnalysisWrapperPass>();
296327}
297328
0 commit comments