mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-14 15:39:00 +00:00
Implement insertGoto and reverseBranchCondition for the X86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15362 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e4d32f6cf9
commit
36f506eddb
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user