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);
// 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,
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 };
MachineInstr *MI = BuildMI(X86::POPr32, 0, regs[idx++]);
MBBI = ++(MBB.insert(MBBI, MI));
}
-
- // insert LEAVE
- MBB.insert(MBBI, BuildMI(X86::LEAVE, 0));
}