[llvm] r272431 - [IRTranslator] Refactor to expose a translateBinaryOp method.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 10 13:50:18 PDT 2016
Author: qcolombet
Date: Fri Jun 10 15:50:18 2016
New Revision: 272431
URL: http://llvm.org/viewvc/llvm-project?rev=272431&view=rev
Log:
[IRTranslator] Refactor to expose a translateBinaryOp method.
This method will be used for every binary operation.
NFC.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=272431&r1=272430&r2=272431&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Fri Jun 10 15:50:18 2016
@@ -87,12 +87,20 @@ private:
// Note: we would need to do something so that we can recognize such operand
// as constants.
// 3. Create the generic instruction.
- bool translateADD(const Instruction &Inst);
bool translateBr(const Instruction &Inst);
bool translateReturn(const Instruction &Inst);
+ /// Translate \p Inst into a binary operation \p Opcode.
+ /// Insert the newly translated instruction right where the MIRBuilder
+ /// is set.
+ ///
+ /// \pre \p Inst is a binary operation.
+ ///
+ /// \return true if the translation succeeded.
+ bool translateBinaryOp(unsigned Opcode, const Instruction &Inst);
+
// Builder for machine instruction a la IRBuilder.
// I.e., compared to regular MIBuilder, this one also inserts the instruction
// in the current block, it can creates block, etc., basically a kind of
Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=272431&r1=272430&r2=272431&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Jun 10 15:50:18 2016
@@ -61,7 +61,7 @@ MachineBasicBlock &IRTranslator::getOrCr
return *MBB;
}
-bool IRTranslator::translateADD(const Instruction &Inst) {
+bool IRTranslator::translateBinaryOp(unsigned Opcode, const Instruction &Inst) {
// Get or create a virtual register for each value.
// Unless the value is a Constant => loadimm cst?
// or inline constant each time?
@@ -69,7 +69,7 @@ bool IRTranslator::translateADD(const In
unsigned Op0 = getOrCreateVReg(*Inst.getOperand(0));
unsigned Op1 = getOrCreateVReg(*Inst.getOperand(1));
unsigned Res = getOrCreateVReg(Inst);
- MIRBuilder.buildInstr(TargetOpcode::G_ADD, Inst.getType(), Res, Op0, Op1);
+ MIRBuilder.buildInstr(Opcode, Inst.getType(), Res, Op0, Op1);
return true;
}
@@ -103,7 +103,7 @@ bool IRTranslator::translate(const Instr
MIRBuilder.setDebugLoc(Inst.getDebugLoc());
switch(Inst.getOpcode()) {
case Instruction::Add:
- return translateADD(Inst);
+ return translateBinaryOp(TargetOpcode::G_ADD, Inst);
case Instruction::Br:
return translateBr(Inst);
case Instruction::Ret:
More information about the llvm-commits
mailing list