[llvm] r277188 - GlobalISel: make translate* functions take the most specialized class possible.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 29 11:11:21 PDT 2016


Author: tnorthover
Date: Fri Jul 29 13:11:21 2016
New Revision: 277188

URL: http://llvm.org/viewvc/llvm-project?rev=277188&view=rev
Log:
GlobalISel: make translate* functions take the most specialized class possible.

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=277188&r1=277187&r2=277188&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Fri Jul 29 13:11:21 2016
@@ -113,17 +113,17 @@ private:
 
   /// Translate \p Inst into a binary operation \p Opcode.
   /// \pre \p Inst is a binary operation.
-  bool translateBinaryOp(unsigned Opcode, const Instruction &Inst);
+  bool translateBinaryOp(unsigned Opcode, const BinaryOperator &Inst);
 
   /// Translate branch (br) instruction.
   /// \pre \p Inst is a branch instruction.
-  bool translateBr(const Instruction &Inst);
+  bool translateBr(const BranchInst &Inst);
 
   /// Translate return (ret) instruction.
   /// The target needs to implement CallLowering::lowerReturn for
   /// this to succeed.
   /// \pre \p Inst is a return instruction.
-  bool translateReturn(const Instruction &Inst);
+  bool translateReturn(const ReturnInst &Inst);
   /// @}
 
   // Builder for machine instruction a la IRBuilder.

Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=277188&r1=277187&r2=277188&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Jul 29 13:11:21 2016
@@ -77,7 +77,10 @@ MachineBasicBlock &IRTranslator::getOrCr
   return *MBB;
 }
 
-bool IRTranslator::translateBinaryOp(unsigned Opcode, const Instruction &Inst) {
+bool IRTranslator::translateBinaryOp(unsigned Opcode,
+                                     const BinaryOperator &Inst) {
+  // FIXME: handle signed/unsigned wrapping flags.
+
   // Get or create a virtual register for each value.
   // Unless the value is a Constant => loadimm cst?
   // or inline constant each time?
@@ -92,19 +95,15 @@ bool IRTranslator::translateBinaryOp(uns
   return true;
 }
 
-bool IRTranslator::translateReturn(const Instruction &Inst) {
-  assert(isa<ReturnInst>(Inst) && "Return expected");
-  const Value *Ret = cast<ReturnInst>(Inst).getReturnValue();
+bool IRTranslator::translateReturn(const ReturnInst &RI) {
+  const Value *Ret = RI.getReturnValue();
   // The target may mess up with the insertion point, but
   // this is not important as a return is the last instruction
   // of the block anyway.
   return CLI->lowerReturn(MIRBuilder, Ret, !Ret ? 0 : getOrCreateVReg(*Ret));
 }
 
-bool IRTranslator::translateBr(const Instruction &Inst) {
-  assert(isa<BranchInst>(Inst) && "Branch expected");
-  const BranchInst &BrInst = *cast<BranchInst>(&Inst);
-
+bool IRTranslator::translateBr(const BranchInst &BrInst) {
   unsigned Succ = 0;
   if (!BrInst.isUnconditional()) {
     // We want a G_BRCOND to the true BB followed by an unconditional branch.
@@ -201,23 +200,23 @@ bool IRTranslator::translate(const Instr
   switch(Inst.getOpcode()) {
   // Arithmetic operations.
   case Instruction::Add:
-    return translateBinaryOp(TargetOpcode::G_ADD, Inst);
+    return translateBinaryOp(TargetOpcode::G_ADD, cast<BinaryOperator>(Inst));
   case Instruction::Sub:
-    return translateBinaryOp(TargetOpcode::G_SUB, Inst);
+    return translateBinaryOp(TargetOpcode::G_SUB, cast<BinaryOperator>(Inst));
 
   // Bitwise operations.
   case Instruction::And:
-    return translateBinaryOp(TargetOpcode::G_AND, Inst);
+    return translateBinaryOp(TargetOpcode::G_AND, cast<BinaryOperator>(Inst));
   case Instruction::Or:
-    return translateBinaryOp(TargetOpcode::G_OR, Inst);
+    return translateBinaryOp(TargetOpcode::G_OR, cast<BinaryOperator>(Inst));
   case Instruction::Xor:
-    return translateBinaryOp(TargetOpcode::G_XOR, Inst);
+    return translateBinaryOp(TargetOpcode::G_XOR, cast<BinaryOperator>(Inst));
 
   // Branch operations.
   case Instruction::Br:
-    return translateBr(Inst);
+    return translateBr(cast<BranchInst>(Inst));
   case Instruction::Ret:
-    return translateReturn(Inst);
+    return translateReturn(cast<ReturnInst>(Inst));
 
   // Casts
   case Instruction::BitCast:




More information about the llvm-commits mailing list