1 //===-- PrologEpilogInserter.h - Prolog/Epilog code insertion -*- C++ -*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass is responsible for finalizing the functions frame layout, saving
11 // callee saved registers, and for emitting prolog & epilog code for the
14 // This pass must be run after register allocation. After this pass is
15 // executed, it is illegal to construct MO_FrameIndex operands.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_LIB_CODEGEN_PROLOGEPILOGINSERTER_H
20 #define LLVM_LIB_CODEGEN_PROLOGEPILOGINSERTER_H
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"
31 class MachineBasicBlock
;
33 class PEI
: public MachineFunctionPass
{
36 PEI() : MachineFunctionPass(ID
) {
37 initializePEIPass(*PassRegistry::getPassRegistry());
40 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
42 /// runOnMachineFunction - Insert prolog/epilog code and replace abstract
43 /// frame indexes with appropriate references.
45 bool runOnMachineFunction(MachineFunction
&Fn
) override
;
50 // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
51 // stack frame indexes.
52 unsigned MinCSFrameIndex
, MaxCSFrameIndex
;
54 // Entry and return blocks of the current function.
55 MachineBasicBlock
* EntryBlock
;
56 SmallVector
<MachineBasicBlock
*, 4> ReturnBlocks
;
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
;
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
,
71 void scavengeFrameVirtualRegs(MachineFunction
&Fn
);
72 void insertPrologEpilogCode(MachineFunction
&Fn
);
74 // Convenience for recognizing return blocks.
75 bool isReturnBlock(MachineBasicBlock
* MBB
);
77 } // End llvm namespace