[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)

Alex Voicu via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 16 05:28:22 PDT 2024


================
@@ -58,7 +58,35 @@ class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
   SPIRVTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
       : CommonSPIRTargetCodeGenInfo(std::make_unique<SPIRVABIInfo>(CGT)) {}
   void setCUDAKernelCallingConvention(const FunctionType *&FT) const override;
+  llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts,
+                                         SyncScope Scope,
+                                         llvm::AtomicOrdering Ordering,
+                                         llvm::LLVMContext &Ctx) const override;
 };
+
+inline StringRef mapClangSyncScopeToLLVM(SyncScope Scope) {
+  switch (Scope) {
+  case SyncScope::HIPSingleThread:
+  case SyncScope::SingleScope:
+    return "singlethread";
+  case SyncScope::HIPWavefront:
+  case SyncScope::OpenCLSubGroup:
+  case SyncScope::WavefrontScope:
+    return "subgroup";
+  case SyncScope::HIPWorkgroup:
+  case SyncScope::OpenCLWorkGroup:
+  case SyncScope::WorkgroupScope:
+    return "workgroup";
+  case SyncScope::HIPAgent:
+  case SyncScope::OpenCLDevice:
+  case SyncScope::DeviceScope:
+    return "device";
+  case SyncScope::SystemScope:
+  case SyncScope::HIPSystem:
+  case SyncScope::OpenCLAllSVMDevices:
+    return "all_svm_devices";
----------------
AlexVlx wrote:

> +1, we should align on the scope string names. Since we may have different languages with different naming for the scope it makes sense to take names from the common specification eg SPIR-V. So probably we should rename `sub_group` (or `subgroup`) to `Subgroup` etc; and `singlethread` should be aliased with `Invocation`.

I'd object to using CamelCase for the IR representation (re-using the SPIR-V naming is fine, which is where `subgroup` vs `sub_group` originated) on the grounds that we don't really use that style anywhere else in IR, and other targets have already gone snake_case.

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


More information about the cfe-commits mailing list