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