mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Emit B (unconditional branch) when -relocation-model=pic and J (jump) when
-relocation-model=static. llvm-svn: 146432
This commit is contained in:
parent
6530764264
commit
b091e73672
@ -29,8 +29,8 @@ using namespace llvm;
|
||||
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
|
||||
: MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
|
||||
TM(tm), IsN64(TM.getSubtarget<MipsSubtarget>().isABI_N64()),
|
||||
RI(*TM.getSubtargetImpl(), *this) {}
|
||||
|
||||
RI(*TM.getSubtargetImpl(), *this),
|
||||
UncondBrOpc(TM.getRelocationModel() == Reloc::PIC_ ? Mips::B : Mips::J) {}
|
||||
|
||||
const MipsRegisterInfo &MipsInstrInfo::getRegisterInfo() const {
|
||||
return RI;
|
||||
@ -236,7 +236,8 @@ static unsigned GetAnalyzableBrOpc(unsigned Opc) {
|
||||
Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ ||
|
||||
Opc == Mips::BEQ64 || Opc == Mips::BNE64 || Opc == Mips::BGTZ64 ||
|
||||
Opc == Mips::BGEZ64 || Opc == Mips::BLTZ64 || Opc == Mips::BLEZ64 ||
|
||||
Opc == Mips::BC1T || Opc == Mips::BC1F || Opc == Mips::B) ?
|
||||
Opc == Mips::BC1T || Opc == Mips::BC1F || Opc == Mips::B ||
|
||||
Opc == Mips::J) ?
|
||||
Opc : 0;
|
||||
}
|
||||
|
||||
@ -320,7 +321,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
||||
// If there is only one terminator instruction, process it.
|
||||
if (!SecondLastOpc) {
|
||||
// Unconditional branch
|
||||
if (LastOpc == Mips::B) {
|
||||
if (LastOpc == UncondBrOpc) {
|
||||
TBB = LastInst->getOperand(0).getMBB();
|
||||
return false;
|
||||
}
|
||||
@ -337,7 +338,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
||||
|
||||
// If second to last instruction is an unconditional branch,
|
||||
// analyze it and remove the last instruction.
|
||||
if (SecondLastOpc == Mips::B) {
|
||||
if (SecondLastOpc == UncondBrOpc) {
|
||||
// Return if the last instruction cannot be removed.
|
||||
if (!AllowModify)
|
||||
return true;
|
||||
@ -349,7 +350,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
||||
|
||||
// Conditional branch followed by an unconditional branch.
|
||||
// The last one must be unconditional.
|
||||
if (LastOpc != Mips::B)
|
||||
if (LastOpc != UncondBrOpc)
|
||||
return true;
|
||||
|
||||
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
|
||||
@ -391,14 +392,14 @@ InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
||||
// Two-way Conditional branch.
|
||||
if (FBB) {
|
||||
BuildCondBr(MBB, TBB, DL, Cond);
|
||||
BuildMI(&MBB, DL, get(Mips::B)).addMBB(FBB);
|
||||
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// One way branch.
|
||||
// Unconditional branch.
|
||||
if (Cond.empty())
|
||||
BuildMI(&MBB, DL, get(Mips::B)).addMBB(TBB);
|
||||
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB);
|
||||
else // Conditional branch.
|
||||
BuildCondBr(MBB, TBB, DL, Cond);
|
||||
return 1;
|
||||
|
@ -34,6 +34,7 @@ class MipsInstrInfo : public MipsGenInstrInfo {
|
||||
MipsTargetMachine &TM;
|
||||
bool IsN64;
|
||||
const MipsRegisterInfo RI;
|
||||
unsigned UncondBrOpc;
|
||||
public:
|
||||
explicit MipsInstrInfo(MipsTargetMachine &TM);
|
||||
|
||||
|
@ -132,6 +132,8 @@ def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
|
||||
def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
|
||||
def IsN64 : Predicate<"Subtarget.isABI_N64()">;
|
||||
def NotN64 : Predicate<"!Subtarget.isABI_N64()">;
|
||||
def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
|
||||
def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Mips Operand, Complex Patterns and Transformations Definitions.
|
||||
@ -477,6 +479,17 @@ class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
|
||||
[(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
|
||||
IIAlu>;
|
||||
|
||||
// Jump
|
||||
class JumpFJ<bits<6> op, string instr_asm>:
|
||||
FJ<op, (outs), (ins jmptarget:$target),
|
||||
!strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch> {
|
||||
let isBranch=1;
|
||||
let isTerminator=1;
|
||||
let isBarrier=1;
|
||||
let hasDelaySlot = 1;
|
||||
let Predicates = [RelocStatic];
|
||||
}
|
||||
|
||||
// Unconditional branch
|
||||
class UncondBranch<bits<6> op, string instr_asm>:
|
||||
BranchBase<op, (outs), (ins brtarget:$imm16),
|
||||
@ -487,6 +500,7 @@ class UncondBranch<bits<6> op, string instr_asm>:
|
||||
let isTerminator = 1;
|
||||
let isBarrier = 1;
|
||||
let hasDelaySlot = 1;
|
||||
let Predicates = [RelocPIC];
|
||||
}
|
||||
|
||||
let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
|
||||
@ -832,6 +846,7 @@ def SC : SCBase<0x38, "sc", CPURegs, mem>, Requires<[NotN64]>;
|
||||
def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
|
||||
|
||||
/// Jump and Branch Instructions
|
||||
def J : JumpFJ<0x02, "j">;
|
||||
def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
|
||||
def JAL : JumpLink<0x03, "jal">;
|
||||
def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
|
||||
|
Loading…
Reference in New Issue
Block a user