1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Cleaning up of prologue/epilogue code for Mips16. First step

here is to make save/restore into variable number of argument instructions.

llvm-svn: 196726
This commit is contained in:
Reed Kotler 2013-12-08 16:51:52 +00:00
parent 2ef97554d8
commit cba0ad1234
8 changed files with 59 additions and 39 deletions

View File

@ -83,6 +83,19 @@ void MipsInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
case Mips::RDHWR64: case Mips::RDHWR64:
O << "\t.set\tpush\n"; O << "\t.set\tpush\n";
O << "\t.set\tmips32r2\n"; O << "\t.set\tmips32r2\n";
break;
case Mips::Save16:
case Mips::SaveX16:
O << "\tsave\t";
printSaveRestore(MI, O);
O << "\n";
return;
case Mips::Restore16:
case Mips::RestoreX16:
O << "\trestore\t";
printSaveRestore(MI, O);
O << "\n";
return;
} }
// Try to print any aliases first. // Try to print any aliases first.
@ -286,3 +299,14 @@ bool MipsInstPrinter::printAlias(const MCInst &MI, raw_ostream &OS) {
default: return false; default: return false;
} }
} }
void MipsInstPrinter::printSaveRestore(const MCInst *MI, raw_ostream &O) {
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
if (i != 0) O << ", ";
if (MI->getOperand(i).isReg())
printRegName(O, MI->getOperand(i).getReg());
else
printUnsignedImm(MI, i, O);
}
}

View File

@ -104,6 +104,7 @@ private:
bool printAlias(const char *Str, const MCInst &MI, unsigned OpNo0, bool printAlias(const char *Str, const MCInst &MI, unsigned OpNo0,
unsigned OpNo1, raw_ostream &OS); unsigned OpNo1, raw_ostream &OS);
bool printAlias(const MCInst &MI, raw_ostream &OS); bool printAlias(const MCInst &MI, raw_ostream &OS);
void printSaveRestore(const MCInst *MI, raw_ostream &O);
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -182,12 +182,17 @@ void Mips16InstrInfo::makeFrame(unsigned SP, int64_t FrameSize,
DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc(); DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
if (!NeverUseSaveRestore) { if (!NeverUseSaveRestore) {
if (isUInt<11>(FrameSize)) if (isUInt<11>(FrameSize))
BuildMI(MBB, I, DL, get(Mips::SaveRaF16)).addImm(FrameSize); //BuildMI(MBB, I, DL, get(Mips::SaveRaF16)).addImm(FrameSize);
BuildMI(MBB, I, DL, get(Mips::SaveX16)).addReg(Mips::RA).
addReg(Mips::S0).
addReg(Mips::S1).addReg(Mips::S2).addImm(FrameSize);
else { else {
int Base = 2040; // should create template function like isUInt that int Base = 2040; // should create template function like isUInt that
// returns largest possible n bit unsigned integer // returns largest possible n bit unsigned integer
int64_t Remainder = FrameSize - Base; int64_t Remainder = FrameSize - Base;
BuildMI(MBB, I, DL, get(Mips::SaveRaF16)). addImm(Base); BuildMI(MBB, I, DL, get(Mips::SaveX16)).addReg(Mips::RA).
addReg(Mips::S0).
addReg(Mips::S1).addReg(Mips::S2).addImm(Base);
if (isInt<16>(-Remainder)) if (isInt<16>(-Remainder))
BuildAddiuSpImm(MBB, I, -Remainder); BuildAddiuSpImm(MBB, I, -Remainder);
else else
@ -224,7 +229,9 @@ void Mips16InstrInfo::restoreFrame(unsigned SP, int64_t FrameSize,
DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc(); DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc();
if (!NeverUseSaveRestore) { if (!NeverUseSaveRestore) {
if (isUInt<11>(FrameSize)) if (isUInt<11>(FrameSize))
BuildMI(MBB, I, DL, get(Mips::RestoreRaF16)).addImm(FrameSize); BuildMI(MBB, I, DL, get(Mips::RestoreX16)).addReg(Mips::RA).
addReg(Mips::S0).
addReg(Mips::S1).addReg(Mips::S2).addImm(FrameSize);
else { else {
int Base = 2040; // should create template function like isUInt that int Base = 2040; // should create template function like isUInt that
// returns largest possible n bit unsigned integer // returns largest possible n bit unsigned integer
@ -233,7 +240,9 @@ void Mips16InstrInfo::restoreFrame(unsigned SP, int64_t FrameSize,
BuildAddiuSpImm(MBB, I, Remainder); BuildAddiuSpImm(MBB, I, Remainder);
else else
adjustStackPtrBig(SP, Remainder, MBB, I, Mips::A0, Mips::A1); adjustStackPtrBig(SP, Remainder, MBB, I, Mips::A0, Mips::A1);
BuildMI(MBB, I, DL, get(Mips::RestoreRaF16)). addImm(Base); BuildMI(MBB, I, DL, get(Mips::RestoreX16)).addReg(Mips::RA).
addReg(Mips::S0).
addReg(Mips::S1).addReg(Mips::S2).addImm(Base);
} }
} }
else { else {

View File

@ -957,26 +957,18 @@ def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
// stack // stack
// //
// fixed form for restoring RA and the frame def Restore16:
// for direct object emitter, encoding needs to be adjusted for the FI8_SVRS16<0b1, (outs), (ins variable_ops),
// frame size "", [], IILoad >, MayLoad {
//
let ra=1, s=0,s0=1,s1=1 in
def RestoreRaF16:
FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
"restore\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IILoad >, MayLoad {
let isCodeGenOnly = 1; let isCodeGenOnly = 1;
let Defs = [S0, S1, S2, RA, SP]; let Defs = [SP];
let Uses = [SP]; let Uses = [SP];
} }
// Use Restore to increment SP since SP is not a Mip 16 register, this
// is an easy way to do that which does not require a register. def RestoreX16:
// FI8_SVRS16<0b1, (outs), (ins variable_ops),
let ra=0, s=0,s0=0,s1=0 in "", [], IILoad >, MayLoad {
def RestoreIncSpF16:
FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
"restore\t$frame_size", [], IILoad >, MayLoad {
let isCodeGenOnly = 1; let isCodeGenOnly = 1;
let Defs = [SP]; let Defs = [SP];
let Uses = [SP]; let Uses = [SP];
@ -989,23 +981,17 @@ def RestoreIncSpF16:
// To set up a stack frame on entry to a subroutine, // To set up a stack frame on entry to a subroutine,
// saving return address and static registers, and adjusting stack // saving return address and static registers, and adjusting stack
// //
let ra=1, s=1,s0=1,s1=1 in def Save16:
def SaveRaF16: FI8_SVRS16<0b1, (outs), (ins variable_ops),
FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size), "", [], IIStore >, MayStore {
"save\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IIStore >, MayStore {
let isCodeGenOnly = 1; let isCodeGenOnly = 1;
let Uses = [RA, SP, S0, S1, S2]; let Uses = [SP];
let Defs = [SP]; let Defs = [SP];
} }
// def SaveX16:
// Use Save to decrement the SP by a constant since SP is not FI8_SVRS16<0b1, (outs), (ins variable_ops),
// a Mips16 register. "", [], IIStore >, MayStore {
//
let ra=0, s=0,s0=0,s1=0 in
def SaveDecSpF16:
FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
"save\t$frame_size", [], IIStore >, MayStore {
let isCodeGenOnly = 1; let isCodeGenOnly = 1;
let Uses = [SP]; let Uses = [SP];
let Defs = [SP]; let Defs = [SP];

View File

@ -25,7 +25,7 @@ entry:
call void @p(i32* %arrayidx1) call void @p(i32* %arrayidx1)
ret void ret void
} }
; 16: save $ra, $s0, $s1, $s2, 2040 ; 16: save $ra, $16, $17, $18, 2040
; 16: addiu $sp, -56 # 16 bit inst ; 16: addiu $sp, -56 # 16 bit inst
; 16: addiu $sp, 56 # 16 bit inst ; 16: addiu $sp, 56 # 16 bit inst
; 16: restore $ra, $s0, $s1, $s2, 2040 ; 16: restore $ra, $16, $17, $18, 2040

View File

@ -20,7 +20,7 @@ entry:
define void @test() nounwind { define void @test() nounwind {
entry: entry:
; 16: .frame $sp,24,$ra ; 16: .frame $sp,24,$ra
; 16: save $ra, $s0, $s1, $s2, 24 ; 16: save $ra, $16, $17, $18, 24
; 16: move $16, $sp ; 16: move $16, $sp
; 16: move ${{[0-9]+}}, $sp ; 16: move ${{[0-9]+}}, $sp
; 16: subu $[[REGISTER:[0-9]+]], ${{[0-9]+}}, ${{[0-9]+}} ; 16: subu $[[REGISTER:[0-9]+]], ${{[0-9]+}}, ${{[0-9]+}}

View File

@ -6,7 +6,7 @@
define i32 @main() { define i32 @main() {
; 16-LABEL: main: ; 16-LABEL: main:
; 16: .cfi_startproc ; 16: .cfi_startproc
; 16: save $ra, $s0, $s1, $s2, 40 ; 16: save $ra, $16, $17, $18, 40
; 16: .cfi_def_cfa_offset 40 ; 16: .cfi_def_cfa_offset 40
; 16: .cfi_offset 18, -8 ; 16: .cfi_offset 18, -8
; 16: .cfi_offset 17, -12 ; 16: .cfi_offset 17, -12

View File

@ -25,7 +25,7 @@ entry:
; SR32: .set noreorder ; SR32: .set noreorder
; SR32: .set nomacro ; SR32: .set nomacro
; SR32: .set noat ; SR32: .set noat
; SR: save $ra, $s0, $s1, $s2, [[FS:[0-9]+]] ; SR: save $ra, $16, $17, $18, [[FS:[0-9]+]]
; PE: .ent main ; PE: .ent main
; PE: .align 2 ; PE: .align 2
; PE-NEXT: li $[[T1:[0-9]+]], %hi(_gp_disp) ; PE-NEXT: li $[[T1:[0-9]+]], %hi(_gp_disp)
@ -37,7 +37,7 @@ entry:
; C2: move $25, ${{[0-9]+}} ; C2: move $25, ${{[0-9]+}}
; C1: move $gp, ${{[0-9]+}} ; C1: move $gp, ${{[0-9]+}}
; C1: jalrc ${{[0-9]+}} ; C1: jalrc ${{[0-9]+}}
; SR: restore $ra, $s0, $s1, $s2, [[FS]] ; SR: restore $ra, $16, $17, $18, [[FS]]
; PE: li $2, 0 ; PE: li $2, 0
; PE: jrc $ra ; PE: jrc $ra