@@ -595,19 +595,19 @@ void OCLToSPIRV::visitCallNDRange(CallInst *CI, StringRef DemangledName) {
595
595
}
596
596
597
597
void OCLToSPIRV::visitCallAsyncWorkGroupCopy (CallInst *CI,
598
- StringRef DemangledName) {
598
+ StringRef DemangledName) {
599
599
assert (CI->getCalledFunction () && " Unexpected indirect call" );
600
600
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
601
- mutateCallInstSPIRV (M, CI,
602
- [=](CallInst *, std::vector<Value *> &Args) {
603
- if (DemangledName ==
604
- OCLUtil::kOCLBuiltinName ::AsyncWorkGroupCopy) {
605
- Args.insert (Args.begin () + 3 , addSizet (1 ));
606
- }
607
- Args.insert (Args.begin (), addInt32 (ScopeWorkgroup));
608
- return getSPIRVFuncName (OpGroupAsyncCopy);
609
- },
610
- &Attrs);
601
+ mutateCallInstSPIRV (
602
+ M, CI,
603
+ [=](CallInst *, std::vector<Value *> &Args) {
604
+ if (DemangledName == OCLUtil::kOCLBuiltinName ::AsyncWorkGroupCopy) {
605
+ Args.insert (Args.begin () + 3 , addSizet (1 ));
606
+ }
607
+ Args.insert (Args.begin (), addInt32 (ScopeWorkgroup));
608
+ return getSPIRVFuncName (OpGroupAsyncCopy);
609
+ },
610
+ &Attrs);
611
611
}
612
612
613
613
CallInst *OCLToSPIRV::visitCallAtomicCmpXchg (CallInst *CI) {
@@ -692,22 +692,23 @@ void OCLToSPIRV::visitCallMemFence(CallInst *CI) {
692
692
}
693
693
694
694
void OCLToSPIRV::transMemoryBarrier (CallInst *CI,
695
- AtomicWorkItemFenceLiterals Lit) {
695
+ AtomicWorkItemFenceLiterals Lit) {
696
696
assert (CI->getCalledFunction () && " Unexpected indirect call" );
697
697
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
698
- mutateCallInstSPIRV (M, CI,
699
- [=](CallInst *, std::vector<Value *> &Args) {
700
- Args.resize (2 );
701
- Args[0 ] = addInt32 (map<Scope>(std::get<2 >(Lit)));
702
- Args[1 ] = addInt32 (mapOCLMemSemanticToSPIRV (
703
- std::get<0 >(Lit), std::get<1 >(Lit)));
704
- return getSPIRVFuncName (OpMemoryBarrier);
705
- },
706
- &Attrs);
698
+ mutateCallInstSPIRV (
699
+ M, CI,
700
+ [=](CallInst *, std::vector<Value *> &Args) {
701
+ Args.resize (2 );
702
+ Args[0 ] = addInt32 (map<Scope>(std::get<2 >(Lit)));
703
+ Args[1 ] = addInt32 (
704
+ mapOCLMemSemanticToSPIRV (std::get<0 >(Lit), std::get<1 >(Lit)));
705
+ return getSPIRVFuncName (OpMemoryBarrier);
706
+ },
707
+ &Attrs);
707
708
}
708
709
709
710
void OCLToSPIRV::visitCallAtomicLegacy (CallInst *CI, StringRef MangledName,
710
- StringRef DemangledName) {
711
+ StringRef DemangledName) {
711
712
StringRef Stem = DemangledName;
712
713
if (Stem.startswith (" atom_" ))
713
714
Stem = Stem.drop_front (strlen (" atom_" ));
@@ -754,7 +755,7 @@ void OCLToSPIRV::visitCallAtomicLegacy(CallInst *CI, StringRef MangledName,
754
755
}
755
756
756
757
void OCLToSPIRV::visitCallAtomicCpp11 (CallInst *CI, StringRef MangledName,
757
- StringRef DemangledName) {
758
+ StringRef DemangledName) {
758
759
StringRef Stem = DemangledName;
759
760
if (Stem.startswith (" atomic_" ))
760
761
Stem = Stem.drop_front (strlen (" atomic_" ));
@@ -839,28 +840,28 @@ void OCLToSPIRV::transAtomicBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
839
840
void OCLToSPIRV::visitCallBarrier (CallInst *CI) {
840
841
auto Lit = getBarrierLiterals (CI);
841
842
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
842
- mutateCallInstSPIRV (M, CI,
843
- [=](CallInst *, std::vector<Value *> &Args) {
844
- Args. resize ( 3 );
845
- // Execution scope
846
- Args[ 0 ] = addInt32 (map<Scope>(std::get< 2 >(Lit)));
847
- // Memory scope
848
- Args[ 1 ] = addInt32 (map<Scope>(std::get< 1 >(Lit)));
849
- // Use sequential consistent memory order by default.
850
- // But if the flags argument is set to 0, we use
851
- // None(Relaxed) memory order.
852
- unsigned MemFenceFlag = std::get< 0 >(Lit);
853
- OCLMemOrderKind MemOrder =
854
- MemFenceFlag ? OCLMO_seq_cst : OCLMO_relaxed;
855
- Args[2 ] = addInt32 (mapOCLMemSemanticToSPIRV (
856
- MemFenceFlag, MemOrder)); // Memory semantics
857
- return getSPIRVFuncName (OpControlBarrier);
858
- },
859
- &Attrs);
843
+ mutateCallInstSPIRV (
844
+ M, CI,
845
+ [=](CallInst *, std::vector<Value *> & Args) {
846
+ Args. resize ( 3 );
847
+ // Execution scope
848
+ Args[ 0 ] = addInt32 (map<Scope>(std::get< 2 >(Lit)));
849
+ // Memory scope
850
+ Args[ 1 ] = addInt32 (map<Scope>(std::get< 1 >(Lit)));
851
+ // Use sequential consistent memory order by default.
852
+ // But if the flags argument is set to 0, we use
853
+ // None(Relaxed) memory order.
854
+ unsigned MemFenceFlag = std::get< 0 >(Lit);
855
+ OCLMemOrderKind MemOrder = MemFenceFlag ? OCLMO_seq_cst : OCLMO_relaxed;
856
+ Args[2 ] = addInt32 (mapOCLMemSemanticToSPIRV (
857
+ MemFenceFlag, MemOrder)); // Memory semantics
858
+ return getSPIRVFuncName (OpControlBarrier);
859
+ },
860
+ &Attrs);
860
861
}
861
862
862
863
void OCLToSPIRV::visitCallConvert (CallInst *CI, StringRef MangledName,
863
- StringRef DemangledName) {
864
+ StringRef DemangledName) {
864
865
if (eraseUselessConvert (CI, MangledName, DemangledName))
865
866
return ;
866
867
Op OC = OpNop;
@@ -904,16 +905,16 @@ void OCLToSPIRV::visitCallConvert(CallInst *CI, StringRef MangledName,
904
905
}
905
906
assert (CI->getCalledFunction () && " Unexpected indirect call" );
906
907
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
907
- mutateCallInstSPIRV (M, CI,
908
- [=](CallInst *, std::vector<Value *> &Args) {
909
- return getSPIRVFuncName (OC,
910
- TargetTyName + Sat + Rounding);
911
- },
912
- &Attrs);
908
+ mutateCallInstSPIRV (
909
+ M, CI,
910
+ [=](CallInst *, std::vector<Value *> &Args) {
911
+ return getSPIRVFuncName (OC, TargetTyName + Sat + Rounding);
912
+ },
913
+ &Attrs);
913
914
}
914
915
915
916
void OCLToSPIRV::visitCallGroupBuiltin (CallInst *CI,
916
- StringRef OrigDemangledName) {
917
+ StringRef OrigDemangledName) {
917
918
auto F = CI->getCalledFunction ();
918
919
std::vector<int > PreOps;
919
920
std::string DemangledName{OrigDemangledName};
@@ -1047,12 +1048,13 @@ void OCLToSPIRV::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
1047
1048
else
1048
1049
return ;
1049
1050
if (!Info.RetTy )
1050
- mutateCallInstSPIRV (M, CI,
1051
- [=](CallInst *, std::vector<Value *> &Args) {
1052
- Info.PostProc (Args);
1053
- return Info.UniqName + Info.Postfix ;
1054
- },
1055
- &Attrs);
1051
+ mutateCallInstSPIRV (
1052
+ M, CI,
1053
+ [=](CallInst *, std::vector<Value *> &Args) {
1054
+ Info.PostProc (Args);
1055
+ return Info.UniqName + Info.Postfix ;
1056
+ },
1057
+ &Attrs);
1056
1058
else
1057
1059
mutateCallInstSPIRV (
1058
1060
M, CI,
@@ -1087,7 +1089,7 @@ void OCLToSPIRV::visitCallReadImageMSAA(CallInst *CI, StringRef MangledName) {
1087
1089
}
1088
1090
1089
1091
void OCLToSPIRV::visitCallReadImageWithSampler (CallInst *CI,
1090
- StringRef MangledName) {
1092
+ StringRef MangledName) {
1091
1093
assert (MangledName.find (kMangledName ::Sampler) != StringRef::npos);
1092
1094
assert (CI->getCalledFunction () && " Unexpected indirect call" );
1093
1095
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
@@ -1141,8 +1143,7 @@ void OCLToSPIRV::visitCallReadImageWithSampler(CallInst *CI,
1141
1143
&Attrs);
1142
1144
}
1143
1145
1144
- void OCLToSPIRV::visitCallGetImageSize (CallInst *CI,
1145
- StringRef DemangledName) {
1146
+ void OCLToSPIRV::visitCallGetImageSize (CallInst *CI, StringRef DemangledName) {
1146
1147
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1147
1148
StringRef TyName;
1148
1149
SmallVector<StringRef, 4 > SubStrs;
@@ -1203,7 +1204,7 @@ void OCLToSPIRV::visitCallGetImageSize(CallInst *CI,
1203
1204
1204
1205
// / Remove trivial conversion functions
1205
1206
bool OCLToSPIRV::eraseUselessConvert (CallInst *CI, StringRef MangledName,
1206
- StringRef DemangledName) {
1207
+ StringRef DemangledName) {
1207
1208
auto TargetTy = CI->getType ();
1208
1209
auto SrcTy = CI->getArgOperand (0 )->getType ();
1209
1210
if (auto *VecTy = dyn_cast<VectorType>(TargetTy))
@@ -1227,7 +1228,7 @@ bool OCLToSPIRV::eraseUselessConvert(CallInst *CI, StringRef MangledName,
1227
1228
}
1228
1229
1229
1230
void OCLToSPIRV::visitCallBuiltinSimple (CallInst *CI, StringRef MangledName,
1230
- StringRef DemangledName) {
1231
+ StringRef DemangledName) {
1231
1232
OCLBuiltinTransInfo Info;
1232
1233
Info.MangledName = MangledName.str ();
1233
1234
Info.UniqName = DemangledName.str ();
@@ -1289,7 +1290,7 @@ void OCLToSPIRV::transWorkItemBuiltinsToVariables() {
1289
1290
}
1290
1291
1291
1292
void OCLToSPIRV::visitCallReadWriteImage (CallInst *CI,
1292
- StringRef DemangledName) {
1293
+ StringRef DemangledName) {
1293
1294
OCLBuiltinTransInfo Info;
1294
1295
if (DemangledName.find (kOCLBuiltinName ::ReadImage) == 0 )
1295
1296
Info.UniqName = kOCLBuiltinName ::ReadImage;
@@ -1371,7 +1372,7 @@ void OCLToSPIRV::visitCallRelational(CallInst *CI, StringRef DemangledName) {
1371
1372
}
1372
1373
1373
1374
void OCLToSPIRV::visitCallVecLoadStore (CallInst *CI, StringRef MangledName,
1374
- StringRef OrigDemangledName) {
1375
+ StringRef OrigDemangledName) {
1375
1376
std::vector<int > PreOps;
1376
1377
std::string DemangledName{OrigDemangledName};
1377
1378
if (DemangledName.find (kOCLBuiltinName ::VLoadPrefix) == 0 &&
@@ -1415,15 +1416,15 @@ void OCLToSPIRV::visitCallGetFence(CallInst *CI, StringRef DemangledName) {
1415
1416
Op OC = OpNop;
1416
1417
OCLSPIRVBuiltinMap::find (DemangledName.str (), &OC);
1417
1418
std::string SPIRVName = getSPIRVFuncName (OC);
1418
- mutateCallInstSPIRV (M, CI,
1419
- [=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
1420
- return SPIRVName;
1421
- },
1422
- [=](CallInst *NewCI) -> Instruction * {
1423
- return BinaryOperator::CreateLShr (NewCI, getInt32 (M, 8 ),
1424
- " " , CI);
1425
- },
1426
- &Attrs);
1419
+ mutateCallInstSPIRV (
1420
+ M, CI,
1421
+ [=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
1422
+ return SPIRVName;
1423
+ },
1424
+ [=](CallInst *NewCI) -> Instruction * {
1425
+ return BinaryOperator::CreateLShr (NewCI, getInt32 (M, 8 ), " " , CI);
1426
+ },
1427
+ &Attrs);
1427
1428
}
1428
1429
1429
1430
void OCLToSPIRV::visitCallDot (CallInst *CI) {
@@ -1434,7 +1435,7 @@ void OCLToSPIRV::visitCallDot(CallInst *CI) {
1434
1435
}
1435
1436
1436
1437
void OCLToSPIRV::visitCallScalToVec (CallInst *CI, StringRef MangledName,
1437
- StringRef DemangledName) {
1438
+ StringRef DemangledName) {
1438
1439
// Check if all arguments have the same type - it's simple case.
1439
1440
auto Uniform = true ;
1440
1441
auto IsArg0Vector = isa<VectorType>(CI->getOperand (0 )->getType ());
@@ -1498,26 +1499,24 @@ void OCLToSPIRV::visitCallScalToVec(CallInst *CI, StringRef MangledName,
1498
1499
&Attrs);
1499
1500
}
1500
1501
1501
- void OCLToSPIRV::visitCallGetImageChannel (CallInst *CI,
1502
- StringRef DemangledName,
1503
- unsigned int Offset) {
1502
+ void OCLToSPIRV::visitCallGetImageChannel (CallInst *CI, StringRef DemangledName,
1503
+ unsigned int Offset) {
1504
1504
assert (CI->getCalledFunction () && " Unexpected indirect call" );
1505
1505
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1506
1506
Op OC = OpNop;
1507
1507
OCLSPIRVBuiltinMap::find (DemangledName.str (), &OC);
1508
1508
std::string SPIRVName = getSPIRVFuncName (OC);
1509
- mutateCallInstSPIRV (M, CI,
1510
- [=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
1511
- return SPIRVName;
1512
- },
1513
- [=](CallInst *NewCI) -> Instruction * {
1514
- return BinaryOperator::CreateAdd (
1515
- NewCI, getInt32 (M, Offset), " " , CI);
1516
- },
1517
- &Attrs);
1509
+ mutateCallInstSPIRV (
1510
+ M, CI,
1511
+ [=](CallInst *, std::vector<Value *> &Args, Type *&Ret) {
1512
+ return SPIRVName;
1513
+ },
1514
+ [=](CallInst *NewCI) -> Instruction * {
1515
+ return BinaryOperator::CreateAdd ( NewCI, getInt32 (M, Offset), " " , CI);
1516
+ },
1517
+ &Attrs);
1518
1518
}
1519
- void OCLToSPIRV::visitCallEnqueueKernel (CallInst *CI,
1520
- StringRef DemangledName) {
1519
+ void OCLToSPIRV::visitCallEnqueueKernel (CallInst *CI, StringRef DemangledName) {
1521
1520
const DataLayout &DL = M->getDataLayout ();
1522
1521
bool HasEvents = DemangledName.find (" events" ) != StringRef::npos;
1523
1522
@@ -1594,29 +1593,29 @@ void OCLToSPIRV::visitCallKernelQuery(CallInst *CI, StringRef DemangledName) {
1594
1593
auto *BlockF = cast<Function>(getUnderlyingObject (BlockFVal));
1595
1594
1596
1595
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1597
- mutateCallInst (M, CI,
1598
- [=](CallInst * CI, std::vector<Value *> &Args) {
1599
- Value *Param = * Args. rbegin ();
1600
- Type *ParamType = getUnderlyingObject (Param)-> getType ();
1601
- if (PointerType *PT = dyn_cast<PointerType>(ParamType)) {
1602
- ParamType = PT-> getElementType ();
1603
- }
1604
- // Last arg corresponds to SPIRV Param operand.
1605
- // Insert Invoke in front of Param.
1606
- // Add Param Size and Param Align at the end .
1607
- Args[BlockFIdx] = BlockF;
1608
- Args. push_back ( getInt32 (M, DL. getTypeStoreSize (ParamType))) ;
1609
- Args.push_back (
1610
- getInt32 (M, DL.getPrefTypeAlignment (ParamType)));
1611
-
1612
- Op Opcode = OCLSPIRVBuiltinMap::map (DemangledName.str ());
1613
- // Adding "__" postfix, so in case we have multiple such
1614
- // functions and their names will have numerical postfix,
1615
- // then the numerical postfix will be droped and we will get
1616
- // correct function name.
1617
- return getSPIRVFuncName (Opcode, kSPIRVName ::Postfix);
1618
- },
1619
- /* BuiltinFuncMangleInfo*/ nullptr , &Attrs);
1596
+ mutateCallInst (
1597
+ M, CI,
1598
+ [=](CallInst *CI, std::vector< Value *> & Args) {
1599
+ Value *Param = *Args. rbegin ();
1600
+ Type *ParamType = getUnderlyingObject (Param)-> getType ();
1601
+ if (PointerType *PT = dyn_cast<PointerType>(ParamType)) {
1602
+ ParamType = PT-> getElementType ();
1603
+ }
1604
+ // Last arg corresponds to SPIRV Param operand .
1605
+ // Insert Invoke in front of Param .
1606
+ // Add Param Size and Param Align at the end.
1607
+ Args[BlockFIdx] = BlockF ;
1608
+ Args.push_back (getInt32 (M, DL. getTypeStoreSize (ParamType)));
1609
+ Args. push_back ( getInt32 (M, DL.getPrefTypeAlignment (ParamType)));
1610
+
1611
+ Op Opcode = OCLSPIRVBuiltinMap::map (DemangledName.str ());
1612
+ // Adding "__" postfix, so in case we have multiple such
1613
+ // functions and their names will have numerical postfix,
1614
+ // then the numerical postfix will be droped and we will get
1615
+ // correct function name.
1616
+ return getSPIRVFuncName (Opcode, kSPIRVName ::Postfix);
1617
+ },
1618
+ /* BuiltinFuncMangleInfo*/ nullptr , &Attrs);
1620
1619
}
1621
1620
1622
1621
// Add postfix to overloaded intel subgroup block read/write builtins
@@ -1673,7 +1672,7 @@ void OCLToSPIRV::visitSubgroupBlockWriteINTEL(CallInst *CI) {
1673
1672
}
1674
1673
1675
1674
void OCLToSPIRV::visitSubgroupImageMediaBlockINTEL (CallInst *CI,
1676
- StringRef DemangledName) {
1675
+ StringRef DemangledName) {
1677
1676
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1678
1677
spv::Op OpCode = DemangledName.rfind (" read" ) != StringRef::npos
1679
1678
? spv::OpSubgroupImageMediaBlockReadINTEL
@@ -1723,7 +1722,7 @@ static Op getSubgroupAVCIntelMCEOpCodeForWrapper(StringRef DemangledName) {
1723
1722
1724
1723
// Handles Subgroup AVC Intel extension generic built-ins.
1725
1724
void OCLToSPIRV::visitSubgroupAVCBuiltinCall (CallInst *CI,
1726
- StringRef DemangledName) {
1725
+ StringRef DemangledName) {
1727
1726
Op OC = OpNop;
1728
1727
std::string FName{DemangledName};
1729
1728
std::string Prefix = kOCLSubgroupsAVCIntel ::Prefix;
@@ -1762,9 +1761,8 @@ void OCLToSPIRV::visitSubgroupAVCBuiltinCall(CallInst *CI,
1762
1761
// 'IME', 'REF' and 'SIC' sets contain wrapper built-ins which don't have
1763
1762
// corresponded instructions in SPIRV and should be translated to a
1764
1763
// conterpart from 'MCE' with conversion for an argument and result (if needed).
1765
- void OCLToSPIRV::visitSubgroupAVCWrapperBuiltinCall (CallInst *CI,
1766
- Op WrappedOC,
1767
- StringRef DemangledName) {
1764
+ void OCLToSPIRV::visitSubgroupAVCWrapperBuiltinCall (CallInst *CI, Op WrappedOC,
1765
+ StringRef DemangledName) {
1768
1766
AttributeList Attrs = CI->getCalledFunction ()->getAttributes ();
1769
1767
std::string Prefix = kOCLSubgroupsAVCIntel ::Prefix;
1770
1768
0 commit comments