13#ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
14#define LLVM_CODEGEN_MACHINEFRAMEINFO_H
57 bool SpilledToReg =
false;
154 bool isStatepointSpillSlot =
false;
158 bool isCalleeSaved =
false;
182 bool PreAllocated =
false;
199 bool IsImmutable,
bool IsSpillSlot,
const AllocaInst *Alloca,
200 bool IsAliased,
uint8_t StackID = 0)
201 : SPOffset(SPOffset),
Size(
Size), Alignment(Alignment),
202 isImmutable(IsImmutable), isSpillSlot(IsSpillSlot), StackID(StackID),
203 Alloca(Alloca), isAliased(IsAliased) {}
207 Align StackAlignment;
220 bool StackRealignable;
226 std::vector<StackObject> Objects;
231 unsigned NumFixedObjects = 0;
235 bool HasVarSizedObjects =
false;
239 bool FrameAddressTaken =
false;
243 bool ReturnAddressTaken =
false;
247 bool HasStackMap =
false;
251 bool HasPatchPoint =
false;
268 int64_t OffsetAdjustment = 0;
282 bool AdjustsStack =
false;
285 bool HasCalls =
false;
292 int StackProtectorIdx = -1;
295 int FunctionContextIdx = -1;
301 uint64_t MaxCallFrameSize = ~UINT64_C(0);
305 unsigned CVBytesOfCalleeSavedRegisters = 0;
311 std::vector<CalleeSavedInfo> CSInfo;
314 bool CSIValid =
false;
321 int64_t LocalFrameSize = 0;
325 Align LocalFrameMaxAlign;
330 bool UseLocalStackAllocationBlock =
false;
334 bool HasOpaqueSPAdjustment =
false;
338 bool HasCopyImplyingStackAdjustment =
false;
341 bool HasVAStart =
false;
344 bool HasMustTailInVarArgFunc =
false;
349 bool HasTailCall =
false;
362 : StackAlignment(StackAlignment),
363 StackRealignable(StackRealignable), ForcedRealign(ForcedRealign) {}
443 LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex,
Offset));
444 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
449 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.size() &&
450 "Invalid local object reference!");
451 return LocalFrameObjects[i];
466 LocalFrameMaxAlign = Alignment;
475 return UseLocalStackAllocationBlock;
482 UseLocalStackAllocationBlock = v;
487 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
488 "Invalid Object Idx!");
489 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
494 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
495 "Invalid Object Idx!");
496 return Objects[ObjectIdx+NumFixedObjects].Size;
501 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
502 "Invalid Object Idx!");
503 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
508 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
509 "Invalid Object Idx!");
510 return Objects[ObjectIdx + NumFixedObjects].Alignment;
532 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
533 "Invalid Object Idx!");
534 Objects[ObjectIdx + NumFixedObjects].Alignment = Alignment;
545 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
546 "Invalid Object Idx!");
547 return Objects[ObjectIdx+NumFixedObjects].Alloca;
553 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
554 "Invalid Object Idx!");
555 Objects[ObjectIdx + NumFixedObjects].Alloca =
nullptr;
561 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
562 "Invalid Object Idx!");
564 "Getting frame offset for a dead object?");
565 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
569 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
570 "Invalid Object Idx!");
571 return Objects[ObjectIdx+NumFixedObjects].isZExt;
575 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
576 "Invalid Object Idx!");
577 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
581 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
582 "Invalid Object Idx!");
583 return Objects[ObjectIdx+NumFixedObjects].isSExt;
587 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
588 "Invalid Object Idx!");
589 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
595 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
596 "Invalid Object Idx!");
598 "Setting frame offset for a dead object?");
599 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
603 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
604 "Invalid Object Idx!");
605 return (
SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
609 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
610 "Invalid Object Idx!");
612 "Setting SSP layout for a dead object?");
613 Objects[ObjectIdx+NumFixedObjects].SSPLayout = Kind;
645 return ForcedRealign || MaxAlignment > StackAlignment;
660 FramePointerPolicy = Kind;
670 return HasCopyImplyingStackAdjustment;
673 HasCopyImplyingStackAdjustment =
B;
698 std::vector<MachineBasicBlock::iterator> *FrameSDOps =
nullptr);
710 return MaxCallFrameSize;
713 return MaxCallFrameSize != ~UINT64_C(0);
720 return CVBytesOfCalleeSavedRegisters;
723 CVBytesOfCalleeSavedRegisters = S;
731 bool IsImmutable,
bool isAliased =
false);
736 bool IsImmutable =
false);
740 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
746 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
747 "Invalid Object Idx!");
748 return Objects[ObjectIdx+NumFixedObjects].isAliased;
753 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
754 "Invalid Object Idx!");
755 Objects[ObjectIdx+NumFixedObjects].isAliased = IsAliased;
763 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
764 "Invalid Object Idx!");
765 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
770 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
771 "Invalid Object Idx!");
772 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
777 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
778 "Invalid Object Idx!");
779 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
783 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
784 "Invalid Object Idx!");
785 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
789 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
790 "Invalid Object Idx!");
791 return Objects[ObjectIdx + NumFixedObjects].isCalleeSaved;
795 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
796 "Invalid Object Idx!");
797 Objects[ObjectIdx + NumFixedObjects].isCalleeSaved = IsCalleeSaved;
802 return Objects[ObjectIdx+NumFixedObjects].StackID;
807 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
808 "Invalid Object Idx!");
809 Objects[ObjectIdx+NumFixedObjects].StackID = ID;
816 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
817 "Invalid Object Idx!");
818 return Objects[ObjectIdx + NumFixedObjects].isDead;
824 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
825 "Invalid Object Idx!");
826 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
830 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
831 "Invalid Object Idx!");
832 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
852 Objects[ObjectIdx + NumFixedObjects].isDead =
true;
871 CSInfo = std::move(CSI);
884 SavePoints = std::move(NewSavePoints);
888 RestorePoints = std::move(NewRestorePoints);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
This file defines the SmallVector class.
an instruction to allocate memory on the stack
CalleeSavedInfo(MCRegister R, int FI=0)
bool isSpilledToReg() const
void setReg(MCRegister R)
MCRegister getReg() const
MCRegister getDstReg() const
void setDstReg(MCRegister SpillReg)
Wrapper class representing physical registers and target specific virtual registers.
constexpr unsigned id() const
bool needsSplitStackProlog() const
Return true if this function requires a split stack prolog, even if it uses no stack space.
void setMaxCallFrameSize(uint64_t S)
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
void clearObjectAllocation(int ObjectIdx)
Remove the underlying Alloca of the specified stack object if it exists.
void setObjectZExt(int ObjectIdx, bool IsZExt)
void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable)
Marks the immutability of an object.
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
void setMaxAlign(Align Alignment)
Overwrite alignment of this function's frame.
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
LLVM_ABI void computeMaxCallFrameSize(MachineFunction &MF, std::vector< MachineBasicBlock::iterator > *FrameSDOps=nullptr)
Computes the maximum size of a callframe.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
void setAdjustsStack(bool V)
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Align getStackAlign() const
Return the alignment of the stack in this function.
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Make sure the function's frame is at least Align bytes aligned.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
MachineFrameInfo(Align StackAlignment, bool StackRealignable, bool ForcedRealign)
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
void setHasPatchPoint(bool s=true)
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
std::vector< CalleeSavedInfo > & getCalleeSavedInfo()
bool isScalableStackID(uint8_t StackID) const
FramePointerKind getFramePointerPolicy() const
void setUseLocalStackAllocationBlock(bool v)
setUseLocalStackAllocationBlock - Set whether the local allocation blob should be allocated together ...
Align getMaxAlign() const
Return alignment of this function's frame.
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
SSPLayoutKind
Stack Smashing Protection (SSP) rules require that vulnerable stack allocations are located close the...
@ SSPLK_SmallArray
Array or nested array < SSP-buffer-size.
@ SSPLK_LargeArray
Array or nested array >= SSP-buffer-size.
@ SSPLK_AddrOf
The address of this allocation is exposed and triggered protection.
@ SSPLK_None
Did not trigger a stack protector.
bool isCalleeSavedObjectIndex(int ObjectIdx) const
void clearRestorePoints()
void markAsStatepointSpillSlotObjectIndex(int ObjectIdx)
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
bool contributesToMaxAlignment(uint8_t StackID)
Should this stack ID be considered in MaxAlignment.
void setFrameAddressIsTaken(bool T)
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
bool shouldRealignStack() const
Return true if stack realignment is forced by function attributes or if the stack alignment.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setHasStackMap(bool s=true)
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
void setSavePoints(SaveRestorePoints NewSavePoints)
bool hasScalableStackID(int ObjectIdx) const
void setFramePointerPolicy(FramePointerKind Kind)
void setObjectSExt(int ObjectIdx, bool IsSExt)
void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind)
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
void setLocalFrameMaxAlign(Align Alignment)
Required alignment of the local object blob, which is the strictest alignment of any object in it.
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
void setCVBytesOfCalleeSavedRegisters(unsigned S)
int getStackProtectorIndex() const
Return the index for the stack protector object.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
void setStackID(int ObjectIdx, uint8_t ID)
void setHasTailCall(bool V=true)
bool hasTailCall() const
Returns true if the function contains a tail call.
bool hasMustTailInVarArgFunc() const
Returns true if the function is variadic and contains a musttail call.
void setStackProtectorIndex(int I)
void setIsAliasedObjectIndex(int ObjectIdx, bool IsAliased)
Set "maybe pointed to by an LLVM IR value" for an object.
void setCalleeSavedInfoValid(bool v)
bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
void setReturnAddressIsTaken(bool s)
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isObjectZExt(int ObjectIdx) const
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
void setHasOpaqueSPAdjustment(bool B)
int64_t getLocalFrameSize() const
Get the size of the local object blob.
bool isObjectSExt(int ObjectIdx) const
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
void setHasCopyImplyingStackAdjustment(bool B)
LLVM_ABI void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
unsigned getNumObjects() const
Return the number of objects.
bool hasVAStart() const
Returns true if the function calls the llvm.va_start intrinsic.
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
LLVM_ABI int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
uint64_t getUnsafeStackSize() const
LLVM_ABI void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
void setRestorePoints(SaveRestorePoints NewRestorePoints)
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
bool hasStackObjects() const
Return true if there are any stack objects in this function.
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
MachineFrameInfo(const MachineFrameInfo &)=delete
bool isStackRealignable() const
uint8_t getStackID(int ObjectIdx) const
const SaveRestorePoints & getRestorePoints() const
unsigned getNumFixedObjects() const
Return the number of fixed objects.
void setIsCalleeSavedObjectIndex(int ObjectIdx, bool IsCalleeSaved)
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool hasFunctionContextIndex() const
void setStackSize(uint64_t Size)
Set the size of the stack.
void setHasVAStart(bool B)
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
const SaveRestorePoints & getSavePoints() const
void setUnsafeStackSize(uint64_t Size)
void setHasMustTailInVarArgFunc(bool B)
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
int getFunctionContextIndex() const
Return the index for the function context object.
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...
void setFunctionContextIndex(int I)
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ ScalablePredicateVector
This is an optimization pass for GlobalISel generic memory operations.
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
This struct is a compact representation of a valid (non-zero power of two) alignment.