[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

Chris B via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 06:18:28 PDT 2024


================
@@ -1206,6 +1233,47 @@ std::string Triple::normalize(StringRef Str) {
     }
   }
 
+  // Normalize DXIL triple if it does not include DXIL version number.
+  // Determine DXIL version number using the minor version number of Shader
+  // Model version specified in target triple, if any. Prior to decoupling DXIL
+  // version numbering from that of Shader Model DXIL version 1.Y corresponds to
+  // SM 6.Y. E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
+  if (Components[0] == "dxil") {
+    if (Components.size() > 4) {
+      Components.resize(4);
+    }
+    // Add DXIL version only if shadermodel is specified in the triple
+    if (OS == Triple::ShaderModel) {
+      VersionTuple Ver =
+          parseVersionFromName(Components[2].drop_front(strlen("shadermodel")));
+      // Default DXIL minor version when Shader Model version is anything other
+      // than 6.[0...8] or 6.x (which translates to latest current SM version)
+      // DXIL version corresponding to Shader Model version other than 6.x
+      // is 1.0
+      unsigned DXILMinor = 0;
+      const unsigned SMMajor = 6;
+      const unsigned LatestCurrentDXILMinor = 8;
+      if (!Ver.empty()) {
+        if (Ver.getMajor() == SMMajor) {
+          if (std::optional<unsigned> SMMinor = Ver.getMinor()) {
+            DXILMinor = *SMMinor;
+            // Ensure specified minor version is supported
+            if (DXILMinor > LatestCurrentDXILMinor) {
+              report_fatal_error("Unsupported Shader Model version", false);
+            }
+          }
+        }
+      } else {
+        // Special case: DXIL minor version is set to LatestCurrentDXILMinor for
+        // shadermodel6.x is
+        if (Components[2] == "shadermodel6.x") {
+          DXILMinor = LatestCurrentDXILMinor;
+        }
+      }
+      Components[0] =
+          Components[0].str().append("v1.").append(std::to_string(DXILMinor));
----------------
llvm-beanz wrote:

@bharadwajy this is your asan failure. You’re setting a stringref to a locally modified string temporary.

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


More information about the llvm-commits mailing list