LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - MachineFrameInfo.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 66 66 100.0 %
Date: 2018-07-13 00:08:38 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13