2012-02-18 20:03:15 +08:00
|
|
|
//===-- MSP430FrameLowering.cpp - MSP430 Frame Information ----------------===//
|
2010-11-15 08:06:54 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-11-15 08:06:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-01-10 20:39:04 +08:00
|
|
|
// This file contains the MSP430 implementation of TargetFrameLowering class.
|
2010-11-15 08:06:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
#include "MSP430FrameLowering.h"
|
2010-11-15 08:06:54 +08:00
|
|
|
#include "MSP430InstrInfo.h"
|
|
|
|
#include "MSP430MachineFunctionInfo.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "MSP430Subtarget.h"
|
2010-11-15 08:06:54 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2010-11-15 08:06:54 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
bool MSP430FrameLowering::hasFP(const MachineFunction &MF) const {
|
2016-07-29 02:40:00 +08:00
|
|
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
2010-11-19 05:19:35 +08:00
|
|
|
|
2011-12-03 06:16:29 +08:00
|
|
|
return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
|
2016-07-29 02:40:00 +08:00
|
|
|
MF.getFrameInfo().hasVarSizedObjects() ||
|
|
|
|
MFI.isFrameAddressTaken());
|
2010-11-19 05:19:35 +08:00
|
|
|
}
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
bool MSP430FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
|
2016-07-29 02:40:00 +08:00
|
|
|
return !MF.getFrameInfo().hasVarSizedObjects();
|
2010-11-19 05:19:35 +08:00
|
|
|
}
|
|
|
|
|
[ShrinkWrap] Add (a simplified version) of shrink-wrapping.
This patch introduces a new pass that computes the safe point to insert the
prologue and epilogue of the function.
The interest is to find safe points that are cheaper than the entry and exits
blocks.
As an example and to avoid regressions to be introduce, this patch also
implements the required bits to enable the shrink-wrapping pass for AArch64.
** Context **
Currently we insert the prologue and epilogue of the method/function in the
entry and exits blocks. Although this is correct, we can do a better job when
those are not immediately required and insert them at less frequently executed
places.
The job of the shrink-wrapping pass is to identify such places.
** Motivating example **
Let us consider the following function that perform a call only in one branch of
a if:
define i32 @f(i32 %a, i32 %b) {
%tmp = alloca i32, align 4
%tmp2 = icmp slt i32 %a, %b
br i1 %tmp2, label %true, label %false
true:
store i32 %a, i32* %tmp, align 4
%tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
br label %false
false:
%tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
ret i32 %tmp.0
}
On AArch64 this code generates (removing the cfi directives to ease
readabilities):
_f: ; @f
; BB#0:
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #16 ; =16
cmp w0, w1
b.ge LBB0_2
; BB#1: ; %true
stur w0, [x29, #-4]
sub x1, x29, #4 ; =4
mov w0, wzr
bl _doSomething
LBB0_2: ; %false
mov sp, x29
ldp x29, x30, [sp], #16
ret
With shrink-wrapping we could generate:
_f: ; @f
; BB#0:
cmp w0, w1
b.ge LBB0_2
; BB#1: ; %true
stp x29, x30, [sp, #-16]!
mov x29, sp
sub sp, sp, #16 ; =16
stur w0, [x29, #-4]
sub x1, x29, #4 ; =4
mov w0, wzr
bl _doSomething
add sp, x29, #16 ; =16
ldp x29, x30, [sp], #16
LBB0_2: ; %false
ret
Therefore, we would pay the overhead of setting up/destroying the frame only if
we actually do the call.
** Proposed Solution **
This patch introduces a new machine pass that perform the shrink-wrapping
analysis (See the comments at the beginning of ShrinkWrap.cpp for more details).
It then stores the safe save and restore point into the MachineFrameInfo
attached to the MachineFunction.
This information is then used by the PrologEpilogInserter (PEI) to place the
related code at the right place. This pass runs right before the PEI.
Unlike the original paper of Chow from PLDI’88, this implementation of
shrink-wrapping does not use expensive data-flow analysis and does not need hack
to properly avoid frequently executed point. Instead, it relies on dominance and
loop properties.
The pass is off by default and each target can opt-in by setting the
EnableShrinkWrap boolean to true in their derived class of TargetPassConfig.
This setting can also be overwritten on the command line by using
-enable-shrink-wrap.
Before you try out the pass for your target, make sure you properly fix your
emitProlog/emitEpilog/adjustForXXX method to cope with basic blocks that are not
necessarily the entry block.
** Design Decisions **
1. ShrinkWrap is its own pass right now. It could frankly be merged into PEI but
for debugging and clarity I thought it was best to have its own file.
2. Right now, we only support one save point and one restore point. At some
point we can expand this to several save point and restore point, the impacted
component would then be:
- The pass itself: New algorithm needed.
- MachineFrameInfo: Hold a list or set of Save/Restore point instead of one
pointer.
- PEI: Should loop over the save point and restore point.
Anyhow, at least for this first iteration, I do not believe this is interesting
to support the complex cases. We should revisit that when we motivating
examples.
Differential Revision: http://reviews.llvm.org/D9210
<rdar://problem/3201744>
llvm-svn: 236507
2015-05-06 01:38:16 +08:00
|
|
|
void MSP430FrameLowering::emitPrologue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
|
|
|
assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
|
2016-07-29 02:40:00 +08:00
|
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
2010-11-15 08:06:54 +08:00
|
|
|
MSP430MachineFunctionInfo *MSP430FI = MF.getInfo<MSP430MachineFunctionInfo>();
|
|
|
|
const MSP430InstrInfo &TII =
|
2014-08-05 10:39:49 +08:00
|
|
|
*static_cast<const MSP430InstrInfo *>(MF.getSubtarget().getInstrInfo());
|
2010-11-15 08:06:54 +08:00
|
|
|
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
|
|
|
|
|
|
|
// Get the number of bytes to allocate from the FrameInfo.
|
2016-07-29 02:40:00 +08:00
|
|
|
uint64_t StackSize = MFI.getStackSize();
|
2010-11-15 08:06:54 +08:00
|
|
|
|
|
|
|
uint64_t NumBytes = 0;
|
2010-11-19 05:19:35 +08:00
|
|
|
if (hasFP(MF)) {
|
2010-11-15 08:06:54 +08:00
|
|
|
// Calculate required stack adjustment
|
|
|
|
uint64_t FrameSize = StackSize - 2;
|
|
|
|
NumBytes = FrameSize - MSP430FI->getCalleeSavedFrameSize();
|
|
|
|
|
|
|
|
// Get the offset of the stack slot for the EBP register... which is
|
|
|
|
// guaranteed to be the last slot by processFunctionBeforeFrameFinalized.
|
|
|
|
// Update the frame offset adjustment.
|
2016-07-29 02:40:00 +08:00
|
|
|
MFI.setOffsetAdjustment(-NumBytes);
|
2010-11-15 08:06:54 +08:00
|
|
|
|
2014-09-10 14:58:14 +08:00
|
|
|
// Save FP into the appropriate stack slot...
|
2010-11-15 08:06:54 +08:00
|
|
|
BuildMI(MBB, MBBI, DL, TII.get(MSP430::PUSH16r))
|
2020-06-26 20:32:01 +08:00
|
|
|
.addReg(MSP430::R4, RegState::Kill);
|
2010-11-15 08:06:54 +08:00
|
|
|
|
2014-09-10 14:58:14 +08:00
|
|
|
// Update FP with the new base value...
|
2020-06-26 20:32:01 +08:00
|
|
|
BuildMI(MBB, MBBI, DL, TII.get(MSP430::MOV16rr), MSP430::R4)
|
2014-09-10 14:58:14 +08:00
|
|
|
.addReg(MSP430::SP);
|
2010-11-15 08:06:54 +08:00
|
|
|
|
|
|
|
// Mark the FramePtr as live-in in every block except the entry.
|
2014-03-02 20:27:27 +08:00
|
|
|
for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
|
2010-11-15 08:06:54 +08:00
|
|
|
I != E; ++I)
|
2020-06-26 20:32:01 +08:00
|
|
|
I->addLiveIn(MSP430::R4);
|
2010-11-15 08:06:54 +08:00
|
|
|
|
|
|
|
} else
|
|
|
|
NumBytes = StackSize - MSP430FI->getCalleeSavedFrameSize();
|
|
|
|
|
|
|
|
// Skip the callee-saved push instructions.
|
|
|
|
while (MBBI != MBB.end() && (MBBI->getOpcode() == MSP430::PUSH16r))
|
|
|
|
++MBBI;
|
|
|
|
|
|
|
|
if (MBBI != MBB.end())
|
|
|
|
DL = MBBI->getDebugLoc();
|
|
|
|
|
2014-09-10 14:58:14 +08:00
|
|
|
if (NumBytes) { // adjust stack pointer: SP -= numbytes
|
|
|
|
// If there is an SUB16ri of SP immediately before this instruction, merge
|
2010-11-15 08:06:54 +08:00
|
|
|
// the two.
|
|
|
|
//NumBytes -= mergeSPUpdates(MBB, MBBI, true);
|
2014-09-10 14:58:14 +08:00
|
|
|
// If there is an ADD16ri or SUB16ri of SP immediately after this
|
2010-11-15 08:06:54 +08:00
|
|
|
// instruction, merge the two instructions.
|
|
|
|
// mergeSPUpdatesDown(MBB, MBBI, &NumBytes);
|
|
|
|
|
|
|
|
if (NumBytes) {
|
|
|
|
MachineInstr *MI =
|
2014-09-10 14:58:14 +08:00
|
|
|
BuildMI(MBB, MBBI, DL, TII.get(MSP430::SUB16ri), MSP430::SP)
|
|
|
|
.addReg(MSP430::SP).addImm(NumBytes);
|
2010-11-15 08:06:54 +08:00
|
|
|
// The SRW implicit def is dead.
|
|
|
|
MI->getOperand(3).setIsDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
void MSP430FrameLowering::emitEpilogue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
2016-07-29 02:40:00 +08:00
|
|
|
const MachineFrameInfo &MFI = MF.getFrameInfo();
|
2010-11-15 08:06:54 +08:00
|
|
|
MSP430MachineFunctionInfo *MSP430FI = MF.getInfo<MSP430MachineFunctionInfo>();
|
|
|
|
const MSP430InstrInfo &TII =
|
2014-08-05 10:39:49 +08:00
|
|
|
*static_cast<const MSP430InstrInfo *>(MF.getSubtarget().getInstrInfo());
|
2010-11-15 08:06:54 +08:00
|
|
|
|
2011-01-14 05:28:52 +08:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
|
2010-11-15 08:06:54 +08:00
|
|
|
unsigned RetOpcode = MBBI->getOpcode();
|
|
|
|
DebugLoc DL = MBBI->getDebugLoc();
|
|
|
|
|
|
|
|
switch (RetOpcode) {
|
|
|
|
case MSP430::RET:
|
|
|
|
case MSP430::RETI: break; // These are ok
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Can only insert epilog into returning blocks");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the number of bytes to allocate from the FrameInfo
|
2016-07-29 02:40:00 +08:00
|
|
|
uint64_t StackSize = MFI.getStackSize();
|
2010-11-15 08:06:54 +08:00
|
|
|
unsigned CSSize = MSP430FI->getCalleeSavedFrameSize();
|
|
|
|
uint64_t NumBytes = 0;
|
|
|
|
|
2010-11-19 05:19:35 +08:00
|
|
|
if (hasFP(MF)) {
|
2010-11-15 08:06:54 +08:00
|
|
|
// Calculate required stack adjustment
|
|
|
|
uint64_t FrameSize = StackSize - 2;
|
|
|
|
NumBytes = FrameSize - CSSize;
|
|
|
|
|
2014-09-10 14:58:14 +08:00
|
|
|
// pop FP.
|
2020-06-26 20:32:01 +08:00
|
|
|
BuildMI(MBB, MBBI, DL, TII.get(MSP430::POP16r), MSP430::R4);
|
2010-11-15 08:06:54 +08:00
|
|
|
} else
|
|
|
|
NumBytes = StackSize - CSSize;
|
|
|
|
|
|
|
|
// Skip the callee-saved pop instructions.
|
|
|
|
while (MBBI != MBB.begin()) {
|
2014-03-02 20:27:27 +08:00
|
|
|
MachineBasicBlock::iterator PI = std::prev(MBBI);
|
2010-11-15 08:06:54 +08:00
|
|
|
unsigned Opc = PI->getOpcode();
|
2011-12-07 15:15:52 +08:00
|
|
|
if (Opc != MSP430::POP16r && !PI->isTerminator())
|
2010-11-15 08:06:54 +08:00
|
|
|
break;
|
|
|
|
--MBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
DL = MBBI->getDebugLoc();
|
|
|
|
|
2014-09-10 14:58:14 +08:00
|
|
|
// If there is an ADD16ri or SUB16ri of SP immediately before this
|
2010-11-15 08:06:54 +08:00
|
|
|
// instruction, merge the two instructions.
|
2016-07-29 02:40:00 +08:00
|
|
|
//if (NumBytes || MFI.hasVarSizedObjects())
|
2010-11-15 08:06:54 +08:00
|
|
|
// mergeSPUpdatesUp(MBB, MBBI, StackPtr, &NumBytes);
|
|
|
|
|
2016-07-29 02:40:00 +08:00
|
|
|
if (MFI.hasVarSizedObjects()) {
|
2010-11-15 08:06:54 +08:00
|
|
|
BuildMI(MBB, MBBI, DL,
|
2020-06-26 20:32:01 +08:00
|
|
|
TII.get(MSP430::MOV16rr), MSP430::SP).addReg(MSP430::R4);
|
2010-11-15 08:06:54 +08:00
|
|
|
if (CSSize) {
|
|
|
|
MachineInstr *MI =
|
|
|
|
BuildMI(MBB, MBBI, DL,
|
2014-09-10 14:58:14 +08:00
|
|
|
TII.get(MSP430::SUB16ri), MSP430::SP)
|
|
|
|
.addReg(MSP430::SP).addImm(CSSize);
|
2010-11-15 08:06:54 +08:00
|
|
|
// The SRW implicit def is dead.
|
|
|
|
MI->getOperand(3).setIsDead();
|
|
|
|
}
|
|
|
|
} else {
|
2014-09-10 14:58:14 +08:00
|
|
|
// adjust stack pointer back: SP += numbytes
|
2010-11-15 08:06:54 +08:00
|
|
|
if (NumBytes) {
|
|
|
|
MachineInstr *MI =
|
2014-09-10 14:58:14 +08:00
|
|
|
BuildMI(MBB, MBBI, DL, TII.get(MSP430::ADD16ri), MSP430::SP)
|
|
|
|
.addReg(MSP430::SP).addImm(NumBytes);
|
2010-11-15 08:06:54 +08:00
|
|
|
// The SRW implicit def is dead.
|
|
|
|
MI->getOperand(3).setIsDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-28 07:05:03 +08:00
|
|
|
|
|
|
|
// FIXME: Can we eleminate these in favour of generic code?
|
2020-02-08 19:14:37 +08:00
|
|
|
bool MSP430FrameLowering::spillCalleeSavedRegisters(
|
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
|
|
|
ArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
|
2010-11-28 07:05:03 +08:00
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DebugLoc DL;
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
|
2010-11-28 07:05:03 +08:00
|
|
|
MSP430MachineFunctionInfo *MFI = MF.getInfo<MSP430MachineFunctionInfo>();
|
|
|
|
MFI->setCalleeSavedFrameSize(CSI.size() * 2);
|
|
|
|
|
|
|
|
for (unsigned i = CSI.size(); i != 0; --i) {
|
|
|
|
unsigned Reg = CSI[i-1].getReg();
|
|
|
|
// Add the callee-saved register as live-in. It's killed at the spill.
|
|
|
|
MBB.addLiveIn(Reg);
|
|
|
|
BuildMI(MBB, MI, DL, TII.get(MSP430::PUSH16r))
|
|
|
|
.addReg(Reg, RegState::Kill);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-29 16:50:23 +08:00
|
|
|
bool MSP430FrameLowering::restoreCalleeSavedRegisters(
|
|
|
|
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
|
|
|
|
MutableArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
|
2010-11-28 07:05:03 +08:00
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DebugLoc DL;
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
|
2010-11-28 07:05:03 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i)
|
|
|
|
BuildMI(MBB, MI, DL, TII.get(MSP430::POP16r), CSI[i].getReg());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-10-18 01:37:11 +08:00
|
|
|
|
2016-04-01 02:33:38 +08:00
|
|
|
MachineBasicBlock::iterator MSP430FrameLowering::eliminateCallFramePseudoInstr(
|
|
|
|
MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2013-02-22 04:05:00 +08:00
|
|
|
const MSP430InstrInfo &TII =
|
2014-08-05 10:39:49 +08:00
|
|
|
*static_cast<const MSP430InstrInfo *>(MF.getSubtarget().getInstrInfo());
|
2013-02-22 04:05:00 +08:00
|
|
|
if (!hasReservedCallFrame(MF)) {
|
|
|
|
// If the stack pointer can be changed after prologue, turn the
|
2014-09-10 14:58:14 +08:00
|
|
|
// adjcallstackup instruction into a 'sub SP, <amt>' and the
|
|
|
|
// adjcallstackdown instruction into 'add SP, <amt>'
|
2013-02-22 04:05:00 +08:00
|
|
|
// TODO: consider using push / pop instead of sub + store / add
|
2016-07-09 05:19:46 +08:00
|
|
|
MachineInstr &Old = *I;
|
2017-05-09 21:35:13 +08:00
|
|
|
uint64_t Amount = TII.getFrameSize(Old);
|
2013-02-22 04:05:00 +08:00
|
|
|
if (Amount != 0) {
|
|
|
|
// We need to keep the stack aligned properly. To do this, we round the
|
|
|
|
// amount of space needed for the outgoing arguments up to the next
|
|
|
|
// alignment boundary.
|
[Alignment][NFC] Use TFL::getStackAlign()
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: dylanmckay, sdardis, nemanjai, hiraditya, kbarton, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76551
2020-03-22 04:41:33 +08:00
|
|
|
Amount = alignTo(Amount, getStackAlign());
|
2013-02-22 04:05:00 +08:00
|
|
|
|
2014-04-25 13:30:21 +08:00
|
|
|
MachineInstr *New = nullptr;
|
2016-07-09 05:19:46 +08:00
|
|
|
if (Old.getOpcode() == TII.getCallFrameSetupOpcode()) {
|
|
|
|
New =
|
|
|
|
BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::SUB16ri), MSP430::SP)
|
|
|
|
.addReg(MSP430::SP)
|
|
|
|
.addImm(Amount);
|
2013-02-22 04:05:00 +08:00
|
|
|
} else {
|
2016-07-09 05:19:46 +08:00
|
|
|
assert(Old.getOpcode() == TII.getCallFrameDestroyOpcode());
|
2013-02-22 04:05:00 +08:00
|
|
|
// factor out the amount the callee already popped.
|
2017-05-09 21:35:13 +08:00
|
|
|
Amount -= TII.getFramePoppedByCallee(Old);
|
2013-02-22 04:05:00 +08:00
|
|
|
if (Amount)
|
2016-07-09 05:19:46 +08:00
|
|
|
New = BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::ADD16ri),
|
|
|
|
MSP430::SP)
|
|
|
|
.addReg(MSP430::SP)
|
|
|
|
.addImm(Amount);
|
2013-02-22 04:05:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (New) {
|
|
|
|
// The SRW implicit def is dead.
|
|
|
|
New->getOperand(3).setIsDead();
|
|
|
|
|
|
|
|
// Replace the pseudo instruction with a new instruction...
|
|
|
|
MBB.insert(I, New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (I->getOpcode() == TII.getCallFrameDestroyOpcode()) {
|
|
|
|
// If we are performing frame pointer elimination and if the callee pops
|
|
|
|
// something off the stack pointer, add it back.
|
2017-05-09 21:35:13 +08:00
|
|
|
if (uint64_t CalleeAmt = TII.getFramePoppedByCallee(*I)) {
|
2016-07-09 05:19:46 +08:00
|
|
|
MachineInstr &Old = *I;
|
2013-02-22 04:05:00 +08:00
|
|
|
MachineInstr *New =
|
2016-07-09 05:19:46 +08:00
|
|
|
BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::SUB16ri), MSP430::SP)
|
|
|
|
.addReg(MSP430::SP)
|
|
|
|
.addImm(CalleeAmt);
|
2013-02-22 04:05:00 +08:00
|
|
|
// The SRW implicit def is dead.
|
|
|
|
New->getOperand(3).setIsDead();
|
|
|
|
|
|
|
|
MBB.insert(I, New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 02:33:38 +08:00
|
|
|
return MBB.erase(I);
|
2013-02-22 04:05:00 +08:00
|
|
|
}
|
|
|
|
|
2012-10-18 01:37:11 +08:00
|
|
|
void
|
2013-03-15 04:33:40 +08:00
|
|
|
MSP430FrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
|
|
|
RegScavenger *) const {
|
2014-09-10 14:58:14 +08:00
|
|
|
// Create a frame entry for the FP register that must be saved.
|
2013-02-22 04:05:00 +08:00
|
|
|
if (hasFP(MF)) {
|
2016-07-29 02:40:00 +08:00
|
|
|
int FrameIdx = MF.getFrameInfo().CreateFixedObject(2, -4, true);
|
2012-10-18 01:37:11 +08:00
|
|
|
(void)FrameIdx;
|
2016-07-29 02:40:00 +08:00
|
|
|
assert(FrameIdx == MF.getFrameInfo().getObjectIndexBegin() &&
|
2014-09-10 14:58:14 +08:00
|
|
|
"Slot for FP register must be last in order to be found!");
|
2012-10-18 01:37:11 +08:00
|
|
|
}
|
|
|
|
}
|