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:
Chris Lattner 2002-12-16 22:29:30 +00:00
parent 4863fe14de
commit 3fc14c2602

View File

@ -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));
}