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

S. Bharadwaj Yadavalli via cfe-commits cfe-commits at lists.llvm.org
Thu May 2 08:54:33 PDT 2024


================
@@ -115,6 +115,30 @@ StringRef Triple::getArchName(ArchType Kind, SubArchType SubArch) {
     if (SubArch == AArch64SubArch_arm64e)
       return "arm64e";
     break;
+  case Triple::dxil:
+    switch (SubArch) {
+    case Triple::NoSubArch:
+    case Triple::DXILSubArch_v1_0:
+      return "dxilv1.0";
+    case Triple::DXILSubArch_v1_1:
+      return "dxilv1.1";
+    case Triple::DXILSubArch_v1_2:
+      return "dxilv1.2";
+    case Triple::DXILSubArch_v1_3:
+      return "dxilv1.3";
+    case Triple::DXILSubArch_v1_4:
+      return "dxilv1.4";
+    case Triple::DXILSubArch_v1_5:
+      return "dxilv1.5";
+    case Triple::DXILSubArch_v1_6:
+      return "dxilv1.6";
+    case Triple::DXILSubArch_v1_7:
+      return "dxilv1.7";
+    case Triple::DXILSubArch_v1_8:
+      return "dxilv1.8";
+    default:
+      return "";
----------------
bharadwajy wrote:

> Would we want to llvm_unreachable or otherwise fail here, or does the caller handle this case well?

The `default` case would be true for a call such as `getArchName(Triple::dxil, Triple::<NonDXILSubArch>)`,
where `NonDXILSubArch` is something other than `DXILSubArch_v1_[0..8]` (e.g., `MipsSubArch_r6`).

I considered 3 options to handle this case:

1. Report failure / crash with a message indicating incorrect DXIL `SubArch`:  not chosen as such behavior is not consistent with other `SuArch`s as pointed out [here](https://github.com/llvm/llvm-project/pull/89823/files#r1581314588) in the feedback for PR #89823.
2. Fall through to return the value of `getArchTypeName(Kind)` where `Kind` is `Triple::dxil` to return the string "dxil": not chosen since "dxil" does **not** represent the `ArchTypeName` for the `Arch/SubArch` combination of `Triple::dxil/Triple::<NonDXILSubArch>` (e.g., `Triple::dxil//Triple::MipsSubArch_r6`) and returning "dxil" would indicate that it is a valid `ArchTypeName`.
3. Return null string (""): chosen to indicate that there is no valid `ArchTypeName` for the `Arch/SubArch` combination of `Triple::dxil/Triple::<NonDXILSubArch>`(e.g., `Triple::dxil/Triple::MipsSubArch_r6`). The consumer of the Triple checks for validity of Arch to issue an error for a non-viable empty architecture name as I think it is a cleaner option compared to either reporting a failure or asserting here.


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


More information about the cfe-commits mailing list