mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 06:32:24 +00:00
Implemented functions for emitting prologues and epilogues;
removed EBP from the list of callee-saved registers (it isn't one). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4929 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1f283ef3e5
commit
2adb3959f6
@ -58,7 +58,7 @@ unsigned X86RegisterInfo::getStackPointer() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const unsigned* X86RegisterInfo::getCalleeSaveRegs() 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 };
|
MRegisterInfo::NoRegister };
|
||||||
return CalleeSaveRegs;
|
return CalleeSaveRegs;
|
||||||
}
|
}
|
||||||
@ -69,3 +69,56 @@ const unsigned* X86RegisterInfo::getCallerSaveRegs() const {
|
|||||||
MRegisterInfo::NoRegister };
|
MRegisterInfo::NoRegister };
|
||||||
return CallerSaveRegs;
|
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* getCalleeSaveRegs() const;
|
||||||
const unsigned* getCallerSaveRegs() 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
|
/// Returns register class appropriate for input SSA register
|
||||||
///
|
///
|
||||||
const TargetRegisterClass *getClassForReg(unsigned Reg) const;
|
const TargetRegisterClass *getClassForReg(unsigned Reg) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user