Skip to content

Commit 0f52193

Browse files
authored
LLVMContext: add getSyncScopeName() to lookup individual scope name (llvm#109484)
This PR adds a `getSyncScopeString(Id)` API to `LLVMContext` that returns the `StringRef` for that ID, if any.
1 parent c71bfc5 commit 0f52193

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

llvm/include/llvm/IR/LLVMContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class LLVMContext {
130130
/// scope names are ordered by increasing synchronization scope IDs.
131131
void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
132132

133+
/// getSyncScopeName - Returns the name of a SyncScope::ID
134+
/// registered with LLVMContext, if any.
135+
std::optional<StringRef> getSyncScopeName(SyncScope::ID Id) const;
136+
133137
/// Define the GC for a function
134138
void setGC(const Function &Fn, std::string GCName);
135139

llvm/lib/IR/LLVMContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ void LLVMContext::getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const {
330330
pImpl->getSyncScopeNames(SSNs);
331331
}
332332

333+
std::optional<StringRef> LLVMContext::getSyncScopeName(SyncScope::ID Id) const {
334+
return pImpl->getSyncScopeName(Id);
335+
}
336+
333337
void LLVMContext::setGC(const Function &Fn, std::string GCName) {
334338
pImpl->GCNames[&Fn] = std::move(GCName);
335339
}

llvm/lib/IR/LLVMContextImpl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ void LLVMContextImpl::getSyncScopeNames(
244244
SSNs[SSE.second] = SSE.first();
245245
}
246246

247+
std::optional<StringRef>
248+
LLVMContextImpl::getSyncScopeName(SyncScope::ID Id) const {
249+
for (const auto &SSE : SSC) {
250+
if (SSE.second != Id)
251+
continue;
252+
return SSE.first();
253+
}
254+
return std::nullopt;
255+
}
256+
247257
/// Gets the OptPassGate for this LLVMContextImpl, which defaults to the
248258
/// singleton OptBisect if not explicitly set.
249259
OptPassGate &LLVMContextImpl::getOptPassGate() const {

llvm/lib/IR/LLVMContextImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,10 @@ class LLVMContextImpl {
16651665
/// scope names are ordered by increasing synchronization scope IDs.
16661666
void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
16671667

1668+
/// getSyncScopeName - Returns the name of a SyncScope::ID
1669+
/// registered with LLVMContext, if any.
1670+
std::optional<StringRef> getSyncScopeName(SyncScope::ID Id) const;
1671+
16681672
/// Maintain the GC name for each function.
16691673
///
16701674
/// This saves allocating an additional word in Function for programs which

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16144,11 +16144,8 @@ static bool atomicIgnoresDenormalModeOrFPModeIsFTZ(const AtomicRMWInst *RMW) {
1614416144

1614516145
static OptimizationRemark emitAtomicRMWLegalRemark(const AtomicRMWInst *RMW) {
1614616146
LLVMContext &Ctx = RMW->getContext();
16147-
SmallVector<StringRef> SSNs;
16148-
Ctx.getSyncScopeNames(SSNs);
16149-
StringRef MemScope = SSNs[RMW->getSyncScopeID()].empty()
16150-
? "system"
16151-
: SSNs[RMW->getSyncScopeID()];
16147+
StringRef SS = Ctx.getSyncScopeName(RMW->getSyncScopeID()).value_or("");
16148+
StringRef MemScope = SS.empty() ? StringRef("system") : SS;
1615216149

1615316150
return OptimizationRemark(DEBUG_TYPE, "Passed", RMW)
1615416151
<< "Hardware instruction generated for atomic "

0 commit comments

Comments
 (0)