@@ -827,16 +827,28 @@ void OCL20ToSPIRV::transAtomicBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
827827 const size_t ArgsCount = Args.size ();
828828 const size_t ScopeIdx = ArgsCount - 1 ;
829829 const size_t OrderIdx = ScopeIdx - NumOrder;
830- Args[ScopeIdx] =
831- mapUInt (M, cast<ConstantInt>(Args[ScopeIdx]), [](unsigned I) {
832- return map<Scope>(static_cast <OCLScopeKind>(I));
830+ if (auto ScopeInt = dyn_cast_or_null<ConstantInt>(Args[ScopeIdx])) {
831+ Args[ScopeIdx] = mapUInt (M, ScopeInt, [](unsigned I) {
832+ return map<Scope>(static_cast <OCLScopeKind>(I));
833+ });
834+ } else {
835+ // SPIR-V 1.3 r6 s2.16.2: All <id> used for Scope and Memory
836+ // Semantics must be of an OpConstant.
837+ Ctx->emitError (CI, " memory_scope argument needs to be constant" );
838+ }
839+ for (size_t I = 0 ; I < NumOrder; ++I) {
840+ if (auto OrderInt =
841+ dyn_cast_or_null<ConstantInt>(Args[OrderIdx + I])) {
842+ Args[OrderIdx + I] = mapUInt (M, OrderInt, [](unsigned Ord) {
843+ return mapOCLMemSemanticToSPIRV (
844+ 0 , static_cast <OCLMemOrderKind>(Ord));
833845 });
834- for ( size_t I = 0 ; I < NumOrder; ++I)
835- Args[OrderIdx + I] = mapUInt (
836- M, cast<ConstantInt>(Args[OrderIdx + I]), []( unsigned Ord) {
837- return mapOCLMemSemanticToSPIRV (
838- 0 , static_cast <OCLMemOrderKind>(Ord));
839- });
846+ } else {
847+ // SPIR-V 1.3 r6 s2.16.2: All <id> used for Scope and Memory
848+ // Semantics must be of an OpConstant.
849+ Ctx-> emitError (CI, " memory_order argument needs to be constant " );
850+ }
851+ }
840852 // Order of args in SPIR-V:
841853 // object, scope, 1-2 order, 0-2 other args
842854 std::swap (Args[1 ], Args[ScopeIdx]);
@@ -1229,9 +1241,9 @@ void OCL20ToSPIRV::transWorkItemBuiltinsToVariables() {
12291241 bool IsVec = I.getFunctionType ()->getNumParams () > 0 ;
12301242 Type *GVType =
12311243 IsVec ? VectorType::get (I.getReturnType (), 3 ) : I.getReturnType ();
1232- auto BV = new GlobalVariable (
1233- *M, GVType, true , GlobalValue::ExternalLinkage, nullptr , BuiltinVarName,
1234- 0 , GlobalVariable::NotThreadLocal, SPIRAS_Constant );
1244+ auto BV = new GlobalVariable (*M, GVType, true , GlobalValue::ExternalLinkage,
1245+ nullptr , BuiltinVarName, 0 ,
1246+ GlobalVariable::NotThreadLocal, SPIRAS_Input );
12351247 std::vector<Instruction *> InstList;
12361248 for (auto UI = I.user_begin (), UE = I.user_end (); UI != UE; ++UI) {
12371249 auto CI = dyn_cast<CallInst>(*UI);
0 commit comments