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

S. Bharadwaj Yadavalli via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 19:06:55 PDT 2024


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

>From 04400db2d84e46adea7e1bc12755fb74a62c228c Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Wed, 21 Aug 2024 15:35:17 -0400
Subject: [PATCH 1/7] [DXIL][Analysis] Infrastructure to collect Function
 properties in Metadata Analysis - Add a map of function-function properties
 to the metadata information. - Add a structure to represent various function
 properties. Currently   numthreads property of a compute shader entry
 function is represented.

---
 .../llvm/Analysis/DXILMetadataAnalysis.h      |  7 ++-
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp    | 50 +++++++++++++++++++
 .../CodeGen/DirectX/Metadata/dxilVer-1.8.ll   |  2 +
 .../Metadata/shaderModel-cs-val-ver-0.0.ll    |  4 +-
 .../DirectX/Metadata/shaderModel-cs.ll        |  2 +
 5 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 0515139c01aee6..6195ac08b0e99c 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_ANALYSIS_DXILMETADATA_H
 #define LLVM_ANALYSIS_DXILMETADATA_H
 
+#include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/VersionTuple.h"
@@ -19,12 +20,16 @@ namespace llvm {
 
 namespace dxil {
 
+struct FunctionProperties {
+  unsigned NumThreads[3];
+};
+
 struct ModuleMetadataInfo {
   VersionTuple DXILVersion{};
   VersionTuple ShaderModelVersion{};
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
   VersionTuple ValidatorVersion{};
-
+  std::unordered_map<Function *, FunctionProperties> FunctionPropertyMap{};
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 192e151565370d..39bd750d69649b 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -8,11 +8,16 @@
 
 #include "llvm/Analysis/DXILMetadataAnalysis.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <memory>
+#include <utility>
 
 #define DEBUG_TYPE "dxil-metadata-analysis"
 
@@ -33,6 +38,37 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
     MMDAI.ValidatorVersion =
         VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
   }
+
+  if (MMDAI.ShaderStage == Triple::EnvironmentType::Compute) {
+    // For all HLSL Shader functions
+    for (auto &F : M.functions()) {
+      if (!F.hasFnAttribute("hlsl.shader"))
+        continue;
+
+      // Get numthreads attribute value
+      StringRef NumThreadsStr =
+          F.getFnAttribute("hlsl.numthreads").getValueAsString();
+      SmallVector<StringRef> NumThreadsVec;
+      NumThreadsStr.split(NumThreadsVec, ',');
+      if (NumThreadsVec.size() != 3) {
+        report_fatal_error(Twine(F.getName()) +
+                               ": Invalid numthreads specified",
+                           /* gen_crash_diag */ false);
+      }
+      FunctionProperties EFP;
+      auto Zip =
+          llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
+      for (auto It : Zip) {
+        StringRef Str = std::get<0>(It);
+        APInt V;
+        assert(!Str.getAsInteger(10, V) &&
+               "Failed to parse numthreads components as integer values");
+        unsigned &Num = std::get<1>(It);
+        Num = V.getLimitedValue();
+      }
+      MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP));
+    }
+  }
   return MMDAI;
 }
 
@@ -42,6 +78,20 @@ void ModuleMetadataInfo::print(raw_ostream &OS) const {
   OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
      << "\n";
   OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
+  for (auto MapItem : FunctionPropertyMap) {
+    MapItem.first->getReturnType()->print(OS, false, true);
+    OS << " " << MapItem.first->getName() << "(";
+    FunctionType *FT = MapItem.first->getFunctionType();
+    for (unsigned I = 0, Sz = FT->getNumParams(); I < Sz; ++I) {
+      if (I)
+        OS << ",";
+      FT->getParamType(I)->print(OS);
+    }
+    OS << ")\n";
+    OS << "  NumThreads: " << MapItem.second.NumThreads[0] << ","
+       << MapItem.second.NumThreads[1] << "," << MapItem.second.NumThreads[2]
+       << "\n";
+  }
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
index 53edcde24b189f..d429b6534e4253 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6.8-compute"
 ; ANALYSIS-NEXT: DXIL Version : 1.8
 ; ANALYSIS-NEXT: Shader Stage : compute
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: NumThreads: 1,2,1
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
index c9ea6c94e36519..b7e6d2fd3cf432 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
@@ -19,5 +19,7 @@ attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1"
 ; ANALYSIS: Shader Model Version : 6.6
 ; ANALYSIS-NEXT: DXIL Version : 1.6
 ; ANALYSIS-NEXT: Shader Stage : compute
-; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: Validator Version : 0.0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT:   NumThreads: 1,2,1
 ; ANALYSIS-EMPTY:
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
index f5e524562ac1e0..77b52ee3478abe 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
@@ -11,6 +11,8 @@ target triple = "dxil-pc-shadermodel6.6-compute"
 ; ANALYSIS-NEXT: DXIL Version : 1.6
 ; ANALYSIS-NEXT: Shader Stage : compute
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT:   NumThreads: 1,2,1
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {

>From 92ffbbb63c1d5599cf7b696c270c49654270ed09 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Tue, 27 Aug 2024 17:58:58 -0400
Subject: [PATCH 2/7] Improvements to entry function information collected in
 Metadata Analysis Pass - Record shader kind specified for entry function from
 hlsl.shader attribute - Record all entry functions irrespective of the target
 shader profile being compute - Update expected output of tests accordingly

---
 .../llvm/Analysis/DXILMetadataAnalysis.h      |  2 +
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp    | 45 ++++++++++---------
 .../CodeGen/DirectX/Metadata/dxilVer-1.0.ll   |  2 +
 .../DirectX/Metadata/shaderModel-as.ll        |  2 +
 .../DirectX/Metadata/shaderModel-gs.ll        |  2 +
 .../DirectX/Metadata/shaderModel-hs.ll        |  2 +
 .../DirectX/Metadata/shaderModel-ms.ll        |  2 +
 .../DirectX/Metadata/shaderModel-ps.ll        |  2 +
 .../DirectX/Metadata/shaderModel-vs.ll        |  2 +
 9 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 6195ac08b0e99c..2277f0153f7fca 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -21,6 +21,8 @@ namespace llvm {
 namespace dxil {
 
 struct FunctionProperties {
+  // Specific target shader stage may be specified for entry functions
+  Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
   unsigned NumThreads[3];
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 39bd750d69649b..9d8fa2fa482e3a 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -39,36 +39,41 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
         VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
   }
 
-  if (MMDAI.ShaderStage == Triple::EnvironmentType::Compute) {
     // For all HLSL Shader functions
     for (auto &F : M.functions()) {
       if (!F.hasFnAttribute("hlsl.shader"))
         continue;
 
-      // Get numthreads attribute value
+      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();
-      SmallVector<StringRef> NumThreadsVec;
-      NumThreadsStr.split(NumThreadsVec, ',');
-      if (NumThreadsVec.size() != 3) {
-        report_fatal_error(Twine(F.getName()) +
-                               ": Invalid numthreads specified",
-                           /* gen_crash_diag */ false);
-      }
-      FunctionProperties EFP;
-      auto Zip =
-          llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
-      for (auto It : Zip) {
-        StringRef Str = std::get<0>(It);
-        APInt V;
-        assert(!Str.getAsInteger(10, V) &&
-               "Failed to parse numthreads components as integer values");
-        unsigned &Num = std::get<1>(It);
-        Num = V.getLimitedValue();
+      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);
+        }
+        auto Zip =
+            llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
+        for (auto It : Zip) {
+          StringRef Str = std::get<0>(It);
+          APInt V;
+          assert(!Str.getAsInteger(10, V) &&
+                 "Failed to parse numthreads components as integer values");
+          unsigned &Num = std::get<1>(It);
+          Num = V.getLimitedValue();
+        }
       }
       MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP));
     }
-  }
   return MMDAI;
 }
 
diff --git a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
index 30797945e8e56c..fc076d675e994a 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6.0-vertex"
 ; ANALYSIS-NEXT: DXIL Version : 1.0
 ; ANALYSIS-NEXT: Shader Stage : vertex
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
index 49c820e14e36b4..618079af215396 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6-amplification"
 ; ANALYSIS-NEXT: DXIL Version : 1.0
 ; ANALYSIS-NEXT: Shader Stage : amplification
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
index fb58312e2c9310..22df8350ed4ad0 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6.6-geometry"
 ; ANALYSIS-NEXT: DXIL Version : 1.6
 ; ANALYSIS-NEXT: Shader Stage : geometry
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
index b12de400698fe1..5237094931b51a 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6.6-hull"
 ; ANALYSIS-NEXT: DXIL Version : 1.6
 ; ANALYSIS-NEXT: Shader Stage : hull
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
index e22dbbcebf5849..d8f4cc578227cc 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel6.6-mesh"
 ; ANALYSIS-NEXT: DXIL Version : 1.6
 ; ANALYSIS-NEXT: Shader Stage : mesh
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
index eb784d71517bba..20ec0b01df6d4c 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel5.0-pixel"
 ; ANALYSIS-NEXT: DXIL Version : 1.0
 ; ANALYSIS-NEXT: Shader Stage : pixel
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
index ac52b5004eb906..e4f32775e28cbb 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
@@ -9,6 +9,8 @@ target triple = "dxil-pc-shadermodel-vertex"
 ; ANALYSIS-NEXT: DXIL Version : 1.0
 ; ANALYSIS-NEXT: Shader Stage : vertex
 ; ANALYSIS-NEXT: Validator Version : 0
+; ANALYSIS-NEXT: void entry()
+; ANALYSIS-NEXT: 0,0,0
 ; ANALYSIS-EMPTY:
 
 define void @entry() #0 {

>From c067683a47d66117ac321813e365433b38d941a0 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Tue, 27 Aug 2024 18:11:29 -0400
Subject: [PATCH 3/7] clang-format

---
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp | 66 +++++++++++-----------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 9d8fa2fa482e3a..7577097f751275 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -39,41 +39,41 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
         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);
-        }
-        auto Zip =
-            llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
-        for (auto It : Zip) {
-          StringRef Str = std::get<0>(It);
-          APInt V;
-          assert(!Str.getAsInteger(10, V) &&
-                 "Failed to parse numthreads components as integer values");
-          unsigned &Num = std::get<1>(It);
-          Num = V.getLimitedValue();
-        }
+  // 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);
+      }
+      auto Zip =
+          llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
+      for (auto It : Zip) {
+        StringRef Str = std::get<0>(It);
+        APInt V;
+        assert(!Str.getAsInteger(10, V) &&
+               "Failed to parse numthreads components as integer values");
+        unsigned &Num = std::get<1>(It);
+        Num = V.getLimitedValue();
       }
-      MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP));
     }
+    MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP));
+  }
   return MMDAI;
 }
 

>From ccb97ccde0222cc0b3d60ff4f53bca00c3e1ab3f Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Wed, 28 Aug 2024 14:01:22 -0400
Subject: [PATCH 4/7] Address PR feedback

Move testing of DXILMetadata Analysis to
llvm/test/Analysis/DXILMetadataAnalysis from
llvm/test/CodeGen/DirectX/Metadata and add a new test
---
 .../llvm/Analysis/DXILMetadataAnalysis.h      |  9 ++--
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp    | 51 ++++++++-----------
 .../DXILMetadataAnalysis/dxilVer-1.0.ll       | 18 +++++++
 .../DXILMetadataAnalysis/dxilVer-1.8.ll       | 18 +++++++
 .../DXILMetadataAnalysis/entry-properties.ll  | 36 +++++++++++++
 .../DXILMetadataAnalysis/shaderModel-as.ll    | 18 +++++++
 .../shaderModel-cs-val-ver-0.0.ll             | 23 +++++++++
 .../DXILMetadataAnalysis/shaderModel-cs.ll    | 19 +++++++
 .../DXILMetadataAnalysis/shaderModel-gs.ll    | 18 +++++++
 .../DXILMetadataAnalysis/shaderModel-hs.ll    | 18 +++++++
 .../DXILMetadataAnalysis/shaderModel-ms.ll    | 18 +++++++
 .../DXILMetadataAnalysis/shaderModel-ps.ll    | 18 +++++++
 .../DXILMetadataAnalysis/shaderModel-vs.ll    | 18 +++++++
 .../CodeGen/DirectX/Metadata/dxilVer-1.0.ll   |  9 ----
 .../CodeGen/DirectX/Metadata/dxilVer-1.8.ll   |  9 ----
 .../DirectX/Metadata/shaderModel-as.ll        |  9 ----
 .../Metadata/shaderModel-cs-val-ver-0.0.ll    |  9 ----
 .../DirectX/Metadata/shaderModel-cs.ll        |  9 ----
 .../DirectX/Metadata/shaderModel-gs.ll        |  9 ----
 .../DirectX/Metadata/shaderModel-hs.ll        |  9 ----
 .../DirectX/Metadata/shaderModel-lib.ll       |  6 ---
 .../DirectX/Metadata/shaderModel-ms.ll        |  9 ----
 .../DirectX/Metadata/shaderModel-ps.ll        |  9 ----
 .../DirectX/Metadata/shaderModel-vs.ll        |  9 ----
 24 files changed, 248 insertions(+), 130 deletions(-)
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.0.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.8.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/entry-properties.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-as.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs-val-ver-0.0.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-gs.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-hs.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ms.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ps.ll
 create mode 100644 llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-vs.ll

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 2277f0153f7fca..30a83f5acebc1b 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_ANALYSIS_DXILMETADATA_H
 #define LLVM_ANALYSIS_DXILMETADATA_H
 
+#include "llvm/ADT/MapVector.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
@@ -20,10 +21,12 @@ namespace llvm {
 
 namespace dxil {
 
-struct FunctionProperties {
+struct EntryProperties {
   // Specific target shader stage may be specified for entry functions
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
-  unsigned NumThreads[3];
+  unsigned NumThreadsX; // X component
+  unsigned NumThreadsY; // Y component
+  unsigned NumThreadsZ; // Z component
 };
 
 struct ModuleMetadataInfo {
@@ -31,7 +34,7 @@ struct ModuleMetadataInfo {
   VersionTuple ShaderModelVersion{};
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
   VersionTuple ValidatorVersion{};
-  std::unordered_map<Function *, FunctionProperties> FunctionPropertyMap{};
+  MapVector<Function *, EntryProperties> EntryPropertyMap;
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 7577097f751275..111efe43f7b0f5 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -8,9 +8,9 @@
 
 #include "llvm/Analysis/DXILMetadataAnalysis.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/Constants.h"
-#include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
@@ -44,9 +44,11 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
     if (!F.hasFnAttribute("hlsl.shader"))
       continue;
 
-    FunctionProperties EFP{};
+    EntryProperties EFP{};
     // Get "hlsl.shader" attribute
     Attribute EntryAttr = F.getFnAttribute("hlsl.shader");
+    assert(EntryAttr.isValid() &&
+           "Invalid value specified for HLSL function attribute hlsl.shader");
     StringRef EntryProfile = EntryAttr.getValueAsString();
     Triple T("", "", "", EntryProfile);
     EFP.ShaderStage = T.getEnvironment();
@@ -56,23 +58,16 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
     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);
-      }
-      auto Zip =
-          llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads));
-      for (auto It : Zip) {
-        StringRef Str = std::get<0>(It);
-        APInt V;
-        assert(!Str.getAsInteger(10, V) &&
-               "Failed to parse numthreads components as integer values");
-        unsigned &Num = std::get<1>(It);
-        Num = V.getLimitedValue();
-      }
+      assert(NumThreadsVec.size() == 3 && "Invalid numthreads specified");
+      // Read in the three component values of numthreads
+      if (!llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10))
+        assert(false && "Failed to parse X component of numthreads");
+      if (!llvm::to_integer(NumThreadsVec[1], EFP.NumThreadsY, 10))
+        assert(false && "Failed to parse Y component of numthreads");
+      if (!llvm::to_integer(NumThreadsVec[2], EFP.NumThreadsZ, 10))
+        assert(false && "Failed to parse Z component of numthreads");
     }
-    MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP));
+    MMDAI.EntryPropertyMap.insert(std::make_pair(std::addressof(F), EFP));
   }
   return MMDAI;
 }
@@ -80,21 +75,15 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
 void ModuleMetadataInfo::print(raw_ostream &OS) const {
   OS << "Shader Model Version : " << ShaderModelVersion.getAsString() << "\n";
   OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
-  OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
+  OS << "Target Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
      << "\n";
   OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
-  for (auto MapItem : FunctionPropertyMap) {
-    MapItem.first->getReturnType()->print(OS, false, true);
-    OS << " " << MapItem.first->getName() << "(";
-    FunctionType *FT = MapItem.first->getFunctionType();
-    for (unsigned I = 0, Sz = FT->getNumParams(); I < Sz; ++I) {
-      if (I)
-        OS << ",";
-      FT->getParamType(I)->print(OS);
-    }
-    OS << ")\n";
-    OS << "  NumThreads: " << MapItem.second.NumThreads[0] << ","
-       << MapItem.second.NumThreads[1] << "," << MapItem.second.NumThreads[2]
+  for (auto MapItem : EntryPropertyMap) {
+    OS << " " << MapItem.first->getName() << "\n";
+    OS << "  Function Shader Stage : "
+       << Triple::getEnvironmentTypeName(MapItem.second.ShaderStage) << "\n";
+    OS << "  NumThreads: " << MapItem.second.NumThreadsX << ","
+       << MapItem.second.NumThreadsY << "," << MapItem.second.NumThreadsZ
        << "\n";
   }
 }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.0.ll b/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.0.ll
new file mode 100644
index 00000000000000..75c05d86dc7818
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.0.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.0-vertex"
+
+; CHECK: Shader Model Version : 6.0
+; CHECK-NEXT: DXIL Version : 1.0
+; CHECK-NEXT: Shader Stage : vertex
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:   Function Shader Stage : vertex
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="vertex" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.8.ll b/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.8.ll
new file mode 100644
index 00000000000000..7a2cb51f9c819f
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/dxilVer-1.8.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.8-compute"
+
+; CHECK: Shader Model Version : 6.8
+; CHECK-NEXT: DXIL Version : 1.8
+; CHECK-NEXT: Shader Stage : compute
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:   Function Shader Stage : compute
+; CHECK-NEXT: NumThreads: 1,2,1
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.numthreads"="1,2,1" "hlsl.shader"="compute" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/entry-properties.ll b/llvm/test/Analysis/DXILMetadataAnalysis/entry-properties.ll
new file mode 100644
index 00000000000000..a2c6c3a7952d41
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/entry-properties.ll
@@ -0,0 +1,36 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.8-library"
+
+; CHECK: Shader Model Version : 6.8
+; CHECK-NEXT: DXIL Version : 1.8
+; CHECK-NEXT: Target Shader Stage : library
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry_as
+; CHECK-NEXT:   Function Shader Stage : amplification
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-NEXT: entry_ms
+; CHECK-NEXT:   Function Shader Stage : mesh
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-NEXT: entry_cs
+; CHECK-NEXT:   Function Shader Stage : compute
+; CHECK-NEXT:   NumThreads: 1,2,1
+; CHECK-EMPTY:
+
+define void @entry_as() #0 {
+entry:
+  ret void
+}
+
+define i32 @entry_ms(i32 %a) #1 {
+entry:
+  ret i32 %a
+}
+
+define float @entry_cs(float %f) #3 {
+entry:
+  ret float %f
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="amplification" }
+attributes #1 = { noinline nounwind "hlsl.shader"="mesh" }
+attributes #3 = { noinline nounwind "hlsl.numthreads"="1,2,1" "hlsl.shader"="compute" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-as.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-as.ll
new file mode 100644
index 00000000000000..6a8496bf731a3b
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-as.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6-amplification"
+
+; CHECK: Shader Model Version : 6
+; CHECK-NEXT: DXIL Version : 1.0
+; CHECK-NEXT: Target Shader Stage : amplification
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : amplification
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="amplification" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs-val-ver-0.0.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs-val-ver-0.0.ll
new file mode 100644
index 00000000000000..e09f4fc4114338
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs-val-ver-0.0.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="compute" }
+
+!dx.valver = !{!0}
+
+!0 = !{i32 0, i32 0}
+
+; CHECK: Shader Model Version : 6.6
+; CHECK-NEXT: DXIL Version : 1.6
+; CHECK-NEXT: Target Shader Stage : compute
+; CHECK-NEXT: Validator Version : 0.0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : compute
+; CHECK-NEXT:   NumThreads: 1,2,1
+; CHECK-EMPTY:
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs.ll
new file mode 100644
index 00000000000000..4d6d696e6b29e4
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-cs.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+; CHECK: Shader Model Version : 6.6
+; CHECK-NEXT: DXIL Version : 1.6
+; CHECK-NEXT: Target Shader Stage : compute
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : compute
+; CHECK-NEXT:   NumThreads: 1,2,1
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="compute" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-gs.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-gs.ll
new file mode 100644
index 00000000000000..e28438901bdfe1
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-gs.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-geometry"
+
+; CHECK: Shader Model Version : 6.6
+; CHECK-NEXT: DXIL Version : 1.6
+; CHECK-NEXT: Shader Stage : geometry
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : geometry
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="geometry" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-hs.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-hs.ll
new file mode 100644
index 00000000000000..fdec1d857118b8
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-hs.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-hull"
+
+; CHECK: Shader Model Version : 6.6
+; CHECK-NEXT: DXIL Version : 1.6
+; CHECK-NEXT: Target Shader Stage : hull
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : hull
+; CHECK-NEXT:  NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="hull" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ms.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ms.ll
new file mode 100644
index 00000000000000..77bc3bbd85f9f2
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ms.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel6.6-mesh"
+
+; CHECK: Shader Model Version : 6.6
+; CHECK-NEXT: DXIL Version : 1.6
+; CHECK-NEXT: Shader Stage : mesh
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : mesh
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="mesh" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ps.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ps.ll
new file mode 100644
index 00000000000000..a02c56dbe17a21
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-ps.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel5.0-pixel"
+
+; CHECK: Shader Model Version : 5.0
+; CHECK-NEXT: DXIL Version : 1.0
+; CHECK-NEXT: Shader Stage : pixel
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : pixel
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="pixel" }
diff --git a/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-vs.ll b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-vs.ll
new file mode 100644
index 00000000000000..107f9fc1f0a24a
--- /dev/null
+++ b/llvm/test/Analysis/DXILMetadataAnalysis/shaderModel-vs.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s
+target triple = "dxil-pc-shadermodel-vertex"
+
+; CHECK: Shader Model Version : 0
+; CHECK-NEXT: DXIL Version : 1.0
+; CHECK-NEXT: Shader Stage : vertex
+; CHECK-NEXT: Validator Version : 0
+; CHECK-NEXT: entry
+; CHECK-NEXT:  Function Shader Stage : vertex
+; CHECK-NEXT:   NumThreads: 0,0,0
+; CHECK-EMPTY:
+
+define void @entry() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="vertex" }
diff --git a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
index fc076d675e994a..3c54d9a8cf576b 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -passes=dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.0-vertex"
 
 ; CHECK: !dx.version = !{![[DXVER:[0-9]+]]}
 ; CHECK: ![[DXVER]] = !{i32 1, i32 0}
 
-; ANALYSIS: Shader Model Version : 6.0
-; ANALYSIS-NEXT: DXIL Version : 1.0
-; ANALYSIS-NEXT: Shader Stage : vertex
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
index d429b6534e4253..9ed0f90fb38d01 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -passes=dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.8-compute"
 
 ; CHECK: !dx.version = !{![[DXVER:[0-9]+]]}
 ; CHECK: ![[DXVER]] = !{i32 1, i32 8}
 
-; ANALYSIS: Shader Model Version : 6.8
-; ANALYSIS-NEXT: DXIL Version : 1.8
-; ANALYSIS-NEXT: Shader Stage : compute
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: NumThreads: 1,2,1
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
index 618079af215396..4db160edb45af1 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6-amplification"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"as", i32 6, i32 0}
 
-; ANALYSIS: Shader Model Version : 6
-; ANALYSIS-NEXT: DXIL Version : 1.0
-; ANALYSIS-NEXT: Shader Stage : amplification
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
index b7e6d2fd3cf432..d674ef3693497e 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll
@@ -1,5 +1,4 @@
 ; RUN: opt -S -dxil-prepare  %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 
 target triple = "dxil-pc-shadermodel6.6-compute"
 
@@ -15,11 +14,3 @@ attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1"
 !dx.valver = !{!0}
 
 !0 = !{i32 0, i32 0}
-
-; ANALYSIS: Shader Model Version : 6.6
-; ANALYSIS-NEXT: DXIL Version : 1.6
-; ANALYSIS-NEXT: Shader Stage : compute
-; ANALYSIS-NEXT: Validator Version : 0.0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT:   NumThreads: 1,2,1
-; ANALYSIS-EMPTY:
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
index 77b52ee3478abe..d055a7435613df 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
@@ -1,20 +1,11 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
 ; RUN: opt -S -dxil-prepare  %s | FileCheck %s  --check-prefix=REMOVE_EXTRA_ATTRIBUTE
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 
 target triple = "dxil-pc-shadermodel6.6-compute"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"cs", i32 6, i32 6}
 
-; ANALYSIS: Shader Model Version : 6.6
-; ANALYSIS-NEXT: DXIL Version : 1.6
-; ANALYSIS-NEXT: Shader Stage : compute
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT:   NumThreads: 1,2,1
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
index 22df8350ed4ad0..6d48826c693bed 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.6-geometry"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"gs", i32 6, i32 6}
 
-; ANALYSIS: Shader Model Version : 6.6
-; ANALYSIS-NEXT: DXIL Version : 1.6
-; ANALYSIS-NEXT: Shader Stage : geometry
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
index 5237094931b51a..cc15460c0bed37 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.6-hull"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"hs", i32 6, i32 6}
 
-; ANALYSIS: Shader Model Version : 6.6
-; ANALYSIS-NEXT: DXIL Version : 1.6
-; ANALYSIS-NEXT: Shader Stage : hull
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll
index d4aa4cfa0ce471..0e8cc4f6504dbc 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll
@@ -1,12 +1,6 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.3-library"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"lib", i32 6, i32 3}
 
-; ANALYSIS: Shader Model Version : 6.3
-; ANALYSIS-NEXT: DXIL Version : 1.3
-; ANALYSIS-NEXT: Shader Stage : library
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-EMPTY:
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
index d8f4cc578227cc..dfab52654eb3f2 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel6.6-mesh"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"ms", i32 6, i32 6}
 
-; ANALYSIS: Shader Model Version : 6.6
-; ANALYSIS-NEXT: DXIL Version : 1.6
-; ANALYSIS-NEXT: Shader Stage : mesh
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
index 20ec0b01df6d4c..71a73f8deb24d7 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel5.0-pixel"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"ps", i32 5, i32 0}
 
-; ANALYSIS: Shader Model Version : 5.0
-; ANALYSIS-NEXT: DXIL Version : 1.0
-; ANALYSIS-NEXT: Shader Stage : pixel
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void
diff --git a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
index e4f32775e28cbb..4bb31b0147379b 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
@@ -1,18 +1,9 @@
 ; RUN: opt -S -dxil-translate-metadata %s | FileCheck %s
-; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
 target triple = "dxil-pc-shadermodel-vertex"
 
 ; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
 ; CHECK: ![[SM]] = !{!"vs", i32 0, i32 0}
 
-; ANALYSIS: Shader Model Version : 0
-; ANALYSIS-NEXT: DXIL Version : 1.0
-; ANALYSIS-NEXT: Shader Stage : vertex
-; ANALYSIS-NEXT: Validator Version : 0
-; ANALYSIS-NEXT: void entry()
-; ANALYSIS-NEXT: 0,0,0
-; ANALYSIS-EMPTY:
-
 define void @entry() #0 {
 entry:
   ret void

>From b3a53622220950460ce2d626f9e212c30a3e8d49 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Fri, 30 Aug 2024 17:48:25 -0400
Subject: [PATCH 5/7] Address latest PR feedback

Collect Entry properties in a SmallVector instead of in a Mapvector.

Use structured binding declaration for printing analysis info.
---
 .../llvm/Analysis/DXILMetadataAnalysis.h      | 13 ++++++----
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp    | 26 +++++++++----------
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 30a83f5acebc1b..50468b590e56eb 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_ANALYSIS_DXILMETADATA_H
 #define LLVM_ANALYSIS_DXILMETADATA_H
 
-#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
@@ -22,11 +22,14 @@ namespace llvm {
 namespace dxil {
 
 struct EntryProperties {
+  const Function *Entry;
   // Specific target shader stage may be specified for entry functions
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
-  unsigned NumThreadsX; // X component
-  unsigned NumThreadsY; // Y component
-  unsigned NumThreadsZ; // Z component
+  unsigned NumThreadsX{0}; // X component
+  unsigned NumThreadsY{0}; // Y component
+  unsigned NumThreadsZ{0}; // Z component
+
+  EntryProperties(const Function &Fn) : Entry(&Fn){};
 };
 
 struct ModuleMetadataInfo {
@@ -34,7 +37,7 @@ struct ModuleMetadataInfo {
   VersionTuple ShaderModelVersion{};
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
   VersionTuple ValidatorVersion{};
-  MapVector<Function *, EntryProperties> EntryPropertyMap;
+  SmallVector<EntryProperties, 4> EntryPropertyVec{};
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 111efe43f7b0f5..0500385b7f772f 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -44,7 +44,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
     if (!F.hasFnAttribute("hlsl.shader"))
       continue;
 
-    EntryProperties EFP{};
+    EntryProperties EFP(F);
     // Get "hlsl.shader" attribute
     Attribute EntryAttr = F.getFnAttribute("hlsl.shader");
     assert(EntryAttr.isValid() &&
@@ -60,14 +60,14 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
       NumThreadsStr.split(NumThreadsVec, ',');
       assert(NumThreadsVec.size() == 3 && "Invalid numthreads specified");
       // Read in the three component values of numthreads
-      if (!llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10))
-        assert(false && "Failed to parse X component of numthreads");
-      if (!llvm::to_integer(NumThreadsVec[1], EFP.NumThreadsY, 10))
-        assert(false && "Failed to parse Y component of numthreads");
-      if (!llvm::to_integer(NumThreadsVec[2], EFP.NumThreadsZ, 10))
-        assert(false && "Failed to parse Z component of numthreads");
+      bool Success = llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10);
+      assert(Success && "Failed to parse X component of numthreads");
+      Success = llvm::to_integer(NumThreadsVec[1], EFP.NumThreadsY, 10);
+      assert(Success && "Failed to parse Y component of numthreads");
+      Success = llvm::to_integer(NumThreadsVec[2], EFP.NumThreadsZ, 10);
+      assert(Success && "Failed to parse Z component of numthreads");
     }
-    MMDAI.EntryPropertyMap.insert(std::make_pair(std::addressof(F), EFP));
+    MMDAI.EntryPropertyVec.push_back(EFP);
   }
   return MMDAI;
 }
@@ -78,13 +78,11 @@ void ModuleMetadataInfo::print(raw_ostream &OS) const {
   OS << "Target Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
      << "\n";
   OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
-  for (auto MapItem : EntryPropertyMap) {
-    OS << " " << MapItem.first->getName() << "\n";
-    OS << "  Function Shader Stage : "
-       << Triple::getEnvironmentTypeName(MapItem.second.ShaderStage) << "\n";
-    OS << "  NumThreads: " << MapItem.second.NumThreadsX << ","
-       << MapItem.second.NumThreadsY << "," << MapItem.second.NumThreadsZ
+  for (const auto [Ent, SS, NX, NY, NZ] : EntryPropertyVec) {
+    OS << " " << Ent->getName() << "\n";
+    OS << "  Function Shader Stage : " << Triple::getEnvironmentTypeName(SS)
        << "\n";
+    OS << "  NumThreads: " << NX << "," << NY << "," << NZ << "\n";
   }
 }
 

>From 93b26bcbbdff253d7593b3d720782fb32041ac06 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Fri, 30 Aug 2024 21:11:11 -0400
Subject: [PATCH 6/7] A few more changes from PR feedback.

---
 .../include/llvm/Analysis/DXILMetadataAnalysis.h |  5 ++---
 llvm/lib/Analysis/DXILMetadataAnalysis.cpp       | 16 ++++++++--------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 50468b590e56eb..1cc2552b99dfec 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -10,15 +10,14 @@
 #define LLVM_ANALYSIS_DXILMETADATA_H
 
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/Triple.h"
-#include <memory>
 
 namespace llvm {
 
+class Function;
 namespace dxil {
 
 struct EntryProperties {
@@ -37,7 +36,7 @@ struct ModuleMetadataInfo {
   VersionTuple ShaderModelVersion{};
   Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
   VersionTuple ValidatorVersion{};
-  SmallVector<EntryProperties, 4> EntryPropertyVec{};
+  SmallVector<EntryProperties> EntryPropertyVec{};
   void print(raw_ostream &OS) const;
 };
 
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 0500385b7f772f..2516af78670e25 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -16,8 +16,6 @@
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/ErrorHandling.h"
-#include <memory>
-#include <utility>
 
 #define DEBUG_TYPE "dxil-metadata-analysis"
 
@@ -60,7 +58,8 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
       NumThreadsStr.split(NumThreadsVec, ',');
       assert(NumThreadsVec.size() == 3 && "Invalid numthreads specified");
       // Read in the three component values of numthreads
-      bool Success = llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10);
+      [[maybe_unused]] bool Success =
+          llvm::to_integer(NumThreadsVec[0], EFP.NumThreadsX, 10);
       assert(Success && "Failed to parse X component of numthreads");
       Success = llvm::to_integer(NumThreadsVec[1], EFP.NumThreadsY, 10);
       assert(Success && "Failed to parse Y component of numthreads");
@@ -78,11 +77,12 @@ void ModuleMetadataInfo::print(raw_ostream &OS) const {
   OS << "Target Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
      << "\n";
   OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
-  for (const auto [Ent, SS, NX, NY, NZ] : EntryPropertyVec) {
-    OS << " " << Ent->getName() << "\n";
-    OS << "  Function Shader Stage : " << Triple::getEnvironmentTypeName(SS)
-       << "\n";
-    OS << "  NumThreads: " << NX << "," << NY << "," << NZ << "\n";
+  for (const auto EP : EntryPropertyVec) {
+    OS << " " << EP.Entry->getName() << "\n";
+    OS << "  Function Shader Stage : "
+       << Triple::getEnvironmentTypeName(EP.ShaderStage) << "\n";
+    OS << "  NumThreads: " << EP.NumThreadsX << "," << EP.NumThreadsY << ","
+       << EP.NumThreadsZ << "\n";
   }
 }
 

>From b54693a4e38e0c856025d0fd78329bbdbd0c0147 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli <Bharadwaj.Yadavalli at microsoft.com>
Date: Fri, 30 Aug 2024 21:44:03 -0400
Subject: [PATCH 7/7] clang-format change

---
 llvm/include/llvm/Analysis/DXILMetadataAnalysis.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index 1cc2552b99dfec..ed342c28b2d78b 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -28,7 +28,7 @@ struct EntryProperties {
   unsigned NumThreadsY{0}; // Y component
   unsigned NumThreadsZ{0}; // Z component
 
-  EntryProperties(const Function &Fn) : Entry(&Fn){};
+  EntryProperties(const Function &Fn) : Entry(&Fn) {};
 };
 
 struct ModuleMetadataInfo {



More information about the llvm-commits mailing list