[llvm] 0f52193 - LLVMContext: add getSyncScopeName() to lookup individual scope name (#109484)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 11:14:00 PDT 2024
Author: gonzalobg
Date: 2024-09-25T11:13:56-07:00
New Revision: 0f521931b85e6b5f798af357cf32a7ae782a848d
URL: https://github.com/llvm/llvm-project/commit/0f521931b85e6b5f798af357cf32a7ae782a848d
DIFF: https://github.com/llvm/llvm-project/commit/0f521931b85e6b5f798af357cf32a7ae782a848d.diff
LOG: LLVMContext: add getSyncScopeName() to lookup individual scope name (#109484)
This PR adds a `getSyncScopeString(Id)` API to `LLVMContext` that
returns the `StringRef` for that ID, if any.
Added:
Modified:
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/LLVMContext.h b/llvm/include/llvm/IR/LLVMContext.h
index 558816e146587a..6d4a59ba6b1f6c 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -130,6 +130,10 @@ class LLVMContext {
/// scope names are ordered by increasing synchronization scope IDs.
void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
+ /// getSyncScopeName - Returns the name of a SyncScope::ID
+ /// registered with LLVMContext, if any.
+ std::optional<StringRef> getSyncScopeName(SyncScope::ID Id) const;
+
/// Define the GC for a function
void setGC(const Function &Fn, std::string GCName);
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 22e60772def43f..e078527b597b44 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -330,6 +330,10 @@ void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
pImpl->getSyncScopeNames(SSNs);
}
+std::optional<StringRef> LLVMContext::getSyncScopeName(SyncScope::ID Id) const {
+ return pImpl->getSyncScopeName(Id);
+}
+
void LLVMContext::setGC(const Function &Fn, std::string GCName) {
pImpl->GCNames[&Fn] = std::move(GCName);
}
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 4f1ef8cec32133..f2c965a45df3ae 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -244,6 +244,16 @@ void LLVMContextImpl::getSyncScopeNames(
SSNs[SSE.second] = SSE.first();
}
+std::optional<StringRef>
+LLVMContextImpl::getSyncScopeName(SyncScope::ID Id) const {
+ for (const auto &SSE : SSC) {
+ if (SSE.second != Id)
+ continue;
+ return SSE.first();
+ }
+ return std::nullopt;
+}
+
/// Gets the OptPassGate for this LLVMContextImpl, which defaults to the
/// singleton OptBisect if not explicitly set.
OptPassGate &LLVMContextImpl::getOptPassGate() const {
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index e76f004b590efe..971091f3040614 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1665,6 +1665,10 @@ class LLVMContextImpl {
/// scope names are ordered by increasing synchronization scope IDs.
void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
+ /// getSyncScopeName - Returns the name of a SyncScope::ID
+ /// registered with LLVMContext, if any.
+ std::optional<StringRef> getSyncScopeName(SyncScope::ID Id) const;
+
/// Maintain the GC name for each function.
///
/// This saves allocating an additional word in Function for programs which
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 2464361d4eece3..885ecab891b1f5 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -16144,11 +16144,8 @@ static bool atomicIgnoresDenormalModeOrFPModeIsFTZ(const AtomicRMWInst *RMW) {
static OptimizationRemark emitAtomicRMWLegalRemark(const AtomicRMWInst *RMW) {
LLVMContext &Ctx = RMW->getContext();
- SmallVector<StringRef> SSNs;
- Ctx.getSyncScopeNames(SSNs);
- StringRef MemScope = SSNs[RMW->getSyncScopeID()].empty()
- ? "system"
- : SSNs[RMW->getSyncScopeID()];
+ StringRef SS = Ctx.getSyncScopeName(RMW->getSyncScopeID()).value_or("");
+ StringRef MemScope = SS.empty() ? StringRef("system") : SS;
return OptimizationRemark(DEBUG_TYPE, "Passed", RMW)
<< "Hardware instruction generated for atomic "
More information about the llvm-commits
mailing list