Skip to content

Commit 82237ec

Browse files
committed
[LLVM] Add LLVMContext API to print one SyncScope ID string
1 parent 4105177 commit 82237ec

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-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
auto It = pImpl->GCNames.find(&Fn);
335339

llvm/lib/IR/LLVMContextImpl.cpp

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

247+
std::optional<StringRef> LLVMContextImpl::getSyncScopeName(SyncScope::ID Id) const {
248+
for (const auto &SSE : SSC) {
249+
if (SSE.second != Id) continue;
250+
return SSE.first();
251+
}
252+
return std::nullopt;
253+
}
254+
247255
/// Gets the OptPassGate for this LLVMContextImpl, which defaults to the
248256
/// singleton OptBisect if not explicitly set.
249257
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)