]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/llvm/Target/TargetFrameLowering.h
Vendor import of llvm trunk r126079:
[FreeBSD/FreeBSD.git] / include / llvm / Target / TargetFrameLowering.h
1 //===-- llvm/Target/TargetFrameLowering.h ---------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface to describe the layout of a stack frame on the target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETFRAMELOWERING_H
15 #define LLVM_TARGET_TARGETFRAMELOWERING_H
16
17 #include "llvm/CodeGen/MachineBasicBlock.h"
18
19 #include <utility>
20 #include <vector>
21
22 namespace llvm {
23   class CalleeSavedInfo;
24   class MachineFunction;
25   class MachineBasicBlock;
26   class MachineMove;
27   class RegScavenger;
28
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.
32 ///
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 TargetFrameLowering {
37 public:
38   enum StackDirection {
39     StackGrowsUp,        // Adding to the stack increases the stack address
40     StackGrowsDown       // Adding to the stack decreases the stack address
41   };
42
43   // Maps a callee saved register to a stack slot with a fixed offset.
44   struct SpillSlot {
45     unsigned Reg;
46     int Offset; // Offset relative to stack pointer on function entry.
47   };
48 private:
49   StackDirection StackDir;
50   unsigned StackAlignment;
51   unsigned TransientStackAlignment;
52   int LocalAreaOffset;
53 public:
54   TargetFrameLowering(StackDirection D, unsigned StackAl, int LAO,
55                       unsigned TransAl = 1)
56     : StackDir(D), StackAlignment(StackAl), TransientStackAlignment(TransAl),
57       LocalAreaOffset(LAO) {}
58
59   virtual ~TargetFrameLowering();
60
61   // These methods return information that describes the abstract stack layout
62   // of the target machine.
63
64   /// getStackGrowthDirection - Return the direction the stack grows
65   ///
66   StackDirection getStackGrowthDirection() const { return StackDir; }
67
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.
71   ///
72   unsigned getStackAlignment() const { return StackAlignment; }
73
74   /// getTransientStackAlignment - This method returns the number of bytes to
75   /// which the stack pointer must be aligned at all times, even between
76   /// calls.
77   ///
78   unsigned getTransientStackAlignment() const {
79     return TransientStackAlignment;
80   }
81
82   /// getOffsetOfLocalArea - This method returns the offset of the local area
83   /// from the stack pointer on entrance to a function.
84   ///
85   int getOffsetOfLocalArea() const { return LocalAreaOffset; }
86
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.
90   ///
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.
95   ///
96   virtual const SpillSlot *
97   getCalleeSavedSpillSlots(unsigned &NumEntries) const {
98     NumEntries = 0;
99     return 0;
100   }
101
102   /// targetHandlesStackFrameRounding - Returns true if the target is
103   /// responsible for rounding up the stack frame (probably at emitPrologue
104   /// time).
105   virtual bool targetHandlesStackFrameRounding() const {
106     return false;
107   }
108
109   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
110   /// the function.
111   virtual void emitPrologue(MachineFunction &MF) const = 0;
112   virtual void emitEpilogue(MachineFunction &MF,
113                             MachineBasicBlock &MBB) const = 0;
114
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 {
123     return false;
124   }
125
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 {
134     return false;
135   }
136
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;
141
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 {
148     return !hasFP(MF);
149   }
150
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);
160   }
161
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;
166
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;
170
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;
176
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 {
182
183   }
184
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.
189   ///
190   virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
191   }
192 };
193
194 } // End llvm namespace
195
196 #endif