[llvm] [NVPTX] Load/Store/Fence syncscope support (PR #106101)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 14:08:30 PDT 2024


================
@@ -233,46 +233,68 @@ void NVPTXInstPrinter::printLdStCode(const MCInst *MI, int OpNum,
       auto Ordering = NVPTX::Ordering(Imm);
       switch (Ordering) {
       case NVPTX::Ordering::NotAtomic:
-        break;
-      case NVPTX::Ordering::Volatile:
-        O << ".volatile";
-        break;
+        return;
       case NVPTX::Ordering::Relaxed:
-        O << ".relaxed.sys";
-        break;
+        O << ".relaxed";
+        return;
       case NVPTX::Ordering::Acquire:
-        O << ".acquire.sys";
-        break;
+        O << ".acquire";
+        return;
       case NVPTX::Ordering::Release:
-        O << ".release.sys";
-        break;
+        O << ".release";
+        return;
+      case NVPTX::Ordering::Volatile:
+        O << ".volatile";
+        return;
       case NVPTX::Ordering::RelaxedMMIO:
-        O << ".mmio.relaxed.sys";
-        break;
+        O << ".mmio.relaxed";
+        return;
       default:
         report_fatal_error(formatv(
-            "NVPTX LdStCode Printer does not support \"{}\" sem modifier.",
-            OrderingToCString(Ordering)));
+            "NVPTX LdStCode Printer does not support \"{}\" sem modifier. "
+            "Loads/Stores cannot be AcquireRelease or SequentiallyConsistent.",
+            OrderingToString(Ordering)));
+      }
+    } else if (!strcmp(Modifier, "sco")) {
+      auto S = NVPTX::Scope(Imm);
+      switch (S) {
+      case NVPTX::Scope::Thread:
+        return;
+      case NVPTX::Scope::System:
+        O << ".sys";
+        return;
+      case NVPTX::Scope::Block:
+        O << ".cta";
+        return;
+      case NVPTX::Scope::Cluster:
+        O << ".cluster";
+        return;
+      case NVPTX::Scope::Device:
+        O << ".gpu";
+        return;
       }
+      report_fatal_error(formatv(
----------------
gonzalobg wrote:

The switch case is and should always be exhaustive, so doing that produces the following warning: 

```
/src/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp:275:7: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
  275 |       default:
      |       ^
1 warning generated.
```

If a new scope is added and the now non-exhaustive switch does not trigger an error, the `fatal_error` after the switch unconditionally fails (otherwise it is dead code so should be removed).

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


More information about the llvm-commits mailing list