1 //===-- llvm/Target/TargetFrameInfo.h ---------------------------*- 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 // Interface to describe the layout of a stack frame on the target machine.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETFRAMEINFO_H
15 #define LLVM_TARGET_TARGETFRAMEINFO_H
17 #include "llvm/CodeGen/MachineBasicBlock.h"
23 class CalleeSavedInfo;
24 class MachineFunction;
25 class MachineBasicBlock;
29 /// Information about stack frame layout on the target. It holds the direction
30 /// of stack growth, the known stack alignment on entry to each function, and
31 /// the offset to the locals area.
33 /// The offset to the local area is the offset from the stack pointer on
34 /// function entry to the first location where function data (local variables,
35 /// spill locations) can be stored.
36 class TargetFrameInfo {
39 StackGrowsUp, // Adding to the stack increases the stack address
40 StackGrowsDown // Adding to the stack decreases the stack address
43 // Maps a callee saved register to a stack slot with a fixed offset.
46 int Offset; // Offset relative to stack pointer on function entry.
49 StackDirection StackDir;
50 unsigned StackAlignment;
51 unsigned TransientStackAlignment;
54 TargetFrameInfo(StackDirection D, unsigned StackAl, int LAO,
56 : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
57 LocalAreaOffset(LAO) {}
59 virtual ~TargetFrameInfo();
61 // These methods return information that describes the abstract stack layout
62 // of the target machine.
64 /// getStackGrowthDirection - Return the direction the stack grows
66 StackDirection getStackGrowthDirection() const { return StackDir; }
68 /// getStackAlignment - This method returns the number of bytes to which the
69 /// stack pointer must be aligned on entry to a function. Typically, this
70 /// is the largest alignment for any data object in the target.
72 unsigned getStackAlignment() const { return StackAlignment; }
74 /// getTransientStackAlignment - This method returns the number of bytes to
75 /// which the stack pointer must be aligned at all times, even between
78 unsigned getTransientStackAlignment() const {
79 return TransientStackAlignment;
82 /// getOffsetOfLocalArea - This method returns the offset of the local area
83 /// from the stack pointer on entrance to a function.
85 int getOffsetOfLocalArea() const { return LocalAreaOffset; }
87 /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
88 /// pairs, that contains an entry for each callee saved register that must be
89 /// spilled to a particular stack location if it is spilled.
91 /// Each entry in this array contains a <register,offset> pair, indicating the
92 /// fixed offset from the incoming stack pointer that each register should be
93 /// spilled at. If a register is not listed here, the code generator is
94 /// allowed to spill it anywhere it chooses.
96 virtual const SpillSlot *
97 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
102 /// targetHandlesStackFrameRounding - Returns true if the target is
103 /// responsible for rounding up the stack frame (probably at emitPrologue
105 virtual bool targetHandlesStackFrameRounding() const {
109 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
111 virtual void emitPrologue(MachineFunction &MF) const = 0;
112 virtual void emitEpilogue(MachineFunction &MF,
113 MachineBasicBlock &MBB) const = 0;
115 /// spillCalleeSavedRegisters - Issues instruction(s) to spill all callee
116 /// saved registers and returns true if it isn't possible / profitable to do
117 /// so by issuing a series of store instructions via
118 /// storeRegToStackSlot(). Returns false otherwise.
119 virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
120 MachineBasicBlock::iterator MI,
121 const std::vector<CalleeSavedInfo> &CSI,
122 const TargetRegisterInfo *TRI) const {
126 /// restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee
127 /// saved registers and returns true if it isn't possible / profitable to do
128 /// so by issuing a series of load instructions via loadRegToStackSlot().
129 /// Returns false otherwise.
130 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
131 MachineBasicBlock::iterator MI,
132 const std::vector<CalleeSavedInfo> &CSI,
133 const TargetRegisterInfo *TRI) const {
137 /// hasFP - Return true if the specified function should have a dedicated
138 /// frame pointer register. For most targets this is true only if the function
139 /// has variable sized allocas or if frame pointer elimination is disabled.
140 virtual bool hasFP(const MachineFunction &MF) const = 0;
142 /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
143 /// not required, we reserve argument space for call sites in the function
144 /// immediately on entry to the current function. This eliminates the need for
145 /// add/sub sp brackets around call sites. Returns true if the call frame is
146 /// included as part of the stack frame.
147 virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
151 /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
152 /// call frame pseudo ops before doing frame index elimination. This is
153 /// possible only when frame index references between the pseudos won't
154 /// need adjusting for the call frame adjustments. Normally, that's true
155 /// if the function has a reserved call frame or a frame pointer. Some
156 /// targets (Thumb2, for example) may have more complicated criteria,
157 /// however, and can override this behavior.
158 virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
159 return hasReservedCallFrame(MF) || hasFP(MF);
162 /// getInitialFrameState - Returns a list of machine moves that are assumed
163 /// on entry to all functions. Note that LabelID is ignored (assumed to be
164 /// the beginning of the function.)
165 virtual void getInitialFrameState(std::vector<MachineMove> &Moves) const;
167 /// getFrameIndexOffset - Returns the displacement from the frame register to
168 /// the stack frame of the specified index.
169 virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
171 /// getFrameIndexReference - This method should return the base register
172 /// and offset used to reference a frame index location. The offset is
173 /// returned directly, and the base register is returned via FrameReg.
174 virtual int getFrameIndexReference(const MachineFunction &MF, int FI,
175 unsigned &FrameReg) const;
177 /// processFunctionBeforeCalleeSavedScan - This method is called immediately
178 /// before PrologEpilogInserter scans the physical registers used to determine
179 /// what callee saved registers should be spilled. This method is optional.
180 virtual void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
181 RegScavenger *RS = NULL) const {
185 /// processFunctionBeforeFrameFinalized - This method is called immediately
186 /// before the specified function's frame layout (MF.getFrameInfo()) is
187 /// finalized. Once the frame is finalized, MO_FrameIndex operands are
188 /// replaced with direct constants. This method is optional.
190 virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
194 } // End llvm namespace