1 //===-- PrologEpilogInserter.h - Prolog/Epilog code insertion -*- C++ -*---===// 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 #ifndef LLVM_CODEGEN_PEI_H 20 #define LLVM_CODEGEN_PEI_H 21 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/SparseBitVector.h" 24 #include "llvm/CodeGen/MachineFunctionPass.h" 25 #include "llvm/CodeGen/MachineLoopInfo.h" 26 #include "llvm/CodeGen/Passes.h" 27 #include "llvm/Target/TargetRegisterInfo.h" 28 29 namespace llvm { 30 class RegScavenger; 31 class MachineBasicBlock; 32 33 class PEI : public MachineFunctionPass { 34 public: 35 static char ID; 36 PEI() : MachineFunctionPass(ID) { 37 initializePEIPass(*PassRegistry::getPassRegistry()); 38 } 39 40 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 41 42 /// runOnMachineFunction - Insert prolog/epilog code and replace abstract 43 /// frame indexes with appropriate references. 44 /// 45 bool runOnMachineFunction(MachineFunction &Fn); 46 47 private: 48 RegScavenger *RS; 49 50 // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved 51 // stack frame indexes. 52 unsigned MinCSFrameIndex, MaxCSFrameIndex; 53 54 // Entry and return blocks of the current function. 55 MachineBasicBlock* EntryBlock; 56 SmallVector<MachineBasicBlock*, 4> ReturnBlocks; 57 58 // Flag to control whether to use the register scavenger to resolve 59 // frame index materialization registers. Set according to 60 // TRI->requiresFrameIndexScavenging() for the curren function. 61 bool FrameIndexVirtualScavenging; 62 63 void calculateSets(MachineFunction &Fn); 64 void calculateCallsInformation(MachineFunction &Fn); 65 void calculateCalleeSavedRegisters(MachineFunction &Fn); 66 void insertCSRSpillsAndRestores(MachineFunction &Fn); 67 void calculateFrameObjectOffsets(MachineFunction &Fn); 68 void replaceFrameIndices(MachineFunction &Fn); 69 void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn, 70 int &SPAdj); 71 void scavengeFrameVirtualRegs(MachineFunction &Fn); 72 void insertPrologEpilogCode(MachineFunction &Fn); 73 74 // Convenience for recognizing return blocks. 75 bool isReturnBlock(MachineBasicBlock* MBB); 76 }; 77 } // End llvm namespace 78 #endif 79