Skip to content

Commit 4cccd5f

Browse files
committed
Always emit SPIR-V MIR for buildConstantFP
1 parent bfb8a65 commit 4cccd5f

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -242,36 +242,27 @@ Register SPIRVGlobalRegistry::buildConstantInt(uint64_t Val,
242242

243243
Register SPIRVGlobalRegistry::buildConstantFP(APFloat Val,
244244
MachineIRBuilder &MIRBuilder,
245-
SPIRVType *SpvType, bool EmitIR) {
245+
SPIRVType *SpvType) {
246246
auto &MF = MIRBuilder.getMF();
247-
const Type *LLVMFPTy;
248-
if (SpvType) {
249-
LLVMFPTy = getTypeForSPIRVType(SpvType);
250-
assert(LLVMFPTy->isFloatingPointTy());
251-
} else {
252-
LLVMFPTy = IntegerType::getFloatTy(MF.getFunction().getContext());
247+
auto &Ctx = MF.getFunction().getContext();
248+
if (!SpvType) {
249+
const Type *LLVMFPTy = Type::getFloatTy(Ctx);
250+
SpvType = getOrCreateSPIRVType(LLVMFPTy, MIRBuilder);
253251
}
254252
// Find a constant in DT or build a new one.
255-
const auto ConstFP = ConstantFP::get(LLVMFPTy->getContext(), Val);
253+
const auto ConstFP = ConstantFP::get(Ctx, Val);
256254
Register Res = DT.find(ConstFP, &MF);
257255
if (!Res.isValid()) {
258-
unsigned BitWidth = SpvType ? getScalarOrVectorBitWidth(SpvType) : 32;
259-
LLT LLTy = LLT::scalar(EmitIR ? BitWidth : 32);
260-
Res = MF.getRegInfo().createGenericVirtualRegister(LLTy);
256+
Res = MF.getRegInfo().createGenericVirtualRegister(LLT::scalar(32));
261257
MF.getRegInfo().setRegClass(Res, &SPIRV::IDRegClass);
262-
assignTypeToVReg(LLVMFPTy, Res, MIRBuilder,
263-
SPIRV::AccessQualifier::ReadWrite, EmitIR);
258+
assignSPIRVTypeToVReg(SpvType, Res, MF);
264259
DT.add(ConstFP, &MF, Res);
265-
if (EmitIR) {
266-
MIRBuilder.buildFConstant(Res, *ConstFP);
267-
} else {
268-
MachineInstrBuilder MIB;
269-
assert(SpvType);
270-
MIB = MIRBuilder.buildInstr(SPIRV::OpConstantF)
271-
.addDef(Res)
272-
.addUse(getSPIRVTypeID(SpvType));
273-
addNumImm(ConstFP->getValueAPF().bitcastToAPInt(), MIB);
274-
}
260+
261+
MachineInstrBuilder MIB;
262+
MIB = MIRBuilder.buildInstr(SPIRV::OpConstantF)
263+
.addDef(Res)
264+
.addUse(getSPIRVTypeID(SpvType));
265+
addNumImm(ConstFP->getValueAPF().bitcastToAPInt(), MIB);
275266
}
276267

277268
return Res;

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class SPIRVGlobalRegistry {
234234
Register getOrCreateConstInt(uint64_t Val, MachineInstr &I,
235235
SPIRVType *SpvType, const SPIRVInstrInfo &TII);
236236
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder,
237-
SPIRVType *SpvType = nullptr, bool EmitIR = true);
237+
SPIRVType *SpvType = nullptr);
238238
Register getOrCreateConsIntVector(uint64_t Val, MachineInstr &I,
239239
SPIRVType *SpvType,
240240
const SPIRVInstrInfo &TII);

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ bool SPIRVInstructionSelector::selectLog10(Register ResVReg,
16001600
? GR.getSPIRVTypeForVReg(ResType->getOperand(1).getReg())
16011601
: ResType;
16021602
Register ScaleReg =
1603-
GR.buildConstantFP(APFloat(0.30103f), MIRBuilder, SpirvScalarType, false);
1603+
GR.buildConstantFP(APFloat(0.30103f), MIRBuilder, SpirvScalarType);
16041604

16051605
// Multiply log2(x) by 0.30103 to get log10(x) result.
16061606
auto Opcode = ResType->getOpcode() == SPIRV::OpTypeVector

0 commit comments

Comments
 (0)