LLVM API Documentation

PrologEpilogInserter.h
Go to the documentation of this file.
00001 //===-- PrologEpilogInserter.h - Prolog/Epilog code insertion -*- C++ -*---===//
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 #ifndef LLVM_LIB_CODEGEN_PROLOGEPILOGINSERTER_H
00020 #define LLVM_LIB_CODEGEN_PROLOGEPILOGINSERTER_H
00021 
00022 #include "llvm/ADT/DenseMap.h"
00023 #include "llvm/ADT/SparseBitVector.h"
00024 #include "llvm/CodeGen/MachineFunctionPass.h"
00025 #include "llvm/CodeGen/MachineLoopInfo.h"
00026 #include "llvm/CodeGen/Passes.h"
00027 #include "llvm/Target/TargetRegisterInfo.h"
00028 
00029 namespace llvm {
00030   class RegScavenger;
00031   class MachineBasicBlock;
00032 
00033   class PEI : public MachineFunctionPass {
00034   public:
00035     static char ID;
00036     PEI() : MachineFunctionPass(ID) {
00037       initializePEIPass(*PassRegistry::getPassRegistry());
00038     }
00039 
00040     void getAnalysisUsage(AnalysisUsage &AU) const override;
00041 
00042     /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
00043     /// frame indexes with appropriate references.
00044     ///
00045     bool runOnMachineFunction(MachineFunction &Fn) override;
00046 
00047   private:
00048     RegScavenger *RS;
00049 
00050     // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
00051     // stack frame indexes.
00052     unsigned MinCSFrameIndex, MaxCSFrameIndex;
00053 
00054     // Entry and return blocks of the current function.
00055     MachineBasicBlock* EntryBlock;
00056     SmallVector<MachineBasicBlock*, 4> ReturnBlocks;
00057 
00058     // Flag to control whether to use the register scavenger to resolve
00059     // frame index materialization registers. Set according to
00060     // TRI->requiresFrameIndexScavenging() for the curren function.
00061     bool FrameIndexVirtualScavenging;
00062 
00063     void calculateSets(MachineFunction &Fn);
00064     void calculateCallsInformation(MachineFunction &Fn);
00065     void calculateCalleeSavedRegisters(MachineFunction &Fn);
00066     void insertCSRSpillsAndRestores(MachineFunction &Fn);
00067     void calculateFrameObjectOffsets(MachineFunction &Fn);
00068     void replaceFrameIndices(MachineFunction &Fn);
00069     void replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &Fn,
00070                              int &SPAdj);
00071     void scavengeFrameVirtualRegs(MachineFunction &Fn);
00072     void insertPrologEpilogCode(MachineFunction &Fn);
00073 
00074     // Convenience for recognizing return blocks.
00075     bool isReturnBlock(MachineBasicBlock* MBB);
00076   };
00077 } // End llvm namespace
00078 #endif