Skip to content

Commit d731b2e

Browse files
committed
Replace lambda with list of operands
1 parent a3db639 commit d731b2e

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,49 +2876,46 @@ static SPIRVType *getInlineSpirvType(const TargetExtType *ExtensionType,
28762876
"parameter");
28772877
auto Opcode = ExtensionType->getIntParameter(0);
28782878

2879-
return GR->getOrCreateUnknownType(
2880-
ExtensionType, MIRBuilder, Opcode,
2881-
[&ExtensionType, &GR, &MIRBuilder](llvm::MachineInstrBuilder Instr) {
2882-
for (llvm::Type *Param : ExtensionType->type_params()) {
2883-
if (const TargetExtType *ParamEType =
2884-
dyn_cast<TargetExtType>(Param)) {
2885-
if (ParamEType->getName() == "spirv.IntegralConstant") {
2886-
assert(ParamEType->getNumTypeParameters() == 1 &&
2887-
"Inline SPIR-V integral constant builtin must have a type "
2888-
"parameter");
2889-
assert(ParamEType->getNumIntParameters() == 1 &&
2890-
"Inline SPIR-V integral constant builtin must have a "
2891-
"value parameter");
2892-
2893-
auto OperandValue = ParamEType->getIntParameter(0);
2894-
auto *OperandType = ParamEType->getTypeParameter(0);
2895-
2896-
const SPIRVType *OperandSPIRVType =
2897-
GR->getOrCreateSPIRVType(OperandType, MIRBuilder);
2898-
2899-
Instr = Instr.addUse(GR->buildConstantInt(
2900-
OperandValue, MIRBuilder, OperandSPIRVType, true));
2901-
continue;
2902-
} else if (ParamEType->getName() == "spirv.Literal") {
2903-
assert(ParamEType->getNumTypeParameters() == 0 &&
2904-
"Inline SPIR-V literal builtin does not take type "
2905-
"parameters");
2906-
assert(ParamEType->getNumIntParameters() == 1 &&
2907-
"Inline SPIR-V literal builtin must have an integer "
2908-
"parameter");
2909-
2910-
auto OperandValue = ParamEType->getIntParameter(0);
2911-
2912-
Instr = Instr.addImm(OperandValue);
2913-
continue;
2914-
}
2915-
}
2916-
const SPIRVType *TypeOperand =
2917-
GR->getOrCreateSPIRVType(Param, MIRBuilder);
2918-
Instr = Instr.addUse(GR->getSPIRVTypeID(TypeOperand));
2919-
}
2920-
return Instr;
2921-
});
2879+
SmallVector<MCOperand> Operands;
2880+
for (llvm::Type *Param : ExtensionType->type_params()) {
2881+
if (const TargetExtType *ParamEType = dyn_cast<TargetExtType>(Param)) {
2882+
if (ParamEType->getName() == "spirv.IntegralConstant") {
2883+
assert(ParamEType->getNumTypeParameters() == 1 &&
2884+
"Inline SPIR-V integral constant builtin must have a type "
2885+
"parameter");
2886+
assert(ParamEType->getNumIntParameters() == 1 &&
2887+
"Inline SPIR-V integral constant builtin must have a "
2888+
"value parameter");
2889+
2890+
auto OperandValue = ParamEType->getIntParameter(0);
2891+
auto *OperandType = ParamEType->getTypeParameter(0);
2892+
2893+
const SPIRVType *OperandSPIRVType =
2894+
GR->getOrCreateSPIRVType(OperandType, MIRBuilder);
2895+
2896+
Operands.push_back(MCOperand::createReg(GR->buildConstantInt(
2897+
OperandValue, MIRBuilder, OperandSPIRVType, true)));
2898+
continue;
2899+
} else if (ParamEType->getName() == "spirv.Literal") {
2900+
assert(ParamEType->getNumTypeParameters() == 0 &&
2901+
"Inline SPIR-V literal builtin does not take type "
2902+
"parameters");
2903+
assert(ParamEType->getNumIntParameters() == 1 &&
2904+
"Inline SPIR-V literal builtin must have an integer "
2905+
"parameter");
2906+
2907+
auto OperandValue = ParamEType->getIntParameter(0);
2908+
2909+
Operands.push_back(MCOperand::createImm(OperandValue));
2910+
continue;
2911+
}
2912+
}
2913+
const SPIRVType *TypeOperand = GR->getOrCreateSPIRVType(Param, MIRBuilder);
2914+
Operands.push_back(MCOperand::createReg(GR->getSPIRVTypeID(TypeOperand)));
2915+
}
2916+
2917+
return GR->getOrCreateUnknownType(ExtensionType, MIRBuilder, Opcode,
2918+
Operands);
29222919
}
29232920

29242921
namespace SPIRV {

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,17 +1408,24 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeByOpcode(
14081408

14091409
SPIRVType *SPIRVGlobalRegistry::getOrCreateUnknownType(
14101410
const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode,
1411-
const std::function<llvm::MachineInstrBuilder(llvm::MachineInstrBuilder)>
1412-
&buildInstr) {
1411+
const ArrayRef<MCOperand> Operands) {
14131412
Register ResVReg = DT.find(Ty, &MIRBuilder.getMF());
14141413
if (ResVReg.isValid())
14151414
return MIRBuilder.getMF().getRegInfo().getUniqueVRegDef(ResVReg);
14161415
ResVReg = createTypeVReg(MIRBuilder);
1417-
SPIRVType *SpirvTy = buildInstr(MIRBuilder.buildInstr(SPIRV::UNKNOWN_type)
1418-
.addDef(ResVReg)
1419-
.addImm(Opcode));
1416+
1417+
MachineInstrBuilder MIB =
1418+
MIRBuilder.buildInstr(SPIRV::UNKNOWN_type).addDef(ResVReg).addImm(Opcode);
1419+
for (MCOperand Operand : Operands) {
1420+
if (Operand.isReg()) {
1421+
MIB.addUse(Operand.getReg());
1422+
} else if (Operand.isImm()) {
1423+
MIB.addImm(Operand.getImm());
1424+
}
1425+
}
1426+
14201427
DT.add(Ty, &MIRBuilder.getMF(), ResVReg);
1421-
return SpirvTy;
1428+
return MIB;
14221429
}
14231430

14241431
const MachineInstr *

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,10 @@ class SPIRVGlobalRegistry {
618618
MachineIRBuilder &MIRBuilder,
619619
unsigned Opcode);
620620

621-
SPIRVType *getOrCreateUnknownType(
622-
const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode,
623-
const std::function<llvm::MachineInstrBuilder(llvm::MachineInstrBuilder)>
624-
&buildInstr);
621+
SPIRVType *getOrCreateUnknownType(const Type *Ty,
622+
MachineIRBuilder &MIRBuilder,
623+
unsigned Opcode,
624+
const ArrayRef<MCOperand> Operands);
625625

626626
const TargetRegisterClass *getRegClass(SPIRVType *SpvType) const;
627627
LLT getRegType(SPIRVType *SpvType) const;

0 commit comments

Comments
 (0)