Skip to content

Commit 30b99de

Browse files
committed
[NVPTX] Add more clear error message for using invalid syncscope
1 parent 916e8f7 commit 30b99de

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ bool NVPTXDAGToDAGISel::tryFence(SDNode *N) {
18361836
return true;
18371837
}
18381838

1839-
NVPTXScopes::NVPTXScopes(LLVMContext &C) {
1839+
NVPTXScopes::NVPTXScopes(LLVMContext &C) : Context(&C) {
18401840
Scopes[C.getOrInsertSyncScopeID("singlethread")] = NVPTX::Scope::Thread;
18411841
Scopes[C.getOrInsertSyncScopeID("")] = NVPTX::Scope::System;
18421842
Scopes[C.getOrInsertSyncScopeID("block")] = NVPTX::Scope::Block;
@@ -1851,11 +1851,24 @@ NVPTX::Scope NVPTXScopes::operator[](SyncScope::ID ID) const {
18511851

18521852
auto S = Scopes.find(ID);
18531853
if (S == Scopes.end()) {
1854-
// TODO:
1855-
// - Add API to LLVMContext to get the name of a single scope.
1856-
// - Use that API here to print an error containing the name
1857-
// of this Unknown ID.
1858-
report_fatal_error(formatv("Could not find scope ID={}.", int(ID)));
1854+
// Get the actual scope name from LLVMContext for a better error message
1855+
std::string scopeName = "<unknown>";
1856+
if (auto name = Context->getSyncScopeName(ID))
1857+
scopeName = name->str();
1858+
1859+
// Build list of supported syncscopes programmatically
1860+
std::string supportedScopes;
1861+
for (const auto &Entry : Scopes) {
1862+
if (!supportedScopes.empty())
1863+
supportedScopes += ", ";
1864+
if (auto name = Context->getSyncScopeName(Entry.first))
1865+
supportedScopes += name->empty() ? "<empty string>" : name->str();
1866+
}
1867+
1868+
reportFatalUsageError(
1869+
formatv("NVPTX backend does not support syncscope \"{0}\" (ID={1}).\n"
1870+
"Supported syncscopes are: {2}.",
1871+
scopeName, int(ID), supportedScopes));
18591872
}
18601873
return S->second;
18611874
}

llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct NVPTXScopes {
3535

3636
private:
3737
SmallMapVector<SyncScope::ID, NVPTX::Scope, 8> Scopes{};
38+
LLVMContext *Context = nullptr;
3839
};
3940

4041
class LLVM_LIBRARY_VISIBILITY NVPTXDAGToDAGISel : public SelectionDAGISel {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not llc -mcpu=sm_100a -mtriple=nvptx64 -mattr=+ptx86 %s 2>&1 | FileCheck %s
2+
3+
; Test that we get a clear error message when using an unsupported syncscope.
4+
5+
; CHECK: NVPTX backend does not support syncscope "agent"
6+
; CHECK: Supported syncscopes are: singlethread, <empty string>, block, cluster, device
7+
define i32 @cmpxchg_unsupported_syncscope_agent(ptr %addr, i32 %cmp, i32 %new) {
8+
%result = cmpxchg ptr %addr, i32 %cmp, i32 %new syncscope("agent") monotonic monotonic
9+
%value = extractvalue { i32, i1 } %result, 0
10+
ret i32 %value
11+
}

0 commit comments

Comments
 (0)