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

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Fri May 3 15:20:58 PDT 2024


================
@@ -1200,6 +1224,27 @@ 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") {
+    std::string DXILVerStr{"dxilv1."};
+    if (Components.size() > 2) {
+      // OS component specified
+      if (Components[2].starts_with("shadermodel6.")) {
+        Components[0] = DXILVerStr.append(
+            Components[2].drop_front(strlen("shadermodel6.")));
+      } else if (Components[2].starts_with("shadermodel")) {
+        // If shader model specified is other than 6.x, set DXIL Version to 1.0
+        Components[0] = DXILVerStr.append("0");
+      }
+    }
----------------
bogner wrote:

This doesn't look right. We've already parsed `Arch` and `OS` above, so I would expect this logic to look something like:
```c++
if (Arch == Triple::DXIL && SubArch == Triple::NoSubArch) {
  VersionTuple Ver = OS != Triple::UnknownOS ? parseVersionFromName(Components[2]) : VersionTuple();
  if (Ver)
    Components[0] = Components[0].append("1.").append(Ver.Minor);
  else (Ver)
    // default case...
}
```

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


More information about the cfe-commits mailing list