Skip to content

Commit

Permalink
LLVMContext: add getSyncScopeName() to lookup individual scope name (l…
Browse files Browse the repository at this point in the history
…lvm#109484)

This PR adds a `getSyncScopeString(Id)` API to `LLVMContext` that
returns the `StringRef` for that ID, if any.
  • Loading branch information
gonzalobg authored Sep 25, 2024
1 parent c71bfc5 commit 0f52193
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/IR/LLVMContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/IR/LLVMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 0f52193

Please sign in to comment.