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

Generated by: LCOV version 1.13