-
Notifications
You must be signed in to change notification settings - Fork 15k
[NVPTX] Add more clear error message for using invalid syncscope #165737
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -1851,11 +1851,22 @@ 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))); | ||
| // Get the actual scope name from LLVMContext for a better error message | ||
| std::string scopeName = "<unknown>"; | ||
| if (auto name = Context->getSyncScopeName(ID)) | ||
| scopeName = name->str(); | ||
|
|
||
| // 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); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error-reporting enhancement LGTM. Would collecting the scopes in a small-vector and then using llvm::join (with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, better yet use StringRefs as well and just comma join the list as part of formatv https://llvm.org/docs/ProgrammersManual.html#formatv-examples There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, didn't know llvm:join existed. Changed to use both, take a look when you get a chance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't even need to use |
||
|
|
||
| reportFatalUsageError( | ||
| formatv("NVPTX backend does not support syncscope \"{0}\" (ID={1}).\n" | ||
| "Supported syncscopes are: {2}.", | ||
| scopeName, int(ID), llvm::join(supportedScopes, ", "))); | ||
| } | ||
| return S->second; | ||
| } | ||
|
|
||
| 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 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this expected to ever happen? If so, please add a test, if not perhaps change to an assert?