Commit 633394ce by Sagar Thakur Committed by Jim Stichnoth

[Subzero][MIPS32] Implements addEpilog for MIPS32

BUG=none R=stichnot@chromium.org Review URL: https://codereview.chromium.org/2096563004 . Patch from Sagar Thakur <sagar.thakur@imgtec.com>.
parent bf19533e
......@@ -80,6 +80,7 @@ template <> const char *InstMIPS32Divu::Opcode = "divu";
template <> const char *InstMIPS32La::Opcode = "la";
template <> const char *InstMIPS32Ldc1::Opcode = "ldc1";
template <> const char *InstMIPS32Lui::Opcode = "lui";
template <> const char *InstMIPS32Lw::Opcode = "lw";
template <> const char *InstMIPS32Lwc1::Opcode = "lwc1";
template <> const char *InstMIPS32Mfc1::Opcode = "mfc1";
template <> const char *InstMIPS32Mfhi::Opcode = "mfhi";
......
......@@ -736,7 +736,7 @@ using InstMIPS32Divu = InstMIPS32ThreeAddrGPR<InstMIPS32::Divu>;
using InstMIPS32La = InstMIPS32UnaryopGPR<InstMIPS32::La>;
using InstMIPS32Ldc1 = InstMIPS32Memory<InstMIPS32::Ldc1>;
using InstMIPS32Lui = InstMIPS32Imm16<InstMIPS32::Lui>;
using InstMIPS32Lw = InstMIPS32Memory<InstMIPS32::Lwc1>;
using InstMIPS32Lw = InstMIPS32Memory<InstMIPS32::Lw>;
using InstMIPS32Lwc1 = InstMIPS32Memory<InstMIPS32::Lwc1>;
using InstMIPS32Mfc1 = InstMIPS32TwoAddrGPR<InstMIPS32::Mfc1>;
using InstMIPS32Mfhi = InstMIPS32UnaryopGPR<InstMIPS32::Mfhi>;
......
......@@ -790,7 +790,6 @@ void TargetMIPS32::addProlog(CfgNode *Node) {
}
uint32_t NumCallee = 0;
size_t PreservedRegsSizeBytes = 0;
// RegClasses is a tuple of
//
......@@ -835,8 +834,8 @@ void TargetMIPS32::addProlog(CfgNode *Node) {
GlobalsSize + LocalsSlotsPaddingBytes;
// Adds the out args space to the stack, and align SP if necessary.
uint32_t TotalStackSizeBytes = PreservedRegsSizeBytes + SpillAreaSizeBytes +
FixedAllocaSizeBytes + MaxOutArgsSizeBytes;
TotalStackSizeBytes = PreservedRegsSizeBytes + SpillAreaSizeBytes +
FixedAllocaSizeBytes + MaxOutArgsSizeBytes;
// Generate "addiu sp, sp, -TotalStackSizeBytes"
if (TotalStackSizeBytes) {
......@@ -926,9 +925,53 @@ void TargetMIPS32::addProlog(CfgNode *Node) {
}
void TargetMIPS32::addEpilog(CfgNode *Node) {
(void)Node;
InstList &Insts = Node->getInsts();
InstList::reverse_iterator RI, E;
for (RI = Insts.rbegin(), E = Insts.rend(); RI != E; ++RI) {
if (llvm::isa<InstMIPS32Ret>(*RI))
break;
}
if (RI == E)
return;
// Convert the reverse_iterator position into its corresponding (forward)
// iterator position.
InstList::iterator InsertPoint = RI.base();
--InsertPoint;
Context.init(Node);
Context.setInsertPoint(InsertPoint);
Variable *SP = getPhysicalRegister(RegMIPS32::Reg_SP);
if (UsesFramePointer) {
Variable *FP = getPhysicalRegister(RegMIPS32::Reg_FP);
// For late-stage liveness analysis (e.g. asm-verbose mode), adding a fake
// use of SP before the assignment of SP=FP keeps previous SP adjustments
// from being dead-code eliminated.
Context.insert<InstFakeUse>(SP);
_mov(SP, FP);
}
VarList::reverse_iterator RIter, END;
if (!PreservedGPRs.empty()) {
uint32_t StackOffset = TotalStackSizeBytes - PreservedRegsSizeBytes;
for (RIter = PreservedGPRs.rbegin(), END = PreservedGPRs.rend();
RIter != END; ++RIter) {
Variable *PhysicalRegister = getPhysicalRegister((*RIter)->getRegNum());
Variable *SP = getPhysicalRegister(RegMIPS32::Reg_SP);
OperandMIPS32Mem *MemoryLocation = OperandMIPS32Mem::create(
Func, IceType_i32, SP,
llvm::cast<ConstantInteger32>(Ctx->getConstantInt32(StackOffset)));
_lw(PhysicalRegister, MemoryLocation);
StackOffset += typeWidthInBytesOnStack(PhysicalRegister->getType());
}
}
if (TotalStackSizeBytes) {
_addiu(SP, SP, TotalStackSizeBytes);
}
return;
UnimplementedError(getFlags());
}
Operand *TargetMIPS32::loOperand(Operand *Operand) {
......
......@@ -234,6 +234,10 @@ public:
Context.insert<InstMIPS32Ldc1>(Value, Mem);
}
void _lw(Variable *Value, OperandMIPS32Mem *Mem) {
Context.insert<InstMIPS32Lw>(Value, Mem);
}
void _lwc1(Variable *Value, OperandMIPS32Mem *Mem) {
Context.insert<InstMIPS32Lwc1>(Value, Mem);
}
......@@ -555,6 +559,7 @@ protected:
bool MaybeLeafFunc = true;
bool PrologEmitsFixedAllocas = false;
uint32_t MaxOutArgsSizeBytes = 0;
uint32_t TotalStackSizeBytes = 0;
static SmallBitVector TypeToRegisterSet[RCMIPS32_NUM];
static SmallBitVector TypeToRegisterSetUnfiltered[RCMIPS32_NUM];
static SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM];
......@@ -566,6 +571,7 @@ protected:
size_t SpillAreaSizeBytes = 0;
size_t FixedAllocaSizeBytes = 0;
size_t FixedAllocaAlignBytes = 0;
size_t PreservedRegsSizeBytes = 0;
private:
ENABLE_MAKE_UNIQUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment