Skip to content

LLVMContext: add getSyncScopeName() to lookup individual scope name #109484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16142,11 +16142,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
Loading