Skip to content
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
22 changes: 16 additions & 6 deletions llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ bool NVPTXDAGToDAGISel::tryFence(SDNode *N) {
return true;
}

NVPTXScopes::NVPTXScopes(LLVMContext &C) {
NVPTXScopes::NVPTXScopes(LLVMContext &C) : Context(&C) {
Scopes[C.getOrInsertSyncScopeID("singlethread")] = NVPTX::Scope::Thread;
Scopes[C.getOrInsertSyncScopeID("")] = NVPTX::Scope::System;
Scopes[C.getOrInsertSyncScopeID("block")] = NVPTX::Scope::Block;
Expand All @@ -1851,11 +1851,21 @@ NVPTX::Scope NVPTXScopes::operator[](SyncScope::ID ID) const {

auto S = Scopes.find(ID);
if (S == Scopes.end()) {
// TODO:
// - Add API to LLVMContext to get the name of a single scope.
// - Use that API here to print an error containing the name
// of this Unknown ID.
report_fatal_error(formatv("Could not find scope ID={}.", int(ID)));
auto scopeName = Context->getSyncScopeName(ID);
assert(scopeName.has_value() && "Scope name must exist.");

// Build list of supported syncscopes programmatically
SmallVector<StringRef> supportedScopes;
for (const auto &Entry : Scopes) {
if (auto name = Context->getSyncScopeName(Entry.first))
supportedScopes.push_back(name->empty() ? "<empty string>" : *name);
}

reportFatalUsageError(
formatv("NVPTX backend does not support syncscope \"{0}\" (ID={1}).\n"
"Supported syncscopes are: {2}.",
scopeName.value(), int(ID),
make_range(supportedScopes.begin(), supportedScopes.end())));
}
return S->second;
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct NVPTXScopes {

private:
SmallMapVector<SyncScope::ID, NVPTX::Scope, 8> Scopes{};
LLVMContext *Context = nullptr;
};

class LLVM_LIBRARY_VISIBILITY NVPTXDAGToDAGISel : public SelectionDAGISel {
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/NVPTX/cmpxchg-unsupported-syncscope.err.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: not llc -mcpu=sm_100a -mtriple=nvptx64 -mattr=+ptx86 %s 2>&1 | FileCheck %s

; Test that we get a clear error message when using an unsupported syncscope.

; CHECK: NVPTX backend does not support syncscope "agent"
; CHECK: Supported syncscopes are: singlethread, <empty string>, block, cluster, device
define i32 @cmpxchg_unsupported_syncscope_agent(ptr %addr, i32 %cmp, i32 %new) {
%result = cmpxchg ptr %addr, i32 %cmp, i32 %new syncscope("agent") monotonic monotonic
%value = extractvalue { i32, i1 } %result, 0
ret i32 %value
}
Loading