Skip to content

Commit a329579

Browse files
AlexeySachkovvmaksimo
authored andcommitted
Apply clang-format to OCLToSPIRV.cpp
1 parent edb267a commit a329579

File tree

1 file changed

+112
-114
lines changed

1 file changed

+112
-114
lines changed

llvm-spirv/lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 112 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -595,19 +595,19 @@ void OCLToSPIRV::visitCallNDRange(CallInst *CI, StringRef DemangledName) {
595595
}
596596

597597
void OCLToSPIRV::visitCallAsyncWorkGroupCopy(CallInst *CI,
598-
StringRef DemangledName) {
598+
StringRef DemangledName) {
599599
assert(CI->getCalledFunction() && "Unexpected indirect call");
600600
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);
611611
}
612612

613613
CallInst *OCLToSPIRV::visitCallAtomicCmpXchg(CallInst *CI) {
@@ -692,22 +692,23 @@ void OCLToSPIRV::visitCallMemFence(CallInst *CI) {
692692
}
693693

694694
void OCLToSPIRV::transMemoryBarrier(CallInst *CI,
695-
AtomicWorkItemFenceLiterals Lit) {
695+
AtomicWorkItemFenceLiterals Lit) {
696696
assert(CI->getCalledFunction() && "Unexpected indirect call");
697697
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);
707708
}
708709

709710
void OCLToSPIRV::visitCallAtomicLegacy(CallInst *CI, StringRef MangledName,
710-
StringRef DemangledName) {
711+
StringRef DemangledName) {
711712
StringRef Stem = DemangledName;
712713
if (Stem.startswith("atom_"))
713714
Stem = Stem.drop_front(strlen("atom_"));
@@ -754,7 +755,7 @@ void OCLToSPIRV::visitCallAtomicLegacy(CallInst *CI, StringRef MangledName,
754755
}
755756

756757
void OCLToSPIRV::visitCallAtomicCpp11(CallInst *CI, StringRef MangledName,
757-
StringRef DemangledName) {
758+
StringRef DemangledName) {
758759
StringRef Stem = DemangledName;
759760
if (Stem.startswith("atomic_"))
760761
Stem = Stem.drop_front(strlen("atomic_"));
@@ -839,28 +840,28 @@ void OCLToSPIRV::transAtomicBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
839840
void OCLToSPIRV::visitCallBarrier(CallInst *CI) {
840841
auto Lit = getBarrierLiterals(CI);
841842
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);
860861
}
861862

862863
void OCLToSPIRV::visitCallConvert(CallInst *CI, StringRef MangledName,
863-
StringRef DemangledName) {
864+
StringRef DemangledName) {
864865
if (eraseUselessConvert(CI, MangledName, DemangledName))
865866
return;
866867
Op OC = OpNop;
@@ -904,16 +905,16 @@ void OCLToSPIRV::visitCallConvert(CallInst *CI, StringRef MangledName,
904905
}
905906
assert(CI->getCalledFunction() && "Unexpected indirect call");
906907
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);
913914
}
914915

915916
void OCLToSPIRV::visitCallGroupBuiltin(CallInst *CI,
916-
StringRef OrigDemangledName) {
917+
StringRef OrigDemangledName) {
917918
auto F = CI->getCalledFunction();
918919
std::vector<int> PreOps;
919920
std::string DemangledName{OrigDemangledName};
@@ -1047,12 +1048,13 @@ void OCLToSPIRV::transBuiltin(CallInst *CI, OCLBuiltinTransInfo &Info) {
10471048
else
10481049
return;
10491050
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);
10561058
else
10571059
mutateCallInstSPIRV(
10581060
M, CI,
@@ -1087,7 +1089,7 @@ void OCLToSPIRV::visitCallReadImageMSAA(CallInst *CI, StringRef MangledName) {
10871089
}
10881090

10891091
void OCLToSPIRV::visitCallReadImageWithSampler(CallInst *CI,
1090-
StringRef MangledName) {
1092+
StringRef MangledName) {
10911093
assert(MangledName.find(kMangledName::Sampler) != StringRef::npos);
10921094
assert(CI->getCalledFunction() && "Unexpected indirect call");
10931095
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
@@ -1141,8 +1143,7 @@ void OCLToSPIRV::visitCallReadImageWithSampler(CallInst *CI,
11411143
&Attrs);
11421144
}
11431145

1144-
void OCLToSPIRV::visitCallGetImageSize(CallInst *CI,
1145-
StringRef DemangledName) {
1146+
void OCLToSPIRV::visitCallGetImageSize(CallInst *CI, StringRef DemangledName) {
11461147
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
11471148
StringRef TyName;
11481149
SmallVector<StringRef, 4> SubStrs;
@@ -1203,7 +1204,7 @@ void OCLToSPIRV::visitCallGetImageSize(CallInst *CI,
12031204

12041205
/// Remove trivial conversion functions
12051206
bool OCLToSPIRV::eraseUselessConvert(CallInst *CI, StringRef MangledName,
1206-
StringRef DemangledName) {
1207+
StringRef DemangledName) {
12071208
auto TargetTy = CI->getType();
12081209
auto SrcTy = CI->getArgOperand(0)->getType();
12091210
if (auto *VecTy = dyn_cast<VectorType>(TargetTy))
@@ -1227,7 +1228,7 @@ bool OCLToSPIRV::eraseUselessConvert(CallInst *CI, StringRef MangledName,
12271228
}
12281229

12291230
void OCLToSPIRV::visitCallBuiltinSimple(CallInst *CI, StringRef MangledName,
1230-
StringRef DemangledName) {
1231+
StringRef DemangledName) {
12311232
OCLBuiltinTransInfo Info;
12321233
Info.MangledName = MangledName.str();
12331234
Info.UniqName = DemangledName.str();
@@ -1289,7 +1290,7 @@ void OCLToSPIRV::transWorkItemBuiltinsToVariables() {
12891290
}
12901291

12911292
void OCLToSPIRV::visitCallReadWriteImage(CallInst *CI,
1292-
StringRef DemangledName) {
1293+
StringRef DemangledName) {
12931294
OCLBuiltinTransInfo Info;
12941295
if (DemangledName.find(kOCLBuiltinName::ReadImage) == 0)
12951296
Info.UniqName = kOCLBuiltinName::ReadImage;
@@ -1371,7 +1372,7 @@ void OCLToSPIRV::visitCallRelational(CallInst *CI, StringRef DemangledName) {
13711372
}
13721373

13731374
void OCLToSPIRV::visitCallVecLoadStore(CallInst *CI, StringRef MangledName,
1374-
StringRef OrigDemangledName) {
1375+
StringRef OrigDemangledName) {
13751376
std::vector<int> PreOps;
13761377
std::string DemangledName{OrigDemangledName};
13771378
if (DemangledName.find(kOCLBuiltinName::VLoadPrefix) == 0 &&
@@ -1415,15 +1416,15 @@ void OCLToSPIRV::visitCallGetFence(CallInst *CI, StringRef DemangledName) {
14151416
Op OC = OpNop;
14161417
OCLSPIRVBuiltinMap::find(DemangledName.str(), &OC);
14171418
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);
14271428
}
14281429

14291430
void OCLToSPIRV::visitCallDot(CallInst *CI) {
@@ -1434,7 +1435,7 @@ void OCLToSPIRV::visitCallDot(CallInst *CI) {
14341435
}
14351436

14361437
void OCLToSPIRV::visitCallScalToVec(CallInst *CI, StringRef MangledName,
1437-
StringRef DemangledName) {
1438+
StringRef DemangledName) {
14381439
// Check if all arguments have the same type - it's simple case.
14391440
auto Uniform = true;
14401441
auto IsArg0Vector = isa<VectorType>(CI->getOperand(0)->getType());
@@ -1498,26 +1499,24 @@ void OCLToSPIRV::visitCallScalToVec(CallInst *CI, StringRef MangledName,
14981499
&Attrs);
14991500
}
15001501

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) {
15041504
assert(CI->getCalledFunction() && "Unexpected indirect call");
15051505
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
15061506
Op OC = OpNop;
15071507
OCLSPIRVBuiltinMap::find(DemangledName.str(), &OC);
15081508
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);
15181518
}
1519-
void OCLToSPIRV::visitCallEnqueueKernel(CallInst *CI,
1520-
StringRef DemangledName) {
1519+
void OCLToSPIRV::visitCallEnqueueKernel(CallInst *CI, StringRef DemangledName) {
15211520
const DataLayout &DL = M->getDataLayout();
15221521
bool HasEvents = DemangledName.find("events") != StringRef::npos;
15231522

@@ -1594,29 +1593,29 @@ void OCLToSPIRV::visitCallKernelQuery(CallInst *CI, StringRef DemangledName) {
15941593
auto *BlockF = cast<Function>(getUnderlyingObject(BlockFVal));
15951594

15961595
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);
16201619
}
16211620

16221621
// Add postfix to overloaded intel subgroup block read/write builtins
@@ -1673,7 +1672,7 @@ void OCLToSPIRV::visitSubgroupBlockWriteINTEL(CallInst *CI) {
16731672
}
16741673

16751674
void OCLToSPIRV::visitSubgroupImageMediaBlockINTEL(CallInst *CI,
1676-
StringRef DemangledName) {
1675+
StringRef DemangledName) {
16771676
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
16781677
spv::Op OpCode = DemangledName.rfind("read") != StringRef::npos
16791678
? spv::OpSubgroupImageMediaBlockReadINTEL
@@ -1723,7 +1722,7 @@ static Op getSubgroupAVCIntelMCEOpCodeForWrapper(StringRef DemangledName) {
17231722

17241723
// Handles Subgroup AVC Intel extension generic built-ins.
17251724
void OCLToSPIRV::visitSubgroupAVCBuiltinCall(CallInst *CI,
1726-
StringRef DemangledName) {
1725+
StringRef DemangledName) {
17271726
Op OC = OpNop;
17281727
std::string FName{DemangledName};
17291728
std::string Prefix = kOCLSubgroupsAVCIntel::Prefix;
@@ -1762,9 +1761,8 @@ void OCLToSPIRV::visitSubgroupAVCBuiltinCall(CallInst *CI,
17621761
// 'IME', 'REF' and 'SIC' sets contain wrapper built-ins which don't have
17631762
// corresponded instructions in SPIRV and should be translated to a
17641763
// 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) {
17681766
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
17691767
std::string Prefix = kOCLSubgroupsAVCIntel::Prefix;
17701768

0 commit comments

Comments
 (0)