2002-12-28 20:43:30 +00:00
|
|
|
//===-- PrologEpilogInserter.cpp - Insert Prolog/Epilog code in function --===//
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-28 20:43:30 +00:00
|
|
|
//
|
|
|
|
// This pass is responsible for finalizing the functions frame layout, saving
|
|
|
|
// callee saved registers, and for emitting prolog & epilog code for the
|
|
|
|
// function.
|
|
|
|
//
|
|
|
|
// This pass must be run after register allocation. After this pass is
|
|
|
|
// executed, it is illegal to construct MO_FrameIndex operands.
|
|
|
|
//
|
2009-05-12 20:33:29 +00:00
|
|
|
// This pass provides an optional shrink wrapping variant of prolog/epilog
|
|
|
|
// insertion, enabled via --shrink-wrap. See ShrinkWrapping.cpp.
|
2009-03-27 06:09:40 +00:00
|
|
|
//
|
2002-12-28 20:43:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-05-13 17:52:11 +00:00
|
|
|
#include "PrologEpilogInserter.h"
|
2009-03-27 06:09:40 +00:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2002-12-28 20:43:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-12-28 21:08:26 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2007-02-23 01:11:26 +00:00
|
|
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
2002-12-28 20:43:30 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-02-10 18:45:23 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2002-12-28 21:00:25 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2003-01-14 22:00:31 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-05-01 09:01:42 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2006-09-28 00:10:27 +00:00
|
|
|
#include <climits>
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2004-02-15 00:14:20 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2009-05-12 20:33:29 +00:00
|
|
|
char PEI::ID = 0;
|
2009-05-11 17:04:19 +00:00
|
|
|
|
2009-05-12 20:33:29 +00:00
|
|
|
static RegisterPass<PEI>
|
|
|
|
X("prologepilog", "Prologue/Epilogue Insertion");
|
2009-05-11 17:04:19 +00:00
|
|
|
|
2002-12-28 20:43:30 +00:00
|
|
|
/// createPrologEpilogCodeInserter - This function returns a pass that inserts
|
|
|
|
/// prolog and epilog code, and eliminates abstract frame references.
|
|
|
|
///
|
2004-02-15 00:14:20 +00:00
|
|
|
FunctionPass *llvm::createPrologEpilogCodeInserter() { return new PEI(); }
|
2002-12-28 20:43:30 +00:00
|
|
|
|
2009-05-12 20:33:29 +00:00
|
|
|
/// runOnMachineFunction - Insert prolog/epilog code and replace abstract
|
|
|
|
/// frame indexes with appropriate references.
|
2009-05-11 17:04:19 +00:00
|
|
|
///
|
2009-05-12 20:33:29 +00:00
|
|
|
bool PEI::runOnMachineFunction(MachineFunction &Fn) {
|
2009-05-11 17:04:19 +00:00
|
|
|
const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
|
2009-05-12 20:33:29 +00:00
|
|
|
RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : NULL;
|
|
|
|
|
|
|
|
// Get MachineModuleInfo so that we can track the construction of the
|
|
|
|
// frame.
|
|
|
|
if (MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>())
|
|
|
|
Fn.getFrameInfo()->setMachineModuleInfo(MMI);
|
|
|
|
|
|
|
|
// Allow the target machine to make some adjustments to the function
|
|
|
|
// e.g. UsedPhysRegs before calculateCalleeSavedRegisters.
|
|
|
|
TRI->processFunctionBeforeCalleeSavedScan(Fn, RS);
|
|
|
|
|
|
|
|
// Scan the function for modified callee saved registers and insert spill
|
|
|
|
// code for any callee saved registers that are modified. Also calculate
|
|
|
|
// the MaxCallFrameSize and HasCalls variables for the function's frame
|
|
|
|
// information and eliminates call frame pseudo instructions.
|
|
|
|
calculateCalleeSavedRegisters(Fn);
|
|
|
|
|
|
|
|
// Determine placement of CSR spill/restore code:
|
|
|
|
// - with shrink wrapping, place spills and restores to tightly
|
|
|
|
// enclose regions in the Machine CFG of the function where
|
|
|
|
// they are used. Without shrink wrapping
|
|
|
|
// - default (no shrink wrapping), place all spills in the
|
|
|
|
// entry block, all restores in return blocks.
|
|
|
|
placeCSRSpillsAndRestores(Fn);
|
|
|
|
|
|
|
|
// Add the code to save and restore the callee saved registers
|
|
|
|
insertCSRSpillsAndRestores(Fn);
|
|
|
|
|
|
|
|
// Allow the target machine to make final modifications to the function
|
|
|
|
// before the frame layout is finalized.
|
|
|
|
TRI->processFunctionBeforeFrameFinalized(Fn);
|
|
|
|
|
|
|
|
// Calculate actual frame offsets for all abstract stack objects...
|
|
|
|
calculateFrameObjectOffsets(Fn);
|
|
|
|
|
|
|
|
// Add prolog and epilog code to the function. This function is required
|
|
|
|
// to align the stack frame as necessary for any stack variables or
|
|
|
|
// called functions. Because of this, calculateCalleeSavedRegisters
|
|
|
|
// must be called before this function in order to set the HasCalls
|
|
|
|
// and MaxCallFrameSize variables.
|
|
|
|
insertPrologEpilogCode(Fn);
|
|
|
|
|
|
|
|
// Replace all MO_FrameIndex operands with physical register references
|
|
|
|
// and actual offsets.
|
|
|
|
//
|
|
|
|
replaceFrameIndices(Fn);
|
2009-05-11 17:04:19 +00:00
|
|
|
|
2009-05-12 20:33:29 +00:00
|
|
|
delete RS;
|
|
|
|
clearAllSets();
|
2009-05-11 17:04:19 +00:00
|
|
|
return true;
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
|
|
|
|
2009-05-12 20:33:29 +00:00
|
|
|
#if 0
|
|
|
|
void PEI::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
if (ShrinkWrapping || ShrinkWrapFunc != "") {
|
|
|
|
AU.addRequired<MachineLoopInfo>();
|
|
|
|
AU.addRequired<MachineDominatorTree>();
|
2009-05-11 17:04:19 +00:00
|
|
|
}
|
2009-05-12 20:33:29 +00:00
|
|
|
AU.addPreserved<MachineLoopInfo>();
|
|
|
|
AU.addPreserved<MachineDominatorTree>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
2009-05-12 20:33:29 +00:00
|
|
|
#endif
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2006-09-28 00:10:27 +00:00
|
|
|
/// calculateCalleeSavedRegisters - Scan the function for modified callee saved
|
2004-08-12 19:01:14 +00:00
|
|
|
/// registers. Also calculate the MaxCallFrameSize and HasCalls variables for
|
2002-12-28 20:43:30 +00:00
|
|
|
/// the function's frame information and eliminates call frame pseudo
|
|
|
|
/// instructions.
|
|
|
|
///
|
2006-09-26 22:29:31 +00:00
|
|
|
void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
|
2004-08-12 19:01:14 +00:00
|
|
|
const TargetFrameInfo *TFI = Fn.getTarget().getFrameInfo();
|
2002-12-28 20:43:30 +00:00
|
|
|
|
|
|
|
// Get the callee saved register list...
|
2007-07-14 14:06:15 +00:00
|
|
|
const unsigned *CSRegs = RegInfo->getCalleeSavedRegs(&Fn);
|
2002-12-28 20:43:30 +00:00
|
|
|
|
|
|
|
// Get the function call frame set-up and tear-down instruction opcode
|
|
|
|
int FrameSetupOpcode = RegInfo->getCallFrameSetupOpcode();
|
|
|
|
int FrameDestroyOpcode = RegInfo->getCallFrameDestroyOpcode();
|
|
|
|
|
2006-12-07 02:25:34 +00:00
|
|
|
// These are used to keep track the callee-save area. Initialize them.
|
|
|
|
MinCSFrameIndex = INT_MAX;
|
|
|
|
MaxCSFrameIndex = 0;
|
|
|
|
|
2002-12-28 20:43:30 +00:00
|
|
|
// Early exit for targets which have no callee saved registers and no call
|
|
|
|
// frame setup/destroy pseudo instructions.
|
|
|
|
if ((CSRegs == 0 || CSRegs[0] == 0) &&
|
|
|
|
FrameSetupOpcode == -1 && FrameDestroyOpcode == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned MaxCallFrameSize = 0;
|
|
|
|
bool HasCalls = false;
|
|
|
|
|
2007-05-01 00:52:08 +00:00
|
|
|
std::vector<MachineBasicBlock::iterator> FrameSDOps;
|
2002-12-28 20:43:30 +00:00
|
|
|
for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB)
|
2007-05-01 00:52:08 +00:00
|
|
|
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
|
2004-02-12 02:27:10 +00:00
|
|
|
if (I->getOpcode() == FrameSetupOpcode ||
|
2004-08-07 07:07:57 +00:00
|
|
|
I->getOpcode() == FrameDestroyOpcode) {
|
2005-05-13 21:07:15 +00:00
|
|
|
assert(I->getNumOperands() >= 1 && "Call Frame Setup/Destroy Pseudo"
|
2004-08-07 07:07:57 +00:00
|
|
|
" instructions should have a single immediate argument!");
|
2007-12-30 20:50:28 +00:00
|
|
|
unsigned Size = I->getOperand(0).getImm();
|
2004-08-07 07:07:57 +00:00
|
|
|
if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
|
|
|
|
HasCalls = true;
|
2007-05-01 00:52:08 +00:00
|
|
|
FrameSDOps.push_back(I);
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
2002-12-28 21:08:26 +00:00
|
|
|
MachineFrameInfo *FFI = Fn.getFrameInfo();
|
2002-12-28 20:43:30 +00:00
|
|
|
FFI->setHasCalls(HasCalls);
|
|
|
|
FFI->setMaxCallFrameSize(MaxCallFrameSize);
|
2007-05-01 09:01:42 +00:00
|
|
|
|
2007-05-01 00:52:08 +00:00
|
|
|
for (unsigned i = 0, e = FrameSDOps.size(); i != e; ++i) {
|
|
|
|
MachineBasicBlock::iterator I = FrameSDOps[i];
|
2007-05-01 09:01:42 +00:00
|
|
|
// If call frames are not being included as part of the stack frame,
|
|
|
|
// and there is no dynamic allocation (therefore referencing frame slots
|
|
|
|
// off sp), leave the pseudo ops alone. We'll eliminate them later.
|
|
|
|
if (RegInfo->hasReservedCallFrame(Fn) || RegInfo->hasFP(Fn))
|
|
|
|
RegInfo->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I);
|
2007-05-01 00:52:08 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
|
|
|
|
// Now figure out which *callee saved* registers are modified by the current
|
|
|
|
// function, thus needing to be saved and restored in the prolog/epilog.
|
|
|
|
//
|
2005-09-30 16:59:07 +00:00
|
|
|
const TargetRegisterClass* const *CSRegClasses =
|
2007-07-14 14:06:15 +00:00
|
|
|
RegInfo->getCalleeSavedRegClasses(&Fn);
|
2006-08-25 22:56:30 +00:00
|
|
|
std::vector<CalleeSavedInfo> CSI;
|
2002-12-28 20:43:30 +00:00
|
|
|
for (unsigned i = 0; CSRegs[i]; ++i) {
|
|
|
|
unsigned Reg = CSRegs[i];
|
2009-05-12 23:59:14 +00:00
|
|
|
if (Fn.getRegInfo().isPhysRegUsed(Reg) || Fn.doesHaveBuiltinSetjmp()) {
|
2005-09-30 16:59:07 +00:00
|
|
|
// If the reg is modified, save it!
|
2006-08-25 19:45:51 +00:00
|
|
|
CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
|
2003-10-08 05:20:08 +00:00
|
|
|
} else {
|
|
|
|
for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
|
2005-01-23 23:13:12 +00:00
|
|
|
*AliasSet; ++AliasSet) { // Check alias registers too.
|
2007-12-31 04:13:23 +00:00
|
|
|
if (Fn.getRegInfo().isPhysRegUsed(*AliasSet)) {
|
2006-08-25 19:45:51 +00:00
|
|
|
CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
|
2004-08-07 07:07:57 +00:00
|
|
|
break;
|
2004-08-07 07:18:41 +00:00
|
|
|
}
|
2003-10-08 05:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
2006-08-25 19:45:51 +00:00
|
|
|
if (CSI.empty())
|
2006-09-28 00:10:27 +00:00
|
|
|
return; // Early exit if no callee saved registers are modified!
|
2002-12-28 20:43:30 +00:00
|
|
|
|
2004-08-12 19:01:14 +00:00
|
|
|
unsigned NumFixedSpillSlots;
|
2004-08-15 09:18:55 +00:00
|
|
|
const std::pair<unsigned,int> *FixedSpillSlots =
|
2007-01-02 21:31:15 +00:00
|
|
|
TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
|
2004-08-12 19:01:14 +00:00
|
|
|
|
2002-12-28 20:43:30 +00:00
|
|
|
// Now that we know which registers need to be saved and restored, allocate
|
|
|
|
// stack slots for them.
|
2006-08-25 19:45:51 +00:00
|
|
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
|
|
|
unsigned Reg = CSI[i].getReg();
|
|
|
|
const TargetRegisterClass *RC = CSI[i].getRegClass();
|
2004-08-12 19:01:14 +00:00
|
|
|
|
|
|
|
// Check to see if this physreg must be spilled to a particular stack slot
|
|
|
|
// on this target.
|
2004-08-15 09:18:55 +00:00
|
|
|
const std::pair<unsigned,int> *FixedSlot = FixedSpillSlots;
|
2004-08-12 19:01:14 +00:00
|
|
|
while (FixedSlot != FixedSpillSlots+NumFixedSpillSlots &&
|
|
|
|
FixedSlot->first != Reg)
|
|
|
|
++FixedSlot;
|
|
|
|
|
2004-08-21 19:45:10 +00:00
|
|
|
int FrameIdx;
|
2004-08-12 19:01:14 +00:00
|
|
|
if (FixedSlot == FixedSpillSlots+NumFixedSpillSlots) {
|
|
|
|
// Nope, just spill it anywhere convenient.
|
2006-09-28 18:52:32 +00:00
|
|
|
unsigned Align = RC->getAlignment();
|
|
|
|
unsigned StackAlign = TFI->getStackAlignment();
|
|
|
|
// We may not be able to sastify the desired alignment specification of
|
2009-03-27 06:09:40 +00:00
|
|
|
// the TargetRegisterClass if the stack alignment is smaller.
|
|
|
|
// Use the min.
|
2006-09-28 18:52:32 +00:00
|
|
|
Align = std::min(Align, StackAlign);
|
|
|
|
FrameIdx = FFI->CreateStackObject(RC->getSize(), Align);
|
2006-09-28 00:10:27 +00:00
|
|
|
if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
|
|
|
|
if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
|
2004-08-12 19:01:14 +00:00
|
|
|
} else {
|
|
|
|
// Spill it to the stack where we must.
|
2005-09-30 17:19:22 +00:00
|
|
|
FrameIdx = FFI->CreateFixedObject(RC->getSize(), FixedSlot->second);
|
2004-08-12 19:01:14 +00:00
|
|
|
}
|
2006-08-25 19:45:51 +00:00
|
|
|
CSI[i].setFrameIdx(FrameIdx);
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
2006-08-25 22:56:30 +00:00
|
|
|
|
|
|
|
FFI->setCalleeSavedInfo(CSI);
|
2004-08-12 19:01:14 +00:00
|
|
|
}
|
|
|
|
|
2009-03-27 06:09:40 +00:00
|
|
|
/// insertCSRSpillsAndRestores - Insert spill and restore code for
|
|
|
|
/// callee saved registers used in the function, handling shrink wrapping.
|
2004-08-12 19:01:14 +00:00
|
|
|
///
|
2009-03-27 06:09:40 +00:00
|
|
|
void PEI::insertCSRSpillsAndRestores(MachineFunction &Fn) {
|
2006-08-25 19:45:51 +00:00
|
|
|
// Get callee saved register information.
|
|
|
|
MachineFrameInfo *FFI = Fn.getFrameInfo();
|
2006-08-25 22:56:30 +00:00
|
|
|
const std::vector<CalleeSavedInfo> &CSI = FFI->getCalleeSavedInfo();
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2006-09-28 00:10:27 +00:00
|
|
|
// Early exit if no callee saved registers are modified!
|
2006-08-25 19:45:51 +00:00
|
|
|
if (CSI.empty())
|
2005-04-21 22:36:52 +00:00
|
|
|
return;
|
2004-08-12 19:01:14 +00:00
|
|
|
|
2008-01-01 21:11:32 +00:00
|
|
|
const TargetInstrInfo &TII = *Fn.getTarget().getInstrInfo();
|
2009-03-27 06:09:40 +00:00
|
|
|
MachineBasicBlock::iterator I;
|
2008-01-31 00:27:49 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
if (! ShrinkWrapThisFunction) {
|
|
|
|
// Spill using target interface.
|
|
|
|
I = EntryBlock->begin();
|
|
|
|
if (!TII.spillCalleeSavedRegisters(*EntryBlock, I, CSI)) {
|
|
|
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
2009-03-27 06:09:40 +00:00
|
|
|
// Add the callee-saved register as live-in.
|
|
|
|
// It's killed at the spill.
|
2009-05-11 17:04:19 +00:00
|
|
|
EntryBlock->addLiveIn(CSI[i].getReg());
|
2009-03-27 06:09:40 +00:00
|
|
|
|
|
|
|
// Insert the spill to the stack frame.
|
2009-05-11 17:04:19 +00:00
|
|
|
TII.storeRegToStackSlot(*EntryBlock, I, CSI[i].getReg(), true,
|
|
|
|
CSI[i].getFrameIdx(), CSI[i].getRegClass());
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
2007-01-02 21:31:15 +00:00
|
|
|
}
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
// Restore using target interface.
|
|
|
|
for (unsigned ri = 0, re = ReturnBlocks.size(); ri != re; ++ri) {
|
|
|
|
MachineBasicBlock* MBB = ReturnBlocks[ri];
|
2004-02-12 02:27:10 +00:00
|
|
|
I = MBB->end(); --I;
|
2002-12-28 20:43:30 +00:00
|
|
|
|
2008-10-31 18:30:19 +00:00
|
|
|
// Skip over all terminator instructions, which are part of the return
|
2005-05-15 03:09:58 +00:00
|
|
|
// sequence.
|
|
|
|
MachineBasicBlock::iterator I2 = I;
|
2008-10-31 18:30:19 +00:00
|
|
|
while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator())
|
2005-05-15 03:09:58 +00:00
|
|
|
I = I2;
|
|
|
|
|
2005-08-29 00:10:46 +00:00
|
|
|
bool AtStart = I == MBB->begin();
|
2005-08-26 22:18:32 +00:00
|
|
|
MachineBasicBlock::iterator BeforeI = I;
|
|
|
|
if (!AtStart)
|
|
|
|
--BeforeI;
|
2009-03-27 06:09:40 +00:00
|
|
|
|
|
|
|
// Restore all registers immediately before the return and any
|
|
|
|
// terminators that preceed it.
|
2008-01-05 00:48:55 +00:00
|
|
|
if (!TII.restoreCalleeSavedRegisters(*MBB, I, CSI)) {
|
2007-01-02 21:31:15 +00:00
|
|
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
2008-01-01 21:11:32 +00:00
|
|
|
TII.loadRegFromStackSlot(*MBB, I, CSI[i].getReg(),
|
2009-03-27 06:09:40 +00:00
|
|
|
CSI[i].getFrameIdx(),
|
|
|
|
CSI[i].getRegClass());
|
2007-01-02 21:31:15 +00:00
|
|
|
assert(I != MBB->begin() &&
|
|
|
|
"loadRegFromStackSlot didn't insert any code!");
|
2009-03-27 06:09:40 +00:00
|
|
|
// Insert in reverse order. loadRegFromStackSlot can insert
|
|
|
|
// multiple instructions.
|
2007-01-02 21:31:15 +00:00
|
|
|
if (AtStart)
|
|
|
|
I = MBB->begin();
|
|
|
|
else {
|
|
|
|
I = BeforeI;
|
|
|
|
++I;
|
|
|
|
}
|
2005-08-26 22:18:32 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
2009-05-11 17:04:19 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
// Insert spills.
|
|
|
|
std::vector<CalleeSavedInfo> blockCSI;
|
|
|
|
for (CSRegBlockMap::iterator BI = CSRSave.begin(),
|
|
|
|
BE = CSRSave.end(); BI != BE; ++BI) {
|
|
|
|
MachineBasicBlock* MBB = BI->first;
|
|
|
|
CSRegSet save = BI->second;
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
if (save.empty())
|
|
|
|
continue;
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
blockCSI.clear();
|
|
|
|
for (CSRegSet::iterator RI = save.begin(),
|
|
|
|
RE = save.end(); RI != RE; ++RI) {
|
|
|
|
blockCSI.push_back(CSI[*RI]);
|
|
|
|
}
|
|
|
|
assert(blockCSI.size() > 0 &&
|
|
|
|
"Could not collect callee saved register info");
|
|
|
|
|
|
|
|
I = MBB->begin();
|
|
|
|
|
|
|
|
// When shrink wrapping, use stack slot stores/loads.
|
|
|
|
for (unsigned i = 0, e = blockCSI.size(); i != e; ++i) {
|
|
|
|
// Add the callee-saved register as live-in.
|
|
|
|
// It's killed at the spill.
|
|
|
|
MBB->addLiveIn(blockCSI[i].getReg());
|
|
|
|
|
|
|
|
// Insert the spill to the stack frame.
|
|
|
|
TII.storeRegToStackSlot(*MBB, I, blockCSI[i].getReg(),
|
|
|
|
true,
|
|
|
|
blockCSI[i].getFrameIdx(),
|
|
|
|
blockCSI[i].getRegClass());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CSRegBlockMap::iterator BI = CSRRestore.begin(),
|
|
|
|
BE = CSRRestore.end(); BI != BE; ++BI) {
|
|
|
|
MachineBasicBlock* MBB = BI->first;
|
|
|
|
CSRegSet restore = BI->second;
|
|
|
|
|
|
|
|
if (restore.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
blockCSI.clear();
|
|
|
|
for (CSRegSet::iterator RI = restore.begin(),
|
|
|
|
RE = restore.end(); RI != RE; ++RI) {
|
|
|
|
blockCSI.push_back(CSI[*RI]);
|
|
|
|
}
|
|
|
|
assert(blockCSI.size() > 0 &&
|
|
|
|
"Could not find callee saved register info");
|
|
|
|
|
|
|
|
// If MBB is empty and needs restores, insert at the _beginning_.
|
|
|
|
if (MBB->empty()) {
|
|
|
|
I = MBB->begin();
|
|
|
|
} else {
|
|
|
|
I = MBB->end();
|
|
|
|
--I;
|
|
|
|
|
|
|
|
// Skip over all terminator instructions, which are part of the
|
|
|
|
// return sequence.
|
|
|
|
if (! I->getDesc().isTerminator()) {
|
|
|
|
++I;
|
2009-03-27 06:09:40 +00:00
|
|
|
} else {
|
2009-05-11 17:04:19 +00:00
|
|
|
MachineBasicBlock::iterator I2 = I;
|
|
|
|
while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator())
|
|
|
|
I = I2;
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
2009-05-11 17:04:19 +00:00
|
|
|
}
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2009-05-11 17:04:19 +00:00
|
|
|
bool AtStart = I == MBB->begin();
|
|
|
|
MachineBasicBlock::iterator BeforeI = I;
|
|
|
|
if (!AtStart)
|
|
|
|
--BeforeI;
|
|
|
|
|
|
|
|
// Restore all registers immediately before the return and any
|
|
|
|
// terminators that preceed it.
|
|
|
|
for (unsigned i = 0, e = blockCSI.size(); i != e; ++i) {
|
|
|
|
TII.loadRegFromStackSlot(*MBB, I, blockCSI[i].getReg(),
|
|
|
|
blockCSI[i].getFrameIdx(),
|
|
|
|
blockCSI[i].getRegClass());
|
|
|
|
assert(I != MBB->begin() &&
|
|
|
|
"loadRegFromStackSlot didn't insert any code!");
|
|
|
|
// Insert in reverse order. loadRegFromStackSlot can insert
|
|
|
|
// multiple instructions.
|
|
|
|
if (AtStart)
|
|
|
|
I = MBB->begin();
|
|
|
|
else {
|
|
|
|
I = BeforeI;
|
|
|
|
++I;
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
2009-03-27 06:09:40 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 01:48:58 +00:00
|
|
|
/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
|
|
|
|
static inline void
|
|
|
|
AdjustStackOffset(MachineFrameInfo *FFI, int FrameIdx,
|
|
|
|
bool StackGrowsDown, int64_t &Offset,
|
|
|
|
unsigned &MaxAlign) {
|
|
|
|
// If stack grows down, we need to add size of find the lowest address of the
|
|
|
|
// object.
|
|
|
|
if (StackGrowsDown)
|
|
|
|
Offset += FFI->getObjectSize(FrameIdx);
|
|
|
|
|
|
|
|
unsigned Align = FFI->getObjectAlignment(FrameIdx);
|
|
|
|
|
|
|
|
// If the alignment of this object is greater than that of the stack, then
|
|
|
|
// increase the stack alignment to match.
|
|
|
|
MaxAlign = std::max(MaxAlign, Align);
|
|
|
|
|
|
|
|
// Adjust to alignment boundary.
|
|
|
|
Offset = (Offset + Align - 1) / Align * Align;
|
|
|
|
|
|
|
|
if (StackGrowsDown) {
|
|
|
|
FFI->setObjectOffset(FrameIdx, -Offset); // Set the computed offset
|
|
|
|
} else {
|
|
|
|
FFI->setObjectOffset(FrameIdx, Offset);
|
|
|
|
Offset += FFI->getObjectSize(FrameIdx);
|
|
|
|
}
|
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
|
|
|
|
/// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
|
2005-01-23 21:45:01 +00:00
|
|
|
/// abstract stack objects.
|
2002-12-28 20:43:30 +00:00
|
|
|
///
|
|
|
|
void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
|
2004-06-02 05:57:12 +00:00
|
|
|
const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2002-12-28 20:43:30 +00:00
|
|
|
bool StackGrowsDown =
|
|
|
|
TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2002-12-28 20:43:30 +00:00
|
|
|
// Loop over all of the stack objects, assigning sequential addresses...
|
2002-12-28 21:08:26 +00:00
|
|
|
MachineFrameInfo *FFI = Fn.getFrameInfo();
|
2002-12-28 20:43:30 +00:00
|
|
|
|
2008-04-23 18:21:50 +00:00
|
|
|
unsigned MaxAlign = FFI->getMaxAlignment();
|
2003-01-16 02:22:08 +00:00
|
|
|
|
2004-02-15 00:14:20 +00:00
|
|
|
// Start at the beginning of the local area.
|
2004-06-10 06:23:35 +00:00
|
|
|
// The Offset is the distance from the stack top in the direction
|
2008-07-16 15:57:10 +00:00
|
|
|
// of stack growth -- so it's always nonnegative.
|
2007-04-25 04:20:54 +00:00
|
|
|
int64_t Offset = TFI.getOffsetOfLocalArea();
|
2004-06-10 06:23:35 +00:00
|
|
|
if (StackGrowsDown)
|
2004-06-11 06:37:11 +00:00
|
|
|
Offset = -Offset;
|
2005-04-21 22:36:52 +00:00
|
|
|
assert(Offset >= 0
|
2004-06-10 06:23:35 +00:00
|
|
|
&& "Local area offset should be in direction of stack growth");
|
|
|
|
|
|
|
|
// If there are fixed sized objects that are preallocated in the local area,
|
|
|
|
// non-fixed objects can't be allocated right at the start of local area.
|
2009-03-27 06:09:40 +00:00
|
|
|
// We currently don't support filling in holes in between fixed sized
|
|
|
|
// objects, so we adjust 'Offset' to point to the end of last fixed sized
|
2004-02-15 00:14:20 +00:00
|
|
|
// preallocated object.
|
|
|
|
for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
|
2007-04-25 04:20:54 +00:00
|
|
|
int64_t FixedOff;
|
2004-06-10 06:23:35 +00:00
|
|
|
if (StackGrowsDown) {
|
|
|
|
// The maximum distance from the stack pointer is at lower address of
|
|
|
|
// the object -- which is given by offset. For down growing stack
|
|
|
|
// the offset is negative, so we negate the offset to get the distance.
|
|
|
|
FixedOff = -FFI->getObjectOffset(i);
|
|
|
|
} else {
|
2005-04-21 22:36:52 +00:00
|
|
|
// The maximum distance from the start pointer is at the upper
|
2004-06-10 06:23:35 +00:00
|
|
|
// address of the object.
|
|
|
|
FixedOff = FFI->getObjectOffset(i) + FFI->getObjectSize(i);
|
2005-04-21 22:36:52 +00:00
|
|
|
}
|
|
|
|
if (FixedOff > Offset) Offset = FixedOff;
|
2004-02-15 00:14:20 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 00:10:27 +00:00
|
|
|
// First assign frame offsets to stack objects that are used to spill
|
2007-01-02 21:31:15 +00:00
|
|
|
// callee saved registers.
|
2006-09-28 00:10:27 +00:00
|
|
|
if (StackGrowsDown) {
|
2007-05-01 00:52:08 +00:00
|
|
|
for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
|
2006-09-28 00:10:27 +00:00
|
|
|
// If stack grows down, we need to add size of find the lowest
|
|
|
|
// address of the object.
|
|
|
|
Offset += FFI->getObjectSize(i);
|
|
|
|
|
|
|
|
unsigned Align = FFI->getObjectAlignment(i);
|
2009-03-27 06:09:40 +00:00
|
|
|
// If the alignment of this object is greater than that of the stack,
|
|
|
|
// then increase the stack alignment to match.
|
2006-09-28 00:10:27 +00:00
|
|
|
MaxAlign = std::max(MaxAlign, Align);
|
|
|
|
// Adjust to alignment boundary
|
|
|
|
Offset = (Offset+Align-1)/Align*Align;
|
|
|
|
|
|
|
|
FFI->setObjectOffset(i, -Offset); // Set the computed offset
|
|
|
|
}
|
|
|
|
} else {
|
2008-06-03 08:46:59 +00:00
|
|
|
int MaxCSFI = MaxCSFrameIndex, MinCSFI = MinCSFrameIndex;
|
|
|
|
for (int i = MaxCSFI; i >= MinCSFI ; --i) {
|
2006-09-28 00:10:27 +00:00
|
|
|
unsigned Align = FFI->getObjectAlignment(i);
|
2009-03-27 06:09:40 +00:00
|
|
|
// If the alignment of this object is greater than that of the stack,
|
|
|
|
// then increase the stack alignment to match.
|
2006-09-28 00:10:27 +00:00
|
|
|
MaxAlign = std::max(MaxAlign, Align);
|
|
|
|
// Adjust to alignment boundary
|
|
|
|
Offset = (Offset+Align-1)/Align*Align;
|
|
|
|
|
|
|
|
FFI->setObjectOffset(i, Offset);
|
|
|
|
Offset += FFI->getObjectSize(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-06 10:02:38 +00:00
|
|
|
// Make sure the special register scavenging spill slot is closest to the
|
|
|
|
// frame pointer if a frame pointer is required.
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
|
2007-03-06 10:02:38 +00:00
|
|
|
if (RS && RegInfo->hasFP(Fn)) {
|
|
|
|
int SFI = RS->getScavengingFrameIndex();
|
2008-11-07 01:48:58 +00:00
|
|
|
if (SFI >= 0)
|
|
|
|
AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
|
2007-03-06 10:02:38 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 02:29:10 +00:00
|
|
|
// Make sure that the stack protector comes before the local variables on the
|
|
|
|
// stack.
|
2008-11-07 01:48:58 +00:00
|
|
|
if (FFI->getStackProtectorIndex() >= 0)
|
|
|
|
AdjustStackOffset(FFI, FFI->getStackProtectorIndex(), StackGrowsDown,
|
|
|
|
Offset, MaxAlign);
|
2008-11-06 02:29:10 +00:00
|
|
|
|
2006-09-28 00:10:27 +00:00
|
|
|
// Then assign frame offsets to stack objects that are not used to spill
|
2007-01-02 21:31:15 +00:00
|
|
|
// callee saved registers.
|
2002-12-28 20:43:30 +00:00
|
|
|
for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
|
2006-09-28 00:10:27 +00:00
|
|
|
if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
|
|
|
|
continue;
|
2007-03-06 10:02:38 +00:00
|
|
|
if (RS && (int)i == RS->getScavengingFrameIndex())
|
|
|
|
continue;
|
2008-02-27 03:04:06 +00:00
|
|
|
if (FFI->isDeadObjectIndex(i))
|
|
|
|
continue;
|
2008-11-06 21:37:09 +00:00
|
|
|
if (FFI->getStackProtectorIndex() == (int)i)
|
|
|
|
continue;
|
2006-09-28 00:10:27 +00:00
|
|
|
|
2008-11-07 01:48:58 +00:00
|
|
|
AdjustStackOffset(FFI, i, StackGrowsDown, Offset, MaxAlign);
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 10:02:38 +00:00
|
|
|
// Make sure the special register scavenging spill slot is closest to the
|
|
|
|
// stack pointer.
|
2007-05-31 18:27:58 +00:00
|
|
|
if (RS && !RegInfo->hasFP(Fn)) {
|
2007-03-06 10:02:38 +00:00
|
|
|
int SFI = RS->getScavengingFrameIndex();
|
2008-11-07 01:48:58 +00:00
|
|
|
if (SFI >= 0)
|
|
|
|
AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
|
2007-03-06 10:02:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 09:38:11 +00:00
|
|
|
// Round up the size to a multiple of the alignment, but only if there are
|
|
|
|
// calls or alloca's in the function. This ensures that any calls to
|
|
|
|
// subroutines have their stack frames suitable aligned.
|
2008-06-26 01:51:13 +00:00
|
|
|
// Also do this if we need runtime alignment of the stack. In this case
|
|
|
|
// offsets will be relative to SP not FP; round up the stack size so this
|
|
|
|
// works.
|
2007-01-25 22:12:41 +00:00
|
|
|
if (!RegInfo->targetHandlesStackFrameRounding() &&
|
2009-03-27 06:09:40 +00:00
|
|
|
(FFI->hasCalls() || FFI->hasVarSizedObjects() ||
|
2008-06-30 20:40:16 +00:00
|
|
|
(RegInfo->needsStackRealignment(Fn) &&
|
|
|
|
FFI->getObjectIndexEnd() != 0))) {
|
2007-05-01 00:52:08 +00:00
|
|
|
// If we have reserved argument space for call sites in the function
|
|
|
|
// immediately on entry to the current function, count it as part of the
|
|
|
|
// overall stack size.
|
|
|
|
if (RegInfo->hasReservedCallFrame(Fn))
|
2007-01-23 09:38:11 +00:00
|
|
|
Offset += FFI->getMaxCallFrameSize();
|
|
|
|
|
2008-06-26 01:51:13 +00:00
|
|
|
unsigned AlignMask = std::max(TFI.getStackAlignment(),MaxAlign) - 1;
|
2007-04-25 04:30:24 +00:00
|
|
|
Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
|
2007-01-23 09:38:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update frame info to pretend that this is part of the stack...
|
2004-06-11 06:37:11 +00:00
|
|
|
FFI->setStackSize(Offset+TFI.getOffsetOfLocalArea());
|
2005-11-06 17:43:20 +00:00
|
|
|
|
|
|
|
// Remember the required stack alignment in case targets need it to perform
|
|
|
|
// dynamic stack alignment.
|
2008-02-27 10:04:56 +00:00
|
|
|
FFI->setMaxAlignment(MaxAlign);
|
2003-01-15 22:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-28 00:10:27 +00:00
|
|
|
/// insertPrologEpilogCode - Scan the function for modified callee saved
|
|
|
|
/// registers, insert spill code for these callee saved registers, then add
|
2003-01-15 22:52:34 +00:00
|
|
|
/// prolog and epilog code to the function.
|
|
|
|
///
|
|
|
|
void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
|
2008-04-23 18:19:47 +00:00
|
|
|
const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
|
|
|
|
|
2003-01-15 22:52:34 +00:00
|
|
|
// Add prologue to the function...
|
2008-04-23 18:19:47 +00:00
|
|
|
TRI->emitPrologue(Fn);
|
2003-01-15 22:52:34 +00:00
|
|
|
|
|
|
|
// Add epilogue to restore the callee-save registers in each exiting block
|
|
|
|
for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
|
|
|
|
// If last instruction is a return instruction, add an epilogue
|
2008-01-07 07:27:27 +00:00
|
|
|
if (!I->empty() && I->back().getDesc().isReturn())
|
2008-04-23 18:19:47 +00:00
|
|
|
TRI->emitEpilogue(Fn, *I);
|
2003-01-15 22:52:34 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
|
|
|
|
/// register references and actual offsets.
|
|
|
|
///
|
|
|
|
void PEI::replaceFrameIndices(MachineFunction &Fn) {
|
|
|
|
if (!Fn.getFrameInfo()->hasStackObjects()) return; // Nothing to do?
|
|
|
|
|
|
|
|
const TargetMachine &TM = Fn.getTarget();
|
|
|
|
assert(TM.getRegisterInfo() && "TM::getRegisterInfo() must be implemented!");
|
2008-02-10 18:45:23 +00:00
|
|
|
const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
|
2007-05-01 09:01:42 +00:00
|
|
|
const TargetFrameInfo *TFI = TM.getFrameInfo();
|
|
|
|
bool StackGrowsDown =
|
|
|
|
TFI->getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
|
2008-02-10 18:45:23 +00:00
|
|
|
int FrameSetupOpcode = TRI.getCallFrameSetupOpcode();
|
|
|
|
int FrameDestroyOpcode = TRI.getCallFrameDestroyOpcode();
|
2002-12-28 20:43:30 +00:00
|
|
|
|
2009-03-27 06:09:40 +00:00
|
|
|
for (MachineFunction::iterator BB = Fn.begin(),
|
|
|
|
E = Fn.end(); BB != E; ++BB) {
|
2007-05-01 09:01:42 +00:00
|
|
|
int SPAdj = 0; // SP offset due to call frame setup / destroy.
|
2007-03-01 02:25:51 +00:00
|
|
|
if (RS) RS->enterBasicBlock(BB);
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2007-04-09 01:19:33 +00:00
|
|
|
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
|
2008-03-03 23:57:28 +00:00
|
|
|
if (I->getOpcode() == TargetInstrInfo::DECLARE) {
|
2008-02-02 04:07:54 +00:00
|
|
|
// Ignore it.
|
2008-03-03 22:11:16 +00:00
|
|
|
++I;
|
2008-03-20 01:22:40 +00:00
|
|
|
continue;
|
2008-03-03 23:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (I->getOpcode() == FrameSetupOpcode ||
|
|
|
|
I->getOpcode() == FrameDestroyOpcode) {
|
|
|
|
// Remember how much SP has been adjusted to create the call
|
|
|
|
// frame.
|
2008-03-20 01:22:40 +00:00
|
|
|
int Size = I->getOperand(0).getImm();
|
2008-03-03 23:57:28 +00:00
|
|
|
|
2008-03-20 01:22:40 +00:00
|
|
|
if ((!StackGrowsDown && I->getOpcode() == FrameSetupOpcode) ||
|
|
|
|
(StackGrowsDown && I->getOpcode() == FrameDestroyOpcode))
|
|
|
|
Size = -Size;
|
2008-03-03 22:11:16 +00:00
|
|
|
|
2008-03-20 01:22:40 +00:00
|
|
|
SPAdj += Size;
|
2008-03-03 23:57:28 +00:00
|
|
|
|
2009-03-19 17:15:43 +00:00
|
|
|
MachineBasicBlock::iterator PrevI = BB->end();
|
|
|
|
if (I != BB->begin()) PrevI = prior(I);
|
2008-03-20 01:22:40 +00:00
|
|
|
TRI.eliminateCallFramePseudoInstr(Fn, *BB, I);
|
2008-03-03 23:57:28 +00:00
|
|
|
|
2008-03-20 01:22:40 +00:00
|
|
|
// Visit the instructions created by eliminateCallFramePseudoInstr().
|
2009-03-19 17:15:43 +00:00
|
|
|
if (PrevI == BB->end())
|
|
|
|
I = BB->begin(); // The replaced instr was the first in the block.
|
|
|
|
else
|
|
|
|
I = next(PrevI);
|
2008-03-20 01:22:40 +00:00
|
|
|
continue;
|
2007-05-01 09:01:42 +00:00
|
|
|
}
|
2008-03-03 22:11:16 +00:00
|
|
|
|
2009-03-24 20:33:17 +00:00
|
|
|
MachineInstr *MI = I;
|
2008-03-03 23:57:28 +00:00
|
|
|
bool DoIncr = true;
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(i).isFI()) {
|
2008-03-20 01:22:40 +00:00
|
|
|
// Some instructions (e.g. inline asm instructions) can have
|
|
|
|
// multiple frame indices and/or cause eliminateFrameIndex
|
|
|
|
// to insert more than one instruction. We need the register
|
|
|
|
// scavenger to go through all of these instructions so that
|
|
|
|
// it can update its register information. We keep the
|
|
|
|
// iterator at the point before insertion so that we can
|
|
|
|
// revisit them in full.
|
|
|
|
bool AtBeginning = (I == BB->begin());
|
|
|
|
if (!AtBeginning) --I;
|
|
|
|
|
|
|
|
// If this instruction has a FrameIndex operand, we need to
|
|
|
|
// use that target machine register info object to eliminate
|
|
|
|
// it.
|
2009-03-27 06:09:40 +00:00
|
|
|
|
2008-03-20 01:22:40 +00:00
|
|
|
TRI.eliminateFrameIndex(MI, SPAdj, RS);
|
|
|
|
|
|
|
|
// Reset the iterator if we were at the beginning of the BB.
|
|
|
|
if (AtBeginning) {
|
|
|
|
I = BB->begin();
|
|
|
|
DoIncr = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MI = 0;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-03 23:57:28 +00:00
|
|
|
|
2009-03-20 05:08:24 +00:00
|
|
|
if (DoIncr && I != BB->end()) ++I;
|
2008-03-03 23:57:28 +00:00
|
|
|
|
2007-02-23 01:11:26 +00:00
|
|
|
// Update register states.
|
2007-04-09 01:19:33 +00:00
|
|
|
if (RS && MI) RS->forward(MI);
|
2007-02-23 01:11:26 +00:00
|
|
|
}
|
2008-03-03 22:11:16 +00:00
|
|
|
|
2007-05-01 09:01:42 +00:00
|
|
|
assert(SPAdj == 0 && "Unbalanced call frame setup / destroy pairs?");
|
2007-02-23 01:11:26 +00:00
|
|
|
}
|
2002-12-28 20:43:30 +00:00
|
|
|
}
|
2009-05-11 17:04:19 +00:00
|
|
|
|