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
21 class MachineFunction;
22 class MachineBasicBlock;
25 /// Information about stack frame layout on the target. It holds the direction
26 /// of stack growth, the known stack alignment on entry to each function, and
27 /// the offset to the locals area.
29 /// The offset to the local area is the offset from the stack pointer on
30 /// function entry to the first location where function data (local variables,
31 /// spill locations) can be stored.
32 class TargetFrameInfo {
35 StackGrowsUp, // Adding to the stack increases the stack address
36 StackGrowsDown // Adding to the stack decreases the stack address
39 // Maps a callee saved register to a stack slot with a fixed offset.
42 int Offset; // Offset relative to stack pointer on function entry.
45 StackDirection StackDir;
46 unsigned StackAlignment;
47 unsigned TransientStackAlignment;
50 TargetFrameInfo(StackDirection D, unsigned StackAl, int LAO,
52 : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
53 LocalAreaOffset(LAO) {}
55 virtual ~TargetFrameInfo();
57 // These methods return information that describes the abstract stack layout
58 // of the target machine.
60 /// getStackGrowthDirection - Return the direction the stack grows
62 StackDirection getStackGrowthDirection() const { return StackDir; }
64 /// getStackAlignment - This method returns the number of bytes to which the
65 /// stack pointer must be aligned on entry to a function. Typically, this
66 /// is the largest alignment for any data object in the target.
68 unsigned getStackAlignment() const { return StackAlignment; }
70 /// getTransientStackAlignment - This method returns the number of bytes to
71 /// which the stack pointer must be aligned at all times, even between
74 unsigned getTransientStackAlignment() const {
75 return TransientStackAlignment;
78 /// getOffsetOfLocalArea - This method returns the offset of the local area
79 /// from the stack pointer on entrance to a function.
81 int getOffsetOfLocalArea() const { return LocalAreaOffset; }
83 /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
84 /// pairs, that contains an entry for each callee saved register that must be
85 /// spilled to a particular stack location if it is spilled.
87 /// Each entry in this array contains a <register,offset> pair, indicating the
88 /// fixed offset from the incoming stack pointer that each register should be
89 /// spilled at. If a register is not listed here, the code generator is
90 /// allowed to spill it anywhere it chooses.
92 virtual const SpillSlot *
93 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
98 /// targetHandlesStackFrameRounding - Returns true if the target is
99 /// responsible for rounding up the stack frame (probably at emitPrologue
101 virtual bool targetHandlesStackFrameRounding() const {
105 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
107 virtual void emitPrologue(MachineFunction &MF) const = 0;
108 virtual void emitEpilogue(MachineFunction &MF,
109 MachineBasicBlock &MBB) const = 0;
111 /// hasFP - Return true if the specified function should have a dedicated
112 /// frame pointer register. For most targets this is true only if the function
113 /// has variable sized allocas or if frame pointer elimination is disabled.
114 virtual bool hasFP(const MachineFunction &MF) const = 0;
116 /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
117 /// not required, we reserve argument space for call sites in the function
118 /// immediately on entry to the current function. This eliminates the need for
119 /// add/sub sp brackets around call sites. Returns true if the call frame is
120 /// included as part of the stack frame.
121 virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
125 /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
126 /// call frame pseudo ops before doing frame index elimination. This is
127 /// possible only when frame index references between the pseudos won't
128 /// need adjusting for the call frame adjustments. Normally, that's true
129 /// if the function has a reserved call frame or a frame pointer. Some
130 /// targets (Thumb2, for example) may have more complicated criteria,
131 /// however, and can override this behavior.
132 virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
133 return hasReservedCallFrame(MF) || hasFP(MF);
136 /// getInitialFrameState - Returns a list of machine moves that are assumed
137 /// on entry to all functions. Note that LabelID is ignored (assumed to be
138 /// the beginning of the function.)
139 virtual void getInitialFrameState(std::vector<MachineMove> &Moves) const;
142 } // End llvm namespace