[clang] [llvm] [AMDGPU] Parse AMDGPU syncscope without a triple (PR #237228)
Arseniy Obolenskiy via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 01:11:38 PST 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/237228
>From b8458f3266f8949c1d96acb31e816ea3f949dff0 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 30 Oct 2026 14:55:48 +0100
Subject: [PATCH 1/2] [NFC][clang][AMDGPU] Build fence scope triple from enums
Mirror #235907 in classic codegen
---
clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index 2f29e9557ba56f..6b600b26ed207e 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -385,7 +385,9 @@ static Value *emitFPIntBuiltin(CodeGenFunction &CGF,
// target by parsing as AMDGPU and re-emitting it.
static inline StringRef mapScopeToSPIRV(const llvm::Triple &TargetTriple,
StringRef AMDGCNScope) {
- static const llvm::Triple AMDGPU("amdgcn-amd-amdhsa");
+ static const llvm::Triple AMDGPU(llvm::Triple::amdgpu,
+ llvm::Triple::NoSubArch, llvm::Triple::AMD,
+ llvm::Triple::AMDHSA);
if (auto Parsed = llvm::parseAtomicScopeIRString(AMDGPU, AMDGCNScope)) {
auto [Scope, IsSingleAddressSpace] = *Parsed;
if (auto Str = llvm::getAtomicScopeIRString(TargetTriple, Scope,
>From eb48381fcf8763b0129d82296143f2aa6ca797aa Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Tue, 3 Nov 2026 10:11:24 +0100
Subject: [PATCH 2/2] Parse AMDGPU syncscope without a dummy triple
---
clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp | 5 +--
clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp | 5 +--
llvm/include/llvm/TargetParser/AtomicScope.h | 40 ++++++++++++-------
3 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp
index 6b87177b80bfdb..4565ff65745e26 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp
@@ -1278,10 +1278,7 @@ CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
std::optional<std::pair<llvm::AtomicScope, bool>> parsed;
if (std::optional<std::string> name =
expr->getArg(1)->tryEvaluateString(getContext())) {
- parsed = llvm::parseAtomicScopeIRString(
- llvm::Triple(llvm::Triple::amdgpu, llvm::Triple::NoSubArch,
- llvm::Triple::AMD, llvm::Triple::AMDHSA),
- *name);
+ parsed = llvm::parseAMDGPUAtomicScopeIRString(*name);
if (!parsed && triple.isSPIRV())
parsed = llvm::parseAtomicScopeIRString(triple, *name);
}
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index 6b600b26ed207e..021564230861d6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -385,10 +385,7 @@ static Value *emitFPIntBuiltin(CodeGenFunction &CGF,
// target by parsing as AMDGPU and re-emitting it.
static inline StringRef mapScopeToSPIRV(const llvm::Triple &TargetTriple,
StringRef AMDGCNScope) {
- static const llvm::Triple AMDGPU(llvm::Triple::amdgpu,
- llvm::Triple::NoSubArch, llvm::Triple::AMD,
- llvm::Triple::AMDHSA);
- if (auto Parsed = llvm::parseAtomicScopeIRString(AMDGPU, AMDGCNScope)) {
+ if (auto Parsed = llvm::parseAMDGPUAtomicScopeIRString(AMDGCNScope)) {
auto [Scope, IsSingleAddressSpace] = *Parsed;
if (auto Str = llvm::getAtomicScopeIRString(TargetTriple, Scope,
IsSingleAddressSpace))
diff --git a/llvm/include/llvm/TargetParser/AtomicScope.h b/llvm/include/llvm/TargetParser/AtomicScope.h
index 9ab4c0e9dd5d18..100d357cc55221 100644
--- a/llvm/include/llvm/TargetParser/AtomicScope.h
+++ b/llvm/include/llvm/TargetParser/AtomicScope.h
@@ -87,6 +87,31 @@ getAtomicScopeIRString(const Triple &T, AtomicScope S,
return std::nullopt;
}
+/// Parses an AMDGPU syncscope string into its abstract scope and whether it is
+/// the single address space variant.
+inline std::optional<std::pair<AtomicScope, bool>>
+parseAMDGPUAtomicScopeIRString(StringRef Name) {
+ using Result = std::optional<std::pair<AtomicScope, bool>>;
+ auto Make = [](AtomicScope S,
+ bool IsSingleAddressSpace) -> std::pair<AtomicScope, bool> {
+ return {S, IsSingleAddressSpace};
+ };
+ return StringSwitch<Result>(Name)
+ .Case("singlethread", Make(AtomicScope::Single, false))
+ .Case("wavefront", Make(AtomicScope::Wavefront, false))
+ .Case("workgroup", Make(AtomicScope::Workgroup, false))
+ .Case("cluster", Make(AtomicScope::Cluster, false))
+ .Case("agent", Make(AtomicScope::Device, false))
+ .Case("", Make(AtomicScope::System, false))
+ .Case("singlethread-one-as", Make(AtomicScope::Single, true))
+ .Case("wavefront-one-as", Make(AtomicScope::Wavefront, true))
+ .Case("workgroup-one-as", Make(AtomicScope::Workgroup, true))
+ .Case("cluster-one-as", Make(AtomicScope::Cluster, true))
+ .Case("agent-one-as", Make(AtomicScope::Device, true))
+ .Case("one-as", Make(AtomicScope::System, true))
+ .Default(std::nullopt);
+}
+
/// Parses a target syncscope string into its abstract scope, the inverse of
/// getAtomicScopeIRString. Returns the scope and whether it is the single
/// address space variant.
@@ -98,20 +123,7 @@ parseAtomicScopeIRString(const Triple &T, StringRef Name) {
return {S, IsSingleAddressSpace};
};
if (T.isAMDGPU())
- return StringSwitch<Result>(Name)
- .Case("singlethread", Make(AtomicScope::Single, false))
- .Case("wavefront", Make(AtomicScope::Wavefront, false))
- .Case("workgroup", Make(AtomicScope::Workgroup, false))
- .Case("cluster", Make(AtomicScope::Cluster, false))
- .Case("agent", Make(AtomicScope::Device, false))
- .Case("", Make(AtomicScope::System, false))
- .Case("singlethread-one-as", Make(AtomicScope::Single, true))
- .Case("wavefront-one-as", Make(AtomicScope::Wavefront, true))
- .Case("workgroup-one-as", Make(AtomicScope::Workgroup, true))
- .Case("cluster-one-as", Make(AtomicScope::Cluster, true))
- .Case("agent-one-as", Make(AtomicScope::Device, true))
- .Case("one-as", Make(AtomicScope::System, true))
- .Default(std::nullopt);
+ return parseAMDGPUAtomicScopeIRString(Name);
if (T.isNVPTX())
return StringSwitch<Result>(Name)
.Case("singlethread", Make(AtomicScope::Single, false))
More information about the cfe-commits
mailing list