[llvm] [DirectX] Infrastructure to collect shader flags for each function (PR #112967)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 00:35:01 PST 2024


================
@@ -60,21 +62,54 @@ struct ComputedShaderFlags {
     return FeatureFlags;
   }
 
-  static ComputedShaderFlags computeFlags(Module &M);
+  uint64_t getModuleFlags() const {
+    uint64_t ModuleFlags = 0;
+#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str)                         \
+  ModuleFlags |= FlagName ? getMask(DxilModuleBit) : 0ull;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+    return ModuleFlags;
+  }
+
+  void merge(const uint64_t IVal) {
+#define SHADER_FEATURE_FLAG(FeatureBit, DxilModuleBit, FlagName, Str)          \
+  FlagName |= (IVal & getMask(DxilModuleBit));
+#define DXIL_MODULE_FLAG(DxilModuleBit, FlagName, Str)                         \
+  FlagName |= (IVal & getMask(DxilModuleBit));
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+    return;
+  }
+
   void print(raw_ostream &OS = dbgs()) const;
   LLVM_DUMP_METHOD void dump() const { print(); }
 };
 
+struct DXILModuleShaderFlagsInfo {
+  DXILModuleShaderFlagsInfo(const Module &);
+  Expected<const ComputedShaderFlags &>
+  getShaderFlagsMask(const Function *) const;
+  const ComputedShaderFlags getCombinedFlags() const;
----------------
bogner wrote:

A few things here:
1. `getShaderFlagsMask` should just return a `const ComputedShaderFlags &`, not an expected. The only way for this to fail if the analysis is in a valid state is if we call this with a function that isn't in the module somehow.
2. `getCombinedFlags` should also return a reference - no need for a copy here.
3. These names are inconsistent (FlagsMask vs Flags) even though they return the same type of thing. Maybe we should simplify a little and call them `getFunctionFlags` and `getCombinedFlags`

https://github.com/llvm/llvm-project/pull/112967


More information about the llvm-commits mailing list