MachineFrameInfo.h revision 218893
1193323Sed//===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// The file defines the MachineFrameInfo class. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed#ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H 15193323Sed#define LLVM_CODEGEN_MACHINEFRAMEINFO_H 16193323Sed 17199481Srdivacky#include "llvm/ADT/SmallVector.h" 18212904Sdim//#include "llvm/ADT/IndexedMap.h" 19218893Sdim#include "llvm/Support/DataTypes.h" 20193323Sed#include <cassert> 21193323Sed#include <vector> 22193323Sed 23193323Sednamespace llvm { 24198090Srdivackyclass raw_ostream; 25193323Sedclass TargetData; 26193323Sedclass TargetRegisterClass; 27193323Sedclass Type; 28193323Sedclass MachineFunction; 29198090Srdivackyclass MachineBasicBlock; 30218893Sdimclass TargetFrameLowering; 31206274Srdivackyclass BitVector; 32193323Sed 33193323Sed/// The CalleeSavedInfo class tracks the information need to locate where a 34212904Sdim/// callee saved register is in the current frame. 35193323Sedclass CalleeSavedInfo { 36193323Sed unsigned Reg; 37193323Sed int FrameIdx; 38212904Sdim 39193323Sedpublic: 40210299Sed explicit CalleeSavedInfo(unsigned R, int FI = 0) 41210299Sed : Reg(R), FrameIdx(FI) {} 42212904Sdim 43193323Sed // Accessors. 44193323Sed unsigned getReg() const { return Reg; } 45193323Sed int getFrameIdx() const { return FrameIdx; } 46193323Sed void setFrameIdx(int FI) { FrameIdx = FI; } 47193323Sed}; 48193323Sed 49193323Sed/// The MachineFrameInfo class represents an abstract stack frame until 50193323Sed/// prolog/epilog code is inserted. This class is key to allowing stack frame 51193323Sed/// representation optimizations, such as frame pointer elimination. It also 52193323Sed/// allows more mundane (but still important) optimizations, such as reordering 53193323Sed/// of abstract objects on the stack frame. 54193323Sed/// 55193323Sed/// To support this, the class assigns unique integer identifiers to stack 56193323Sed/// objects requested clients. These identifiers are negative integers for 57193323Sed/// fixed stack objects (such as arguments passed on the stack) or nonnegative 58193323Sed/// for objects that may be reordered. Instructions which refer to stack 59193323Sed/// objects use a special MO_FrameIndex operand to represent these frame 60193323Sed/// indexes. 61193323Sed/// 62193323Sed/// Because this class keeps track of all references to the stack frame, it 63193323Sed/// knows when a variable sized object is allocated on the stack. This is the 64193323Sed/// sole condition which prevents frame pointer elimination, which is an 65193323Sed/// important optimization on register-poor architectures. Because original 66193323Sed/// variable sized alloca's in the source program are the only source of 67193323Sed/// variable sized stack objects, it is safe to decide whether there will be 68193323Sed/// any variable sized objects before all stack objects are known (for 69193323Sed/// example, register allocator spill code never needs variable sized 70193323Sed/// objects). 71193323Sed/// 72193323Sed/// When prolog/epilog code emission is performed, the final stack frame is 73193323Sed/// built and the machine instructions are modified to refer to the actual 74193323Sed/// stack offsets of the object, eliminating all MO_FrameIndex operands from 75193323Sed/// the program. 76193323Sed/// 77193323Sed/// @brief Abstract Stack Frame Information 78193323Sedclass MachineFrameInfo { 79193323Sed 80193323Sed // StackObject - Represent a single object allocated on the stack. 81193323Sed struct StackObject { 82198396Srdivacky // SPOffset - The offset of this object from the stack pointer on entry to 83198396Srdivacky // the function. This field has no meaning for a variable sized element. 84198396Srdivacky int64_t SPOffset; 85212904Sdim 86193323Sed // The size of this object on the stack. 0 means a variable sized object, 87193323Sed // ~0ULL means a dead object. 88193323Sed uint64_t Size; 89193323Sed 90193323Sed // Alignment - The required alignment of this stack slot. 91193323Sed unsigned Alignment; 92193323Sed 93193323Sed // isImmutable - If true, the value of the stack object is set before 94193323Sed // entering the function and is not modified inside the function. By 95193323Sed // default, fixed objects are immutable unless marked otherwise. 96193323Sed bool isImmutable; 97193323Sed 98212904Sdim // isSpillSlot - If true the stack object is used as spill slot. It 99198396Srdivacky // cannot alias any other memory objects. 100198396Srdivacky bool isSpillSlot; 101198396Srdivacky 102212904Sdim // MayNeedSP - If true the stack object triggered the creation of the stack 103212904Sdim // protector. We should allocate this object right after the stack 104212904Sdim // protector. 105212904Sdim bool MayNeedSP; 106212904Sdim 107212904Sdim // PreAllocated - If true, the object was mapped into the local frame 108212904Sdim // block and doesn't need additional handling for allocation beyond that. 109212904Sdim bool PreAllocated; 110212904Sdim 111212904Sdim StackObject(uint64_t Sz, unsigned Al, int64_t SP, bool IM, 112212904Sdim bool isSS, bool NSP) 113198396Srdivacky : SPOffset(SP), Size(Sz), Alignment(Al), isImmutable(IM), 114212904Sdim isSpillSlot(isSS), MayNeedSP(NSP), PreAllocated(false) {} 115193323Sed }; 116193323Sed 117193323Sed /// Objects - The list of stack objects allocated... 118193323Sed /// 119193323Sed std::vector<StackObject> Objects; 120193323Sed 121193323Sed /// NumFixedObjects - This contains the number of fixed objects contained on 122193323Sed /// the stack. Because fixed objects are stored at a negative index in the 123193323Sed /// Objects list, this is also the index to the 0th object in the list. 124193323Sed /// 125193323Sed unsigned NumFixedObjects; 126193323Sed 127193323Sed /// HasVarSizedObjects - This boolean keeps track of whether any variable 128193323Sed /// sized objects have been allocated yet. 129193323Sed /// 130193323Sed bool HasVarSizedObjects; 131193323Sed 132193323Sed /// FrameAddressTaken - This boolean keeps track of whether there is a call 133193323Sed /// to builtin \@llvm.frameaddress. 134193323Sed bool FrameAddressTaken; 135193323Sed 136208599Srdivacky /// ReturnAddressTaken - This boolean keeps track of whether there is a call 137208599Srdivacky /// to builtin \@llvm.returnaddress. 138208599Srdivacky bool ReturnAddressTaken; 139208599Srdivacky 140193323Sed /// StackSize - The prolog/epilog code inserter calculates the final stack 141193323Sed /// offsets for all of the fixed size objects, updating the Objects list 142193323Sed /// above. It then updates StackSize to contain the number of bytes that need 143193323Sed /// to be allocated on entry to the function. 144193323Sed /// 145193323Sed uint64_t StackSize; 146212904Sdim 147193323Sed /// OffsetAdjustment - The amount that a frame offset needs to be adjusted to 148198090Srdivacky /// have the actual offset from the stack/frame pointer. The exact usage of 149198090Srdivacky /// this is target-dependent, but it is typically used to adjust between 150198090Srdivacky /// SP-relative and FP-relative offsets. E.G., if objects are accessed via 151198090Srdivacky /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set 152198090Srdivacky /// to the distance between the initial SP and the value in FP. For many 153198090Srdivacky /// targets, this value is only used when generating debug info (via 154198090Srdivacky /// TargetRegisterInfo::getFrameIndexOffset); when generating code, the 155198090Srdivacky /// corresponding adjustments are performed directly. 156193323Sed int OffsetAdjustment; 157212904Sdim 158212904Sdim /// MaxAlignment - The prolog/epilog code inserter may process objects 159193323Sed /// that require greater alignment than the default alignment the target 160212904Sdim /// provides. To handle this, MaxAlignment is set to the maximum alignment 161193323Sed /// needed by the objects on the current frame. If this is greater than the 162193323Sed /// native alignment maintained by the compiler, dynamic alignment code will 163193323Sed /// be needed. 164193323Sed /// 165193323Sed unsigned MaxAlignment; 166193323Sed 167208599Srdivacky /// AdjustsStack - Set to true if this function adjusts the stack -- e.g., 168208599Srdivacky /// when calling another function. This is only valid during and after 169208599Srdivacky /// prolog/epilog code insertion. 170208599Srdivacky bool AdjustsStack; 171208599Srdivacky 172208599Srdivacky /// HasCalls - Set to true if this function has any function calls. 173193323Sed bool HasCalls; 174193323Sed 175193323Sed /// StackProtectorIdx - The frame index for the stack protector. 176193323Sed int StackProtectorIdx; 177193323Sed 178193323Sed /// MaxCallFrameSize - This contains the size of the largest call frame if the 179193323Sed /// target uses frame setup/destroy pseudo instructions (as defined in the 180193323Sed /// TargetFrameInfo class). This information is important for frame pointer 181193323Sed /// elimination. If is only valid during and after prolog/epilog code 182193323Sed /// insertion. 183193323Sed /// 184193323Sed unsigned MaxCallFrameSize; 185212904Sdim 186193323Sed /// CSInfo - The prolog/epilog code inserter fills in this vector with each 187193323Sed /// callee saved register saved in the frame. Beyond its use by the prolog/ 188193323Sed /// epilog code inserter, this data used for debug info and exception 189193323Sed /// handling. 190193323Sed std::vector<CalleeSavedInfo> CSInfo; 191198090Srdivacky 192198090Srdivacky /// CSIValid - Has CSInfo been set yet? 193198090Srdivacky bool CSIValid; 194198090Srdivacky 195218893Sdim /// TargetFrameLowering - Target information about frame layout. 196193323Sed /// 197218893Sdim const TargetFrameLowering &TFI; 198199481Srdivacky 199212904Sdim /// LocalFrameObjects - References to frame indices which are mapped 200212904Sdim /// into the local frame allocation block. <FrameIdx, LocalOffset> 201212904Sdim SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects; 202212904Sdim 203212904Sdim /// LocalFrameSize - Size of the pre-allocated local frame block. 204212904Sdim int64_t LocalFrameSize; 205212904Sdim 206212904Sdim /// Required alignment of the local object blob, which is the strictest 207212904Sdim /// alignment of any object in it. 208212904Sdim unsigned LocalFrameMaxAlign; 209212904Sdim 210212904Sdim /// Whether the local object blob needs to be allocated together. If not, 211212904Sdim /// PEI should ignore the isPreAllocated flags on the stack objects and 212212904Sdim /// just allocate them normally. 213212904Sdim bool UseLocalStackAllocationBlock; 214212904Sdim 215193323Sedpublic: 216218893Sdim explicit MachineFrameInfo(const TargetFrameLowering &tfi) : TFI(tfi) { 217193323Sed StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0; 218193323Sed HasVarSizedObjects = false; 219193323Sed FrameAddressTaken = false; 220208599Srdivacky ReturnAddressTaken = false; 221208599Srdivacky AdjustsStack = false; 222193323Sed HasCalls = false; 223193323Sed StackProtectorIdx = -1; 224193323Sed MaxCallFrameSize = 0; 225198090Srdivacky CSIValid = false; 226212904Sdim LocalFrameSize = 0; 227212904Sdim LocalFrameMaxAlign = 0; 228212904Sdim UseLocalStackAllocationBlock = false; 229193323Sed } 230193323Sed 231193323Sed /// hasStackObjects - Return true if there are any stack objects in this 232193323Sed /// function. 233193323Sed /// 234193323Sed bool hasStackObjects() const { return !Objects.empty(); } 235193323Sed 236193323Sed /// hasVarSizedObjects - This method may be called any time after instruction 237193323Sed /// selection is complete to determine if the stack frame for this function 238193323Sed /// contains any variable sized objects. 239193323Sed /// 240193323Sed bool hasVarSizedObjects() const { return HasVarSizedObjects; } 241193323Sed 242193323Sed /// getStackProtectorIndex/setStackProtectorIndex - Return the index for the 243193323Sed /// stack protector object. 244193323Sed /// 245193323Sed int getStackProtectorIndex() const { return StackProtectorIdx; } 246193323Sed void setStackProtectorIndex(int I) { StackProtectorIdx = I; } 247193323Sed 248193323Sed /// isFrameAddressTaken - This method may be called any time after instruction 249193323Sed /// selection is complete to determine if there is a call to 250193323Sed /// \@llvm.frameaddress in this function. 251193323Sed bool isFrameAddressTaken() const { return FrameAddressTaken; } 252193323Sed void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; } 253193323Sed 254212904Sdim /// isReturnAddressTaken - This method may be called any time after 255212904Sdim /// instruction selection is complete to determine if there is a call to 256208599Srdivacky /// \@llvm.returnaddress in this function. 257208599Srdivacky bool isReturnAddressTaken() const { return ReturnAddressTaken; } 258208599Srdivacky void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; } 259208599Srdivacky 260193323Sed /// getObjectIndexBegin - Return the minimum frame object index. 261193323Sed /// 262193323Sed int getObjectIndexBegin() const { return -NumFixedObjects; } 263193323Sed 264193323Sed /// getObjectIndexEnd - Return one past the maximum frame object index. 265193323Sed /// 266193323Sed int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; } 267193323Sed 268212904Sdim /// getNumFixedObjects - Return the number of fixed objects. 269193323Sed unsigned getNumFixedObjects() const { return NumFixedObjects; } 270193323Sed 271212904Sdim /// getNumObjects - Return the number of objects. 272193323Sed /// 273193323Sed unsigned getNumObjects() const { return Objects.size(); } 274193323Sed 275212904Sdim /// mapLocalFrameObject - Map a frame index into the local object block 276212904Sdim void mapLocalFrameObject(int ObjectIndex, int64_t Offset) { 277212904Sdim LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset)); 278212904Sdim Objects[ObjectIndex + NumFixedObjects].PreAllocated = true; 279212904Sdim } 280212904Sdim 281212904Sdim /// getLocalFrameObjectMap - Get the local offset mapping for a for an object 282212904Sdim std::pair<int, int64_t> getLocalFrameObjectMap(int i) { 283212904Sdim assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() && 284212904Sdim "Invalid local object reference!"); 285212904Sdim return LocalFrameObjects[i]; 286212904Sdim } 287212904Sdim 288212904Sdim /// getLocalFrameObjectCount - Return the number of objects allocated into 289212904Sdim /// the local object block. 290212904Sdim int64_t getLocalFrameObjectCount() { return LocalFrameObjects.size(); } 291212904Sdim 292212904Sdim /// setLocalFrameSize - Set the size of the local object blob. 293212904Sdim void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; } 294212904Sdim 295212904Sdim /// getLocalFrameSize - Get the size of the local object blob. 296212904Sdim int64_t getLocalFrameSize() const { return LocalFrameSize; } 297212904Sdim 298212904Sdim /// setLocalFrameMaxAlign - Required alignment of the local object blob, 299212904Sdim /// which is the strictest alignment of any object in it. 300212904Sdim void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; } 301212904Sdim 302212904Sdim /// getLocalFrameMaxAlign - Return the required alignment of the local 303212904Sdim /// object blob. 304212904Sdim unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; } 305212904Sdim 306212904Sdim /// getUseLocalStackAllocationBlock - Get whether the local allocation blob 307212904Sdim /// should be allocated together or let PEI allocate the locals in it 308212904Sdim /// directly. 309212904Sdim bool getUseLocalStackAllocationBlock() {return UseLocalStackAllocationBlock;} 310212904Sdim 311212904Sdim /// setUseLocalStackAllocationBlock - Set whether the local allocation blob 312212904Sdim /// should be allocated together or let PEI allocate the locals in it 313212904Sdim /// directly. 314212904Sdim void setUseLocalStackAllocationBlock(bool v) { 315212904Sdim UseLocalStackAllocationBlock = v; 316212904Sdim } 317212904Sdim 318212904Sdim /// isObjectPreAllocated - Return true if the object was pre-allocated into 319212904Sdim /// the local block. 320212904Sdim bool isObjectPreAllocated(int ObjectIdx) const { 321212904Sdim assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 322212904Sdim "Invalid Object Idx!"); 323212904Sdim return Objects[ObjectIdx+NumFixedObjects].PreAllocated; 324212904Sdim } 325212904Sdim 326193323Sed /// getObjectSize - Return the size of the specified object. 327193323Sed /// 328193323Sed int64_t getObjectSize(int ObjectIdx) const { 329193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 330193323Sed "Invalid Object Idx!"); 331193323Sed return Objects[ObjectIdx+NumFixedObjects].Size; 332193323Sed } 333193323Sed 334193323Sed /// setObjectSize - Change the size of the specified stack object. 335193323Sed void setObjectSize(int ObjectIdx, int64_t Size) { 336193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 337193323Sed "Invalid Object Idx!"); 338193323Sed Objects[ObjectIdx+NumFixedObjects].Size = Size; 339193323Sed } 340193323Sed 341193323Sed /// getObjectAlignment - Return the alignment of the specified stack object. 342193323Sed unsigned getObjectAlignment(int ObjectIdx) const { 343193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 344193323Sed "Invalid Object Idx!"); 345193323Sed return Objects[ObjectIdx+NumFixedObjects].Alignment; 346193323Sed } 347193323Sed 348193323Sed /// setObjectAlignment - Change the alignment of the specified stack object. 349193323Sed void setObjectAlignment(int ObjectIdx, unsigned Align) { 350193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 351193323Sed "Invalid Object Idx!"); 352193323Sed Objects[ObjectIdx+NumFixedObjects].Alignment = Align; 353203954Srdivacky MaxAlignment = std::max(MaxAlignment, Align); 354193323Sed } 355193323Sed 356212904Sdim /// NeedsStackProtector - Returns true if the object may need stack 357212904Sdim /// protectors. 358212904Sdim bool MayNeedStackProtector(int ObjectIdx) const { 359212904Sdim assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 360212904Sdim "Invalid Object Idx!"); 361212904Sdim return Objects[ObjectIdx+NumFixedObjects].MayNeedSP; 362212904Sdim } 363212904Sdim 364193323Sed /// getObjectOffset - Return the assigned stack offset of the specified object 365193323Sed /// from the incoming stack pointer. 366193323Sed /// 367193323Sed int64_t getObjectOffset(int ObjectIdx) const { 368193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 369193323Sed "Invalid Object Idx!"); 370193323Sed assert(!isDeadObjectIndex(ObjectIdx) && 371193323Sed "Getting frame offset for a dead object?"); 372193323Sed return Objects[ObjectIdx+NumFixedObjects].SPOffset; 373193323Sed } 374193323Sed 375193323Sed /// setObjectOffset - Set the stack frame offset of the specified object. The 376193323Sed /// offset is relative to the stack pointer on entry to the function. 377193323Sed /// 378193323Sed void setObjectOffset(int ObjectIdx, int64_t SPOffset) { 379193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 380193323Sed "Invalid Object Idx!"); 381193323Sed assert(!isDeadObjectIndex(ObjectIdx) && 382193323Sed "Setting frame offset for a dead object?"); 383193323Sed Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset; 384193323Sed } 385193323Sed 386193323Sed /// getStackSize - Return the number of bytes that must be allocated to hold 387193323Sed /// all of the fixed size frame objects. This is only valid after 388193323Sed /// Prolog/Epilog code insertion has finalized the stack frame layout. 389193323Sed /// 390193323Sed uint64_t getStackSize() const { return StackSize; } 391193323Sed 392193323Sed /// setStackSize - Set the size of the stack... 393193323Sed /// 394193323Sed void setStackSize(uint64_t Size) { StackSize = Size; } 395212904Sdim 396193323Sed /// getOffsetAdjustment - Return the correction for frame offsets. 397193323Sed /// 398193323Sed int getOffsetAdjustment() const { return OffsetAdjustment; } 399212904Sdim 400193323Sed /// setOffsetAdjustment - Set the correction for frame offsets. 401193323Sed /// 402193323Sed void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; } 403193323Sed 404212904Sdim /// getMaxAlignment - Return the alignment in bytes that this function must be 405212904Sdim /// aligned to, which is greater than the default stack alignment provided by 406193323Sed /// the target. 407193323Sed /// 408193323Sed unsigned getMaxAlignment() const { return MaxAlignment; } 409212904Sdim 410193323Sed /// setMaxAlignment - Set the preferred alignment. 411193323Sed /// 412193323Sed void setMaxAlignment(unsigned Align) { MaxAlignment = Align; } 413200581Srdivacky 414208599Srdivacky /// AdjustsStack - Return true if this function adjusts the stack -- e.g., 415208599Srdivacky /// when calling another function. This is only valid during and after 416208599Srdivacky /// prolog/epilog code insertion. 417208599Srdivacky bool adjustsStack() const { return AdjustsStack; } 418208599Srdivacky void setAdjustsStack(bool V) { AdjustsStack = V; } 419208599Srdivacky 420208599Srdivacky /// hasCalls - Return true if the current function has any function calls. 421193323Sed bool hasCalls() const { return HasCalls; } 422193323Sed void setHasCalls(bool V) { HasCalls = V; } 423193323Sed 424193323Sed /// getMaxCallFrameSize - Return the maximum size of a call frame that must be 425193323Sed /// allocated for an outgoing function call. This is only available if 426193323Sed /// CallFrameSetup/Destroy pseudo instructions are used by the target, and 427193323Sed /// then only during or after prolog/epilog code insertion. 428193323Sed /// 429193323Sed unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; } 430193323Sed void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; } 431193323Sed 432193323Sed /// CreateFixedObject - Create a new object at a fixed location on the stack. 433193323Sed /// All fixed objects should be created before other objects are created for 434193323Sed /// efficiency. By default, fixed objects are immutable. This returns an 435193323Sed /// index with a negative value. 436193323Sed /// 437210299Sed int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable); 438212904Sdim 439212904Sdim 440193323Sed /// isFixedObjectIndex - Returns true if the specified index corresponds to a 441193323Sed /// fixed stack object. 442193323Sed bool isFixedObjectIndex(int ObjectIdx) const { 443193323Sed return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects); 444193323Sed } 445193323Sed 446193323Sed /// isImmutableObjectIndex - Returns true if the specified index corresponds 447193323Sed /// to an immutable object. 448193323Sed bool isImmutableObjectIndex(int ObjectIdx) const { 449193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 450193323Sed "Invalid Object Idx!"); 451193323Sed return Objects[ObjectIdx+NumFixedObjects].isImmutable; 452193323Sed } 453193323Sed 454198396Srdivacky /// isSpillSlotObjectIndex - Returns true if the specified index corresponds 455198396Srdivacky /// to a spill slot.. 456198396Srdivacky bool isSpillSlotObjectIndex(int ObjectIdx) const { 457198396Srdivacky assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 458198396Srdivacky "Invalid Object Idx!"); 459198396Srdivacky return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;; 460198396Srdivacky } 461198396Srdivacky 462193323Sed /// isDeadObjectIndex - Returns true if the specified index corresponds to 463193323Sed /// a dead object. 464193323Sed bool isDeadObjectIndex(int ObjectIdx) const { 465193323Sed assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 466193323Sed "Invalid Object Idx!"); 467193323Sed return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL; 468193323Sed } 469193323Sed 470212904Sdim /// CreateStackObject - Create a new statically sized stack object, returning 471212904Sdim /// a nonnegative identifier to represent it. 472193323Sed /// 473212904Sdim int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, 474212904Sdim bool MayNeedSP = false) { 475193323Sed assert(Size != 0 && "Cannot allocate zero size stack objects!"); 476212904Sdim Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, MayNeedSP)); 477212904Sdim int Index = (int)Objects.size() - NumFixedObjects - 1; 478199481Srdivacky assert(Index >= 0 && "Bad frame index!"); 479203954Srdivacky MaxAlignment = std::max(MaxAlignment, Alignment); 480199481Srdivacky return Index; 481193323Sed } 482193323Sed 483212904Sdim /// CreateSpillStackObject - Create a new statically sized stack object that 484212904Sdim /// represents a spill slot, returning a nonnegative identifier to represent 485212904Sdim /// it. 486199481Srdivacky /// 487199481Srdivacky int CreateSpillStackObject(uint64_t Size, unsigned Alignment) { 488212904Sdim CreateStackObject(Size, Alignment, true, false); 489212904Sdim int Index = (int)Objects.size() - NumFixedObjects - 1; 490203954Srdivacky MaxAlignment = std::max(MaxAlignment, Alignment); 491199481Srdivacky return Index; 492199481Srdivacky } 493199481Srdivacky 494193323Sed /// RemoveStackObject - Remove or mark dead a statically sized stack object. 495193323Sed /// 496193323Sed void RemoveStackObject(int ObjectIdx) { 497193323Sed // Mark it dead. 498193323Sed Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL; 499193323Sed } 500193323Sed 501193323Sed /// CreateVariableSizedObject - Notify the MachineFrameInfo object that a 502193323Sed /// variable sized object has been created. This must be created whenever a 503193323Sed /// variable sized object is created, whether or not the index returned is 504193323Sed /// actually used. 505193323Sed /// 506212904Sdim int CreateVariableSizedObject(unsigned Alignment) { 507193323Sed HasVarSizedObjects = true; 508212904Sdim Objects.push_back(StackObject(0, Alignment, 0, false, false, true)); 509212904Sdim MaxAlignment = std::max(MaxAlignment, Alignment); 510193323Sed return (int)Objects.size()-NumFixedObjects-1; 511193323Sed } 512199481Srdivacky 513193323Sed /// getCalleeSavedInfo - Returns a reference to call saved info vector for the 514193323Sed /// current function. 515193323Sed const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const { 516193323Sed return CSInfo; 517193323Sed } 518193323Sed 519193323Sed /// setCalleeSavedInfo - Used by prolog/epilog inserter to set the function's 520193323Sed /// callee saved information. 521212904Sdim void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) { 522193323Sed CSInfo = CSI; 523193323Sed } 524193323Sed 525198090Srdivacky /// isCalleeSavedInfoValid - Has the callee saved info been calculated yet? 526198090Srdivacky bool isCalleeSavedInfoValid() const { return CSIValid; } 527198090Srdivacky 528198090Srdivacky void setCalleeSavedInfoValid(bool v) { CSIValid = v; } 529198090Srdivacky 530198090Srdivacky /// getPristineRegs - Return a set of physical registers that are pristine on 531198090Srdivacky /// entry to the MBB. 532198090Srdivacky /// 533198090Srdivacky /// Pristine registers hold a value that is useless to the current function, 534198090Srdivacky /// but that must be preserved - they are callee saved registers that have not 535198090Srdivacky /// been saved yet. 536198090Srdivacky /// 537198090Srdivacky /// Before the PrologueEpilogueInserter has placed the CSR spill code, this 538198090Srdivacky /// method always returns an empty set. 539198090Srdivacky BitVector getPristineRegs(const MachineBasicBlock *MBB) const; 540198090Srdivacky 541193323Sed /// print - Used by the MachineFunction printer to print information about 542212904Sdim /// stack objects. Implemented in MachineFunction.cpp 543193323Sed /// 544198090Srdivacky void print(const MachineFunction &MF, raw_ostream &OS) const; 545193323Sed 546198090Srdivacky /// dump - Print the function to stderr. 547193323Sed void dump(const MachineFunction &MF) const; 548193323Sed}; 549193323Sed 550193323Sed} // End llvm namespace 551193323Sed 552193323Sed#endif 553