32
32
using namespace llvm ;
33
33
using namespace llvm ::dxil;
34
34
35
- static bool hasUAVsAtEveryStage (DXILResourceMap &DRM,
35
+ static bool hasUAVsAtEveryStage (const DXILResourceMap &DRM,
36
36
const ModuleMetadataInfo &MMDI) {
37
37
if (DRM.uavs ().empty ())
38
38
return false ;
@@ -143,7 +143,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
143
143
}
144
144
145
145
if (CSF.LowPrecisionPresent ) {
146
- if (CanSetNativeLowPrecisionMode )
146
+ if (CSF. NativeLowPrecisionMode )
147
147
CSF.NativeLowPrecision = true ;
148
148
else
149
149
CSF.MinimumPrecision = true ;
@@ -207,26 +207,73 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
207
207
}
208
208
}
209
209
210
+ // / Set shader flags that apply to all functions within the module
211
+ ComputedShaderFlags
212
+ ModuleShaderFlags::gatherGlobalModuleFlags (const Module &M,
213
+ const DXILResourceMap &DRM,
214
+ const ModuleMetadataInfo &MMDI) {
215
+
216
+ ComputedShaderFlags CSF;
217
+
218
+ // Set DisableOptimizations flag based on the presence of OptimizeNone
219
+ // attribute of entry functions.
220
+ if (MMDI.EntryPropertyVec .size () > 0 ) {
221
+ CSF.DisableOptimizations = MMDI.EntryPropertyVec [0 ].Entry ->hasFnAttribute (
222
+ llvm::Attribute::OptimizeNone);
223
+ // Ensure all entry functions have the same optimization attribute
224
+ for (const auto &EntryFunProps : MMDI.EntryPropertyVec )
225
+ if (CSF.DisableOptimizations !=
226
+ EntryFunProps.Entry ->hasFnAttribute (llvm::Attribute::OptimizeNone))
227
+ EntryFunProps.Entry ->getContext ().diagnose (DiagnosticInfoUnsupported (
228
+ *(EntryFunProps.Entry ), " Inconsistent optnone attribute " ));
229
+ }
230
+
231
+ CSF.UAVsAtEveryStage = hasUAVsAtEveryStage (DRM, MMDI);
232
+
233
+ // Set the Max64UAVs flag if the number of UAVs is > 8
234
+ uint32_t NumUAVs = 0 ;
235
+ for (auto &UAV : DRM.uavs ())
236
+ if (MMDI.ValidatorVersion < VersionTuple (1 , 6 ))
237
+ NumUAVs++;
238
+ else // MMDI.ValidatorVersion >= VersionTuple(1, 6)
239
+ NumUAVs += UAV.getBinding ().Size ;
240
+ if (NumUAVs > 8 )
241
+ CSF.Max64UAVs = true ;
242
+
243
+ // Set the module flag that enables native low-precision execution mode.
244
+ // NativeLowPrecisionMode can only be set when the command line option
245
+ // -enable-16bit-types is provided. This is indicated by the dx.nativelowprec
246
+ // module flag being set
247
+ // This flag is needed even if the module does not use 16-bit types because a
248
+ // corresponding debug module may include 16-bit types, and tools that use the
249
+ // debug module may expect it to have the same flags as the original
250
+ if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
251
+ M.getModuleFlag (" dx.nativelowprec" )))
252
+ if (MMDI.ShaderModelVersion >= VersionTuple (6 , 2 ))
253
+ CSF.NativeLowPrecisionMode = NativeLowPrec->getValue ().getBoolValue ();
254
+
255
+ // Set ResMayNotAlias to true if DXIL validator version < 1.8 and there
256
+ // are UAVs present globally.
257
+ if (CanSetResMayNotAlias && MMDI.ValidatorVersion < VersionTuple (1 , 8 ))
258
+ CSF.ResMayNotAlias = !DRM.uavs ().empty ();
259
+
260
+ return CSF;
261
+ }
262
+
210
263
// / Construct ModuleShaderFlags for module Module M
211
264
void ModuleShaderFlags::initialize (Module &M, DXILResourceTypeMap &DRTM,
212
- DXILResourceMap &DRM,
265
+ const DXILResourceMap &DRM,
213
266
const ModuleMetadataInfo &MMDI) {
214
267
215
268
CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple (1 , 7 );
216
269
// The command line option -res-may-alias will set the dx.resmayalias module
217
270
// flag to 1, thereby disabling the ability to set the ResMayNotAlias flag
218
271
if (auto *ResMayAlias = mdconst::extract_or_null<ConstantInt>(
219
272
M.getModuleFlag (" dx.resmayalias" )))
220
- CanSetResMayNotAlias = !ResMayAlias->getValue ().getBoolValue ();
273
+ if (ResMayAlias->getValue ().getBoolValue ())
274
+ CanSetResMayNotAlias = false ;
221
275
222
- // NativeLowPrecisionMode can only be set when the command line option
223
- // -enable-16bit-types is provided. This is indicated by the dx.nativelowprec
224
- // module flag being set
225
- CanSetNativeLowPrecisionMode = false ;
226
- if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
227
- M.getModuleFlag (" dx.nativelowprec" )))
228
- if (MMDI.ShaderModelVersion >= VersionTuple (6 , 2 ))
229
- CanSetNativeLowPrecisionMode = NativeLowPrec->getValue ().getBoolValue ();
276
+ ComputedShaderFlags GlobalSFMask = gatherGlobalModuleFlags (M, DRM, MMDI);
230
277
231
278
CallGraph CG (M);
232
279
@@ -252,7 +299,7 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
252
299
continue ;
253
300
}
254
301
255
- ComputedShaderFlags CSF;
302
+ ComputedShaderFlags CSF = GlobalSFMask ;
256
303
for (const auto &BB : *F)
257
304
for (const auto &I : BB)
258
305
updateFunctionFlags (CSF, I, DRTM, MMDI);
@@ -273,43 +320,6 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
273
320
// Merge SCCSF with that of F
274
321
FunctionFlags[F].merge (SCCSF);
275
322
}
276
-
277
- // Set DisableOptimizations flag based on the presence of OptimizeNone
278
- // attribute of entry functions.
279
- if (MMDI.EntryPropertyVec .size () > 0 ) {
280
- CombinedSFMask.DisableOptimizations =
281
- MMDI.EntryPropertyVec [0 ].Entry ->hasFnAttribute (
282
- llvm::Attribute::OptimizeNone);
283
- // Ensure all entry functions have the same optimization attribute
284
- for (const auto &EntryFunProps : MMDI.EntryPropertyVec )
285
- if (CombinedSFMask.DisableOptimizations !=
286
- EntryFunProps.Entry ->hasFnAttribute (llvm::Attribute::OptimizeNone))
287
- EntryFunProps.Entry ->getContext ().diagnose (DiagnosticInfoUnsupported (
288
- *(EntryFunProps.Entry ), " Inconsistent optnone attribute " ));
289
- }
290
-
291
- // Set ResMayNotAlias to true if DXIL validator version < 1.8 and there
292
- // are UAVs present globally.
293
- if (CanSetResMayNotAlias && MMDI.ValidatorVersion < VersionTuple (1 , 8 ))
294
- CombinedSFMask.ResMayNotAlias = !DRM.uavs ().empty ();
295
-
296
- // Set the module flag that enables native low-precision execution mode. This
297
- // is needed even if the module does not use 16-bit types because a
298
- // corresponding debug module may include 16-bit types, and tools that use the
299
- // debug module may expect it to have the same flags as the original
300
- CombinedSFMask.NativeLowPrecisionMode = CanSetNativeLowPrecisionMode;
301
-
302
- // Set the Max64UAVs flag if the number of UAVs is > 8
303
- uint32_t NumUAVs = 0 ;
304
- for (auto &UAV : DRM.uavs ())
305
- if (MMDI.ValidatorVersion < VersionTuple (1 , 6 ))
306
- NumUAVs++;
307
- else // MMDI.ValidatorVersion >= VersionTuple(1, 6)
308
- NumUAVs += UAV.getBinding ().Size ;
309
- if (NumUAVs > 8 )
310
- CombinedSFMask.Max64UAVs = true ;
311
-
312
- CombinedSFMask.UAVsAtEveryStage = hasUAVsAtEveryStage (DRM, MMDI);
313
323
}
314
324
315
325
void ComputedShaderFlags::print (raw_ostream &OS) const {
0 commit comments