mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-05 13:09:10 +00:00
Fix prolog/epilog in the presence of alloca
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5087 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4863fe14de
commit
3fc14c2602
@ -117,6 +117,14 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
||||
MachineBasicBlock::iterator MBBI = MBB.begin();
|
||||
|
||||
// PUSH all callee-save registers
|
||||
const unsigned* regs = getCalleeSaveRegs();
|
||||
while (*regs) {
|
||||
MachineInstr *MI = BuildMI(X86::PUSHr32, 1).addReg(*regs);
|
||||
MBBI = ++MBB.insert(MBBI, MI);
|
||||
++regs;
|
||||
}
|
||||
|
||||
// PUSH ebp
|
||||
MachineInstr *MI = BuildMI(X86::PUSHr32, 1).addReg(X86::EBP);
|
||||
MBBI = ++MBB.insert(MBBI, MI);
|
||||
@ -128,14 +136,6 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF,
|
||||
// adjust stack pointer: ESP -= numbytes
|
||||
MI = BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(numBytes);
|
||||
MBBI = ++MBB.insert(MBBI, MI);
|
||||
|
||||
// PUSH all callee-save registers
|
||||
const unsigned* regs = getCalleeSaveRegs();
|
||||
while (*regs) {
|
||||
MI = BuildMI(X86::PUSHr32, 1).addReg(*regs);
|
||||
MBBI = ++MBB.insert(MBBI, MI);
|
||||
++regs;
|
||||
}
|
||||
}
|
||||
|
||||
void X86RegisterInfo::emitEpilogue(MachineBasicBlock &MBB,
|
||||
@ -144,6 +144,9 @@ void X86RegisterInfo::emitEpilogue(MachineBasicBlock &MBB,
|
||||
assert((*MBBI)->getOpcode() == X86::RET &&
|
||||
"Can only insert epilog into returning blocks");
|
||||
|
||||
// insert LEAVE
|
||||
MBBI = ++MBB.insert(MBBI, BuildMI(X86::LEAVE, 0));
|
||||
|
||||
// POP all callee-save registers in REVERSE ORDER
|
||||
static const unsigned regs[] = { X86::EBX, X86::EDI, X86::ESI,
|
||||
MRegisterInfo::NoRegister };
|
||||
@ -152,7 +155,4 @@ void X86RegisterInfo::emitEpilogue(MachineBasicBlock &MBB,
|
||||
MachineInstr *MI = BuildMI(X86::POPr32, 0, regs[idx++]);
|
||||
MBBI = ++(MBB.insert(MBBI, MI));
|
||||
}
|
||||
|
||||
// insert LEAVE
|
||||
MBB.insert(MBBI, BuildMI(X86::LEAVE, 0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user