[llvm] [DXIL][Analysis] Collect Function properties in Metadata Analysis (PR #105728)

S. Bharadwaj Yadavalli via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 17:23:27 PDT 2024


================
@@ -33,6 +38,42 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
     MMDAI.ValidatorVersion =
         VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
   }
+
+  // For all HLSL Shader functions
+  for (auto &F : M.functions()) {
+    if (!F.hasFnAttribute("hlsl.shader"))
+      continue;
+
+    FunctionProperties EFP{};
+    // Get "hlsl.shader" attribute
+    Attribute EntryAttr = F.getFnAttribute("hlsl.shader");
+    StringRef EntryProfile = EntryAttr.getValueAsString();
+    Triple T("", "", "", EntryProfile);
+    EFP.ShaderStage = T.getEnvironment();
+    // Get numthreads attribute value, if one exists
+    StringRef NumThreadsStr =
+        F.getFnAttribute("hlsl.numthreads").getValueAsString();
+    if (!NumThreadsStr.empty()) {
+      SmallVector<StringRef> NumThreadsVec;
+      NumThreadsStr.split(NumThreadsVec, ',');
+      if (NumThreadsVec.size() != 3) {
+        report_fatal_error(Twine(F.getName()) +
+                               ": Invalid numthreads specified",
+                           /* gen_crash_diag */ false);
+      }
----------------
bharadwajy wrote:

> This should just be an assert - we expect the IR to be valid at this point. No need for `report_fatal_error` here.

Changed.

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


More information about the llvm-commits mailing list