112 lines
3.5 KiB
C++
112 lines
3.5 KiB
C++
#include "FootFrameLowering.h"
|
|
|
|
#include "MCTargetDesc/FootMCTargetDesc.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
|
|
|
using namespace llvm;
|
|
|
|
bool FootFrameLowering::hasFPImpl(const MachineFunction& MF) const {
|
|
return false;
|
|
}
|
|
|
|
void FootFrameLowering::emitPrologue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const {
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
int FrameIndex = MFI.CreateFixedObject(4, -4, true);
|
|
|
|
unsigned NumBytes = MFI.getStackSize();
|
|
|
|
if (NumBytes > 0) {
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
if (NumBytes < (1 << 5)) {
|
|
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::SUBT_D_D_M_A), Foot::RSP)
|
|
.addReg(Foot::RSP)
|
|
.addImm(NumBytes);
|
|
}
|
|
else {
|
|
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::SUBT_D_D_D_A), Foot::RSP)
|
|
.addReg(Foot::RSP)
|
|
.addReg(Foot::R27);
|
|
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::CNST_D_A), Foot::R27)
|
|
.addImm(NumBytes);
|
|
}
|
|
}
|
|
|
|
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::BWOR_I_D_M_A))
|
|
.addFrameIndex(FrameIndex)
|
|
.addReg(Foot::RRA)
|
|
.addImm(0);
|
|
}
|
|
|
|
void FootFrameLowering::emitEpilogue(MachineFunction &MF,
|
|
MachineBasicBlock &MBB) const {
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
unsigned NumBytes = MFI.getStackSize();
|
|
|
|
if (NumBytes > 0) {
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
if (NumBytes < (1 << 5)) {
|
|
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_M_A), Foot::RSP)
|
|
.addReg(Foot::RSP)
|
|
.addImm(NumBytes);
|
|
}
|
|
else {
|
|
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_D_A), Foot::RSP)
|
|
.addReg(Foot::RSP)
|
|
.addReg(Foot::R27);
|
|
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::CNST_D_A), Foot::R27)
|
|
.addImm(NumBytes);
|
|
}
|
|
}
|
|
|
|
const auto& I = MBB.getFirstTerminator();
|
|
BuildMI(MBB, I, I->getDebugLoc(), TII->get(Foot::BWOR_D_I_M_A))
|
|
.addReg(Foot::RPC)
|
|
.addFrameIndex(0)
|
|
.addImm(0);
|
|
|
|
MBB.erase(I);
|
|
}
|
|
|
|
MachineBasicBlock::iterator FootFrameLowering::eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MI) const {
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
assert(hasReservedCallFrame(MF) && "Foot doesn't have an FP register");
|
|
|
|
if (Opc != TII->getCallFrameSetupOpcode() &&
|
|
Opc != TII->getCallFrameDestroyOpcode()) {
|
|
report_fatal_error("Unexpected frame psuedo instruction");
|
|
}
|
|
|
|
if (MI->getOperand(1).getImm() != 0) {
|
|
report_fatal_error("callee pop count not supported");
|
|
}
|
|
|
|
return MBB.erase(MI);
|
|
}
|
|
|
|
StackOffset FootFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FrameIndex,
|
|
Register &FrameReg) const {
|
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
|
|
|
int Offset = MFI.getObjectSize(FrameIndex) + getOffsetOfLocalArea() +
|
|
MFI.getStackSize();
|
|
|
|
if (hasFP(MF)) {
|
|
llvm_unreachable("foot has no frame pointer");
|
|
}
|
|
|
|
FrameReg = Foot::RSP;
|
|
|
|
return StackOffset::getFixed(Offset);
|
|
}
|