@@ -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}
0 commit comments