13#ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
14#define LLVM_CODEGEN_MACHINEFRAMEINFO_H
26class MachineBasicBlock;
55 bool SpilledToReg =
false;
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) {}
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;
254 int OffsetAdjustment = 0;
268 bool AdjustsStack =
false;
271 bool HasCalls =
false;
274 int StackProtectorIdx = -1;
277 int FunctionContextIdx = -1;
283 unsigned MaxCallFrameSize = ~0
u;
287 unsigned CVBytesOfCalleeSavedRegisters = 0;
293 std::vector<CalleeSavedInfo> CSInfo;
296 bool CSIValid =
false;
300 SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
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;
334 MachineBasicBlock *Save =
nullptr;
336 MachineBasicBlock *Restore =
nullptr;
344 : StackAlignment(StackAlignment),
345 StackRealignable(StackRealignable), ForcedRealign(ForcedRealign) {}
420 LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex,
Offset));
421 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
426 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.size() &&
427 "Invalid local object reference!");
428 return LocalFrameObjects[i];
443 LocalFrameMaxAlign = Alignment;
452 return UseLocalStackAllocationBlock;
459 UseLocalStackAllocationBlock = v;
464 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
465 "Invalid Object Idx!");
466 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
471 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
472 "Invalid Object Idx!");
473 return Objects[ObjectIdx+NumFixedObjects].Size;
478 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
479 "Invalid Object Idx!");
480 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
485 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
486 "Invalid Object Idx!");
487 return Objects[ObjectIdx + NumFixedObjects].Alignment;
498 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
499 "Invalid Object Idx!");
500 Objects[ObjectIdx + NumFixedObjects].Alignment = Alignment;
511 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
512 "Invalid Object Idx!");
513 return Objects[ObjectIdx+NumFixedObjects].Alloca;
519 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
520 "Invalid Object Idx!");
521 Objects[ObjectIdx + NumFixedObjects].Alloca =
nullptr;
527 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
528 "Invalid Object Idx!");
530 "Getting frame offset for a dead object?");
531 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
535 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
536 "Invalid Object Idx!");
537 return Objects[ObjectIdx+NumFixedObjects].isZExt;
541 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
542 "Invalid Object Idx!");
543 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
547 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
548 "Invalid Object Idx!");
549 return Objects[ObjectIdx+NumFixedObjects].isSExt;
553 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
554 "Invalid Object Idx!");
555 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
561 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
562 "Invalid Object Idx!");
564 "Setting frame offset for a dead object?");
565 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
569 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
570 "Invalid Object Idx!");
571 return (
SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
575 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
576 "Invalid Object Idx!");
578 "Setting SSP layout for a dead object?");
579 Objects[ObjectIdx+NumFixedObjects].SSPLayout = Kind;
623 return HasCopyImplyingStackAdjustment;
626 HasCopyImplyingStackAdjustment =
B;
659 return MaxCallFrameSize;
662 return MaxCallFrameSize != ~0u;
669 return CVBytesOfCalleeSavedRegisters;
672 CVBytesOfCalleeSavedRegisters = S;
680 bool isAliased =
false);
685 bool IsImmutable =
false);
689 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
695 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
696 "Invalid Object Idx!");
697 return Objects[ObjectIdx+NumFixedObjects].isAliased;
705 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
706 "Invalid Object Idx!");
707 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
712 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
713 "Invalid Object Idx!");
714 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
719 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
720 "Invalid Object Idx!");
721 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
725 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
726 "Invalid Object Idx!");
727 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
732 return Objects[ObjectIdx+NumFixedObjects].StackID;
737 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
738 "Invalid Object Idx!");
739 Objects[ObjectIdx+NumFixedObjects].StackID =
ID;
746 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
747 "Invalid Object Idx!");
748 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
754 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
755 "Invalid Object Idx!");
756 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
760 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
761 "Invalid Object Idx!");
762 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
778 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
796 CSInfo = std::move(CSI);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
an instruction to allocate memory on the stack
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
void setDstReg(Register SpillReg)
unsigned getDstReg() const
bool isSpilledToReg() const
CalleeSavedInfo(unsigned R, int FI=0)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool needsSplitStackProlog() const
Return true if this function requires a split stack prolog, even if it uses no stack space.
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
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
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.
void setRestorePoint(MachineBasicBlock *NewRestore)
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
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.
void ensureMaxAlignment(Align Alignment)
Make sure the function 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()
void setUseLocalStackAllocationBlock(bool v)
setUseLocalStackAllocationBlock - Set whether the local allocation blob should be allocated together ...
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
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.
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)
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 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 ...
MachineBasicBlock * getRestorePoint() const
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.
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
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)
int getOffsetAdjustment() const
Return the correction for frame offsets.
void setCalleeSavedInfoValid(bool v)
bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
void setReturnAddressIsTaken(bool s)
void computeMaxCallFrameSize(const MachineFunction &MF)
Computes the maximum size of a callframe and the AdjustsStack property.
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.
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
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
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...
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)
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.
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setSavePoint(MachineBasicBlock *NewSave)
uint64_t getUnsafeStackSize() const
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
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.
void setMaxCallFrameSize(unsigned S)
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
uint8_t getStackID(int ObjectIdx) const
unsigned getNumFixedObjects() const
Return the number of fixed objects.
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.
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.
MachineBasicBlock * getSavePoint() const
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)
Wrapper class representing virtual and physical registers.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.