summaryrefslogtreecommitdiffstats
path: root/lib/Target/X86
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-07-31 09:38:47 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-07-31 09:38:47 +0000
commit36f506eddb25d5198240a1e3fabcb0912111c7ee (patch)
treef4eaa025087176e241ba4aa2663994ba4e3d1a83 /lib/Target/X86
parente4d32f6cf96566f8d37e50212e4f67330150ee20 (diff)
downloadexternal_llvm-36f506eddb25d5198240a1e3fabcb0912111c7ee.zip
external_llvm-36f506eddb25d5198240a1e3fabcb0912111c7ee.tar.gz
external_llvm-36f506eddb25d5198240a1e3fabcb0912111c7ee.tar.bz2
Implement insertGoto and reverseBranchCondition for the X86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15362 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r--lib/Target/X86/X86InstrInfo.cpp33
-rw-r--r--lib/Target/X86/X86InstrInfo.h10
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index f934093..5f5d0b3 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -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;
+}
diff --git a/lib/Target/X86/X86InstrInfo.h b/lib/Target/X86/X86InstrInfo.h
index 5b3ddd0..eb920d6 100644
--- a/lib/Target/X86/X86InstrInfo.h
+++ b/lib/Target/X86/X86InstrInfo.h
@@ -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.
//