@@ -194,7 +194,7 @@ static Value *emitFPIntBuiltin(CodeGenFunction &CGF,
194194
195195// For processing memory ordering and memory scope arguments of various
196196// amdgcn builtins.
197- // \p Order takes a C++11 comptabile memory-ordering specifier and converts
197+ // \p Order takes a C++11 compatible memory-ordering specifier and converts
198198// it into LLVM's memory ordering specifier using atomic C ABI, and writes
199199// to \p AO. \p Scope takes a const char * and converts it into AMDGCN
200200// specific SyncScopeID and writes it to \p SSID.
@@ -227,6 +227,12 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order, Value *Scope,
227227 // Some of the atomic builtins take the scope as a string name.
228228 StringRef scp;
229229 if (llvm::getConstantStringInfo (Scope, scp)) {
230+ if (getTarget ().getTriple ().isSPIRV ()) {
231+ if (scp == " agent" )
232+ scp = " device" ;
233+ else if (scp == " wavefront" )
234+ scp = " subgroup" ;
235+ }
230236 SSID = getLLVMContext ().getOrInsertSyncScopeID (scp);
231237 return ;
232238 }
@@ -238,13 +244,19 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order, Value *Scope,
238244 SSID = llvm::SyncScope::System;
239245 break ;
240246 case 1 : // __MEMORY_SCOPE_DEVICE
241- SSID = getLLVMContext ().getOrInsertSyncScopeID (" agent" );
247+ if (getTarget ().getTriple ().isSPIRV ())
248+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" device" );
249+ else
250+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" agent" );
242251 break ;
243252 case 2 : // __MEMORY_SCOPE_WRKGRP
244253 SSID = getLLVMContext ().getOrInsertSyncScopeID (" workgroup" );
245254 break ;
246255 case 3 : // __MEMORY_SCOPE_WVFRNT
247- SSID = getLLVMContext ().getOrInsertSyncScopeID (" wavefront" );
256+ if (getTarget ().getTriple ().isSPIRV ())
257+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" subgroup" );
258+ else
259+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" wavefront" );
248260 break ;
249261 case 4 : // __MEMORY_SCOPE_SINGLE
250262 SSID = llvm::SyncScope::SingleThread;
@@ -1381,7 +1393,10 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
13811393 //
13821394 // The global/flat cases need to use agent scope to consistently produce
13831395 // the native instruction instead of a cmpxchg expansion.
1384- SSID = getLLVMContext ().getOrInsertSyncScopeID (" agent" );
1396+ if (getTarget ().getTriple ().isSPIRV ())
1397+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" device" );
1398+ else
1399+ SSID = getLLVMContext ().getOrInsertSyncScopeID (" agent" );
13851400 AO = AtomicOrdering::Monotonic;
13861401
13871402 // The v2bf16 builtin uses i16 instead of a natural bfloat type.
0 commit comments