/// \return The newly created instruction.
MachineInstrBuilder buildConstant(LLT Ty, unsigned Res, int64_t Val);
+ /// Build and insert \p Res = G_FCONSTANT \p Ty \p Val
+ ///
+ /// G_FCONSTANT is a floating-point constant with the specified size and
+ /// value.
+ ///
+ /// \pre setBasicBlock or setMI must have been called.
+ ///
+ /// \return The newly created instruction.
+ MachineInstrBuilder buildFConstant(LLT Ty, unsigned Res,
+ const ConstantFP &Val);
+
/// Build and insert \p Res<def> = COPY Op
///
/// Register-to-register COPY sets \p Res to \p Op.
let hasSideEffects = 0;
}
+def G_FCONSTANT : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$imm);
+ let hasSideEffects = 0;
+}
+
//------------------------------------------------------------------------------
// Binary ops.
//------------------------------------------------------------------------------
/// Generic integer constant.
HANDLE_TARGET_OPCODE(G_CONSTANT)
+/// Generic floating constant.
+HANDLE_TARGET_OPCODE(G_FCONSTANT)
+
// Generic sign extend
HANDLE_TARGET_OPCODE(G_SEXT)
bool IRTranslator::translate(const Constant &C, unsigned Reg) {
if (auto CI = dyn_cast<ConstantInt>(&C))
EntryBuilder.buildConstant(LLT{*CI->getType()}, Reg, CI->getZExtValue());
+ else if (auto CF = dyn_cast<ConstantFP>(&C))
+ EntryBuilder.buildFConstant(LLT{*CF->getType()}, Reg, *CF);
else if (isa<UndefValue>(C))
EntryBuilder.buildInstr(TargetOpcode::IMPLICIT_DEF).addDef(Reg);
else if (isa<ConstantPointerNull>(C))
return buildInstr(TargetOpcode::G_CONSTANT, Ty).addDef(Res).addImm(Val);
}
+MachineInstrBuilder MachineIRBuilder::buildFConstant(LLT Ty, unsigned Res,
+ const ConstantFP &Val) {
+ return buildInstr(TargetOpcode::G_FCONSTANT, Ty).addDef(Res).addFPImm(&Val);
+}
+
MachineInstrBuilder MachineIRBuilder::buildBrCond(LLT Ty, unsigned Tst,
MachineBasicBlock &Dest) {
return buildInstr(TargetOpcode::G_BRCOND, Ty).addUse(Tst).addMBB(&Dest);
store double %fp, double* %addr
ret void
}
+
+; CHECK-LABEL: name: test_constant_float
+; CHECK: [[ADDR:%[0-9]+]](64) = COPY %x0
+; CHECK: [[TMP:%[0-9]+]](32) = G_FCONSTANT s32 float 1.500000e+00
+; CHECK: G_STORE { s32, p0 } [[TMP]], [[ADDR]]
+define void @test_constant_float(float* %addr) {
+ store float 1.5, float* %addr
+ ret void
+}