From: Tim Northover Date: Fri, 19 Aug 2016 20:09:15 +0000 (+0000) Subject: GlobalISel: translate floating-point constants X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b16734fbaa1b0a70c8349414239d1484e99fd018;p=platform%2Fupstream%2Fllvm.git GlobalISel: translate floating-point constants llvm-svn: 279311 --- diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index 70f7001..c8531e2 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -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 = COPY Op /// /// Register-to-register COPY sets \p Res to \p Op. diff --git a/llvm/include/llvm/Target/GenericOpcodes.td b/llvm/include/llvm/Target/GenericOpcodes.td index e832ca7..9a4fde0 100644 --- a/llvm/include/llvm/Target/GenericOpcodes.td +++ b/llvm/include/llvm/Target/GenericOpcodes.td @@ -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. //------------------------------------------------------------------------------ diff --git a/llvm/include/llvm/Target/TargetOpcodes.def b/llvm/include/llvm/Target/TargetOpcodes.def index ea9bfaf..ad87497 100644 --- a/llvm/include/llvm/Target/TargetOpcodes.def +++ b/llvm/include/llvm/Target/TargetOpcodes.def @@ -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) diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 58235c2..1a243c5 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -408,6 +408,8 @@ bool IRTranslator::translate(const Instruction &Inst) { bool IRTranslator::translate(const Constant &C, unsigned Reg) { if (auto CI = dyn_cast(&C)) EntryBuilder.buildConstant(LLT{*CI->getType()}, Reg, CI->getZExtValue()); + else if (auto CF = dyn_cast(&C)) + EntryBuilder.buildFConstant(LLT{*CF->getType()}, Reg, *CF); else if (isa(C)) EntryBuilder.buildInstr(TargetOpcode::IMPLICIT_DEF).addDef(Reg); else if (isa(C)) diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 0d2fae6..2fe6eab 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -100,6 +100,11 @@ MachineInstrBuilder MachineIRBuilder::buildConstant(LLT Ty, unsigned Res, 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); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 8340bc8..fd823f9 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -784,3 +784,12 @@ define void @test_uitofp(double* %addr, i32 %in) { 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 +}