PrologEpilogInserter.cpp revision bbeeb2a61ea19fbb5449260165b56c40fdc4860b
1//===-- PrologEpilogInserter.cpp - Insert Prolog/Epilog code in function --===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass is responsible for finalizing the functions frame layout, saving
11// callee saved registers, and for emitting prolog & epilog code for the
12// function.
13//
14// This pass must be run after register allocation.  After this pass is
15// executed, it is illegal to construct MO_FrameIndex operands.
16//
17//===----------------------------------------------------------------------===//
18
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/CodeGen/MachineFunctionPass.h"
21#include "llvm/CodeGen/MachineInstr.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineModuleInfo.h"
24#include "llvm/CodeGen/MachineRegisterInfo.h"
25#include "llvm/CodeGen/RegisterScavenging.h"
26#include "llvm/Target/TargetMachine.h"
27#include "llvm/Target/TargetRegisterInfo.h"
28#include "llvm/Target/TargetFrameInfo.h"
29#include "llvm/Target/TargetInstrInfo.h"
30#include "llvm/Support/Compiler.h"
31#include "llvm/ADT/STLExtras.h"
32#include <climits>
33using namespace llvm;
34
35namespace {
36  struct VISIBILITY_HIDDEN PEI : public MachineFunctionPass {
37    static char ID;
38    PEI() : MachineFunctionPass(&ID) {}
39
40    const char *getPassName() const {
41      return "Prolog/Epilog Insertion & Frame Finalization";
42    }
43
44    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
45      AU.setPreservesAll();
46      MachineFunctionPass::getAnalysisUsage(AU);
47    }
48
49    /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
50    /// frame indexes with appropriate references.
51    ///
52    bool runOnMachineFunction(MachineFunction &Fn) {
53      const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
54      RS = TRI->requiresRegisterScavenging(Fn) ? new RegScavenger() : NULL;
55
56      // Get MachineModuleInfo so that we can track the construction of the
57      // frame.
58      if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>())
59        Fn.getFrameInfo()->setMachineModuleInfo(MMI);
60
61      // Allow the target machine to make some adjustments to the function
62      // e.g. UsedPhysRegs before calculateCalleeSavedRegisters.
63      TRI->processFunctionBeforeCalleeSavedScan(Fn, RS);
64
65      // Scan the function for modified callee saved registers and insert spill
66      // code for any callee saved registers that are modified.  Also calculate
67      // the MaxCallFrameSize and HasCalls variables for the function's frame
68      // information and eliminates call frame pseudo instructions.
69      calculateCalleeSavedRegisters(Fn);
70
71      // Add the code to save and restore the callee saved registers
72      saveCalleeSavedRegisters(Fn);
73
74      // Allow the target machine to make final modifications to the function
75      // before the frame layout is finalized.
76      TRI->processFunctionBeforeFrameFinalized(Fn);
77
78      // Calculate actual frame offsets for all of the abstract stack objects...
79      calculateFrameObjectOffsets(Fn);
80
81      // Add prolog and epilog code to the function.  This function is required
82      // to align the stack frame as necessary for any stack variables or
83      // called functions.  Because of this, calculateCalleeSavedRegisters
84      // must be called before this function in order to set the HasCalls
85      // and MaxCallFrameSize variables.
86      insertPrologEpilogCode(Fn);
87
88      // Replace all MO_FrameIndex operands with physical register references
89      // and actual offsets.
90      //
91      replaceFrameIndices(Fn);
92
93      delete RS;
94      return true;
95    }
96
97  private:
98    RegScavenger *RS;
99
100    // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
101    // stack frame indexes.
102    unsigned MinCSFrameIndex, MaxCSFrameIndex;
103
104    void calculateCalleeSavedRegisters(MachineFunction &Fn);
105    void saveCalleeSavedRegisters(MachineFunction &Fn);
106    void calculateFrameObjectOffsets(MachineFunction &Fn);
107    void replaceFrameIndices(MachineFunction &Fn);
108    void insertPrologEpilogCode(MachineFunction &Fn);
109  };
110  char PEI::ID = 0;
111}
112
113
114/// createPrologEpilogCodeInserter - This function returns a pass that inserts
115/// prolog and epilog code, and eliminates abstract frame references.
116///
117FunctionPass *llvm::createPrologEpilogCodeInserter() { return new PEI(); }
118
119
120/// calculateCalleeSavedRegisters - Scan the function for modified callee saved
121/// registers.  Also calculate the MaxCallFrameSize and HasCalls variables for
122/// the function's frame information and eliminates call frame pseudo
123/// instructions.
124///
125void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
126  const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
127  const TargetFrameInfo *TFI = Fn.getTarget().getFrameInfo();
128
129  // Get the callee saved register list...
130  const unsigned *CSRegs = RegInfo->getCalleeSavedRegs(&Fn);
131
132  // Get the function call frame set-up and tear-down instruction opcode
133  int FrameSetupOpcode   = RegInfo->getCallFrameSetupOpcode();
134  int FrameDestroyOpcode = RegInfo->getCallFrameDestroyOpcode();
135
136  // These are used to keep track the callee-save area. Initialize them.
137  MinCSFrameIndex = INT_MAX;
138  MaxCSFrameIndex = 0;
139
140  // Early exit for targets which have no callee saved registers and no call
141  // frame setup/destroy pseudo instructions.
142  if ((CSRegs == 0 || CSRegs[0] == 0) &&
143      FrameSetupOpcode == -1 && FrameDestroyOpcode == -1)
144    return;
145
146  unsigned MaxCallFrameSize = 0;
147  bool HasCalls = false;
148
149  std::vector<MachineBasicBlock::iterator> FrameSDOps;
150  for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB)
151    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I)
152      if (I->getOpcode() == FrameSetupOpcode ||
153          I->getOpcode() == FrameDestroyOpcode) {
154        assert(I->getNumOperands() >= 1 && "Call Frame Setup/Destroy Pseudo"
155               " instructions should have a single immediate argument!");
156        unsigned Size = I->getOperand(0).getImm();
157        if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
158        HasCalls = true;
159        FrameSDOps.push_back(I);
160      }
161
162  MachineFrameInfo *FFI = Fn.getFrameInfo();
163  FFI->setHasCalls(HasCalls);
164  FFI->setMaxCallFrameSize(MaxCallFrameSize);
165
166  for (unsigned i = 0, e = FrameSDOps.size(); i != e; ++i) {
167    MachineBasicBlock::iterator I = FrameSDOps[i];
168    // If call frames are not being included as part of the stack frame,
169    // and there is no dynamic allocation (therefore referencing frame slots
170    // off sp), leave the pseudo ops alone. We'll eliminate them later.
171    if (RegInfo->hasReservedCallFrame(Fn) || RegInfo->hasFP(Fn))
172      RegInfo->eliminateCallFramePseudoInstr(Fn, *I->getParent(), I);
173  }
174
175  // Now figure out which *callee saved* registers are modified by the current
176  // function, thus needing to be saved and restored in the prolog/epilog.
177  //
178  const TargetRegisterClass* const *CSRegClasses =
179    RegInfo->getCalleeSavedRegClasses(&Fn);
180  std::vector<CalleeSavedInfo> CSI;
181  for (unsigned i = 0; CSRegs[i]; ++i) {
182    unsigned Reg = CSRegs[i];
183    if (Fn.getRegInfo().isPhysRegUsed(Reg)) {
184        // If the reg is modified, save it!
185      CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
186    } else {
187      for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
188           *AliasSet; ++AliasSet) {  // Check alias registers too.
189        if (Fn.getRegInfo().isPhysRegUsed(*AliasSet)) {
190          CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
191          break;
192        }
193      }
194    }
195  }
196
197  if (CSI.empty())
198    return;   // Early exit if no callee saved registers are modified!
199
200  unsigned NumFixedSpillSlots;
201  const std::pair<unsigned,int> *FixedSpillSlots =
202    TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
203
204  // Now that we know which registers need to be saved and restored, allocate
205  // stack slots for them.
206  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
207    unsigned Reg = CSI[i].getReg();
208    const TargetRegisterClass *RC = CSI[i].getRegClass();
209
210    // Check to see if this physreg must be spilled to a particular stack slot
211    // on this target.
212    const std::pair<unsigned,int> *FixedSlot = FixedSpillSlots;
213    while (FixedSlot != FixedSpillSlots+NumFixedSpillSlots &&
214           FixedSlot->first != Reg)
215      ++FixedSlot;
216
217    int FrameIdx;
218    if (FixedSlot == FixedSpillSlots+NumFixedSpillSlots) {
219      // Nope, just spill it anywhere convenient.
220      unsigned Align = RC->getAlignment();
221      unsigned StackAlign = TFI->getStackAlignment();
222      // We may not be able to sastify the desired alignment specification of
223      // the TargetRegisterClass if the stack alignment is smaller. Use the min.
224      Align = std::min(Align, StackAlign);
225      FrameIdx = FFI->CreateStackObject(RC->getSize(), Align);
226      if ((unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
227      if ((unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
228    } else {
229      // Spill it to the stack where we must.
230      FrameIdx = FFI->CreateFixedObject(RC->getSize(), FixedSlot->second);
231    }
232    CSI[i].setFrameIdx(FrameIdx);
233  }
234
235  FFI->setCalleeSavedInfo(CSI);
236}
237
238/// saveCalleeSavedRegisters -  Insert spill code for any callee saved registers
239/// that are modified in the function.
240///
241void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
242  // Get callee saved register information.
243  MachineFrameInfo *FFI = Fn.getFrameInfo();
244  const std::vector<CalleeSavedInfo> &CSI = FFI->getCalleeSavedInfo();
245
246  // Early exit if no callee saved registers are modified!
247  if (CSI.empty())
248    return;
249
250  const TargetInstrInfo &TII = *Fn.getTarget().getInstrInfo();
251
252  // Now that we have a stack slot for each register to be saved, insert spill
253  // code into the entry block.
254  MachineBasicBlock *MBB = Fn.begin();
255  MachineBasicBlock::iterator I = MBB->begin();
256
257  if (!TII.spillCalleeSavedRegisters(*MBB, I, CSI)) {
258    for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
259      // Add the callee-saved register as live-in. It's killed at the spill.
260      MBB->addLiveIn(CSI[i].getReg());
261
262      // Insert the spill to the stack frame.
263      TII.storeRegToStackSlot(*MBB, I, CSI[i].getReg(), true,
264                                   CSI[i].getFrameIdx(), CSI[i].getRegClass());
265    }
266  }
267
268  // Add code to restore the callee-save registers in each exiting block.
269  for (MachineFunction::iterator FI = Fn.begin(), E = Fn.end(); FI != E; ++FI)
270    // If last instruction is a return instruction, add an epilogue.
271    if (!FI->empty() && FI->back().getDesc().isReturn()) {
272      MBB = FI;
273      I = MBB->end(); --I;
274
275      // Skip over all terminator instructions, which are part of the return
276      // sequence.
277      MachineBasicBlock::iterator I2 = I;
278      while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator())
279        I = I2;
280
281      bool AtStart = I == MBB->begin();
282      MachineBasicBlock::iterator BeforeI = I;
283      if (!AtStart)
284        --BeforeI;
285
286      // Restore all registers immediately before the return and any terminators
287      // that preceed it.
288      if (!TII.restoreCalleeSavedRegisters(*MBB, I, CSI)) {
289        for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
290          TII.loadRegFromStackSlot(*MBB, I, CSI[i].getReg(),
291                                        CSI[i].getFrameIdx(),
292                                        CSI[i].getRegClass());
293          assert(I != MBB->begin() &&
294                 "loadRegFromStackSlot didn't insert any code!");
295          // Insert in reverse order.  loadRegFromStackSlot can insert multiple
296          // instructions.
297          if (AtStart)
298            I = MBB->begin();
299          else {
300            I = BeforeI;
301            ++I;
302          }
303        }
304      }
305    }
306}
307
308
309/// calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
310/// abstract stack objects.
311///
312void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
313  const TargetFrameInfo &TFI = *Fn.getTarget().getFrameInfo();
314
315  bool StackGrowsDown =
316    TFI.getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
317
318  // Loop over all of the stack objects, assigning sequential addresses...
319  MachineFrameInfo *FFI = Fn.getFrameInfo();
320
321  unsigned MaxAlign = FFI->getMaxAlignment();
322
323  // Start at the beginning of the local area.
324  // The Offset is the distance from the stack top in the direction
325  // of stack growth -- so it's always nonnegative.
326  int64_t Offset = TFI.getOffsetOfLocalArea();
327  if (StackGrowsDown)
328    Offset = -Offset;
329  assert(Offset >= 0
330         && "Local area offset should be in direction of stack growth");
331
332  // If there are fixed sized objects that are preallocated in the local area,
333  // non-fixed objects can't be allocated right at the start of local area.
334  // We currently don't support filling in holes in between fixed sized objects,
335  // so we adjust 'Offset' to point to the end of last fixed sized
336  // preallocated object.
337  for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
338    int64_t FixedOff;
339    if (StackGrowsDown) {
340      // The maximum distance from the stack pointer is at lower address of
341      // the object -- which is given by offset. For down growing stack
342      // the offset is negative, so we negate the offset to get the distance.
343      FixedOff = -FFI->getObjectOffset(i);
344    } else {
345      // The maximum distance from the start pointer is at the upper
346      // address of the object.
347      FixedOff = FFI->getObjectOffset(i) + FFI->getObjectSize(i);
348    }
349    if (FixedOff > Offset) Offset = FixedOff;
350  }
351
352  // First assign frame offsets to stack objects that are used to spill
353  // callee saved registers.
354  if (StackGrowsDown) {
355    for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
356      // If stack grows down, we need to add size of find the lowest
357      // address of the object.
358      Offset += FFI->getObjectSize(i);
359
360      unsigned Align = FFI->getObjectAlignment(i);
361      // If the alignment of this object is greater than that of the stack, then
362      // increase the stack alignment to match.
363      MaxAlign = std::max(MaxAlign, Align);
364      // Adjust to alignment boundary
365      Offset = (Offset+Align-1)/Align*Align;
366
367      FFI->setObjectOffset(i, -Offset);        // Set the computed offset
368    }
369  } else {
370    int MaxCSFI = MaxCSFrameIndex, MinCSFI = MinCSFrameIndex;
371    for (int i = MaxCSFI; i >= MinCSFI ; --i) {
372      unsigned Align = FFI->getObjectAlignment(i);
373      // If the alignment of this object is greater than that of the stack, then
374      // increase the stack alignment to match.
375      MaxAlign = std::max(MaxAlign, Align);
376      // Adjust to alignment boundary
377      Offset = (Offset+Align-1)/Align*Align;
378
379      FFI->setObjectOffset(i, Offset);
380      Offset += FFI->getObjectSize(i);
381    }
382  }
383
384  // Make sure the special register scavenging spill slot is closest to the
385  // frame pointer if a frame pointer is required.
386  const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
387  if (RS && RegInfo->hasFP(Fn)) {
388    int SFI = RS->getScavengingFrameIndex();
389    if (SFI >= 0) {
390      // If stack grows down, we need to add size of the lowest
391      // address of the object.
392      if (StackGrowsDown)
393        Offset += FFI->getObjectSize(SFI);
394
395      unsigned Align = FFI->getObjectAlignment(SFI);
396      // Adjust to alignment boundary
397      Offset = (Offset+Align-1)/Align*Align;
398
399      if (StackGrowsDown) {
400        FFI->setObjectOffset(SFI, -Offset);        // Set the computed offset
401      } else {
402        FFI->setObjectOffset(SFI, Offset);
403        Offset += FFI->getObjectSize(SFI);
404      }
405    }
406  }
407
408  // Then assign frame offsets to stack objects that are not used to spill
409  // callee saved registers.
410  for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
411    if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
412      continue;
413    if (RS && (int)i == RS->getScavengingFrameIndex())
414      continue;
415    if (FFI->isDeadObjectIndex(i))
416      continue;
417
418    // If stack grows down, we need to add size of find the lowest
419    // address of the object.
420    if (StackGrowsDown)
421      Offset += FFI->getObjectSize(i);
422
423    unsigned Align = FFI->getObjectAlignment(i);
424    // If the alignment of this object is greater than that of the stack, then
425    // increase the stack alignment to match.
426    MaxAlign = std::max(MaxAlign, Align);
427    // Adjust to alignment boundary
428    Offset = (Offset+Align-1)/Align*Align;
429
430    if (StackGrowsDown) {
431      FFI->setObjectOffset(i, -Offset);        // Set the computed offset
432    } else {
433      FFI->setObjectOffset(i, Offset);
434      Offset += FFI->getObjectSize(i);
435    }
436  }
437
438  // Make sure the special register scavenging spill slot is closest to the
439  // stack pointer.
440  if (RS && !RegInfo->hasFP(Fn)) {
441    int SFI = RS->getScavengingFrameIndex();
442    if (SFI >= 0) {
443      // If stack grows down, we need to add size of find the lowest
444      // address of the object.
445      if (StackGrowsDown)
446        Offset += FFI->getObjectSize(SFI);
447
448      unsigned Align = FFI->getObjectAlignment(SFI);
449      // If the alignment of this object is greater than that of the
450      // stack, then increase the stack alignment to match.
451      MaxAlign = std::max(MaxAlign, Align);
452      // Adjust to alignment boundary
453      Offset = (Offset+Align-1)/Align*Align;
454
455      if (StackGrowsDown) {
456        FFI->setObjectOffset(SFI, -Offset);        // Set the computed offset
457      } else {
458        FFI->setObjectOffset(SFI, Offset);
459        Offset += FFI->getObjectSize(SFI);
460      }
461    }
462  }
463
464  // Round up the size to a multiple of the alignment, but only if there are
465  // calls or alloca's in the function.  This ensures that any calls to
466  // subroutines have their stack frames suitable aligned.
467  // Also do this if we need runtime alignment of the stack.  In this case
468  // offsets will be relative to SP not FP; round up the stack size so this
469  // works.
470  if (!RegInfo->targetHandlesStackFrameRounding() &&
471      (FFI->hasCalls() || FFI->hasVarSizedObjects() ||
472       (RegInfo->needsStackRealignment(Fn) &&
473        FFI->getObjectIndexEnd() != 0))) {
474    // If we have reserved argument space for call sites in the function
475    // immediately on entry to the current function, count it as part of the
476    // overall stack size.
477    if (RegInfo->hasReservedCallFrame(Fn))
478      Offset += FFI->getMaxCallFrameSize();
479
480    unsigned AlignMask = std::max(TFI.getStackAlignment(),MaxAlign) - 1;
481    Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
482  }
483
484  // Update frame info to pretend that this is part of the stack...
485  FFI->setStackSize(Offset+TFI.getOffsetOfLocalArea());
486
487  // Remember the required stack alignment in case targets need it to perform
488  // dynamic stack alignment.
489  FFI->setMaxAlignment(MaxAlign);
490}
491
492
493/// insertPrologEpilogCode - Scan the function for modified callee saved
494/// registers, insert spill code for these callee saved registers, then add
495/// prolog and epilog code to the function.
496///
497void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
498  const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
499
500  // Add prologue to the function...
501  TRI->emitPrologue(Fn);
502
503  // Add epilogue to restore the callee-save registers in each exiting block
504  for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
505    // If last instruction is a return instruction, add an epilogue
506    if (!I->empty() && I->back().getDesc().isReturn())
507      TRI->emitEpilogue(Fn, *I);
508  }
509}
510
511
512/// replaceFrameIndices - Replace all MO_FrameIndex operands with physical
513/// register references and actual offsets.
514///
515void PEI::replaceFrameIndices(MachineFunction &Fn) {
516  if (!Fn.getFrameInfo()->hasStackObjects()) return; // Nothing to do?
517
518  const TargetMachine &TM = Fn.getTarget();
519  assert(TM.getRegisterInfo() && "TM::getRegisterInfo() must be implemented!");
520  const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
521  const TargetFrameInfo *TFI = TM.getFrameInfo();
522  bool StackGrowsDown =
523    TFI->getStackGrowthDirection() == TargetFrameInfo::StackGrowsDown;
524  int FrameSetupOpcode   = TRI.getCallFrameSetupOpcode();
525  int FrameDestroyOpcode = TRI.getCallFrameDestroyOpcode();
526
527  for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
528    int SPAdj = 0;  // SP offset due to call frame setup / destroy.
529    if (RS) RS->enterBasicBlock(BB);
530    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
531      MachineInstr *MI = I;
532
533      if (I->getOpcode() == TargetInstrInfo::DECLARE) {
534        // Ignore it.
535        ++I;
536        continue;
537      }
538
539      if (I->getOpcode() == FrameSetupOpcode ||
540          I->getOpcode() == FrameDestroyOpcode) {
541        // Remember how much SP has been adjusted to create the call
542        // frame.
543        int Size = I->getOperand(0).getImm();
544
545        if ((!StackGrowsDown && I->getOpcode() == FrameSetupOpcode) ||
546            (StackGrowsDown && I->getOpcode() == FrameDestroyOpcode))
547          Size = -Size;
548
549        SPAdj += Size;
550
551        MachineBasicBlock::iterator PrevI = prior(I);
552        TRI.eliminateCallFramePseudoInstr(Fn, *BB, I);
553
554        // Visit the instructions created by eliminateCallFramePseudoInstr().
555        I = next(PrevI);
556        continue;
557      }
558
559      bool DoIncr = true;
560
561      for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
562        if (MI->getOperand(i).isFrameIndex()) {
563          // Some instructions (e.g. inline asm instructions) can have
564          // multiple frame indices and/or cause eliminateFrameIndex
565          // to insert more than one instruction. We need the register
566          // scavenger to go through all of these instructions so that
567          // it can update its register information. We keep the
568          // iterator at the point before insertion so that we can
569          // revisit them in full.
570          bool AtBeginning = (I == BB->begin());
571          if (!AtBeginning) --I;
572
573          // If this instruction has a FrameIndex operand, we need to
574          // use that target machine register info object to eliminate
575          // it.
576          TRI.eliminateFrameIndex(MI, SPAdj, RS);
577
578          // Reset the iterator if we were at the beginning of the BB.
579          if (AtBeginning) {
580            I = BB->begin();
581            DoIncr = false;
582          }
583
584          MI = 0;
585          break;
586        }
587
588      if (DoIncr) ++I;
589
590      // Update register states.
591      if (RS && MI) RS->forward(MI);
592    }
593
594    assert(SPAdj == 0 && "Unbalanced call frame setup / destroy pairs?");
595  }
596}
597