From: Chris Lattner Date: Mon, 16 Dec 2002 22:29:30 +0000 (+0000) Subject: Fix prolog/epilog in the presence of alloca X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3fc14c2602b37863c65c47b9e3eef1b93c4e6f40;p=llvm 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 --- diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 30095e69dcc..c96bbd86b01 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -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)); }