• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- 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 // The file defines the MachineFrameInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
15 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/DataTypes.h"
19 #include <cassert>
20 #include <vector>
21 
22 namespace llvm {
23 class raw_ostream;
24 class DataLayout;
25 class TargetRegisterClass;
26 class Type;
27 class MachineFunction;
28 class MachineBasicBlock;
29 class TargetFrameLowering;
30 class TargetMachine;
31 class BitVector;
32 class Value;
33 class AllocaInst;
34 
35 /// The CalleeSavedInfo class tracks the information need to locate where a
36 /// callee saved register is in the current frame.
37 class CalleeSavedInfo {
38   unsigned Reg;
39   int FrameIdx;
40 
41 public:
42   explicit CalleeSavedInfo(unsigned R, int FI = 0)
Reg(R)43   : Reg(R), FrameIdx(FI) {}
44 
45   // Accessors.
getReg()46   unsigned getReg()                        const { return Reg; }
getFrameIdx()47   int getFrameIdx()                        const { return FrameIdx; }
setFrameIdx(int FI)48   void setFrameIdx(int FI)                       { FrameIdx = FI; }
49 };
50 
51 /// The MachineFrameInfo class represents an abstract stack frame until
52 /// prolog/epilog code is inserted.  This class is key to allowing stack frame
53 /// representation optimizations, such as frame pointer elimination.  It also
54 /// allows more mundane (but still important) optimizations, such as reordering
55 /// of abstract objects on the stack frame.
56 ///
57 /// To support this, the class assigns unique integer identifiers to stack
58 /// objects requested clients.  These identifiers are negative integers for
59 /// fixed stack objects (such as arguments passed on the stack) or nonnegative
60 /// for objects that may be reordered.  Instructions which refer to stack
61 /// objects use a special MO_FrameIndex operand to represent these frame
62 /// indexes.
63 ///
64 /// Because this class keeps track of all references to the stack frame, it
65 /// knows when a variable sized object is allocated on the stack.  This is the
66 /// sole condition which prevents frame pointer elimination, which is an
67 /// important optimization on register-poor architectures.  Because original
68 /// variable sized alloca's in the source program are the only source of
69 /// variable sized stack objects, it is safe to decide whether there will be
70 /// any variable sized objects before all stack objects are known (for
71 /// example, register allocator spill code never needs variable sized
72 /// objects).
73 ///
74 /// When prolog/epilog code emission is performed, the final stack frame is
75 /// built and the machine instructions are modified to refer to the actual
76 /// stack offsets of the object, eliminating all MO_FrameIndex operands from
77 /// the program.
78 ///
79 /// @brief Abstract Stack Frame Information
80 class MachineFrameInfo {
81 
82   // Represent a single object allocated on the stack.
83   struct StackObject {
84     // The offset of this object from the stack pointer on entry to
85     // the function.  This field has no meaning for a variable sized element.
86     int64_t SPOffset;
87 
88     // The size of this object on the stack. 0 means a variable sized object,
89     // ~0ULL means a dead object.
90     uint64_t Size;
91 
92     // The required alignment of this stack slot.
93     unsigned Alignment;
94 
95     // If true, the value of the stack object is set before
96     // entering the function and is not modified inside the function. By
97     // default, fixed objects are immutable unless marked otherwise.
98     bool isImmutable;
99 
100     // If true the stack object is used as spill slot. It
101     // cannot alias any other memory objects.
102     bool isSpillSlot;
103 
104     /// If true, this stack slot is used to spill a value (could be deopt
105     /// and/or GC related) over a statepoint. We know that the address of the
106     /// slot can't alias any LLVM IR value.  This is very similiar to a Spill
107     /// Slot, but is created by statepoint lowering is SelectionDAG, not the
108     /// register allocator.
109     bool isStatepointSpillSlot;
110 
111     /// If this stack object is originated from an Alloca instruction
112     /// this value saves the original IR allocation. Can be NULL.
113     const AllocaInst *Alloca;
114 
115     // If true, the object was mapped into the local frame
116     // block and doesn't need additional handling for allocation beyond that.
117     bool PreAllocated;
118 
119     // If true, an LLVM IR value might point to this object.
120     // Normally, spill slots and fixed-offset objects don't alias IR-accessible
121     // objects, but there are exceptions (on PowerPC, for example, some byval
122     // arguments have ABI-prescribed offsets).
123     bool isAliased;
124 
125     /// If true, the object has been zero-extended.
126     bool isZExt;
127 
128     /// If true, the object has been zero-extended.
129     bool isSExt;
130 
StackObjectStackObject131     StackObject(uint64_t Sz, unsigned Al, int64_t SP, bool IM,
132                 bool isSS, const AllocaInst *Val, bool A)
133       : SPOffset(SP), Size(Sz), Alignment(Al), isImmutable(IM),
134         isSpillSlot(isSS), isStatepointSpillSlot(false), Alloca(Val),
135         PreAllocated(false), isAliased(A), isZExt(false), isSExt(false) {}
136   };
137 
138   /// The alignment of the stack.
139   unsigned StackAlignment;
140 
141   /// Can the stack be realigned. This can be false if the target does not
142   /// support stack realignment, or if the user asks us not to realign the
143   /// stack. In this situation, overaligned allocas are all treated as dynamic
144   /// allocations and the target must handle them as part of DYNAMIC_STACKALLOC
145   /// lowering. All non-alloca stack objects have their alignment clamped to the
146   /// base ABI stack alignment.
147   /// FIXME: There is room for improvement in this case, in terms of
148   /// grouping overaligned allocas into a "secondary stack frame" and
149   /// then only use a single alloca to allocate this frame and only a
150   /// single virtual register to access it. Currently, without such an
151   /// optimization, each such alloca gets it's own dynamic
152   /// realignment.
153   bool StackRealignable;
154 
155   /// Whether the function has the \c alignstack attribute.
156   bool ForcedRealign;
157 
158   /// The list of stack objects allocated.
159   std::vector<StackObject> Objects;
160 
161   /// This contains the number of fixed objects contained on
162   /// the stack.  Because fixed objects are stored at a negative index in the
163   /// Objects list, this is also the index to the 0th object in the list.
164   unsigned NumFixedObjects = 0;
165 
166   /// This boolean keeps track of whether any variable
167   /// sized objects have been allocated yet.
168   bool HasVarSizedObjects = false;
169 
170   /// This boolean keeps track of whether there is a call
171   /// to builtin \@llvm.frameaddress.
172   bool FrameAddressTaken = false;
173 
174   /// This boolean keeps track of whether there is a call
175   /// to builtin \@llvm.returnaddress.
176   bool ReturnAddressTaken = false;
177 
178   /// This boolean keeps track of whether there is a call
179   /// to builtin \@llvm.experimental.stackmap.
180   bool HasStackMap = false;
181 
182   /// This boolean keeps track of whether there is a call
183   /// to builtin \@llvm.experimental.patchpoint.
184   bool HasPatchPoint = false;
185 
186   /// The prolog/epilog code inserter calculates the final stack
187   /// offsets for all of the fixed size objects, updating the Objects list
188   /// above.  It then updates StackSize to contain the number of bytes that need
189   /// to be allocated on entry to the function.
190   uint64_t StackSize = 0;
191 
192   /// The amount that a frame offset needs to be adjusted to
193   /// have the actual offset from the stack/frame pointer.  The exact usage of
194   /// this is target-dependent, but it is typically used to adjust between
195   /// SP-relative and FP-relative offsets.  E.G., if objects are accessed via
196   /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set
197   /// to the distance between the initial SP and the value in FP.  For many
198   /// targets, this value is only used when generating debug info (via
199   /// TargetRegisterInfo::getFrameIndexReference); when generating code, the
200   /// corresponding adjustments are performed directly.
201   int OffsetAdjustment = 0;
202 
203   /// The prolog/epilog code inserter may process objects that require greater
204   /// alignment than the default alignment the target provides.
205   /// To handle this, MaxAlignment is set to the maximum alignment
206   /// needed by the objects on the current frame.  If this is greater than the
207   /// native alignment maintained by the compiler, dynamic alignment code will
208   /// be needed.
209   ///
210   unsigned MaxAlignment = 0;
211 
212   /// Set to true if this function adjusts the stack -- e.g.,
213   /// when calling another function. This is only valid during and after
214   /// prolog/epilog code insertion.
215   bool AdjustsStack = false;
216 
217   /// Set to true if this function has any function calls.
218   bool HasCalls = false;
219 
220   /// The frame index for the stack protector.
221   int StackProtectorIdx = -1;
222 
223   /// The frame index for the function context. Used for SjLj exceptions.
224   int FunctionContextIdx = -1;
225 
226   /// This contains the size of the largest call frame if the target uses frame
227   /// setup/destroy pseudo instructions (as defined in the TargetFrameInfo
228   /// class).  This information is important for frame pointer elimination.
229   /// It is only valid during and after prolog/epilog code insertion.
230   unsigned MaxCallFrameSize = 0;
231 
232   /// The prolog/epilog code inserter fills in this vector with each
233   /// callee saved register saved in the frame.  Beyond its use by the prolog/
234   /// epilog code inserter, this data used for debug info and exception
235   /// handling.
236   std::vector<CalleeSavedInfo> CSInfo;
237 
238   /// Has CSInfo been set yet?
239   bool CSIValid = false;
240 
241   /// References to frame indices which are mapped
242   /// into the local frame allocation block. <FrameIdx, LocalOffset>
243   SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
244 
245   /// Size of the pre-allocated local frame block.
246   int64_t LocalFrameSize = 0;
247 
248   /// Required alignment of the local object blob, which is the strictest
249   /// alignment of any object in it.
250   unsigned LocalFrameMaxAlign = 0;
251 
252   /// Whether the local object blob needs to be allocated together. If not,
253   /// PEI should ignore the isPreAllocated flags on the stack objects and
254   /// just allocate them normally.
255   bool UseLocalStackAllocationBlock = false;
256 
257   /// True if the function dynamically adjusts the stack pointer through some
258   /// opaque mechanism like inline assembly or Win32 EH.
259   bool HasOpaqueSPAdjustment = false;
260 
261   /// True if the function contains operations which will lower down to
262   /// instructions which manipulate the stack pointer.
263   bool HasCopyImplyingStackAdjustment = false;
264 
265   /// True if the function contains a call to the llvm.vastart intrinsic.
266   bool HasVAStart = false;
267 
268   /// True if this is a varargs function that contains a musttail call.
269   bool HasMustTailInVarArgFunc = false;
270 
271   /// True if this function contains a tail call. If so immutable objects like
272   /// function arguments are no longer so. A tail call *can* override fixed
273   /// stack objects like arguments so we can't treat them as immutable.
274   bool HasTailCall = false;
275 
276   /// Not null, if shrink-wrapping found a better place for the prologue.
277   MachineBasicBlock *Save = nullptr;
278   /// Not null, if shrink-wrapping found a better place for the epilogue.
279   MachineBasicBlock *Restore = nullptr;
280 
281 public:
MachineFrameInfo(unsigned StackAlignment,bool StackRealignable,bool ForcedRealign)282   explicit MachineFrameInfo(unsigned StackAlignment, bool StackRealignable,
283                             bool ForcedRealign)
284       : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
285         ForcedRealign(ForcedRealign) {}
286 
287   /// Return true if there are any stack objects in this function.
hasStackObjects()288   bool hasStackObjects() const { return !Objects.empty(); }
289 
290   /// This method may be called any time after instruction
291   /// selection is complete to determine if the stack frame for this function
292   /// contains any variable sized objects.
hasVarSizedObjects()293   bool hasVarSizedObjects() const { return HasVarSizedObjects; }
294 
295   /// Return the index for the stack protector object.
getStackProtectorIndex()296   int getStackProtectorIndex() const { return StackProtectorIdx; }
setStackProtectorIndex(int I)297   void setStackProtectorIndex(int I) { StackProtectorIdx = I; }
hasStackProtectorIndex()298   bool hasStackProtectorIndex() const { return StackProtectorIdx != -1; }
299 
300   /// Return the index for the function context object.
301   /// This object is used for SjLj exceptions.
getFunctionContextIndex()302   int getFunctionContextIndex() const { return FunctionContextIdx; }
setFunctionContextIndex(int I)303   void setFunctionContextIndex(int I) { FunctionContextIdx = I; }
304 
305   /// This method may be called any time after instruction
306   /// selection is complete to determine if there is a call to
307   /// \@llvm.frameaddress in this function.
isFrameAddressTaken()308   bool isFrameAddressTaken() const { return FrameAddressTaken; }
setFrameAddressIsTaken(bool T)309   void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
310 
311   /// This method may be called any time after
312   /// instruction selection is complete to determine if there is a call to
313   /// \@llvm.returnaddress in this function.
isReturnAddressTaken()314   bool isReturnAddressTaken() const { return ReturnAddressTaken; }
setReturnAddressIsTaken(bool s)315   void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; }
316 
317   /// This method may be called any time after instruction
318   /// selection is complete to determine if there is a call to builtin
319   /// \@llvm.experimental.stackmap.
hasStackMap()320   bool hasStackMap() const { return HasStackMap; }
321   void setHasStackMap(bool s = true) { HasStackMap = s; }
322 
323   /// This method may be called any time after instruction
324   /// selection is complete to determine if there is a call to builtin
325   /// \@llvm.experimental.patchpoint.
hasPatchPoint()326   bool hasPatchPoint() const { return HasPatchPoint; }
327   void setHasPatchPoint(bool s = true) { HasPatchPoint = s; }
328 
329   /// Return the minimum frame object index.
getObjectIndexBegin()330   int getObjectIndexBegin() const { return -NumFixedObjects; }
331 
332   /// Return one past the maximum frame object index.
getObjectIndexEnd()333   int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; }
334 
335   /// Return the number of fixed objects.
getNumFixedObjects()336   unsigned getNumFixedObjects() const { return NumFixedObjects; }
337 
338   /// Return the number of objects.
getNumObjects()339   unsigned getNumObjects() const { return Objects.size(); }
340 
341   /// Map a frame index into the local object block
mapLocalFrameObject(int ObjectIndex,int64_t Offset)342   void mapLocalFrameObject(int ObjectIndex, int64_t Offset) {
343     LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
344     Objects[ObjectIndex + NumFixedObjects].PreAllocated = true;
345   }
346 
347   /// Get the local offset mapping for a for an object.
getLocalFrameObjectMap(int i)348   std::pair<int, int64_t> getLocalFrameObjectMap(int i) const {
349     assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() &&
350             "Invalid local object reference!");
351     return LocalFrameObjects[i];
352   }
353 
354   /// Return the number of objects allocated into the local object block.
getLocalFrameObjectCount()355   int64_t getLocalFrameObjectCount() const { return LocalFrameObjects.size(); }
356 
357   /// Set the size of the local object blob.
setLocalFrameSize(int64_t sz)358   void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; }
359 
360   /// Get the size of the local object blob.
getLocalFrameSize()361   int64_t getLocalFrameSize() const { return LocalFrameSize; }
362 
363   /// Required alignment of the local object blob,
364   /// which is the strictest alignment of any object in it.
setLocalFrameMaxAlign(unsigned Align)365   void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
366 
367   /// Return the required alignment of the local object blob.
getLocalFrameMaxAlign()368   unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; }
369 
370   /// Get whether the local allocation blob should be allocated together or
371   /// let PEI allocate the locals in it directly.
getUseLocalStackAllocationBlock()372   bool getUseLocalStackAllocationBlock() const {
373     return UseLocalStackAllocationBlock;
374   }
375 
376   /// setUseLocalStackAllocationBlock - Set whether the local allocation blob
377   /// should be allocated together or let PEI allocate the locals in it
378   /// directly.
setUseLocalStackAllocationBlock(bool v)379   void setUseLocalStackAllocationBlock(bool v) {
380     UseLocalStackAllocationBlock = v;
381   }
382 
383   /// Return true if the object was pre-allocated into the local block.
isObjectPreAllocated(int ObjectIdx)384   bool isObjectPreAllocated(int ObjectIdx) const {
385     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
386            "Invalid Object Idx!");
387     return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
388   }
389 
390   /// Return the size of the specified object.
getObjectSize(int ObjectIdx)391   int64_t getObjectSize(int ObjectIdx) const {
392     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
393            "Invalid Object Idx!");
394     return Objects[ObjectIdx+NumFixedObjects].Size;
395   }
396 
397   /// Change the size of the specified stack object.
setObjectSize(int ObjectIdx,int64_t Size)398   void setObjectSize(int ObjectIdx, int64_t Size) {
399     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
400            "Invalid Object Idx!");
401     Objects[ObjectIdx+NumFixedObjects].Size = Size;
402   }
403 
404   /// Return the alignment of the specified stack object.
getObjectAlignment(int ObjectIdx)405   unsigned getObjectAlignment(int ObjectIdx) const {
406     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
407            "Invalid Object Idx!");
408     return Objects[ObjectIdx+NumFixedObjects].Alignment;
409   }
410 
411   /// setObjectAlignment - Change the alignment of the specified stack object.
setObjectAlignment(int ObjectIdx,unsigned Align)412   void setObjectAlignment(int ObjectIdx, unsigned Align) {
413     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
414            "Invalid Object Idx!");
415     Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
416     ensureMaxAlignment(Align);
417   }
418 
419   /// Return the underlying Alloca of the specified
420   /// stack object if it exists. Returns 0 if none exists.
getObjectAllocation(int ObjectIdx)421   const AllocaInst* getObjectAllocation(int ObjectIdx) const {
422     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
423            "Invalid Object Idx!");
424     return Objects[ObjectIdx+NumFixedObjects].Alloca;
425   }
426 
427   /// Return the assigned stack offset of the specified object
428   /// from the incoming stack pointer.
getObjectOffset(int ObjectIdx)429   int64_t getObjectOffset(int ObjectIdx) const {
430     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
431            "Invalid Object Idx!");
432     assert(!isDeadObjectIndex(ObjectIdx) &&
433            "Getting frame offset for a dead object?");
434     return Objects[ObjectIdx+NumFixedObjects].SPOffset;
435   }
436 
isObjectZExt(int ObjectIdx)437   bool isObjectZExt(int ObjectIdx) const {
438     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
439            "Invalid Object Idx!");
440     return Objects[ObjectIdx+NumFixedObjects].isZExt;
441   }
442 
setObjectZExt(int ObjectIdx,bool IsZExt)443   void setObjectZExt(int ObjectIdx, bool IsZExt) {
444     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
445            "Invalid Object Idx!");
446     Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
447   }
448 
isObjectSExt(int ObjectIdx)449   bool isObjectSExt(int ObjectIdx) const {
450     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
451            "Invalid Object Idx!");
452     return Objects[ObjectIdx+NumFixedObjects].isSExt;
453   }
454 
setObjectSExt(int ObjectIdx,bool IsSExt)455   void setObjectSExt(int ObjectIdx, bool IsSExt) {
456     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
457            "Invalid Object Idx!");
458     Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
459   }
460 
461   /// Set the stack frame offset of the specified object. The
462   /// offset is relative to the stack pointer on entry to the function.
setObjectOffset(int ObjectIdx,int64_t SPOffset)463   void setObjectOffset(int ObjectIdx, int64_t SPOffset) {
464     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
465            "Invalid Object Idx!");
466     assert(!isDeadObjectIndex(ObjectIdx) &&
467            "Setting frame offset for a dead object?");
468     Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
469   }
470 
471   /// Return the number of bytes that must be allocated to hold
472   /// all of the fixed size frame objects.  This is only valid after
473   /// Prolog/Epilog code insertion has finalized the stack frame layout.
getStackSize()474   uint64_t getStackSize() const { return StackSize; }
475 
476   /// Set the size of the stack.
setStackSize(uint64_t Size)477   void setStackSize(uint64_t Size) { StackSize = Size; }
478 
479   /// Estimate and return the size of the stack frame.
480   unsigned estimateStackSize(const MachineFunction &MF) const;
481 
482   /// Return the correction for frame offsets.
getOffsetAdjustment()483   int getOffsetAdjustment() const { return OffsetAdjustment; }
484 
485   /// Set the correction for frame offsets.
setOffsetAdjustment(int Adj)486   void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; }
487 
488   /// Return the alignment in bytes that this function must be aligned to,
489   /// which is greater than the default stack alignment provided by the target.
getMaxAlignment()490   unsigned getMaxAlignment() const { return MaxAlignment; }
491 
492   /// Make sure the function is at least Align bytes aligned.
493   void ensureMaxAlignment(unsigned Align);
494 
495   /// Return true if this function adjusts the stack -- e.g.,
496   /// when calling another function. This is only valid during and after
497   /// prolog/epilog code insertion.
adjustsStack()498   bool adjustsStack() const { return AdjustsStack; }
setAdjustsStack(bool V)499   void setAdjustsStack(bool V) { AdjustsStack = V; }
500 
501   /// Return true if the current function has any function calls.
hasCalls()502   bool hasCalls() const { return HasCalls; }
setHasCalls(bool V)503   void setHasCalls(bool V) { HasCalls = V; }
504 
505   /// Returns true if the function contains opaque dynamic stack adjustments.
hasOpaqueSPAdjustment()506   bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
setHasOpaqueSPAdjustment(bool B)507   void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }
508 
509   /// Returns true if the function contains operations which will lower down to
510   /// instructions which manipulate the stack pointer.
hasCopyImplyingStackAdjustment()511   bool hasCopyImplyingStackAdjustment() const {
512     return HasCopyImplyingStackAdjustment;
513   }
setHasCopyImplyingStackAdjustment(bool B)514   void setHasCopyImplyingStackAdjustment(bool B) {
515     HasCopyImplyingStackAdjustment = B;
516   }
517 
518   /// Returns true if the function calls the llvm.va_start intrinsic.
hasVAStart()519   bool hasVAStart() const { return HasVAStart; }
setHasVAStart(bool B)520   void setHasVAStart(bool B) { HasVAStart = B; }
521 
522   /// Returns true if the function is variadic and contains a musttail call.
hasMustTailInVarArgFunc()523   bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; }
setHasMustTailInVarArgFunc(bool B)524   void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; }
525 
526   /// Returns true if the function contains a tail call.
hasTailCall()527   bool hasTailCall() const { return HasTailCall; }
setHasTailCall()528   void setHasTailCall() { HasTailCall = true; }
529 
530   /// Return the maximum size of a call frame that must be
531   /// allocated for an outgoing function call.  This is only available if
532   /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
533   /// then only during or after prolog/epilog code insertion.
534   ///
getMaxCallFrameSize()535   unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; }
setMaxCallFrameSize(unsigned S)536   void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
537 
538   /// Create a new object at a fixed location on the stack.
539   /// All fixed objects should be created before other objects are created for
540   /// efficiency. By default, fixed objects are not pointed to by LLVM IR
541   /// values. This returns an index with a negative value.
542   int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable,
543                         bool isAliased = false);
544 
545   /// Create a spill slot at a fixed location on the stack.
546   /// Returns an index with a negative value.
547   int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset);
548 
549   /// Returns true if the specified index corresponds to a fixed stack object.
isFixedObjectIndex(int ObjectIdx)550   bool isFixedObjectIndex(int ObjectIdx) const {
551     return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
552   }
553 
554   /// Returns true if the specified index corresponds
555   /// to an object that might be pointed to by an LLVM IR value.
isAliasedObjectIndex(int ObjectIdx)556   bool isAliasedObjectIndex(int ObjectIdx) const {
557     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
558            "Invalid Object Idx!");
559     return Objects[ObjectIdx+NumFixedObjects].isAliased;
560   }
561 
562   /// isImmutableObjectIndex - Returns true if the specified index corresponds
563   /// to an immutable object.
isImmutableObjectIndex(int ObjectIdx)564   bool isImmutableObjectIndex(int ObjectIdx) const {
565     // Tail calling functions can clobber their function arguments.
566     if (HasTailCall)
567       return false;
568     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
569            "Invalid Object Idx!");
570     return Objects[ObjectIdx+NumFixedObjects].isImmutable;
571   }
572 
573   /// Returns true if the specified index corresponds to a spill slot.
isSpillSlotObjectIndex(int ObjectIdx)574   bool isSpillSlotObjectIndex(int ObjectIdx) const {
575     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
576            "Invalid Object Idx!");
577     return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
578   }
579 
isStatepointSpillSlotObjectIndex(int ObjectIdx)580   bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const {
581     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
582            "Invalid Object Idx!");
583     return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
584   }
585 
586   /// Returns true if the specified index corresponds to a dead object.
isDeadObjectIndex(int ObjectIdx)587   bool isDeadObjectIndex(int ObjectIdx) const {
588     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
589            "Invalid Object Idx!");
590     return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
591   }
592 
593   /// Returns true if the specified index corresponds to a variable sized
594   /// object.
isVariableSizedObjectIndex(int ObjectIdx)595   bool isVariableSizedObjectIndex(int ObjectIdx) const {
596     assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
597            "Invalid Object Idx!");
598     return Objects[ObjectIdx + NumFixedObjects].Size == 0;
599   }
600 
markAsStatepointSpillSlotObjectIndex(int ObjectIdx)601   void markAsStatepointSpillSlotObjectIndex(int ObjectIdx) {
602     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
603            "Invalid Object Idx!");
604     Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot = true;
605     assert(isStatepointSpillSlotObjectIndex(ObjectIdx) && "inconsistent");
606   }
607 
608   /// Create a new statically sized stack object, returning
609   /// a nonnegative identifier to represent it.
610   int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,
611                         const AllocaInst *Alloca = nullptr);
612 
613   /// Create a new statically sized stack object that represents a spill slot,
614   /// returning a nonnegative identifier to represent it.
615   int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
616 
617   /// Remove or mark dead a statically sized stack object.
RemoveStackObject(int ObjectIdx)618   void RemoveStackObject(int ObjectIdx) {
619     // Mark it dead.
620     Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
621   }
622 
623   /// Notify the MachineFrameInfo object that a variable sized object has been
624   /// created.  This must be created whenever a variable sized object is
625   /// created, whether or not the index returned is actually used.
626   int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
627 
628   /// Returns a reference to call saved info vector for the current function.
getCalleeSavedInfo()629   const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const {
630     return CSInfo;
631   }
632 
633   /// Used by prolog/epilog inserter to set the function's callee saved
634   /// information.
setCalleeSavedInfo(const std::vector<CalleeSavedInfo> & CSI)635   void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) {
636     CSInfo = CSI;
637   }
638 
639   /// Has the callee saved info been calculated yet?
isCalleeSavedInfoValid()640   bool isCalleeSavedInfoValid() const { return CSIValid; }
641 
setCalleeSavedInfoValid(bool v)642   void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
643 
getSavePoint()644   MachineBasicBlock *getSavePoint() const { return Save; }
setSavePoint(MachineBasicBlock * NewSave)645   void setSavePoint(MachineBasicBlock *NewSave) { Save = NewSave; }
getRestorePoint()646   MachineBasicBlock *getRestorePoint() const { return Restore; }
setRestorePoint(MachineBasicBlock * NewRestore)647   void setRestorePoint(MachineBasicBlock *NewRestore) { Restore = NewRestore; }
648 
649   /// Return a set of physical registers that are pristine.
650   ///
651   /// Pristine registers hold a value that is useless to the current function,
652   /// but that must be preserved - they are callee saved registers that are not
653   /// saved.
654   ///
655   /// Before the PrologueEpilogueInserter has placed the CSR spill code, this
656   /// method always returns an empty set.
657   BitVector getPristineRegs(const MachineFunction &MF) const;
658 
659   /// Used by the MachineFunction printer to print information about
660   /// stack objects. Implemented in MachineFunction.cpp.
661   void print(const MachineFunction &MF, raw_ostream &OS) const;
662 
663   /// dump - Print the function to stderr.
664   void dump(const MachineFunction &MF) const;
665 };
666 
667 } // End llvm namespace
668 
669 #endif
670