forked from OSchip/llvm-project
Implemented functions for emitting prologues and epilogues;
removed EBP from the list of callee-saved registers (it isn't one). llvm-svn: 4929
This commit is contained in:
parent
ab2ffedb38
commit
83e62f14dd
|
@ -58,7 +58,7 @@ unsigned X86RegisterInfo::getStackPointer() const {
|
|||
}
|
||||
|
||||
const unsigned* X86RegisterInfo::getCalleeSaveRegs() const {
|
||||
static const unsigned CalleeSaveRegs[] = { X86::ESI, X86::EDI, X86::EBX, X86::EBP,
|
||||
static const unsigned CalleeSaveRegs[] = { X86::ESI, X86::EDI, X86::EBX,
|
||||
MRegisterInfo::NoRegister };
|
||||
return CalleeSaveRegs;
|
||||
}
|
||||
|
@ -69,3 +69,56 @@ const unsigned* X86RegisterInfo::getCallerSaveRegs() const {
|
|||
MRegisterInfo::NoRegister };
|
||||
return CallerSaveRegs;
|
||||
}
|
||||
|
||||
MachineBasicBlock::iterator
|
||||
X86RegisterInfo::emitPrologue(MachineBasicBlock *MBB,
|
||||
MachineBasicBlock::iterator MBBI,
|
||||
unsigned numBytes) const
|
||||
{
|
||||
MachineInstr *MI;
|
||||
|
||||
// PUSH ebp
|
||||
MI = BuildMI (X86::PUSHr32, 1).addReg(X86::EBP);
|
||||
MBBI = ++(MBB->insert(MBBI, MI));
|
||||
|
||||
// MOV ebp, esp
|
||||
MI = BuildMI (X86::MOVrr32, 2).addReg(X86::EBP).addReg(X86::ESP);
|
||||
MBBI = ++(MBB->insert(MBBI, MI));
|
||||
|
||||
// adjust stack pointer
|
||||
MI = BuildMI(X86::SUBri32, 2).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;
|
||||
}
|
||||
|
||||
return MBBI;
|
||||
}
|
||||
|
||||
MachineBasicBlock::iterator
|
||||
X86RegisterInfo::emitEpilogue(MachineBasicBlock *MBB,
|
||||
MachineBasicBlock::iterator MBBI,
|
||||
unsigned numBytes) const
|
||||
{
|
||||
MachineInstr *MI;
|
||||
|
||||
// POP all callee-save registers in REVERSE ORDER
|
||||
static const unsigned regs[] = { X86::EBX, X86::EDI, X86::ESI,
|
||||
MRegisterInfo::NoRegister };
|
||||
unsigned idx = 0;
|
||||
while (regs[idx]) {
|
||||
MI = BuildMI(X86::POPr32, 1).addReg(regs[idx++]);
|
||||
MBBI = ++(MBB->insert(MBBI, MI));
|
||||
}
|
||||
|
||||
// insert LEAVE
|
||||
MI = BuildMI(X86::LEAVE, 0);
|
||||
MBBI = ++(MBB->insert(MBBI, MI));
|
||||
|
||||
return MBBI;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,14 @@ struct X86RegisterInfo : public MRegisterInfo {
|
|||
const unsigned* getCalleeSaveRegs() const;
|
||||
const unsigned* getCallerSaveRegs() const;
|
||||
|
||||
MachineBasicBlock::iterator emitPrologue(MachineBasicBlock *MBB,
|
||||
MachineBasicBlock::iterator MBBI,
|
||||
unsigned numBytes) const;
|
||||
|
||||
MachineBasicBlock::iterator emitEpilogue(MachineBasicBlock *MBB,
|
||||
MachineBasicBlock::iterator MBBI,
|
||||
unsigned numBytes) const;
|
||||
|
||||
/// Returns register class appropriate for input SSA register
|
||||
///
|
||||
const TargetRegisterClass *getClassForReg(unsigned Reg) const;
|
||||
|
|
Loading…
Reference in New Issue