13 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H 14 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H 24 class MachineFunction;
25 class MachineBasicBlock;
61 unsigned getReg()
const {
return Reg; }
149 bool isStatepointSpillSlot =
false;
168 bool PreAllocated =
false;
184 StackObject(uint64_t Size,
Align Alignment, int64_t SPOffset,
185 bool IsImmutable,
bool IsSpillSlot,
const AllocaInst *Alloca,
186 bool IsAliased, uint8_t StackID = 0)
187 : SPOffset(SPOffset),
Size(Size), Alignment(Alignment),
188 isImmutable(IsImmutable), isSpillSlot(IsSpillSlot), StackID(StackID),
189 Alloca(Alloca), isAliased(IsAliased), SSPLayout(SSPLK_None) {}
193 Align StackAlignment;
206 bool StackRealignable;
212 std::vector<StackObject> Objects;
217 unsigned NumFixedObjects = 0;
221 bool HasVarSizedObjects =
false;
225 bool FrameAddressTaken =
false;
229 bool ReturnAddressTaken =
false;
233 bool HasStackMap =
false;
237 bool HasPatchPoint =
false;
243 uint64_t StackSize = 0;
254 int OffsetAdjustment = 0;
268 bool AdjustsStack =
false;
274 int StackProtectorIdx = -1;
277 int FunctionContextIdx = -1;
283 unsigned MaxCallFrameSize = ~0u;
287 unsigned CVBytesOfCalleeSavedRegisters = 0;
293 std::vector<CalleeSavedInfo> CSInfo;
296 bool CSIValid =
false;
303 int64_t LocalFrameSize = 0;
307 Align LocalFrameMaxAlign;
312 bool UseLocalStackAllocationBlock =
false;
316 bool HasOpaqueSPAdjustment =
false;
320 bool HasCopyImplyingStackAdjustment =
false;
323 bool HasVAStart =
false;
326 bool HasMustTailInVarArgFunc =
false;
331 bool HasTailCall =
false;
342 StackRealignable(StackRealignable), ForcedRealign(ForcedRealign) {}
400 LocalFrameObjects.
push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
401 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
406 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.
size() &&
407 "Invalid local object reference!");
408 return LocalFrameObjects[i];
423 LocalFrameMaxAlign = Alignment;
432 return UseLocalStackAllocationBlock;
439 UseLocalStackAllocationBlock = v;
444 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
445 "Invalid Object Idx!");
446 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
451 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
452 "Invalid Object Idx!");
453 return Objects[ObjectIdx+NumFixedObjects].Size;
458 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
459 "Invalid Object Idx!");
460 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
465 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
466 "Invalid Object Idx!");
467 return Objects[ObjectIdx + NumFixedObjects].Alignment.value();
472 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
473 "Invalid Object Idx!");
474 Objects[ObjectIdx + NumFixedObjects].Alignment =
assumeAligned(Align);
477 if (getStackID(ObjectIdx) == 0)
478 ensureMaxAlignment(Align);
484 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
485 "Invalid Object Idx!");
486 return Objects[ObjectIdx+NumFixedObjects].Alloca;
492 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
493 "Invalid Object Idx!");
494 assert(!isDeadObjectIndex(ObjectIdx) &&
495 "Getting frame offset for a dead object?");
496 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
500 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
501 "Invalid Object Idx!");
502 return Objects[ObjectIdx+NumFixedObjects].isZExt;
506 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
507 "Invalid Object Idx!");
508 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
512 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
513 "Invalid Object Idx!");
514 return Objects[ObjectIdx+NumFixedObjects].isSExt;
518 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
519 "Invalid Object Idx!");
520 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
526 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
527 "Invalid Object Idx!");
528 assert(!isDeadObjectIndex(ObjectIdx) &&
529 "Setting frame offset for a dead object?");
530 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
534 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
535 "Invalid Object Idx!");
536 return (
SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
540 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
541 "Invalid Object Idx!");
542 assert(!isDeadObjectIndex(ObjectIdx) &&
543 "Setting SSP layout for a dead object?");
544 Objects[ObjectIdx+NumFixedObjects].SSPLayout =
Kind;
569 void ensureMaxAlignment(
Align Alignment);
592 return HasCopyImplyingStackAdjustment;
595 HasCopyImplyingStackAdjustment =
B;
626 if (!isMaxCallFrameSizeComputed())
628 return MaxCallFrameSize;
631 return MaxCallFrameSize != ~0u;
638 return CVBytesOfCalleeSavedRegisters;
641 CVBytesOfCalleeSavedRegisters = S;
648 int CreateFixedObject(uint64_t
Size, int64_t SPOffset,
bool IsImmutable,
649 bool isAliased =
false);
653 int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset,
654 bool IsImmutable =
false);
658 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
664 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
665 "Invalid Object Idx!");
666 return Objects[ObjectIdx+NumFixedObjects].isAliased;
674 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
675 "Invalid Object Idx!");
676 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
681 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
682 "Invalid Object Idx!");
683 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
688 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
689 "Invalid Object Idx!");
690 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
694 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
695 "Invalid Object Idx!");
696 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
701 return Objects[ObjectIdx+NumFixedObjects].StackID;
706 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
707 "Invalid Object Idx!");
708 Objects[ObjectIdx+NumFixedObjects].StackID =
ID;
715 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
716 "Invalid Object Idx!");
717 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
723 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
724 "Invalid Object Idx!");
725 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
729 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
730 "Invalid Object Idx!");
731 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
732 assert(isStatepointSpillSlotObjectIndex(ObjectIdx) &&
"inconsistent");
737 int CreateStackObject(uint64_t Size,
Align Alignment,
bool isSpillSlot,
744 return CreateStackObject(Size,
assumeAligned(Alignment), isSpillSlot,
750 int CreateSpillStackObject(uint64_t Size,
Align Alignment);
753 return CreateSpillStackObject(Size,
assumeAligned(Alignment));
759 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
765 int CreateVariableSizedObject(
Align Alignment,
const AllocaInst *Alloca);
768 return CreateVariableSizedObject(
assumeAligned(Alignment), Alloca);
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
unsigned getNumFixedObjects() const
Return the number of fixed objects.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
void setSavePoint(MachineBasicBlock *NewSave)
void setObjectZExt(int ObjectIdx, bool IsZExt)
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setRestorePoint(MachineBasicBlock *NewRestore)
bool isSpilledToReg() const
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
int getFunctionContextIndex() const
Return the index for the function context object.
void setCalleeSavedInfoValid(bool v)
This class represents lattice values for constants.
unsigned getNumObjects() const
Return the number of objects.
bool hasVAStart() const
Returns true if the function calls the llvm.va_start intrinsic.
bool hasStackProtectorIndex() const
bool hasStackObjects() const
Return true if there are any stack objects in this function.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void push_back(const T &Elt)
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
int64_t getLocalFrameSize() const
Get the size of the local object blob.
void setDstReg(unsigned SpillReg)
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
block Block Frequency true
void ensureMaxAlignment(unsigned Align)
FIXME: Remove this once transition to Align is over.
unsigned getDstReg() const
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
void setHasPatchPoint(bool s=true)
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
void setUseLocalStackAllocationBlock(bool v)
setUseLocalStackAllocationBlock - Set whether the local allocation blob should be allocated together ...
MachineBasicBlock * getRestorePoint() const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
void setLocalFrameMaxAlign(Align Alignment)
Required alignment of the local object blob, which is the strictest alignment of any object in it...
bool isObjectSExt(int ObjectIdx) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
void setFunctionContextIndex(int I)
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
bool isObjectZExt(int ObjectIdx) const
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
void setHasMustTailInVarArgFunc(bool B)
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
void setHasCopyImplyingStackAdjustment(bool B)
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
void setObjectSExt(int ObjectIdx, bool IsSExt)
uint64_t value() const
This is a hole in the type system and should not be abused.
void setStackProtectorIndex(int I)
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
void setHasOpaqueSPAdjustment(bool B)
void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind)
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
FIXME: Remove this function when transition to Align is over.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getStackProtectorIndex() const
Return the index for the stack protector object.
void setHasVAStart(bool B)
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
MachineFrameInfo(unsigned StackAlignment, bool StackRealignable, bool ForcedRealign)
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
void setStackID(int ObjectIdx, uint8_t ID)
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
FIXME: Remove this function when transition to Align is over.
This struct is a compact representation of a valid (non-zero power of two) alignment.
void markAsStatepointSpillSlotObjectIndex(int ObjectIdx)
CalleeSavedInfo(unsigned R, int FI=0)
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SSPLayoutKind
Stack Smashing Protection (SSP) rules require that vulnerable stack allocations are located close the...
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
bool hasMustTailInVarArgFunc() const
Returns true if the function is variadic and contains a musttail call.
void setAdjustsStack(bool V)
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool isAliasedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an object that might be pointed to by an LLVM IR v...
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setMaxCallFrameSize(unsigned S)
int getOffsetAdjustment() const
Return the correction for frame offsets.
void setCVBytesOfCalleeSavedRegisters(unsigned S)
void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable)
Marks the immutability of an object.
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
FIXME: Remove this function when transition to Align is over.
uint8_t getStackID(int ObjectIdx) const
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
MachineBasicBlock * getSavePoint() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setReturnAddressIsTaken(bool s)
This class implements an extremely fast bulk output stream that can only output to a stream...
bool isMaxCallFrameSizeComputed() const
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
bool hasTailCall() const
Returns true if the function contains a tail call.
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
std::vector< CalleeSavedInfo > & getCalleeSavedInfo()
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
bool hasCalls() const
Return true if the current function has any function calls.
an instruction to allocate memory on the stack