mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-26 12:20:42 +00:00
[mips][mips64r6] Use JALR for returns instead of JR (which is not available on MIPS32r6/MIPS64r6)
Summary:
RET, and RET_MM have been replaced by a pseudo named PseudoReturn.
In addition a version with a 64-bit GPR named PseudoReturn64 has been
added.
Instruction selection for a return matches RetRA, which is expanded post
register allocation to PseudoReturn/PseudoReturn64. During MipsAsmPrinter,
this PseudoReturn/PseudoReturn64 are emitted as:
- (JALR64 $zero, $rs) on MIPS64r6
- (JALR $zero, $rs) on MIPS32r6
- (JR_MM $rs) on microMIPS
- (JR $rs) otherwise
On MIPS32r6/MIPS64r6, 'jr $rs' is an alias for 'jalr $zero, $rs'. To aid
development and review (specifically, to ensure all cases of jr are
updated), these aliases are temporarily named 'r6.jr' instead of 'jr'.
A follow up patch will change them back to the correct mnemonic.
Added (JALR $zero, $rs) to MipsNaClELFStreamer's definition of an indirect
jump, and removed it from its definition of a call.
Note: I haven't accounted for MIPS64 in MipsNaClELFStreamer since it's
doesn't appear to account for any MIPS64-specifics.
The return instruction created as part of eh_return expansion is now expanded
using expandRetRA() so we use the right return instruction on MIPS32r6/MIPS64r6
('jalr $zero, $rs').
Also, fixed a misuse of isABI_N64() to detect 64-bit wide registers in
expandEhReturn().
Reviewers: jkolek, vmedic, mseaborn, zoran.jovanovic, dsanders
Reviewed By: dsanders
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D4268
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -91,6 +91,42 @@ bool MipsAsmPrinter::lowerOperand(const MachineOperand &MO, MCOperand &MCOp) {
|
||||
|
||||
#include "MipsGenMCPseudoLowering.inc"
|
||||
|
||||
void MipsAsmPrinter::emitPseudoReturn(MCStreamer &OutStreamer,
|
||||
const MachineInstr *MI) {
|
||||
// Lower PseudoReturn to JR, JR_MM, JALR, or JALR64 as appropriate for the
|
||||
// target
|
||||
bool HasLinkReg = false;
|
||||
MCInst TmpInst0;
|
||||
|
||||
if (Subtarget->hasMips64r6()) {
|
||||
// MIPS64r6 should use (JALR64 ZERO_64, $rs)
|
||||
TmpInst0.setOpcode(Mips::JALR64);
|
||||
HasLinkReg = true;
|
||||
} else if (Subtarget->hasMips32r6()) {
|
||||
// MIPS32r6 should use (JALR ZERO, $rs)
|
||||
TmpInst0.setOpcode(Mips::JALR);
|
||||
HasLinkReg = true;
|
||||
} else if (Subtarget->inMicroMipsMode())
|
||||
// microMIPS should use (JR_MM $rs)
|
||||
TmpInst0.setOpcode(Mips::JR_MM);
|
||||
else {
|
||||
// Everything else should use (JR $rs)
|
||||
TmpInst0.setOpcode(Mips::JR);
|
||||
}
|
||||
|
||||
MCOperand MCOp;
|
||||
|
||||
if (HasLinkReg) {
|
||||
unsigned ZeroReg = Subtarget->isGP64bit() ? Mips::ZERO_64 : Mips::ZERO;
|
||||
TmpInst0.addOperand(MCOperand::CreateReg(ZeroReg));
|
||||
}
|
||||
|
||||
lowerOperand(MI->getOperand(0), MCOp);
|
||||
TmpInst0.addOperand(MCOp);
|
||||
|
||||
EmitToStreamer(OutStreamer, TmpInst0);
|
||||
}
|
||||
|
||||
void MipsAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||
MipsTargetStreamer &TS = getTargetStreamer();
|
||||
TS.setCanHaveModuleDir(false);
|
||||
@@ -144,6 +180,12 @@ void MipsAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||
if (emitPseudoExpansionLowering(OutStreamer, &*I))
|
||||
continue;
|
||||
|
||||
if (I->getOpcode() == Mips::PseudoReturn ||
|
||||
I->getOpcode() == Mips::PseudoReturn64) {
|
||||
emitPseudoReturn(OutStreamer, &*I);
|
||||
continue;
|
||||
}
|
||||
|
||||
// The inMips16Mode() test is not permanent.
|
||||
// Some instructions are marked as pseudo right now which
|
||||
// would make the test fail for the wrong reason but
|
||||
|
||||
Reference in New Issue
Block a user