mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-20 10:24:12 +00:00
Emit B (unconditional branch) when -relocation-model=pic and J (jump) when
-relocation-model=static. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146432 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -29,8 +29,8 @@ using namespace llvm;
|
|||||||
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
|
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
|
||||||
: MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
|
: MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
|
||||||
TM(tm), IsN64(TM.getSubtarget<MipsSubtarget>().isABI_N64()),
|
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 {
|
const MipsRegisterInfo &MipsInstrInfo::getRegisterInfo() const {
|
||||||
return RI;
|
return RI;
|
||||||
@ -236,7 +236,8 @@ static unsigned GetAnalyzableBrOpc(unsigned Opc) {
|
|||||||
Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ ||
|
Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ ||
|
||||||
Opc == Mips::BEQ64 || Opc == Mips::BNE64 || Opc == Mips::BGTZ64 ||
|
Opc == Mips::BEQ64 || Opc == Mips::BNE64 || Opc == Mips::BGTZ64 ||
|
||||||
Opc == Mips::BGEZ64 || Opc == Mips::BLTZ64 || Opc == Mips::BLEZ64 ||
|
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;
|
Opc : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +321,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
|||||||
// If there is only one terminator instruction, process it.
|
// If there is only one terminator instruction, process it.
|
||||||
if (!SecondLastOpc) {
|
if (!SecondLastOpc) {
|
||||||
// Unconditional branch
|
// Unconditional branch
|
||||||
if (LastOpc == Mips::B) {
|
if (LastOpc == UncondBrOpc) {
|
||||||
TBB = LastInst->getOperand(0).getMBB();
|
TBB = LastInst->getOperand(0).getMBB();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -337,7 +338,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
|||||||
|
|
||||||
// If second to last instruction is an unconditional branch,
|
// If second to last instruction is an unconditional branch,
|
||||||
// analyze it and remove the last instruction.
|
// analyze it and remove the last instruction.
|
||||||
if (SecondLastOpc == Mips::B) {
|
if (SecondLastOpc == UncondBrOpc) {
|
||||||
// Return if the last instruction cannot be removed.
|
// Return if the last instruction cannot be removed.
|
||||||
if (!AllowModify)
|
if (!AllowModify)
|
||||||
return true;
|
return true;
|
||||||
@ -349,7 +350,7 @@ bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
|||||||
|
|
||||||
// Conditional branch followed by an unconditional branch.
|
// Conditional branch followed by an unconditional branch.
|
||||||
// The last one must be unconditional.
|
// The last one must be unconditional.
|
||||||
if (LastOpc != Mips::B)
|
if (LastOpc != UncondBrOpc)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
|
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
|
||||||
@ -391,14 +392,14 @@ InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|||||||
// Two-way Conditional branch.
|
// Two-way Conditional branch.
|
||||||
if (FBB) {
|
if (FBB) {
|
||||||
BuildCondBr(MBB, TBB, DL, Cond);
|
BuildCondBr(MBB, TBB, DL, Cond);
|
||||||
BuildMI(&MBB, DL, get(Mips::B)).addMBB(FBB);
|
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// One way branch.
|
// One way branch.
|
||||||
// Unconditional branch.
|
// Unconditional branch.
|
||||||
if (Cond.empty())
|
if (Cond.empty())
|
||||||
BuildMI(&MBB, DL, get(Mips::B)).addMBB(TBB);
|
BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB);
|
||||||
else // Conditional branch.
|
else // Conditional branch.
|
||||||
BuildCondBr(MBB, TBB, DL, Cond);
|
BuildCondBr(MBB, TBB, DL, Cond);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -34,6 +34,7 @@ class MipsInstrInfo : public MipsGenInstrInfo {
|
|||||||
MipsTargetMachine &TM;
|
MipsTargetMachine &TM;
|
||||||
bool IsN64;
|
bool IsN64;
|
||||||
const MipsRegisterInfo RI;
|
const MipsRegisterInfo RI;
|
||||||
|
unsigned UncondBrOpc;
|
||||||
public:
|
public:
|
||||||
explicit MipsInstrInfo(MipsTargetMachine &TM);
|
explicit MipsInstrInfo(MipsTargetMachine &TM);
|
||||||
|
|
||||||
|
@ -132,6 +132,8 @@ def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
|
|||||||
def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
|
def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
|
||||||
def IsN64 : Predicate<"Subtarget.isABI_N64()">;
|
def IsN64 : Predicate<"Subtarget.isABI_N64()">;
|
||||||
def NotN64 : 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.
|
// 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))],
|
[(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
|
||||||
IIAlu>;
|
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
|
// Unconditional branch
|
||||||
class UncondBranch<bits<6> op, string instr_asm>:
|
class UncondBranch<bits<6> op, string instr_asm>:
|
||||||
BranchBase<op, (outs), (ins brtarget:$imm16),
|
BranchBase<op, (outs), (ins brtarget:$imm16),
|
||||||
@ -487,6 +500,7 @@ class UncondBranch<bits<6> op, string instr_asm>:
|
|||||||
let isTerminator = 1;
|
let isTerminator = 1;
|
||||||
let isBarrier = 1;
|
let isBarrier = 1;
|
||||||
let hasDelaySlot = 1;
|
let hasDelaySlot = 1;
|
||||||
|
let Predicates = [RelocPIC];
|
||||||
}
|
}
|
||||||
|
|
||||||
let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
|
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]>;
|
def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
|
||||||
|
|
||||||
/// Jump and Branch Instructions
|
/// Jump and Branch Instructions
|
||||||
|
def J : JumpFJ<0x02, "j">;
|
||||||
def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
|
def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
|
||||||
def JAL : JumpLink<0x03, "jal">;
|
def JAL : JumpLink<0x03, "jal">;
|
||||||
def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
|
def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
|
||||||
|
Reference in New Issue
Block a user