Implement insertGoto and reverseBranchCondition for the X86.
authorAlkis Evlogimenos <alkis@evlogimenos.com>
Sat, 31 Jul 2004 09:38:47 +0000 (09:38 +0000)
committerAlkis Evlogimenos <alkis@evlogimenos.com>
Sat, 31 Jul 2004 09:38:47 +0000 (09:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h

index f93409361ba8cef942d786de1358d5e5cf2d38bd..5f5d0b32a7a16f4c11b4dfdf125fb3a3a6345003 100644 (file)
@@ -38,3 +38,36 @@ bool X86InstrInfo::isMoveInstr(const MachineInstr& MI,
   }
   return false;
 }
+
+void X86InstrInfo::insertGoto(MachineBasicBlock& MBB,
+                              MachineBasicBlock& TMBB) const {
+  BuildMI(MBB, MBB.end(), X86::JMP, 1).addMBB(&TMBB);
+}
+
+MachineBasicBlock::iterator
+X86InstrInfo::reverseBranchCondition(MachineBasicBlock::iterator MI) const {
+  unsigned Opcode = MI->getOpcode();
+  assert(isBranch(Opcode) && "MachineInstr must be a branch");
+  unsigned ROpcode;
+  switch (Opcode) {
+  case X86::JB:  ROpcode = X86::JAE;
+  case X86::JAE: ROpcode = X86::JB;
+  case X86::JE:  ROpcode = X86::JNE;
+  case X86::JNE: ROpcode = X86::JE;
+  case X86::JBE: ROpcode = X86::JA;
+  case X86::JA:  ROpcode = X86::JBE;
+  case X86::JS:  ROpcode = X86::JNS;
+  case X86::JNS: ROpcode = X86::JS;
+  case X86::JL:  ROpcode = X86::JGE;
+  case X86::JGE: ROpcode = X86::JL;
+  case X86::JLE: ROpcode = X86::JG;
+  case X86::JG:  ROpcode = X86::JLE;
+  default:
+    assert(0 && "Cannot reverse uncodnitional branches!");
+  }
+  MachineBasicBlock* MBB = MI->getParent();
+  MachineBasicBlock* TMBB = MI->getOperand(0).getMachineBasicBlock();
+  MachineInstrBuilder IB = BuildMI(*MBB, MBB->erase(MI), ROpcode, 1);
+  IB.addMBB(TMBB);
+  return IB;
+}
index 5b3ddd06abc32e7d619b0fd5ebb148c0b8d18347..eb920d67d87a504e2b55175b165a2c79b771f8a7 100644 (file)
@@ -203,6 +203,16 @@ public:
                            unsigned& sourceReg,
                            unsigned& destReg) const;
 
+  /// Insert a goto (unconditional branch) sequence to TMBB, at the
+  /// end of MBB
+  virtual void insertGoto(MachineBasicBlock& MBB,
+                          MachineBasicBlock& TMBB) const;
+
+  /// Reverses the branch condition of the MachineInstr pointed by
+  /// MI. The instruction is replaced and the new MI is returned.
+  virtual MachineBasicBlock::iterator
+  reverseBranchCondition(MachineBasicBlock::iterator MI) const;
+
   // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
   // specified opcode number.
   //