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
20 class MachineFunction;
21 class MachineBasicBlock;
23 /// Information about stack frame layout on the target. It holds the direction
24 /// of stack growth, the known stack alignment on entry to each function, and
25 /// the offset to the locals area.
27 /// The offset to the local area is the offset from the stack pointer on
28 /// function entry to the first location where function data (local variables,
29 /// spill locations) can be stored.
30 class TargetFrameInfo {
33 StackGrowsUp, // Adding to the stack increases the stack address
34 StackGrowsDown // Adding to the stack decreases the stack address
37 // Maps a callee saved register to a stack slot with a fixed offset.
40 int Offset; // Offset relative to stack pointer on function entry.
43 StackDirection StackDir;
44 unsigned StackAlignment;
45 unsigned TransientStackAlignment;
48 TargetFrameInfo(StackDirection D, unsigned StackAl, int LAO,
50 : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
51 LocalAreaOffset(LAO) {}
53 virtual ~TargetFrameInfo();
55 // These methods return information that describes the abstract stack layout
56 // of the target machine.
58 /// getStackGrowthDirection - Return the direction the stack grows
60 StackDirection getStackGrowthDirection() const { return StackDir; }
62 /// getStackAlignment - This method returns the number of bytes to which the
63 /// stack pointer must be aligned on entry to a function. Typically, this
64 /// is the largest alignment for any data object in the target.
66 unsigned getStackAlignment() const { return StackAlignment; }
68 /// getTransientStackAlignment - This method returns the number of bytes to
69 /// which the stack pointer must be aligned at all times, even between
72 unsigned getTransientStackAlignment() const {
73 return TransientStackAlignment;
76 /// getOffsetOfLocalArea - This method returns the offset of the local area
77 /// from the stack pointer on entrance to a function.
79 int getOffsetOfLocalArea() const { return LocalAreaOffset; }
81 /// getCalleeSavedSpillSlots - This method returns a pointer to an array of
82 /// pairs, that contains an entry for each callee saved register that must be
83 /// spilled to a particular stack location if it is spilled.
85 /// Each entry in this array contains a <register,offset> pair, indicating the
86 /// fixed offset from the incoming stack pointer that each register should be
87 /// spilled at. If a register is not listed here, the code generator is
88 /// allowed to spill it anywhere it chooses.
90 virtual const SpillSlot *
91 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
96 /// targetHandlesStackFrameRounding - Returns true if the target is
97 /// responsible for rounding up the stack frame (probably at emitPrologue
99 virtual bool targetHandlesStackFrameRounding() const {
103 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
105 virtual void emitPrologue(MachineFunction &MF) const = 0;
106 virtual void emitEpilogue(MachineFunction &MF,
107 MachineBasicBlock &MBB) const = 0;
109 /// hasFP - Return true if the specified function should have a dedicated
110 /// frame pointer register. For most targets this is true only if the function
111 /// has variable sized allocas or if frame pointer elimination is disabled.
112 virtual bool hasFP(const MachineFunction &MF) const = 0;
114 /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
115 /// not required, we reserve argument space for call sites in the function
116 /// immediately on entry to the current function. This eliminates the need for
117 /// add/sub sp brackets around call sites. Returns true if the call frame is
118 /// included as part of the stack frame.
119 virtual bool hasReservedCallFrame(const MachineFunction &MF) const {
123 /// canSimplifyCallFramePseudos - When possible, it's best to simplify the
124 /// call frame pseudo ops before doing frame index elimination. This is
125 /// possible only when frame index references between the pseudos won't
126 /// need adjusting for the call frame adjustments. Normally, that's true
127 /// if the function has a reserved call frame or a frame pointer. Some
128 /// targets (Thumb2, for example) may have more complicated criteria,
129 /// however, and can override this behavior.
130 virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const {
131 return hasReservedCallFrame(MF) || hasFP(MF);
136 } // End llvm namespace