[llvm] r279311 - GlobalISel: translate floating-point constants
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 13:09:15 PDT 2016
Author: tnorthover
Date: Fri Aug 19 15:09:15 2016
New Revision: 279311
URL: http://llvm.org/viewvc/llvm-project?rev=279311&view=rev
Log:
GlobalISel: translate floating-point constants
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/trunk/include/llvm/Target/GenericOpcodes.td
llvm/trunk/include/llvm/Target/TargetOpcodes.def
llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h Fri Aug 19 15:09:15 2016
@@ -185,6 +185,17 @@ public:
/// \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.
Modified: llvm/trunk/include/llvm/Target/GenericOpcodes.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/GenericOpcodes.td?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GenericOpcodes.td (original)
+++ llvm/trunk/include/llvm/Target/GenericOpcodes.td Fri Aug 19 15:09:15 2016
@@ -79,6 +79,12 @@ def G_CONSTANT : Instruction {
let hasSideEffects = 0;
}
+def G_FCONSTANT : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$imm);
+ let hasSideEffects = 0;
+}
+
//------------------------------------------------------------------------------
// Binary ops.
//------------------------------------------------------------------------------
Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.def?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOpcodes.def (original)
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.def Fri Aug 19 15:09:15 2016
@@ -244,6 +244,9 @@ HANDLE_TARGET_OPCODE(G_TRUNC)
/// Generic integer constant.
HANDLE_TARGET_OPCODE(G_CONSTANT)
+/// Generic floating constant.
+HANDLE_TARGET_OPCODE(G_FCONSTANT)
+
// Generic sign extend
HANDLE_TARGET_OPCODE(G_SEXT)
Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Aug 19 15:09:15 2016
@@ -408,6 +408,8 @@ bool IRTranslator::translate(const Instr
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))
Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp Fri Aug 19 15:09:15 2016
@@ -100,6 +100,11 @@ MachineInstrBuilder MachineIRBuilder::bu
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);
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll?rev=279311&r1=279310&r2=279311&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Fri Aug 19 15:09:15 2016
@@ -784,3 +784,12 @@ define void @test_uitofp(double* %addr,
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
+}
More information about the llvm-commits
mailing list