[llvm] [DirectX] Set whole-module flags prior to evaluating per-function flags (PR #139967)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 15:02:06 PDT 2025
================
@@ -207,26 +207,69 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
}
}
-/// Construct ModuleShaderFlags for module Module M
-void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM,
- DXILResourceMap &DRM,
- const ModuleMetadataInfo &MMDI) {
+/// Set shader flags that apply to all functions within the module
+void ModuleShaderFlags::gatherGlobalModuleFlags(
+ ComputedShaderFlags &CSF, const Module &M, const DXILResourceMap &DRM,
+ const ModuleMetadataInfo &MMDI) {
- CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple(1, 7);
- // The command line option -res-may-alias will set the dx.resmayalias module
- // flag to 1, thereby disabling the ability to set the ResMayNotAlias flag
- if (auto *ResMayAlias = mdconst::extract_or_null<ConstantInt>(
- M.getModuleFlag("dx.resmayalias")))
- CanSetResMayNotAlias = !ResMayAlias->getValue().getBoolValue();
+ // Set DisableOptimizations flag based on the presence of OptimizeNone
+ // attribute of entry functions.
+ if (MMDI.EntryPropertyVec.size() > 0) {
+ CSF.DisableOptimizations = MMDI.EntryPropertyVec[0].Entry->hasFnAttribute(
+ llvm::Attribute::OptimizeNone);
+ // Ensure all entry functions have the same optimization attribute
+ for (const auto &EntryFunProps : MMDI.EntryPropertyVec)
+ if (CSF.DisableOptimizations !=
+ EntryFunProps.Entry->hasFnAttribute(llvm::Attribute::OptimizeNone))
+ EntryFunProps.Entry->getContext().diagnose(DiagnosticInfoUnsupported(
+ *(EntryFunProps.Entry), "Inconsistent optnone attribute "));
+ }
+
+ CSF.UAVsAtEveryStage = hasUAVsAtEveryStage(DRM, MMDI);
+ // Set the Max64UAVs flag if the number of UAVs is > 8
+ uint32_t NumUAVs = 0;
+ for (auto &UAV : DRM.uavs())
+ if (MMDI.ValidatorVersion < VersionTuple(1, 6))
+ NumUAVs++;
+ else // MMDI.ValidatorVersion >= VersionTuple(1, 6)
+ NumUAVs += UAV.getBinding().Size;
+ if (NumUAVs > 8)
+ CSF.Max64UAVs = true;
+
+ // Set the module flag that enables native low-precision execution mode.
// NativeLowPrecisionMode can only be set when the command line option
// -enable-16bit-types is provided. This is indicated by the dx.nativelowprec
// module flag being set
- CanSetNativeLowPrecisionMode = false;
+ // This flag is needed even if the module does not use 16-bit types because a
+ // corresponding debug module may include 16-bit types, and tools that use the
+ // debug module may expect it to have the same flags as the original
if (auto *NativeLowPrec = mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag("dx.nativelowprec")))
if (MMDI.ShaderModelVersion >= VersionTuple(6, 2))
- CanSetNativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
+ CSF.NativeLowPrecisionMode = NativeLowPrec->getValue().getBoolValue();
+
+ CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple(1, 7);
+ // The command line option -res-may-alias will set the dx.resmayalias module
+ // flag to 1, thereby disabling the ability to set the ResMayNotAlias flag
+ if (auto *ResMayAlias = mdconst::extract_or_null<ConstantInt>(
+ M.getModuleFlag("dx.resmayalias")))
+ if (ResMayAlias->getValue().getBoolValue())
+ CanSetResMayNotAlias = false;
----------------
bogner wrote:
Computing and setting this member variable inside the function like this is a bit of a surprising side effect. I think we should hoist the calculation of `CanSetResMayNotAlias` to its own thing and do it explicitly in `ModuleShaderFlags::initialize`
https://github.com/llvm/llvm-project/pull/139967
More information about the llvm-commits
mailing list