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