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

Vyacheslav Levytskyy via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 03:49:51 PDT 2024


================
@@ -251,6 +251,24 @@ SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord) {
   llvm_unreachable(nullptr);
 }
 
+SPIRV::Scope::Scope getMemScope(const LLVMContext &Ctx, SyncScope::ID ID) {
----------------
VyacheslavLevytskyy wrote:

@AlexVlx If you don't mind, let's do this function as the following:

```
SPIRV::Scope::Scope getMemScope(LLVMContext &Context, SyncScope::ID Id) {
  // Named by
  // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id We
  // don't need aliases for Invocation and CrossDevice, as we already have them
  // covered by "singlethread" and "" strings respectively (see implementation
  // of LLVMContext::LLVMContext()).
  static llvm::SyncScope::ID SubGroupSSID =
      Context.getOrInsertSyncScopeID("subgroup");
  static llvm::SyncScope::ID WorkGroupSSID =
      Context.getOrInsertSyncScopeID("workgroup");
  static llvm::SyncScope::ID DeviceSSID =
      Context.getOrInsertSyncScopeID("device");

  if (Id == SyncScope::SingleThread)
    return SPIRV::Scope::Invocation;
  if (Id == SubGroupSSID)
    return SPIRV::Scope::Subgroup;
  if (Id == WorkGroupSSID)
    return SPIRV::Scope::Workgroup;
  if (Id == DeviceSSID)
    return SPIRV::Scope::Device;
  if (Id == SyncScope::System)
    return SPIRV::Scope::CrossDevice;

  // This function assumes that known memory sync scopes may appear to be the
  // non-exhaustive list and allows to use the most conservative/safe choice as
  // the default in case of an unknown SyncScope::ID value.
  return SPIRV::Scope::CrossDevice;
}
```

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


More information about the llvm-commits mailing list