Skip to content

Commit 2647573

Browse files
committed
[LLVM] Add LLVMContext API to print one SyncScope ID string
1 parent d1edef5 commit 2647573

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
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

0 commit comments

Comments
 (0)