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