]> granicus.if.org Git - llvm/commitdiff
[IRTranslator] Refactor to expose a translateBinaryOp method.
authorQuentin Colombet <qcolombet@apple.com>
Fri, 10 Jun 2016 20:50:18 +0000 (20:50 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Fri, 10 Jun 2016 20:50:18 +0000 (20:50 +0000)
This method will be used for every binary operation.

NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272431 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/IRTranslator.h
lib/CodeGen/GlobalISel/IRTranslator.cpp

index fcd6e1a3452e85ab8c68d6fefb21aa1868083386..5e38b6195c3a37e0dc2df13fa79648769714ed74 100644 (file)
@@ -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
index 98af7608592542b15ff4676174c50e4dcca8d37c..ea11b3162550bd81558a5ab90c356ebbc58e7c40 100644 (file)
@@ -61,7 +61,7 @@ MachineBasicBlock &IRTranslator::getOrCreateBB(const BasicBlock &BB) {
   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 Instruction &Inst) {
   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 Instruction &Inst) {
   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: