[llvm-commits] CVS: llvm/lib/Target/X86/X86InstrInfo.h X86InstrInfo.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Sat Jul 31 02:38:57 PDT 2004



Changes in directory llvm/lib/Target/X86:

X86InstrInfo.h updated: 1.40 -> 1.41
X86InstrInfo.cpp updated: 1.26 -> 1.27

---
Log message:

Implement insertGoto and reverseBranchCondition for the X86.


---
Diffs of the changes:  (+43 -0)

Index: llvm/lib/Target/X86/X86InstrInfo.h
diff -u llvm/lib/Target/X86/X86InstrInfo.h:1.40 llvm/lib/Target/X86/X86InstrInfo.h:1.41
--- llvm/lib/Target/X86/X86InstrInfo.h:1.40	Thu Jun 10 23:41:24 2004
+++ llvm/lib/Target/X86/X86InstrInfo.h	Sat Jul 31 04:38:47 2004
@@ -203,6 +203,16 @@
                            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.
   //


Index: llvm/lib/Target/X86/X86InstrInfo.cpp
diff -u llvm/lib/Target/X86/X86InstrInfo.cpp:1.26 llvm/lib/Target/X86/X86InstrInfo.cpp:1.27
--- llvm/lib/Target/X86/X86InstrInfo.cpp:1.26	Sun Feb 29 02:50:03 2004
+++ llvm/lib/Target/X86/X86InstrInfo.cpp	Sat Jul 31 04:38:47 2004
@@ -38,3 +38,36 @@
   }
   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;
+}





More information about the llvm-commits mailing list