1 //===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The file defines the MachineFrameInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
15 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/DataTypes.h"
24 class MachineFunction;
25 class MachineBasicBlock;
29 /// The CalleeSavedInfo class tracks the information need to locate where a
30 /// callee saved register is in the current frame.
31 class CalleeSavedInfo {
34 /// Flag indicating whether the register is actually restored in the epilog.
35 /// In most cases, if a register is saved, it is also restored. There are
36 /// some situations, though, when this is not the case. For example, the
37 /// LR register on ARM is usually saved, but on exit from the function its
38 /// saved value may be loaded directly into PC. Since liveness tracking of
39 /// physical registers treats callee-saved registers are live outside of
40 /// the function, LR would be treated as live-on-exit, even though in these
41 /// scenarios it is not. This flag is added to indicate that the saved
42 /// register described by this object is not restored in the epilog.
43 /// The long-term solution is to model the liveness of callee-saved registers
44 /// by implicit uses on the return instructions, however, the required
45 /// changes in the ARM backend would be quite extensive.
49 explicit CalleeSavedInfo(unsigned R, int FI = 0)
50 : Reg(R), FrameIdx(FI), Restored(true) {}
53 unsigned getReg() const { return Reg; }
54 int getFrameIdx() const { return FrameIdx; }
55 void setFrameIdx(int FI) { FrameIdx = FI; }
56 bool isRestored() const { return Restored; }
57 void setRestored(bool R) { Restored = R; }
60 /// The MachineFrameInfo class represents an abstract stack frame until
61 /// prolog/epilog code is inserted. This class is key to allowing stack frame
62 /// representation optimizations, such as frame pointer elimination. It also
63 /// allows more mundane (but still important) optimizations, such as reordering
64 /// of abstract objects on the stack frame.
66 /// To support this, the class assigns unique integer identifiers to stack
67 /// objects requested clients. These identifiers are negative integers for
68 /// fixed stack objects (such as arguments passed on the stack) or nonnegative
69 /// for objects that may be reordered. Instructions which refer to stack
70 /// objects use a special MO_FrameIndex operand to represent these frame
73 /// Because this class keeps track of all references to the stack frame, it
74 /// knows when a variable sized object is allocated on the stack. This is the
75 /// sole condition which prevents frame pointer elimination, which is an
76 /// important optimization on register-poor architectures. Because original
77 /// variable sized alloca's in the source program are the only source of
78 /// variable sized stack objects, it is safe to decide whether there will be
79 /// any variable sized objects before all stack objects are known (for
80 /// example, register allocator spill code never needs variable sized
83 /// When prolog/epilog code emission is performed, the final stack frame is
84 /// built and the machine instructions are modified to refer to the actual
85 /// stack offsets of the object, eliminating all MO_FrameIndex operands from
88 /// Abstract Stack Frame Information
89 class MachineFrameInfo {
91 /// Stack Smashing Protection (SSP) rules require that vulnerable stack
92 /// allocations are located close the stack protector.
94 SSPLK_None, ///< Did not trigger a stack protector. No effect on data
96 SSPLK_LargeArray, ///< Array or nested array >= SSP-buffer-size. Closest
97 ///< to the stack protector.
98 SSPLK_SmallArray, ///< Array or nested array < SSP-buffer-size. 2nd closest
99 ///< to the stack protector.
100 SSPLK_AddrOf ///< The address of this allocation is exposed and
101 ///< triggered protection. 3rd closest to the protector.
105 // Represent a single object allocated on the stack.
107 // The offset of this object from the stack pointer on entry to
108 // the function. This field has no meaning for a variable sized element.
111 // The size of this object on the stack. 0 means a variable sized object,
112 // ~0ULL means a dead object.
115 // The required alignment of this stack slot.
118 // If true, the value of the stack object is set before
119 // entering the function and is not modified inside the function. By
120 // default, fixed objects are immutable unless marked otherwise.
123 // If true the stack object is used as spill slot. It
124 // cannot alias any other memory objects.
127 /// If true, this stack slot is used to spill a value (could be deopt
128 /// and/or GC related) over a statepoint. We know that the address of the
129 /// slot can't alias any LLVM IR value. This is very similar to a Spill
130 /// Slot, but is created by statepoint lowering is SelectionDAG, not the
131 /// register allocator.
132 bool isStatepointSpillSlot = false;
134 /// Identifier for stack memory type analagous to address space. If this is
135 /// non-0, the meaning is target defined. Offsets cannot be directly
136 /// compared between objects with different stack IDs. The object may not
137 /// necessarily reside in the same contiguous memory block as other stack
138 /// objects. Objects with differing stack IDs should not be merged or
139 /// replaced substituted for each other.
141 /// It is assumed a target uses consecutive, increasing stack IDs starting
145 /// If this stack object is originated from an Alloca instruction
146 /// this value saves the original IR allocation. Can be NULL.
147 const AllocaInst *Alloca;
149 // If true, the object was mapped into the local frame
150 // block and doesn't need additional handling for allocation beyond that.
151 bool PreAllocated = false;
153 // If true, an LLVM IR value might point to this object.
154 // Normally, spill slots and fixed-offset objects don't alias IR-accessible
155 // objects, but there are exceptions (on PowerPC, for example, some byval
156 // arguments have ABI-prescribed offsets).
159 /// If true, the object has been zero-extended.
162 /// If true, the object has been zero-extended.
167 StackObject(uint64_t Size, unsigned Alignment, int64_t SPOffset,
168 bool IsImmutable, bool IsSpillSlot, const AllocaInst *Alloca,
169 bool IsAliased, uint8_t StackID = 0)
170 : SPOffset(SPOffset), Size(Size), Alignment(Alignment),
171 isImmutable(IsImmutable), isSpillSlot(IsSpillSlot),
172 StackID(StackID), Alloca(Alloca), isAliased(IsAliased),
173 SSPLayout(SSPLK_None) {}
176 /// The alignment of the stack.
177 unsigned StackAlignment;
179 /// Can the stack be realigned. This can be false if the target does not
180 /// support stack realignment, or if the user asks us not to realign the
181 /// stack. In this situation, overaligned allocas are all treated as dynamic
182 /// allocations and the target must handle them as part of DYNAMIC_STACKALLOC
183 /// lowering. All non-alloca stack objects have their alignment clamped to the
184 /// base ABI stack alignment.
185 /// FIXME: There is room for improvement in this case, in terms of
186 /// grouping overaligned allocas into a "secondary stack frame" and
187 /// then only use a single alloca to allocate this frame and only a
188 /// single virtual register to access it. Currently, without such an
189 /// optimization, each such alloca gets its own dynamic realignment.
190 bool StackRealignable;
192 /// Whether the function has the \c alignstack attribute.
195 /// The list of stack objects allocated.
196 std::vector<StackObject> Objects;
198 /// This contains the number of fixed objects contained on
199 /// the stack. Because fixed objects are stored at a negative index in the
200 /// Objects list, this is also the index to the 0th object in the list.
201 unsigned NumFixedObjects = 0;
203 /// This boolean keeps track of whether any variable
204 /// sized objects have been allocated yet.
205 bool HasVarSizedObjects = false;
207 /// This boolean keeps track of whether there is a call
208 /// to builtin \@llvm.frameaddress.
209 bool FrameAddressTaken = false;
211 /// This boolean keeps track of whether there is a call
212 /// to builtin \@llvm.returnaddress.
213 bool ReturnAddressTaken = false;
215 /// This boolean keeps track of whether there is a call
216 /// to builtin \@llvm.experimental.stackmap.
217 bool HasStackMap = false;
219 /// This boolean keeps track of whether there is a call
220 /// to builtin \@llvm.experimental.patchpoint.
221 bool HasPatchPoint = false;
223 /// The prolog/epilog code inserter calculates the final stack
224 /// offsets for all of the fixed size objects, updating the Objects list
225 /// above. It then updates StackSize to contain the number of bytes that need
226 /// to be allocated on entry to the function.
227 uint64_t StackSize = 0;
229 /// The amount that a frame offset needs to be adjusted to
230 /// have the actual offset from the stack/frame pointer. The exact usage of
231 /// this is target-dependent, but it is typically used to adjust between
232 /// SP-relative and FP-relative offsets. E.G., if objects are accessed via
233 /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set
234 /// to the distance between the initial SP and the value in FP. For many
235 /// targets, this value is only used when generating debug info (via
236 /// TargetRegisterInfo::getFrameIndexReference); when generating code, the
237 /// corresponding adjustments are performed directly.
238 int OffsetAdjustment = 0;
240 /// The prolog/epilog code inserter may process objects that require greater
241 /// alignment than the default alignment the target provides.
242 /// To handle this, MaxAlignment is set to the maximum alignment
243 /// needed by the objects on the current frame. If this is greater than the
244 /// native alignment maintained by the compiler, dynamic alignment code will
247 unsigned MaxAlignment = 0;
249 /// Set to true if this function adjusts the stack -- e.g.,
250 /// when calling another function. This is only valid during and after
251 /// prolog/epilog code insertion.
252 bool AdjustsStack = false;
254 /// Set to true if this function has any function calls.
255 bool HasCalls = false;
257 /// The frame index for the stack protector.
258 int StackProtectorIdx = -1;
260 /// The frame index for the function context. Used for SjLj exceptions.
261 int FunctionContextIdx = -1;
263 /// This contains the size of the largest call frame if the target uses frame
264 /// setup/destroy pseudo instructions (as defined in the TargetFrameInfo
265 /// class). This information is important for frame pointer elimination.
266 /// It is only valid during and after prolog/epilog code insertion.
267 unsigned MaxCallFrameSize = ~0u;
269 /// The prolog/epilog code inserter fills in this vector with each
270 /// callee saved register saved in the frame. Beyond its use by the prolog/
271 /// epilog code inserter, this data used for debug info and exception
273 std::vector<CalleeSavedInfo> CSInfo;
275 /// Has CSInfo been set yet?
276 bool CSIValid = false;
278 /// References to frame indices which are mapped
279 /// into the local frame allocation block. <FrameIdx, LocalOffset>
280 SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
282 /// Size of the pre-allocated local frame block.
283 int64_t LocalFrameSize = 0;
285 /// Required alignment of the local object blob, which is the strictest
286 /// alignment of any object in it.
287 unsigned LocalFrameMaxAlign = 0;
289 /// Whether the local object blob needs to be allocated together. If not,
290 /// PEI should ignore the isPreAllocated flags on the stack objects and
291 /// just allocate them normally.
292 bool UseLocalStackAllocationBlock = false;
294 /// True if the function dynamically adjusts the stack pointer through some
295 /// opaque mechanism like inline assembly or Win32 EH.
296 bool HasOpaqueSPAdjustment = false;
298 /// True if the function contains operations which will lower down to
299 /// instructions which manipulate the stack pointer.
300 bool HasCopyImplyingStackAdjustment = false;
302 /// True if the function contains a call to the llvm.vastart intrinsic.
303 bool HasVAStart = false;
305 /// True if this is a varargs function that contains a musttail call.
306 bool HasMustTailInVarArgFunc = false;
308 /// True if this function contains a tail call. If so immutable objects like
309 /// function arguments are no longer so. A tail call *can* override fixed
310 /// stack objects like arguments so we can't treat them as immutable.
311 bool HasTailCall = false;
313 /// Not null, if shrink-wrapping found a better place for the prologue.
314 MachineBasicBlock *Save = nullptr;
315 /// Not null, if shrink-wrapping found a better place for the epilogue.
316 MachineBasicBlock *Restore = nullptr;
319 explicit MachineFrameInfo(unsigned StackAlignment, bool StackRealignable,
321 : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
322 ForcedRealign(ForcedRealign) {}
324 /// Return true if there are any stack objects in this function.
325 bool hasStackObjects() const { return !Objects.empty(); }
327 /// This method may be called any time after instruction
328 /// selection is complete to determine if the stack frame for this function
329 /// contains any variable sized objects.
330 bool hasVarSizedObjects() const { return HasVarSizedObjects; }
332 /// Return the index for the stack protector object.
333 int getStackProtectorIndex() const { return StackProtectorIdx; }
334 void setStackProtectorIndex(int I) { StackProtectorIdx = I; }
335 bool hasStackProtectorIndex() const { return StackProtectorIdx != -1; }
337 /// Return the index for the function context object.
338 /// This object is used for SjLj exceptions.
339 int getFunctionContextIndex() const { return FunctionContextIdx; }
340 void setFunctionContextIndex(int I) { FunctionContextIdx = I; }
342 /// This method may be called any time after instruction
343 /// selection is complete to determine if there is a call to
344 /// \@llvm.frameaddress in this function.
345 bool isFrameAddressTaken() const { return FrameAddressTaken; }
346 void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
348 /// This method may be called any time after
349 /// instruction selection is complete to determine if there is a call to
350 /// \@llvm.returnaddress in this function.
351 bool isReturnAddressTaken() const { return ReturnAddressTaken; }
352 void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; }
354 /// This method may be called any time after instruction
355 /// selection is complete to determine if there is a call to builtin
356 /// \@llvm.experimental.stackmap.
357 bool hasStackMap() const { return HasStackMap; }
358 void setHasStackMap(bool s = true) { HasStackMap = s; }
360 /// This method may be called any time after instruction
361 /// selection is complete to determine if there is a call to builtin
362 /// \@llvm.experimental.patchpoint.
363 bool hasPatchPoint() const { return HasPatchPoint; }
364 void setHasPatchPoint(bool s = true) { HasPatchPoint = s; }
366 /// Return the minimum frame object index.
367 int getObjectIndexBegin() const { return -NumFixedObjects; }
369 /// Return one past the maximum frame object index.
370 int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; }
372 /// Return the number of fixed objects.
373 unsigned getNumFixedObjects() const { return NumFixedObjects; }
375 /// Return the number of objects.
376 unsigned getNumObjects() const { return Objects.size(); }
378 /// Map a frame index into the local object block
379 void mapLocalFrameObject(int ObjectIndex, int64_t Offset) {
380 LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
381 Objects[ObjectIndex + NumFixedObjects].PreAllocated = true;
384 /// Get the local offset mapping for a for an object.
385 std::pair<int, int64_t> getLocalFrameObjectMap(int i) const {
386 assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() &&
387 "Invalid local object reference!");
388 return LocalFrameObjects[i];
391 /// Return the number of objects allocated into the local object block.
392 int64_t getLocalFrameObjectCount() const { return LocalFrameObjects.size(); }
394 /// Set the size of the local object blob.
395 void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; }
397 /// Get the size of the local object blob.
398 int64_t getLocalFrameSize() const { return LocalFrameSize; }
400 /// Required alignment of the local object blob,
401 /// which is the strictest alignment of any object in it.
402 void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
404 /// Return the required alignment of the local object blob.
405 unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; }
407 /// Get whether the local allocation blob should be allocated together or
408 /// let PEI allocate the locals in it directly.
409 bool getUseLocalStackAllocationBlock() const {
410 return UseLocalStackAllocationBlock;
413 /// setUseLocalStackAllocationBlock - Set whether the local allocation blob
414 /// should be allocated together or let PEI allocate the locals in it
416 void setUseLocalStackAllocationBlock(bool v) {
417 UseLocalStackAllocationBlock = v;
420 /// Return true if the object was pre-allocated into the local block.
421 bool isObjectPreAllocated(int ObjectIdx) const {
422 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
423 "Invalid Object Idx!");
424 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
427 /// Return the size of the specified object.
428 int64_t getObjectSize(int ObjectIdx) const {
429 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
430 "Invalid Object Idx!");
431 return Objects[ObjectIdx+NumFixedObjects].Size;
434 /// Change the size of the specified stack object.
435 void setObjectSize(int ObjectIdx, int64_t Size) {
436 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
437 "Invalid Object Idx!");
438 Objects[ObjectIdx+NumFixedObjects].Size = Size;
441 /// Return the alignment of the specified stack object.
442 unsigned getObjectAlignment(int ObjectIdx) const {
443 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444 "Invalid Object Idx!");
445 return Objects[ObjectIdx+NumFixedObjects].Alignment;
448 /// setObjectAlignment - Change the alignment of the specified stack object.
449 void setObjectAlignment(int ObjectIdx, unsigned Align) {
450 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
451 "Invalid Object Idx!");
452 Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
453 ensureMaxAlignment(Align);
456 /// Return the underlying Alloca of the specified
457 /// stack object if it exists. Returns 0 if none exists.
458 const AllocaInst* getObjectAllocation(int ObjectIdx) const {
459 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
460 "Invalid Object Idx!");
461 return Objects[ObjectIdx+NumFixedObjects].Alloca;
464 /// Return the assigned stack offset of the specified object
465 /// from the incoming stack pointer.
466 int64_t getObjectOffset(int ObjectIdx) const {
467 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
468 "Invalid Object Idx!");
469 assert(!isDeadObjectIndex(ObjectIdx) &&
470 "Getting frame offset for a dead object?");
471 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
474 bool isObjectZExt(int ObjectIdx) const {
475 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
476 "Invalid Object Idx!");
477 return Objects[ObjectIdx+NumFixedObjects].isZExt;
480 void setObjectZExt(int ObjectIdx, bool IsZExt) {
481 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
482 "Invalid Object Idx!");
483 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
486 bool isObjectSExt(int ObjectIdx) const {
487 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
488 "Invalid Object Idx!");
489 return Objects[ObjectIdx+NumFixedObjects].isSExt;
492 void setObjectSExt(int ObjectIdx, bool IsSExt) {
493 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
494 "Invalid Object Idx!");
495 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
498 /// Set the stack frame offset of the specified object. The
499 /// offset is relative to the stack pointer on entry to the function.
500 void setObjectOffset(int ObjectIdx, int64_t SPOffset) {
501 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
502 "Invalid Object Idx!");
503 assert(!isDeadObjectIndex(ObjectIdx) &&
504 "Setting frame offset for a dead object?");
505 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
508 SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const {
509 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
510 "Invalid Object Idx!");
511 return (SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
514 void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind) {
515 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
516 "Invalid Object Idx!");
517 assert(!isDeadObjectIndex(ObjectIdx) &&
518 "Setting SSP layout for a dead object?");
519 Objects[ObjectIdx+NumFixedObjects].SSPLayout = Kind;
522 /// Return the number of bytes that must be allocated to hold
523 /// all of the fixed size frame objects. This is only valid after
524 /// Prolog/Epilog code insertion has finalized the stack frame layout.
525 uint64_t getStackSize() const { return StackSize; }
527 /// Set the size of the stack.
528 void setStackSize(uint64_t Size) { StackSize = Size; }
530 /// Estimate and return the size of the stack frame.
531 unsigned estimateStackSize(const MachineFunction &MF) const;
533 /// Return the correction for frame offsets.
534 int getOffsetAdjustment() const { return OffsetAdjustment; }
536 /// Set the correction for frame offsets.
537 void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; }
539 /// Return the alignment in bytes that this function must be aligned to,
540 /// which is greater than the default stack alignment provided by the target.
541 unsigned getMaxAlignment() const { return MaxAlignment; }
543 /// Make sure the function is at least Align bytes aligned.
544 void ensureMaxAlignment(unsigned Align);
546 /// Return true if this function adjusts the stack -- e.g.,
547 /// when calling another function. This is only valid during and after
548 /// prolog/epilog code insertion.
549 bool adjustsStack() const { return AdjustsStack; }
550 void setAdjustsStack(bool V) { AdjustsStack = V; }
552 /// Return true if the current function has any function calls.
553 bool hasCalls() const { return HasCalls; }
554 void setHasCalls(bool V) { HasCalls = V; }
556 /// Returns true if the function contains opaque dynamic stack adjustments.
557 bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
558 void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }
560 /// Returns true if the function contains operations which will lower down to
561 /// instructions which manipulate the stack pointer.
562 bool hasCopyImplyingStackAdjustment() const {
563 return HasCopyImplyingStackAdjustment;
565 void setHasCopyImplyingStackAdjustment(bool B) {
566 HasCopyImplyingStackAdjustment = B;
569 /// Returns true if the function calls the llvm.va_start intrinsic.
570 bool hasVAStart() const { return HasVAStart; }
571 void setHasVAStart(bool B) { HasVAStart = B; }
573 /// Returns true if the function is variadic and contains a musttail call.
574 bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; }
575 void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; }
577 /// Returns true if the function contains a tail call.
578 bool hasTailCall() const { return HasTailCall; }
579 void setHasTailCall() { HasTailCall = true; }
581 /// Computes the maximum size of a callframe and the AdjustsStack property.
582 /// This only works for targets defining
583 /// TargetInstrInfo::getCallFrameSetupOpcode(), getCallFrameDestroyOpcode(),
584 /// and getFrameSize().
585 /// This is usually computed by the prologue epilogue inserter but some
586 /// targets may call this to compute it earlier.
587 void computeMaxCallFrameSize(const MachineFunction &MF);
589 /// Return the maximum size of a call frame that must be
590 /// allocated for an outgoing function call. This is only available if
591 /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
592 /// then only during or after prolog/epilog code insertion.
594 unsigned getMaxCallFrameSize() const {
595 // TODO: Enable this assert when targets are fixed.
596 //assert(isMaxCallFrameSizeComputed() && "MaxCallFrameSize not computed yet");
597 if (!isMaxCallFrameSizeComputed())
599 return MaxCallFrameSize;
601 bool isMaxCallFrameSizeComputed() const {
602 return MaxCallFrameSize != ~0u;
604 void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
606 /// Create a new object at a fixed location on the stack.
607 /// All fixed objects should be created before other objects are created for
608 /// efficiency. By default, fixed objects are not pointed to by LLVM IR
609 /// values. This returns an index with a negative value.
610 int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable,
611 bool isAliased = false);
613 /// Create a spill slot at a fixed location on the stack.
614 /// Returns an index with a negative value.
615 int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset,
616 bool IsImmutable = false);
618 /// Returns true if the specified index corresponds to a fixed stack object.
619 bool isFixedObjectIndex(int ObjectIdx) const {
620 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
623 /// Returns true if the specified index corresponds
624 /// to an object that might be pointed to by an LLVM IR value.
625 bool isAliasedObjectIndex(int ObjectIdx) const {
626 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
627 "Invalid Object Idx!");
628 return Objects[ObjectIdx+NumFixedObjects].isAliased;
631 /// Returns true if the specified index corresponds to an immutable object.
632 bool isImmutableObjectIndex(int ObjectIdx) const {
633 // Tail calling functions can clobber their function arguments.
636 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
637 "Invalid Object Idx!");
638 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
641 /// Marks the immutability of an object.
642 void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable) {
643 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
644 "Invalid Object Idx!");
645 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
648 /// Returns true if the specified index corresponds to a spill slot.
649 bool isSpillSlotObjectIndex(int ObjectIdx) const {
650 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
651 "Invalid Object Idx!");
652 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
655 bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const {
656 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
657 "Invalid Object Idx!");
658 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
662 uint8_t getStackID(int ObjectIdx) const {
663 return Objects[ObjectIdx+NumFixedObjects].StackID;
667 void setStackID(int ObjectIdx, uint8_t ID) {
668 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
669 "Invalid Object Idx!");
670 Objects[ObjectIdx+NumFixedObjects].StackID = ID;
673 /// Returns true if the specified index corresponds to a dead object.
674 bool isDeadObjectIndex(int ObjectIdx) const {
675 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
676 "Invalid Object Idx!");
677 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
680 /// Returns true if the specified index corresponds to a variable sized
682 bool isVariableSizedObjectIndex(int ObjectIdx) const {
683 assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
684 "Invalid Object Idx!");
685 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
688 void markAsStatepointSpillSlotObjectIndex(int ObjectIdx) {
689 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
690 "Invalid Object Idx!");
691 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot = true;
692 assert(isStatepointSpillSlotObjectIndex(ObjectIdx) && "inconsistent");
695 /// Create a new statically sized stack object, returning
696 /// a nonnegative identifier to represent it.
697 int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSpillSlot,
698 const AllocaInst *Alloca = nullptr, uint8_t ID = 0);
700 /// Create a new statically sized stack object that represents a spill slot,
701 /// returning a nonnegative identifier to represent it.
702 int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
704 /// Remove or mark dead a statically sized stack object.
705 void RemoveStackObject(int ObjectIdx) {
707 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
710 /// Notify the MachineFrameInfo object that a variable sized object has been
711 /// created. This must be created whenever a variable sized object is
712 /// created, whether or not the index returned is actually used.
713 int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
715 /// Returns a reference to call saved info vector for the current function.
716 const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const {
719 /// \copydoc getCalleeSavedInfo()
720 std::vector<CalleeSavedInfo> &getCalleeSavedInfo() { return CSInfo; }
722 /// Used by prolog/epilog inserter to set the function's callee saved
724 void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) {
728 /// Has the callee saved info been calculated yet?
729 bool isCalleeSavedInfoValid() const { return CSIValid; }
731 void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
733 MachineBasicBlock *getSavePoint() const { return Save; }
734 void setSavePoint(MachineBasicBlock *NewSave) { Save = NewSave; }
735 MachineBasicBlock *getRestorePoint() const { return Restore; }
736 void setRestorePoint(MachineBasicBlock *NewRestore) { Restore = NewRestore; }
738 /// Return a set of physical registers that are pristine.
740 /// Pristine registers hold a value that is useless to the current function,
741 /// but that must be preserved - they are callee saved registers that are not
744 /// Before the PrologueEpilogueInserter has placed the CSR spill code, this
745 /// method always returns an empty set.
746 BitVector getPristineRegs(const MachineFunction &MF) const;
748 /// Used by the MachineFunction printer to print information about
749 /// stack objects. Implemented in MachineFunction.cpp.
750 void print(const MachineFunction &MF, raw_ostream &OS) const;
752 /// dump - Print the function to stderr.
753 void dump(const MachineFunction &MF) const;
756 } // End llvm namespace