[Orc] Include <system_error> in OrcTargetClient.
[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 a call to the llvm.vastart intrinsic.
255   bool HasVAStart;
256
257   /// True if this is a varargs function that contains a musttail call.
258   bool HasMustTailInVarArgFunc;
259
260   /// True if this function contains a tail call. If so immutable objects like
261   /// function arguments are no longer so. A tail call *can* override fixed
262   /// stack objects like arguments so we can't treat them as immutable.
263   bool HasTailCall;
264
265   /// Not null, if shrink-wrapping found a better place for the prologue.
266   MachineBasicBlock *Save;
267   /// Not null, if shrink-wrapping found a better place for the epilogue.
268   MachineBasicBlock *Restore;
269
270 public:
271   explicit MachineFrameInfo(unsigned StackAlign, bool isStackRealign,
272                             bool RealignOpt)
273       : StackAlignment(StackAlign), StackRealignable(isStackRealign),
274         RealignOption(RealignOpt) {
275     StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
276     HasVarSizedObjects = false;
277     FrameAddressTaken = false;
278     ReturnAddressTaken = false;
279     HasStackMap = false;
280     HasPatchPoint = false;
281     AdjustsStack = false;
282     HasCalls = false;
283     StackProtectorIdx = -1;
284     FunctionContextIdx = -1;
285     MaxCallFrameSize = 0;
286     CSIValid = false;
287     LocalFrameSize = 0;
288     LocalFrameMaxAlign = 0;
289     UseLocalStackAllocationBlock = false;
290     HasOpaqueSPAdjustment = false;
291     HasVAStart = false;
292     HasMustTailInVarArgFunc = false;
293     Save = nullptr;
294     Restore = nullptr;
295     HasTailCall = false;
296   }
297
298   /// Return true if there are any stack objects in this function.
299   bool hasStackObjects() const { return !Objects.empty(); }
300
301   /// This method may be called any time after instruction
302   /// selection is complete to determine if the stack frame for this function
303   /// contains any variable sized objects.
304   bool hasVarSizedObjects() const { return HasVarSizedObjects; }
305
306   /// Return the index for the stack protector object.
307   int getStackProtectorIndex() const { return StackProtectorIdx; }
308   void setStackProtectorIndex(int I) { StackProtectorIdx = I; }
309   bool hasStackProtectorIndex() const { return StackProtectorIdx != -1; }
310
311   /// Return the index for the function context object.
312   /// This object is used for SjLj exceptions.
313   int getFunctionContextIndex() const { return FunctionContextIdx; }
314   void setFunctionContextIndex(int I) { FunctionContextIdx = I; }
315
316   /// This method may be called any time after instruction
317   /// selection is complete to determine if there is a call to
318   /// \@llvm.frameaddress in this function.
319   bool isFrameAddressTaken() const { return FrameAddressTaken; }
320   void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
321
322   /// This method may be called any time after
323   /// instruction selection is complete to determine if there is a call to
324   /// \@llvm.returnaddress in this function.
325   bool isReturnAddressTaken() const { return ReturnAddressTaken; }
326   void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; }
327
328   /// This method may be called any time after instruction
329   /// selection is complete to determine if there is a call to builtin
330   /// \@llvm.experimental.stackmap.
331   bool hasStackMap() const { return HasStackMap; }
332   void setHasStackMap(bool s = true) { HasStackMap = s; }
333
334   /// This method may be called any time after instruction
335   /// selection is complete to determine if there is a call to builtin
336   /// \@llvm.experimental.patchpoint.
337   bool hasPatchPoint() const { return HasPatchPoint; }
338   void setHasPatchPoint(bool s = true) { HasPatchPoint = s; }
339
340   /// Return the minimum frame object index.
341   int getObjectIndexBegin() const { return -NumFixedObjects; }
342
343   /// Return one past the maximum frame object index.
344   int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; }
345
346   /// Return the number of fixed objects.
347   unsigned getNumFixedObjects() const { return NumFixedObjects; }
348
349   /// Return the number of objects.
350   unsigned getNumObjects() const { return Objects.size(); }
351
352   /// Map a frame index into the local object block
353   void mapLocalFrameObject(int ObjectIndex, int64_t Offset) {
354     LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
355     Objects[ObjectIndex + NumFixedObjects].PreAllocated = true;
356   }
357
358   /// Get the local offset mapping for a for an object.
359   std::pair<int, int64_t> getLocalFrameObjectMap(int i) const {
360     assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() &&
361             "Invalid local object reference!");
362     return LocalFrameObjects[i];
363   }
364
365   /// Return the number of objects allocated into the local object block.
366   int64_t getLocalFrameObjectCount() const { return LocalFrameObjects.size(); }
367
368   /// Set the size of the local object blob.
369   void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; }
370
371   /// Get the size of the local object blob.
372   int64_t getLocalFrameSize() const { return LocalFrameSize; }
373
374   /// Required alignment of the local object blob,
375   /// which is the strictest alignment of any object in it.
376   void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
377
378   /// Return the required alignment of the local object blob.
379   unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; }
380
381   /// Get whether the local allocation blob should be allocated together or
382   /// let PEI allocate the locals in it directly.
383   bool getUseLocalStackAllocationBlock() const {
384     return UseLocalStackAllocationBlock;
385   }
386
387   /// setUseLocalStackAllocationBlock - Set whether the local allocation blob
388   /// should be allocated together or let PEI allocate the locals in it
389   /// directly.
390   void setUseLocalStackAllocationBlock(bool v) {
391     UseLocalStackAllocationBlock = v;
392   }
393
394   /// Return true if the object was pre-allocated into the local block.
395   bool isObjectPreAllocated(int ObjectIdx) const {
396     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
397            "Invalid Object Idx!");
398     return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
399   }
400
401   /// Return the size of the specified object.
402   int64_t getObjectSize(int ObjectIdx) const {
403     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
404            "Invalid Object Idx!");
405     return Objects[ObjectIdx+NumFixedObjects].Size;
406   }
407
408   /// Change the size of the specified stack object.
409   void setObjectSize(int ObjectIdx, int64_t Size) {
410     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
411            "Invalid Object Idx!");
412     Objects[ObjectIdx+NumFixedObjects].Size = Size;
413   }
414
415   /// Return the alignment of the specified stack object.
416   unsigned getObjectAlignment(int ObjectIdx) const {
417     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
418            "Invalid Object Idx!");
419     return Objects[ObjectIdx+NumFixedObjects].Alignment;
420   }
421
422   /// setObjectAlignment - Change the alignment of the specified stack object.
423   void setObjectAlignment(int ObjectIdx, unsigned Align) {
424     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
425            "Invalid Object Idx!");
426     Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
427     ensureMaxAlignment(Align);
428   }
429
430   /// Return the underlying Alloca of the specified
431   /// stack object if it exists. Returns 0 if none exists.
432   const AllocaInst* getObjectAllocation(int ObjectIdx) const {
433     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
434            "Invalid Object Idx!");
435     return Objects[ObjectIdx+NumFixedObjects].Alloca;
436   }
437
438   /// Return the assigned stack offset of the specified object
439   /// from the incoming stack pointer.
440   int64_t getObjectOffset(int ObjectIdx) const {
441     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
442            "Invalid Object Idx!");
443     assert(!isDeadObjectIndex(ObjectIdx) &&
444            "Getting frame offset for a dead object?");
445     return Objects[ObjectIdx+NumFixedObjects].SPOffset;
446   }
447
448   /// Set the stack frame offset of the specified object. The
449   /// offset is relative to the stack pointer on entry to the function.
450   void setObjectOffset(int ObjectIdx, int64_t SPOffset) {
451     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
452            "Invalid Object Idx!");
453     assert(!isDeadObjectIndex(ObjectIdx) &&
454            "Setting frame offset for a dead object?");
455     Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
456   }
457
458   /// Return the number of bytes that must be allocated to hold
459   /// all of the fixed size frame objects.  This is only valid after
460   /// Prolog/Epilog code insertion has finalized the stack frame layout.
461   uint64_t getStackSize() const { return StackSize; }
462
463   /// Set the size of the stack.
464   void setStackSize(uint64_t Size) { StackSize = Size; }
465
466   /// Estimate and return the size of the stack frame.
467   unsigned estimateStackSize(const MachineFunction &MF) const;
468
469   /// Return the correction for frame offsets.
470   int getOffsetAdjustment() const { return OffsetAdjustment; }
471
472   /// Set the correction for frame offsets.
473   void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; }
474
475   /// Return the alignment in bytes that this function must be aligned to,
476   /// which is greater than the default stack alignment provided by the target.
477   unsigned getMaxAlignment() const { return MaxAlignment; }
478
479   /// Make sure the function is at least Align bytes aligned.
480   void ensureMaxAlignment(unsigned Align);
481
482   /// Return true if this function adjusts the stack -- e.g.,
483   /// when calling another function. This is only valid during and after
484   /// prolog/epilog code insertion.
485   bool adjustsStack() const { return AdjustsStack; }
486   void setAdjustsStack(bool V) { AdjustsStack = V; }
487
488   /// Return true if the current function has any function calls.
489   bool hasCalls() const { return HasCalls; }
490   void setHasCalls(bool V) { HasCalls = V; }
491
492   /// Returns true if the function contains opaque dynamic stack adjustments.
493   bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
494   void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }
495
496   /// Returns true if the function calls the llvm.va_start intrinsic.
497   bool hasVAStart() const { return HasVAStart; }
498   void setHasVAStart(bool B) { HasVAStart = B; }
499
500   /// Returns true if the function is variadic and contains a musttail call.
501   bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; }
502   void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; }
503
504   /// Returns true if the function contains a tail call.
505   bool hasTailCall() const { return HasTailCall; }
506   void setHasTailCall() { HasTailCall = true; }
507
508   /// Return the maximum size of a call frame that must be
509   /// allocated for an outgoing function call.  This is only available if
510   /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
511   /// then only during or after prolog/epilog code insertion.
512   ///
513   unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; }
514   void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
515
516   /// Create a new object at a fixed location on the stack.
517   /// All fixed objects should be created before other objects are created for
518   /// efficiency. By default, fixed objects are not pointed to by LLVM IR
519   /// values. This returns an index with a negative value.
520   int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable,
521                         bool isAliased = false);
522
523   /// Create a spill slot at a fixed location on the stack.
524   /// Returns an index with a negative value.
525   int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset);
526
527   /// Returns true if the specified index corresponds to a fixed stack object.
528   bool isFixedObjectIndex(int ObjectIdx) const {
529     return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
530   }
531
532   /// Returns true if the specified index corresponds
533   /// to an object that might be pointed to by an LLVM IR value.
534   bool isAliasedObjectIndex(int ObjectIdx) const {
535     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
536            "Invalid Object Idx!");
537     return Objects[ObjectIdx+NumFixedObjects].isAliased;
538   }
539
540   /// isImmutableObjectIndex - Returns true if the specified index corresponds
541   /// to an immutable object.
542   bool isImmutableObjectIndex(int ObjectIdx) const {
543     // Tail calling functions can clobber their function arguments.
544     if (HasTailCall)
545       return false;
546     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
547            "Invalid Object Idx!");
548     return Objects[ObjectIdx+NumFixedObjects].isImmutable;
549   }
550
551   /// Returns true if the specified index corresponds to a spill slot.
552   bool isSpillSlotObjectIndex(int ObjectIdx) const {
553     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
554            "Invalid Object Idx!");
555     return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
556   }
557
558   bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const {
559     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
560            "Invalid Object Idx!");
561     return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
562   }
563
564   /// Returns true if the specified index corresponds to a dead object.
565   bool isDeadObjectIndex(int ObjectIdx) const {
566     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
567            "Invalid Object Idx!");
568     return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
569   }
570
571   /// Returns true if the specified index corresponds to a variable sized
572   /// object.
573   bool isVariableSizedObjectIndex(int ObjectIdx) const {
574     assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
575            "Invalid Object Idx!");
576     return Objects[ObjectIdx + NumFixedObjects].Size == 0;
577   }
578
579   void markAsStatepointSpillSlotObjectIndex(int ObjectIdx) {
580     assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
581            "Invalid Object Idx!");
582     Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot = true;
583     assert(isStatepointSpillSlotObjectIndex(ObjectIdx) && "inconsistent");
584   }
585
586   /// Create a new statically sized stack object, returning
587   /// a nonnegative identifier to represent it.
588   int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,
589                         const AllocaInst *Alloca = nullptr);
590
591   /// Create a new statically sized stack object that represents a spill slot,
592   /// returning a nonnegative identifier to represent it.
593   int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
594
595   /// Remove or mark dead a statically sized stack object.
596   void RemoveStackObject(int ObjectIdx) {
597     // Mark it dead.
598     Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
599   }
600
601   /// Notify the MachineFrameInfo object that a variable sized object has been
602   /// created.  This must be created whenever a variable sized object is
603   /// created, whether or not the index returned is actually used.
604   int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
605
606   /// Returns a reference to call saved info vector for the current function.
607   const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const {
608     return CSInfo;
609   }
610
611   /// Used by prolog/epilog inserter to set the function's callee saved
612   /// information.
613   void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) {
614     CSInfo = CSI;
615   }
616
617   /// Has the callee saved info been calculated yet?
618   bool isCalleeSavedInfoValid() const { return CSIValid; }
619
620   void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
621
622   MachineBasicBlock *getSavePoint() const { return Save; }
623   void setSavePoint(MachineBasicBlock *NewSave) { Save = NewSave; }
624   MachineBasicBlock *getRestorePoint() const { return Restore; }
625   void setRestorePoint(MachineBasicBlock *NewRestore) { Restore = NewRestore; }
626
627   /// Return a set of physical registers that are pristine.
628   ///
629   /// Pristine registers hold a value that is useless to the current function,
630   /// but that must be preserved - they are callee saved registers that are not
631   /// saved.
632   ///
633   /// Before the PrologueEpilogueInserter has placed the CSR spill code, this
634   /// method always returns an empty set.
635   BitVector getPristineRegs(const MachineFunction &MF) const;
636
637   /// Used by the MachineFunction printer to print information about
638   /// stack objects. Implemented in MachineFunction.cpp.
639   void print(const MachineFunction &MF, raw_ostream &OS) const;
640
641   /// dump - Print the function to stderr.
642   void dump(const MachineFunction &MF) const;
643 };
644
645 } // End llvm namespace
646
647 #endif