LLVM API Documentation

PrologEpilogInserter.cpp

Go to the documentation of this file.
00001 //===-- PrologEpilogInserter.cpp - Insert Prolog/Epilog code in function --===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This pass is responsible for finalizing the functions frame layout, saving
00011 // callee saved registers, and for emitting prolog & epilog code for the
00012 // function.
00013 //
00014 // This pass must be run after register allocation.  After this pass is
00015 // executed, it is illegal to construct MO_FrameIndex operands.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #include "llvm/CodeGen/Passes.h"
00020 #include "llvm/CodeGen/MachineFunctionPass.h"
00021 #include "llvm/CodeGen/MachineInstr.h"
00022 #include "llvm/CodeGen/MachineFrameInfo.h"
00023 #include "llvm/CodeGen/MachineModuleInfo.h"
00024 #include "llvm/CodeGen/MachineRegisterInfo.h"
00025 #include "llvm/CodeGen/RegisterScavenging.h"
00026 #include "llvm/Target/TargetMachine.h"
00027 #include "llvm/Target/TargetRegisterInfo.h"
00028 #include "llvm/Target/TargetFrameInfo.h"
00029 #include "llvm/Target/TargetInstrInfo.h"
00030 #include "llvm/Support/Compiler.h"
00031 #include "llvm/ADT/STLExtras.h"
00032 #include <climits>
00033 using namespace llvm;
00034 
00035 namespace {
00036   struct VISIBILITY_HIDDEN PEI : public MachineFunctionPass {
00037     static char ID;
00038     PEI() : MachineFunctionPass(&ID) {}
00039 
00040     const char *getPassName() const {
00041       return "Prolog/Epilog Insertion & Frame Finalization";
00042     }
00043 
00044     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00045       AU.addPreservedID(MachineLoopInfoID);
00046       AU.addPreservedID(MachineDominatorsID);
00047       MachineFunctionPass::getAnalysisUsage(AU);
00048     }
00049 
00050     /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
00051     /// frame indexes with appropriate references.
00052     ///
00053     bool runOnMachineFunction(MachineFunction &Fn) {
00054       const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
00055       RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : NULL;
00056 
00057       // Get MachineModuleInfo so that we can track the construction of the
00058       // frame.
00059       if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>())
00060         Fn.getFrameInfo()->setMachineModuleInfo(MMI);
00061 
00062       // Allow the target machine to make some adjustments to the function
00063       // e.g. UsedPhysRegs before calculateCalleeSavedRegisters.
00064       TRI->processFunctionBeforeCalleeSavedScan(Fn, RS);
00065 
00066       // Scan the function for modified callee saved registers and insert spill
00067       // code for any callee saved registers that are modified.  Also calculate
00068       // the MaxCallFrameSize and HasCalls variables for the function's frame
00069       // information and eliminates call frame pseudo instructions.
00070       calculateCalleeSavedRegisters(Fn);
00071 
00072       // Add the code to save and restore the callee saved registers
00073       saveCalleeSavedRegisters(Fn);
00074 
00075       // Allow the target machine to make final modifications to the function
00076       // before the frame layout is finalized.
00077       TRI->processFunctionBeforeFrameFinalized(Fn);
00078 
00079       // Calculate actual frame offsets for all of the abstract stack objects...
00080       calculateFrameObjectOffsets(Fn);
00081 
00082       // Add prolog and epilog code to the function.  This function is required
00083       // to align the stack frame as necessary for any stack variables or
00084       // called functions.  Because of this, calculateCalleeSavedRegisters
00085       // must be called before this function in order to set the HasCalls
00086       // and MaxCallFrameSize variables.
00087       insertPrologEpilogCode(Fn);
00088 
00089       // Replace all MO_FrameIndex operands with physical register references
00090       // and actual offsets.
00091       //
00092       replaceFrameIndices(Fn);
00093 
00094       delete RS;
00095       return true;
00096     }
00097   
00098   private:
00099     RegScavenger *RS;
00100 
00101     // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
00102     // stack frame indexes.
00103     unsigned MinCSFrameIndex, MaxCSFrameIndex;
00104 
00105     void calculateCalleeSavedRegisters(MachineFunction &Fn);
00106     void saveCalleeSavedRegisters(MachineFunction &Fn);
00107     void calculateFrameObjectOffsets(MachineFunction &Fn);
00108     void replaceFrameIndices(MachineFunction &Fn);
00109     void insertPrologEpilogCode(MachineFunction &Fn);
00110   };
00111   char PEI::ID = 0;
00112 }
00113 
00114 
00115 /// createPrologEpilogCodeInserter - This function returns a pass that inserts
00116 /// prolog and epilog code, and eliminates abstract frame references.
00117 ///
00118 FunctionPass *llvm::createPrologEpilogCodeInserter() { return new PEI(); }
00119 
00120 
00121 /// calculateCalleeSavedRegisters - Scan the function for modified callee saved
00122 /// registers.  Also calculate the MaxCallFrameSize and HasCalls variables for
00123 /// the function's frame information and eliminates call frame pseudo
00124 /// instructions.
00125 ///
00126 void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
00127   const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
00128   const TargetFrameInfo *TFI = Fn.getTarget().getFrameInfo();
00129 
00130   // Get the callee saved register list...
00131   const unsigned *CSRegs = RegInfo->getCalleeSavedRegs(&Fn);
00132 
00133   // Get the function call frame set-up and tear-down instruction opcode
00134   int FrameSetupOpcode   = RegInfo->getCallFrameSetupOpcode();
00135   int FrameDestroyOpcode = RegInfo->getCallFrameDestroyOpcode();
00136 
00137   // These are used to keep track the callee-save area. Initialize them.
00138   MinCSFrameIndex = INT_MAX;
00139   MaxCSFrameIndex = 0;
00140 
00141   // Early exit for targets which have no callee saved registers and no call
00142   // frame setup/destroy pseudo instructions.
00143   if ((CSRegs == 0 || CSRegs[0] == 0) &&
00144       FrameSetupOpcode == -1 && FrameDestroyOpcode == -1)
00145     return;
00146 
00147   unsigned MaxCallFrameSize = 0;
00148   bool HasCalls = false;
00149 
00150   std::vector<MachineBasicBlock::iterator> FrameSDOps;
00151   for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB)
00152     for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
00153       if (I->getOpcode() == FrameSetupOpcode ||
00154           I->getOpcode() == FrameDestroyOpcode) {
00155         assert(I->getNumOperands() >= 1 && "Call Frame Setup/Destroy Pseudo"
00156                " instructions should have a single immediate argument!");
00157         unsigned Size = I->getOperand(0).getImm();
00158         if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
00159         HasCalls = true;
00160         FrameSDOps.push_back(I);
00161       }
00162 
00163   MachineFrameInfo *FFI = Fn.getFrameInfo();
00164   FFI->setHasCalls(HasCalls);
00165   FFI->setMaxCallFrameSize(MaxCallFrameSize);
00166 
00167   for (unsigned i = 0, e = FrameSDOps.size(); i != e; ++i) {
00168     MachineBasicBlock::iterator I = FrameSDOps[i];
00169     // If call frames are not being included as part of the stack frame,
00170     // and there is no dynamic allocation (therefore referencing frame slots
00171     // off sp), leave the pseudo ops alone. We'll eliminate them later.
00172     if (RegInfo->hasReservedCallFrame(Fn) || RegInfo->hasFP(Fn))
00173       RegInfo->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I);
00174   }
00175 
00176   // Now figure out which *callee saved* registers are modified by the current
00177   // function, thus needing to be saved and restored in the prolog/epilog.
00178   //
00179   const TargetRegisterClass* const *CSRegClasses =
00180     RegInfo->getCalleeSavedRegClasses(&Fn);
00181   std::vector<CalleeSavedInfo> CSI;
00182   for (unsigned i = 0; CSRegs[i]; ++i) {
00183     unsigned Reg = CSRegs[i];
00184     if (Fn.getRegInfo().isPhysRegUsed(Reg)) {
00185         // If the reg is modified, save it!
00186       CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
00187     } else {
00188       for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
00189            *AliasSet; ++AliasSet) {  // Check alias registers too.
00190         if (Fn.getRegInfo().isPhysRegUsed(*AliasSet)) {
00191           CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
00192           break;
00193         }
00194       }
00195     }
00196   }
00197 
00198   if (CSI.empty())
00199     return;   // Early exit if no callee saved registers are modified!
00200 
00201   unsigned NumFixedSpillSlots;
00202   const std::pair<unsigned,int> *FixedSpillSlots =
00203     TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
00204 
00205   // Now that we know which registers need to be saved and restored, allocate
00206   // stack slots for them.
00207   for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
00208     unsigned Reg = CSI[i].getReg();
00209     const TargetRegisterClass *RC = CSI[i].getRegClass();
00210 
00211     // Check to see if this physreg must be spilled to a particular stack slot
00212     // on this target.
00213     const std::pair<unsigned,int> *FixedSlot = FixedSpillSlots;
00214     while (FixedSlot != FixedSpillSlots+NumFixedSpillSlots &&
00215            FixedSlot->first != Reg)
00216       ++FixedSlot;
00217 
00218     int FrameIdx;
00219     if (FixedSlot == FixedSpillSlots+NumFixedSpillSlots) {
00220       // Nope, just spill it anywhere convenient.
00221       unsigned Align = RC->getAlignment();
00222       unsigned StackAlign = TFI->getStackAlignment();
00223       // We may not be able to sastify the desired alignment specification of
00224       // the TargetRegisterClass if the stack alignment is smaller. Use the min.
00225       Align = std::min(Align, StackAlign);
00226       FrameIdx = FFI->CreateStackObject(RC->getSize(), Align);
00227       if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
00228       if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
00229     } else {
00230       // Spill it to the stack where we must.
00231       FrameIdx = FFI->CreateFixedObject(RC->getSize(), FixedSlot->second);
00232     }
00233     CSI[i].setFrameIdx(FrameIdx);
00234   }
00235 
00236   FFI->setCalleeSavedInfo(CSI);
00237 }
00238 
00239 /// saveCalleeSavedRegisters -  Insert spill code for any callee saved registers
00240 /// that are modified in the function.
00241 ///
00242 void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
00243   // Get callee saved register information.
00244   MachineFrameInfo *FFI = Fn.getFrameInfo();
00245   const std::vector<CalleeSavedInfo> &CSI = FFI->getCalleeSavedInfo();
00246   
00247   // Early exit if no callee saved registers are modified!
00248   if (CSI.empty())
00249     return;
00250 
00251   const TargetInstrInfo &TII = *Fn.getTarget().getInstrInfo();
00252 
00253   // Now that we have a stack slot for each register to be saved, insert spill
00254   // code into the entry block.
00255   MachineBasicBlock *MBB = Fn.begin();
00256   MachineBasicBlock::iterator I = MBB->begin();
00257 
00258   if (!TII.spillCalleeSavedRegisters(*MBB, I, CSI)) {
00259     for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
00260       // Add the callee-saved register as live-in. It's killed at the spill.
00261       MBB->addLiveIn(CSI[i].getReg());
00262 
00263       // Insert the spill to the stack frame.
00264       TII.storeRegToStackSlot(*MBB, I, CSI[i].getReg(), true,
00265                                    CSI[i].getFrameIdx(), CSI[i].getRegClass());
00266     }
00267   }
00268 
00269   // Add code to restore the callee-save registers in each exiting block.
00270   for (MachineFunction::iterator FI = Fn.begin(), E = Fn.end(); FI != E; ++FI)
00271     // If last instruction is a return instruction, add an epilogue.
00272     if (!FI->empty() && FI->back().getDesc().isReturn()) {
00273       MBB = FI;
00274       I = MBB->end(); --I;
00275 
00276       // Skip over all terminator instructions, which are part of the return
00277       // sequence.
00278       MachineBasicBlock::iterator I2 = I;
00279       while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator())
00280         I = I2;
00281 
00282       bool AtStart = I == MBB->begin();
00283       MachineBasicBlock::iterator BeforeI = I;
00284       if (!AtStart)
00285         --BeforeI;
00286       
00287       // Restore all registers immediately before the return and any terminators
00288       // that preceed it.
00289       if (!TII.restoreCalleeSavedRegisters(*MBB, I, CSI)) {
00290         for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
00291           TII.loadRegFromStackSlot(*MBB, I, CSI[i].getReg(),
00292                                         CSI[i].getFrameIdx(),
00293                                         CSI[i].getRegClass());
00294           assert(I != MBB->begin() &&
00295                  "loadRegFromStackSlot didn't insert any code!");
00296           // Insert in reverse order.  loadRegFromStackSlot can insert multiple
00297           // instructions.
00298           if (AtStart)
00299             I = MBB->begin();
00300           else {
00301             I = BeforeI;
00302             ++I;
00303           }
00304         }
00305       }
00306     }
00307 }
00308 
00309 /// AdjustStackOffset - Helper function used to adjust the stack frame offset.
00310 static inline void
00311 AdjustStackOffset(MachineFrameInfo *FFI, int FrameIdx,
00312                   bool StackGrowsDown, int64_t &Offset,
00313                   unsigned &MaxAlign) {
00314   // If stack grows down, we need to add size of find the lowest address of the
00315   // object.
00316   if (StackGrowsDown)
00317     Offset += FFI->getObjectSize(FrameIdx);
00318 
00319   unsigned Align = FFI->getObjectAlignment(FrameIdx);
00320 
00321   // If the alignment of this object is greater than that of the stack, then
00322   // increase the stack alignment to match.
00323   MaxAlign = std::max(MaxAlign, Align);
00324 
00325   // Adjust to alignment boundary.
00326   Offset = (Offset + Align - 1) / Align * Align;
00327 
00328   if (StackGrowsDown) {
00329     FFI->setObjectOffset(FrameIdx, -Offset); // Set the computed offset
00330   } else {
00331     FFI->setObjectOffset(FrameIdx, Offset);
00332     Offset += FFI->getObjectSize(FrameIdx);
00333   }
00334 }
00335 
00336 /// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
00337 /// abstract stack objects.
00338 ///
00339 void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
00340   const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
00341 
00342   bool StackGrowsDown =
00343     TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
00344 
00345   // Loop over all of the stack objects, assigning sequential addresses...
00346   MachineFrameInfo *FFI = Fn.getFrameInfo();
00347 
00348   unsigned MaxAlign = FFI->getMaxAlignment();
00349 
00350   // Start at the beginning of the local area.
00351   // The Offset is the distance from the stack top in the direction
00352   // of stack growth -- so it's always nonnegative.
00353   int64_t Offset = TFI.getOffsetOfLocalArea();
00354   if (StackGrowsDown)
00355     Offset = -Offset;
00356   assert(Offset >= 0
00357          && "Local area offset should be in direction of stack growth");
00358 
00359   // If there are fixed sized objects that are preallocated in the local area,
00360   // non-fixed objects can't be allocated right at the start of local area.
00361   // We currently don't support filling in holes in between fixed sized objects,
00362   // so we adjust 'Offset' to point to the end of last fixed sized
00363   // preallocated object.
00364   for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
00365     int64_t FixedOff;
00366     if (StackGrowsDown) {
00367       // The maximum distance from the stack pointer is at lower address of
00368       // the object -- which is given by offset. For down growing stack
00369       // the offset is negative, so we negate the offset to get the distance.
00370       FixedOff = -FFI->getObjectOffset(i);
00371     } else {
00372       // The maximum distance from the start pointer is at the upper
00373       // address of the object.
00374       FixedOff = FFI->getObjectOffset(i) + FFI->getObjectSize(i);
00375     }
00376     if (FixedOff > Offset) Offset = FixedOff;
00377   }
00378 
00379   // First assign frame offsets to stack objects that are used to spill
00380   // callee saved registers.
00381   if (StackGrowsDown) {
00382     for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
00383       // If stack grows down, we need to add size of find the lowest
00384       // address of the object.
00385       Offset += FFI->getObjectSize(i);
00386 
00387       unsigned Align = FFI->getObjectAlignment(i);
00388       // If the alignment of this object is greater than that of the stack, then
00389       // increase the stack alignment to match.
00390       MaxAlign = std::max(MaxAlign, Align);
00391       // Adjust to alignment boundary
00392       Offset = (Offset+Align-1)/Align*Align;
00393 
00394       FFI->setObjectOffset(i, -Offset);        // Set the computed offset
00395     }
00396   } else {
00397     int MaxCSFI = MaxCSFrameIndex, MinCSFI = MinCSFrameIndex;
00398     for (int i = MaxCSFI; i >= MinCSFI ; --i) {
00399       unsigned Align = FFI->getObjectAlignment(i);
00400       // If the alignment of this object is greater than that of the stack, then
00401       // increase the stack alignment to match.
00402       MaxAlign = std::max(MaxAlign, Align);
00403       // Adjust to alignment boundary
00404       Offset = (Offset+Align-1)/Align*Align;
00405 
00406       FFI->setObjectOffset(i, Offset);
00407       Offset += FFI->getObjectSize(i);
00408     }
00409   }
00410 
00411   // Make sure the special register scavenging spill slot is closest to the
00412   // frame pointer if a frame pointer is required.
00413   const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
00414   if (RS && RegInfo->hasFP(Fn)) {
00415     int SFI = RS->getScavengingFrameIndex();
00416     if (SFI >= 0)
00417       AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
00418   }
00419 
00420   // Make sure that the stack protector comes before the local variables on the
00421   // stack.
00422   if (FFI->getStackProtectorIndex() >= 0)
00423     AdjustStackOffset(FFI, FFI->getStackProtectorIndex(), StackGrowsDown,
00424                       Offset, MaxAlign);
00425 
00426   // Then assign frame offsets to stack objects that are not used to spill
00427   // callee saved registers.
00428   for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
00429     if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
00430       continue;
00431     if (RS && (int)i == RS->getScavengingFrameIndex())
00432       continue;
00433     if (FFI->isDeadObjectIndex(i))
00434       continue;
00435     if (FFI->getStackProtectorIndex() == (int)i)
00436       continue;
00437 
00438     AdjustStackOffset(FFI, i, StackGrowsDown, Offset, MaxAlign);
00439   }
00440 
00441   // Make sure the special register scavenging spill slot is closest to the
00442   // stack pointer.
00443   if (RS && !RegInfo->hasFP(Fn)) {
00444     int SFI = RS->getScavengingFrameIndex();
00445     if (SFI >= 0)
00446       AdjustStackOffset(FFI, SFI, StackGrowsDown, Offset, MaxAlign);
00447   }
00448 
00449   // Round up the size to a multiple of the alignment, but only if there are
00450   // calls or alloca's in the function.  This ensures that any calls to
00451   // subroutines have their stack frames suitable aligned.
00452   // Also do this if we need runtime alignment of the stack.  In this case
00453   // offsets will be relative to SP not FP; round up the stack size so this
00454   // works.
00455   if (!RegInfo->targetHandlesStackFrameRounding() &&
00456       (FFI->hasCalls() || FFI->hasVarSizedObjects() || 
00457        (RegInfo->needsStackRealignment(Fn) &&
00458         FFI->getObjectIndexEnd() != 0))) {
00459     // If we have reserved argument space for call sites in the function
00460     // immediately on entry to the current function, count it as part of the
00461     // overall stack size.
00462     if (RegInfo->hasReservedCallFrame(Fn))
00463       Offset += FFI->getMaxCallFrameSize();
00464 
00465     unsigned AlignMask = std::max(TFI.getStackAlignment(),MaxAlign) - 1;
00466     Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
00467   }
00468 
00469   // Update frame info to pretend that this is part of the stack...
00470   FFI->setStackSize(Offset+TFI.getOffsetOfLocalArea());
00471 
00472   // Remember the required stack alignment in case targets need it to perform
00473   // dynamic stack alignment.
00474   FFI->setMaxAlignment(MaxAlign);
00475 }
00476 
00477 
00478 /// insertPrologEpilogCode - Scan the function for modified callee saved
00479 /// registers, insert spill code for these callee saved registers, then add
00480 /// prolog and epilog code to the function.
00481 ///
00482 void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
00483   const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
00484 
00485   // Add prologue to the function...
00486   TRI->emitPrologue(Fn);
00487 
00488   // Add epilogue to restore the callee-save registers in each exiting block
00489   for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
00490     // If last instruction is a return instruction, add an epilogue
00491     if (!I->empty() && I->back().getDesc().isReturn())
00492       TRI->emitEpilogue(Fn, *I);
00493   }
00494 }
00495 
00496 
00497 /// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
00498 /// register references and actual offsets.
00499 ///
00500 void PEI::replaceFrameIndices(MachineFunction &Fn) {
00501   if (!Fn.getFrameInfo()->hasStackObjects()) return; // Nothing to do?
00502 
00503   const TargetMachine &TM = Fn.getTarget();
00504   assert(TM.getRegisterInfo() && "TM::getRegisterInfo() must be implemented!");
00505   const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
00506   const TargetFrameInfo *TFI = TM.getFrameInfo();
00507   bool StackGrowsDown =
00508     TFI->getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
00509   int FrameSetupOpcode   = TRI.getCallFrameSetupOpcode();
00510   int FrameDestroyOpcode = TRI.getCallFrameDestroyOpcode();
00511 
00512   for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
00513     int SPAdj = 0;  // SP offset due to call frame setup / destroy.
00514     if (RS) RS->enterBasicBlock(BB);
00515     for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
00516       MachineInstr *MI = I;
00517 
00518       if (I->getOpcode() == TargetInstrInfo::DECLARE) {
00519         // Ignore it.
00520         ++I;
00521         continue;
00522       }
00523 
00524       if (I->getOpcode() == FrameSetupOpcode ||
00525           I->getOpcode() == FrameDestroyOpcode) {
00526         // Remember how much SP has been adjusted to create the call
00527         // frame.
00528         int Size = I->getOperand(0).getImm();
00529 
00530         if ((!StackGrowsDown && I->getOpcode() == FrameSetupOpcode) ||
00531             (StackGrowsDown && I->getOpcode() == FrameDestroyOpcode))
00532           Size = -Size;
00533 
00534         SPAdj += Size;
00535 
00536         MachineBasicBlock::iterator PrevI = prior(I);
00537         TRI.eliminateCallFramePseudoInstr(Fn, *BB, I);
00538 
00539         // Visit the instructions created by eliminateCallFramePseudoInstr().
00540         I = next(PrevI);
00541         continue;
00542       }
00543 
00544       bool DoIncr = true;
00545 
00546       for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
00547         if (MI->getOperand(i).isFI()) {
00548           // Some instructions (e.g. inline asm instructions) can have
00549           // multiple frame indices and/or cause eliminateFrameIndex
00550           // to insert more than one instruction. We need the register
00551           // scavenger to go through all of these instructions so that
00552           // it can update its register information. We keep the
00553           // iterator at the point before insertion so that we can
00554           // revisit them in full.
00555           bool AtBeginning = (I == BB->begin());
00556           if (!AtBeginning) --I;
00557 
00558           // If this instruction has a FrameIndex operand, we need to
00559           // use that target machine register info object to eliminate
00560           // it.
00561           TRI.eliminateFrameIndex(MI, SPAdj, RS);
00562 
00563           // Reset the iterator if we were at the beginning of the BB.
00564           if (AtBeginning) {
00565             I = BB->begin();
00566             DoIncr = false;
00567           }
00568 
00569           MI = 0;
00570           break;
00571         }
00572 
00573       if (DoIncr) ++I;
00574 
00575       // Update register states.
00576       if (RS && MI) RS->forward(MI);
00577     }
00578 
00579     assert(SPAdj == 0 && "Unbalanced call frame setup / destroy pairs?");
00580   }
00581 }



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.