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