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 // StackObject - Represent a single object allocated on the stack. 83 struct StackObject { 84 // SPOffset - 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 // Alignment - The required alignment of this stack slot. 93 unsigned Alignment; 94 95 // isImmutable - 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 // isSpillSlot - If true the stack object is used as spill slot. It 101 // cannot alias any other memory objects. 102 bool isSpillSlot; 103 104 /// Alloca - 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 // PreAllocated - 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 /// StackAlignment - The alignment of the stack. 125 unsigned StackAlignment; 126 127 /// StackRealignable - Can the stack be realigned. 128 bool StackRealignable; 129 130 /// Objects - The list of stack objects allocated... 131 /// 132 std::vector<StackObject> Objects; 133 134 /// NumFixedObjects - This contains the number of fixed objects contained on 135 /// the stack. Because fixed objects are stored at a negative index in the 136 /// Objects list, this is also the index to the 0th object in the list. 137 /// 138 unsigned NumFixedObjects; 139 140 /// HasVarSizedObjects - This boolean keeps track of whether any variable 141 /// sized objects have been allocated yet. 142 /// 143 bool HasVarSizedObjects; 144 145 /// FrameAddressTaken - This boolean keeps track of whether there is a call 146 /// to builtin \@llvm.frameaddress. 147 bool FrameAddressTaken; 148 149 /// ReturnAddressTaken - This boolean keeps track of whether there is a call 150 /// to builtin \@llvm.returnaddress. 151 bool ReturnAddressTaken; 152 153 /// HasStackMap - This boolean keeps track of whether there is a call 154 /// to builtin \@llvm.experimental.stackmap. 155 bool HasStackMap; 156 157 /// HasPatchPoint - This boolean keeps track of whether there is a call 158 /// to builtin \@llvm.experimental.patchpoint. 159 bool HasPatchPoint; 160 161 /// StackSize - The prolog/epilog code inserter calculates the final stack 162 /// offsets for all of the fixed size objects, updating the Objects list 163 /// above. It then updates StackSize to contain the number of bytes that need 164 /// to be allocated on entry to the function. 165 /// 166 uint64_t StackSize; 167 168 /// OffsetAdjustment - The amount that a frame offset needs to be adjusted to 169 /// have the actual offset from the stack/frame pointer. The exact usage of 170 /// this is target-dependent, but it is typically used to adjust between 171 /// SP-relative and FP-relative offsets. E.G., if objects are accessed via 172 /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set 173 /// to the distance between the initial SP and the value in FP. For many 174 /// targets, this value is only used when generating debug info (via 175 /// TargetRegisterInfo::getFrameIndexOffset); when generating code, the 176 /// corresponding adjustments are performed directly. 177 int OffsetAdjustment; 178 179 /// MaxAlignment - The prolog/epilog code inserter may process objects 180 /// that require greater alignment than the default alignment the target 181 /// provides. To handle this, MaxAlignment is set to the maximum alignment 182 /// needed by the objects on the current frame. If this is greater than the 183 /// native alignment maintained by the compiler, dynamic alignment code will 184 /// be needed. 185 /// 186 unsigned MaxAlignment; 187 188 /// AdjustsStack - Set to true if this function adjusts the stack -- e.g., 189 /// when calling another function. This is only valid during and after 190 /// prolog/epilog code insertion. 191 bool AdjustsStack; 192 193 /// HasCalls - Set to true if this function has any function calls. 194 bool HasCalls; 195 196 /// StackProtectorIdx - The frame index for the stack protector. 197 int StackProtectorIdx; 198 199 /// FunctionContextIdx - The frame index for the function context. Used for 200 /// SjLj exceptions. 201 int FunctionContextIdx; 202 203 /// MaxCallFrameSize - This contains the size of the largest call frame if the 204 /// target uses frame setup/destroy pseudo instructions (as defined in the 205 /// TargetFrameInfo class). This information is important for frame pointer 206 /// elimination. If is only valid during and after prolog/epilog code 207 /// insertion. 208 /// 209 unsigned MaxCallFrameSize; 210 211 /// CSInfo - The prolog/epilog code inserter fills in this vector with each 212 /// callee saved register saved in the frame. Beyond its use by the prolog/ 213 /// epilog code inserter, this data used for debug info and exception 214 /// handling. 215 std::vector<CalleeSavedInfo> CSInfo; 216 217 /// CSIValid - Has CSInfo been set yet? 218 bool CSIValid; 219 220 /// LocalFrameObjects - References to frame indices which are mapped 221 /// into the local frame allocation block. <FrameIdx, LocalOffset> 222 SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects; 223 224 /// LocalFrameSize - Size of the pre-allocated local frame block. 225 int64_t LocalFrameSize; 226 227 /// Required alignment of the local object blob, which is the strictest 228 /// alignment of any object in it. 229 unsigned LocalFrameMaxAlign; 230 231 /// Whether the local object blob needs to be allocated together. If not, 232 /// PEI should ignore the isPreAllocated flags on the stack objects and 233 /// just allocate them normally. 234 bool UseLocalStackAllocationBlock; 235 236 /// Whether the "realign-stack" option is on. 237 bool RealignOption; 238 239 /// True if the function includes inline assembly that adjusts the stack 240 /// pointer. 241 bool HasInlineAsmWithSPAdjust; 242 243 /// True if the function contains a call to the llvm.vastart intrinsic. 244 bool HasVAStart; 245 246 /// True if this is a varargs function that contains a musttail call. 247 bool HasMustTailInVarArgFunc; 248 249 public: MachineFrameInfo(unsigned StackAlign,bool isStackRealign,bool RealignOpt)250 explicit MachineFrameInfo(unsigned StackAlign, bool isStackRealign, 251 bool RealignOpt) 252 : StackAlignment(StackAlign), StackRealignable(isStackRealign), 253 RealignOption(RealignOpt) { 254 StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0; 255 HasVarSizedObjects = false; 256 FrameAddressTaken = false; 257 ReturnAddressTaken = false; 258 HasStackMap = false; 259 HasPatchPoint = false; 260 AdjustsStack = false; 261 HasCalls = false; 262 StackProtectorIdx = -1; 263 FunctionContextIdx = -1; 264 MaxCallFrameSize = 0; 265 CSIValid = false; 266 LocalFrameSize = 0; 267 LocalFrameMaxAlign = 0; 268 UseLocalStackAllocationBlock = false; 269 HasInlineAsmWithSPAdjust = false; 270 HasVAStart = false; 271 HasMustTailInVarArgFunc = false; 272 } 273 274 /// hasStackObjects - Return true if there are any stack objects in this 275 /// function. 276 /// hasStackObjects()277 bool hasStackObjects() const { return !Objects.empty(); } 278 279 /// hasVarSizedObjects - This method may be called any time after instruction 280 /// selection is complete to determine if the stack frame for this function 281 /// contains any variable sized objects. 282 /// hasVarSizedObjects()283 bool hasVarSizedObjects() const { return HasVarSizedObjects; } 284 285 /// getStackProtectorIndex/setStackProtectorIndex - Return the index for the 286 /// stack protector object. 287 /// getStackProtectorIndex()288 int getStackProtectorIndex() const { return StackProtectorIdx; } setStackProtectorIndex(int I)289 void setStackProtectorIndex(int I) { StackProtectorIdx = I; } 290 291 /// getFunctionContextIndex/setFunctionContextIndex - Return the index for the 292 /// function context object. This object is used for SjLj exceptions. getFunctionContextIndex()293 int getFunctionContextIndex() const { return FunctionContextIdx; } setFunctionContextIndex(int I)294 void setFunctionContextIndex(int I) { FunctionContextIdx = I; } 295 296 /// isFrameAddressTaken - This method may be called any time after instruction 297 /// selection is complete to determine if there is a call to 298 /// \@llvm.frameaddress in this function. isFrameAddressTaken()299 bool isFrameAddressTaken() const { return FrameAddressTaken; } setFrameAddressIsTaken(bool T)300 void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; } 301 302 /// isReturnAddressTaken - This method may be called any time after 303 /// instruction selection is complete to determine if there is a call to 304 /// \@llvm.returnaddress in this function. isReturnAddressTaken()305 bool isReturnAddressTaken() const { return ReturnAddressTaken; } setReturnAddressIsTaken(bool s)306 void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; } 307 308 /// hasStackMap - This method may be called any time after instruction 309 /// selection is complete to determine if there is a call to builtin 310 /// \@llvm.experimental.stackmap. hasStackMap()311 bool hasStackMap() const { return HasStackMap; } 312 void setHasStackMap(bool s = true) { HasStackMap = s; } 313 314 /// hasPatchPoint - This method may be called any time after instruction 315 /// selection is complete to determine if there is a call to builtin 316 /// \@llvm.experimental.patchpoint. hasPatchPoint()317 bool hasPatchPoint() const { return HasPatchPoint; } 318 void setHasPatchPoint(bool s = true) { HasPatchPoint = s; } 319 320 /// getObjectIndexBegin - Return the minimum frame object index. 321 /// getObjectIndexBegin()322 int getObjectIndexBegin() const { return -NumFixedObjects; } 323 324 /// getObjectIndexEnd - Return one past the maximum frame object index. 325 /// getObjectIndexEnd()326 int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; } 327 328 /// getNumFixedObjects - Return the number of fixed objects. getNumFixedObjects()329 unsigned getNumFixedObjects() const { return NumFixedObjects; } 330 331 /// getNumObjects - Return the number of objects. 332 /// getNumObjects()333 unsigned getNumObjects() const { return Objects.size(); } 334 335 /// mapLocalFrameObject - Map a frame index into the local object block mapLocalFrameObject(int ObjectIndex,int64_t Offset)336 void mapLocalFrameObject(int ObjectIndex, int64_t Offset) { 337 LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset)); 338 Objects[ObjectIndex + NumFixedObjects].PreAllocated = true; 339 } 340 341 /// getLocalFrameObjectMap - Get the local offset mapping for a for an object getLocalFrameObjectMap(int i)342 std::pair<int, int64_t> getLocalFrameObjectMap(int i) { 343 assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() && 344 "Invalid local object reference!"); 345 return LocalFrameObjects[i]; 346 } 347 348 /// getLocalFrameObjectCount - Return the number of objects allocated into 349 /// the local object block. getLocalFrameObjectCount()350 int64_t getLocalFrameObjectCount() { return LocalFrameObjects.size(); } 351 352 /// setLocalFrameSize - Set the size of the local object blob. setLocalFrameSize(int64_t sz)353 void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; } 354 355 /// getLocalFrameSize - Get the size of the local object blob. getLocalFrameSize()356 int64_t getLocalFrameSize() const { return LocalFrameSize; } 357 358 /// setLocalFrameMaxAlign - Required alignment of the local object blob, 359 /// which is the strictest alignment of any object in it. setLocalFrameMaxAlign(unsigned Align)360 void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; } 361 362 /// getLocalFrameMaxAlign - Return the required alignment of the local 363 /// object blob. getLocalFrameMaxAlign()364 unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; } 365 366 /// getUseLocalStackAllocationBlock - Get whether the local allocation blob 367 /// should be allocated together or let PEI allocate the locals in it 368 /// directly. getUseLocalStackAllocationBlock()369 bool getUseLocalStackAllocationBlock() {return UseLocalStackAllocationBlock;} 370 371 /// setUseLocalStackAllocationBlock - Set whether the local allocation blob 372 /// should be allocated together or let PEI allocate the locals in it 373 /// directly. setUseLocalStackAllocationBlock(bool v)374 void setUseLocalStackAllocationBlock(bool v) { 375 UseLocalStackAllocationBlock = v; 376 } 377 378 /// isObjectPreAllocated - Return true if the object was pre-allocated into 379 /// the local block. isObjectPreAllocated(int ObjectIdx)380 bool isObjectPreAllocated(int ObjectIdx) const { 381 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 382 "Invalid Object Idx!"); 383 return Objects[ObjectIdx+NumFixedObjects].PreAllocated; 384 } 385 386 /// getObjectSize - Return the size of the specified object. 387 /// getObjectSize(int ObjectIdx)388 int64_t getObjectSize(int ObjectIdx) const { 389 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 390 "Invalid Object Idx!"); 391 return Objects[ObjectIdx+NumFixedObjects].Size; 392 } 393 394 /// setObjectSize - Change the size of the specified stack object. setObjectSize(int ObjectIdx,int64_t Size)395 void setObjectSize(int ObjectIdx, int64_t Size) { 396 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 397 "Invalid Object Idx!"); 398 Objects[ObjectIdx+NumFixedObjects].Size = Size; 399 } 400 401 /// getObjectAlignment - Return the alignment of the specified stack object. getObjectAlignment(int ObjectIdx)402 unsigned getObjectAlignment(int ObjectIdx) const { 403 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 404 "Invalid Object Idx!"); 405 return Objects[ObjectIdx+NumFixedObjects].Alignment; 406 } 407 408 /// setObjectAlignment - Change the alignment of the specified stack object. setObjectAlignment(int ObjectIdx,unsigned Align)409 void setObjectAlignment(int ObjectIdx, unsigned Align) { 410 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 411 "Invalid Object Idx!"); 412 Objects[ObjectIdx+NumFixedObjects].Alignment = Align; 413 ensureMaxAlignment(Align); 414 } 415 416 /// getObjectAllocation - Return the underlying Alloca of the specified 417 /// stack object if it exists. Returns 0 if none exists. getObjectAllocation(int ObjectIdx)418 const AllocaInst* getObjectAllocation(int ObjectIdx) const { 419 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 420 "Invalid Object Idx!"); 421 return Objects[ObjectIdx+NumFixedObjects].Alloca; 422 } 423 424 /// getObjectOffset - Return the assigned stack offset of the specified object 425 /// from the incoming stack pointer. 426 /// getObjectOffset(int ObjectIdx)427 int64_t getObjectOffset(int ObjectIdx) const { 428 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 429 "Invalid Object Idx!"); 430 assert(!isDeadObjectIndex(ObjectIdx) && 431 "Getting frame offset for a dead object?"); 432 return Objects[ObjectIdx+NumFixedObjects].SPOffset; 433 } 434 435 /// setObjectOffset - Set the stack frame offset of the specified object. The 436 /// offset is relative to the stack pointer on entry to the function. 437 /// setObjectOffset(int ObjectIdx,int64_t SPOffset)438 void setObjectOffset(int ObjectIdx, int64_t SPOffset) { 439 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 440 "Invalid Object Idx!"); 441 assert(!isDeadObjectIndex(ObjectIdx) && 442 "Setting frame offset for a dead object?"); 443 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset; 444 } 445 446 /// getStackSize - Return the number of bytes that must be allocated to hold 447 /// all of the fixed size frame objects. This is only valid after 448 /// Prolog/Epilog code insertion has finalized the stack frame layout. 449 /// getStackSize()450 uint64_t getStackSize() const { return StackSize; } 451 452 /// setStackSize - Set the size of the stack... 453 /// setStackSize(uint64_t Size)454 void setStackSize(uint64_t Size) { StackSize = Size; } 455 456 /// Estimate and return the size of the stack frame. 457 unsigned estimateStackSize(const MachineFunction &MF) const; 458 459 /// getOffsetAdjustment - Return the correction for frame offsets. 460 /// getOffsetAdjustment()461 int getOffsetAdjustment() const { return OffsetAdjustment; } 462 463 /// setOffsetAdjustment - Set the correction for frame offsets. 464 /// setOffsetAdjustment(int Adj)465 void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; } 466 467 /// getMaxAlignment - Return the alignment in bytes that this function must be 468 /// aligned to, which is greater than the default stack alignment provided by 469 /// the target. 470 /// getMaxAlignment()471 unsigned getMaxAlignment() const { return MaxAlignment; } 472 473 /// ensureMaxAlignment - Make sure the function is at least Align bytes 474 /// aligned. 475 void ensureMaxAlignment(unsigned Align); 476 477 /// AdjustsStack - Return true if this function adjusts the stack -- e.g., 478 /// when calling another function. This is only valid during and after 479 /// prolog/epilog code insertion. adjustsStack()480 bool adjustsStack() const { return AdjustsStack; } setAdjustsStack(bool V)481 void setAdjustsStack(bool V) { AdjustsStack = V; } 482 483 /// hasCalls - Return true if the current function has any function calls. hasCalls()484 bool hasCalls() const { return HasCalls; } setHasCalls(bool V)485 void setHasCalls(bool V) { HasCalls = V; } 486 487 /// Returns true if the function contains any stack-adjusting inline assembly. hasInlineAsmWithSPAdjust()488 bool hasInlineAsmWithSPAdjust() const { return HasInlineAsmWithSPAdjust; } setHasInlineAsmWithSPAdjust(bool B)489 void setHasInlineAsmWithSPAdjust(bool B) { HasInlineAsmWithSPAdjust = B; } 490 491 /// Returns true if the function calls the llvm.va_start intrinsic. hasVAStart()492 bool hasVAStart() const { return HasVAStart; } setHasVAStart(bool B)493 void setHasVAStart(bool B) { HasVAStart = B; } 494 495 /// Returns true if the function is variadic and contains a musttail call. hasMustTailInVarArgFunc()496 bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; } setHasMustTailInVarArgFunc(bool B)497 void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; } 498 499 /// getMaxCallFrameSize - Return the maximum size of a call frame that must be 500 /// allocated for an outgoing function call. This is only available if 501 /// CallFrameSetup/Destroy pseudo instructions are used by the target, and 502 /// then only during or after prolog/epilog code insertion. 503 /// getMaxCallFrameSize()504 unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; } setMaxCallFrameSize(unsigned S)505 void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; } 506 507 /// CreateFixedObject - Create a new object at a fixed location on the stack. 508 /// All fixed objects should be created before other objects are created for 509 /// efficiency. By default, fixed objects are not pointed to by LLVM IR 510 /// values. This returns an index with a negative value. 511 /// 512 int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, 513 bool isAliased = false); 514 515 /// CreateFixedSpillStackObject - Create a spill slot at a fixed location 516 /// on the stack. Returns an index with a negative value. 517 int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset); 518 519 /// isFixedObjectIndex - Returns true if the specified index corresponds to a 520 /// fixed stack object. isFixedObjectIndex(int ObjectIdx)521 bool isFixedObjectIndex(int ObjectIdx) const { 522 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects); 523 } 524 525 /// isAliasedObjectIndex - Returns true if the specified index corresponds 526 /// to an object that might be pointed to by an LLVM IR value. isAliasedObjectIndex(int ObjectIdx)527 bool isAliasedObjectIndex(int ObjectIdx) const { 528 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 529 "Invalid Object Idx!"); 530 return Objects[ObjectIdx+NumFixedObjects].isAliased; 531 } 532 533 /// isImmutableObjectIndex - Returns true if the specified index corresponds 534 /// to an immutable object. isImmutableObjectIndex(int ObjectIdx)535 bool isImmutableObjectIndex(int ObjectIdx) const { 536 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 537 "Invalid Object Idx!"); 538 return Objects[ObjectIdx+NumFixedObjects].isImmutable; 539 } 540 541 /// isSpillSlotObjectIndex - Returns true if the specified index corresponds 542 /// to a spill slot.. isSpillSlotObjectIndex(int ObjectIdx)543 bool isSpillSlotObjectIndex(int ObjectIdx) const { 544 assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && 545 "Invalid Object Idx!"); 546 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot; 547 } 548 549 /// isDeadObjectIndex - Returns true if the specified index corresponds to 550 /// 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 /// CreateStackObject - Create a new statically sized stack object, returning 558 /// a nonnegative identifier to represent it. 559 /// 560 int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, 561 const AllocaInst *Alloca = nullptr); 562 563 /// CreateSpillStackObject - Create a new statically sized stack object that 564 /// represents a spill slot, returning a nonnegative identifier to represent 565 /// it. 566 /// 567 int CreateSpillStackObject(uint64_t Size, unsigned Alignment); 568 569 /// RemoveStackObject - Remove or mark dead a statically sized stack object. 570 /// RemoveStackObject(int ObjectIdx)571 void RemoveStackObject(int ObjectIdx) { 572 // Mark it dead. 573 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL; 574 } 575 576 /// CreateVariableSizedObject - Notify the MachineFrameInfo object that a 577 /// variable sized object has been created. This must be created whenever a 578 /// variable sized object is created, whether or not the index returned is 579 /// actually used. 580 /// 581 int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca); 582 583 /// getCalleeSavedInfo - Returns a reference to call saved info vector for the 584 /// current function. getCalleeSavedInfo()585 const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const { 586 return CSInfo; 587 } 588 589 /// setCalleeSavedInfo - Used by prolog/epilog inserter to set the function's 590 /// callee saved information. setCalleeSavedInfo(const std::vector<CalleeSavedInfo> & CSI)591 void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) { 592 CSInfo = CSI; 593 } 594 595 /// isCalleeSavedInfoValid - Has the callee saved info been calculated yet? isCalleeSavedInfoValid()596 bool isCalleeSavedInfoValid() const { return CSIValid; } 597 setCalleeSavedInfoValid(bool v)598 void setCalleeSavedInfoValid(bool v) { CSIValid = v; } 599 600 /// getPristineRegs - Return a set of physical registers that are pristine on 601 /// entry to the MBB. 602 /// 603 /// Pristine registers hold a value that is useless to the current function, 604 /// but that must be preserved - they are callee saved registers that have not 605 /// been saved yet. 606 /// 607 /// Before the PrologueEpilogueInserter has placed the CSR spill code, this 608 /// method always returns an empty set. 609 BitVector getPristineRegs(const MachineBasicBlock *MBB) const; 610 611 /// print - Used by the MachineFunction printer to print information about 612 /// stack objects. Implemented in MachineFunction.cpp 613 /// 614 void print(const MachineFunction &MF, raw_ostream &OS) const; 615 616 /// dump - Print the function to stderr. 617 void dump(const MachineFunction &MF) const; 618 }; 619 620 } // End llvm namespace 621 622 #endif 623