14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
15 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
18 #include "llvm/Support/DataTypes.h"
24 class MachineFunction;
25 class MachineBasicBlock;
37 : Reg(R), FrameIdx(FI) {}
40 unsigned getReg()
const {
return Reg; }
103 bool isStatepointSpillSlot;
125 StackObject(uint64_t Sz,
unsigned Al, int64_t SP,
bool IM,
127 : SPOffset(SP),
Size(Sz), Alignment(Al), isImmutable(IM),
128 isSpillSlot(isSS), isStatepointSpillSlot(
false), Alloca(Val),
129 PreAllocated(
false), isAliased(A), isZExt(
false), isSExt(
false) {}
133 unsigned StackAlignment;
146 bool StackRealignable;
152 std::vector<StackObject> Objects;
157 unsigned NumFixedObjects = 0;
161 bool HasVarSizedObjects =
false;
165 bool FrameAddressTaken =
false;
169 bool ReturnAddressTaken =
false;
173 bool HasStackMap =
false;
177 bool HasPatchPoint =
false;
183 uint64_t StackSize = 0;
194 int OffsetAdjustment = 0;
203 unsigned MaxAlignment = 0;
208 bool AdjustsStack =
false;
211 bool HasCalls =
false;
214 int StackProtectorIdx = -1;
217 int FunctionContextIdx = -1;
223 unsigned MaxCallFrameSize = ~0u;
229 std::vector<CalleeSavedInfo> CSInfo;
232 bool CSIValid =
false;
239 int64_t LocalFrameSize = 0;
243 unsigned LocalFrameMaxAlign = 0;
248 bool UseLocalStackAllocationBlock =
false;
252 bool HasOpaqueSPAdjustment =
false;
256 bool HasCopyImplyingStackAdjustment =
false;
259 bool HasVAStart =
false;
262 bool HasMustTailInVarArgFunc =
false;
267 bool HasTailCall =
false;
277 : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
278 ForcedRealign(ForcedRealign) {}
336 LocalFrameObjects.
push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
337 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
342 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.
size() &&
343 "Invalid local object reference!");
344 return LocalFrameObjects[i];
366 return UseLocalStackAllocationBlock;
373 UseLocalStackAllocationBlock = v;
378 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
379 "Invalid Object Idx!");
380 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
385 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
386 "Invalid Object Idx!");
387 return Objects[ObjectIdx+NumFixedObjects].Size;
392 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
393 "Invalid Object Idx!");
394 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
399 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
400 "Invalid Object Idx!");
401 return Objects[ObjectIdx+NumFixedObjects].Alignment;
406 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
407 "Invalid Object Idx!");
408 Objects[ObjectIdx+NumFixedObjects].Alignment =
Align;
415 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
416 "Invalid Object Idx!");
417 return Objects[ObjectIdx+NumFixedObjects].Alloca;
423 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
424 "Invalid Object Idx!");
426 "Getting frame offset for a dead object?");
427 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
431 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
432 "Invalid Object Idx!");
433 return Objects[ObjectIdx+NumFixedObjects].isZExt;
437 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
438 "Invalid Object Idx!");
439 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
443 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444 "Invalid Object Idx!");
445 return Objects[ObjectIdx+NumFixedObjects].isSExt;
449 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
450 "Invalid Object Idx!");
451 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
457 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
458 "Invalid Object Idx!");
460 "Setting frame offset for a dead object?");
461 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
505 return HasCopyImplyingStackAdjustment;
508 HasCopyImplyingStackAdjustment =
B;
541 return MaxCallFrameSize;
544 return MaxCallFrameSize != ~0u;
553 bool isAliased =
false);
558 bool Immutable =
false);
562 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
568 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
569 "Invalid Object Idx!");
570 return Objects[ObjectIdx+NumFixedObjects].isAliased;
578 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
579 "Invalid Object Idx!");
580 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
585 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
586 "Invalid Object Idx!");
587 Objects[ObjectIdx+NumFixedObjects].isImmutable = Immutable;
592 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
593 "Invalid Object Idx!");
594 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
598 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
599 "Invalid Object Idx!");
600 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
605 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
606 "Invalid Object Idx!");
607 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
613 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
614 "Invalid Object Idx!");
615 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
619 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
620 "Invalid Object Idx!");
621 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
637 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
void setHasStackMap(bool s=true)
int getFunctionContextIndex() const
Return the index for the function context object.
void setFrameAddressIsTaken(bool T)
void push_back(const T &Elt)
void setSavePoint(MachineBasicBlock *NewSave)
void setObjectZExt(int ObjectIdx, bool IsZExt)
void setRestorePoint(MachineBasicBlock *NewRestore)
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
void setCalleeSavedInfoValid(bool v)
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
MachineBasicBlock * getRestorePoint() const
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
unsigned getNumObjects() const
Return the number of objects.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasStackProtectorIndex() const
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
int64_t getLocalFrameSize() const
Get the size of the local object blob.
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 ...
bool isObjectZExt(int ObjectIdx) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
void setFunctionContextIndex(int I)
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool Immutable=false)
Create a spill slot at a fixed location on the stack.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
void setHasMustTailInVarArgFunc(bool B)
int getOffsetAdjustment() const
Return the correction for frame offsets.
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
void setLocalFrameMaxAlign(unsigned Align)
Required alignment of the local object blob, which is the strictest alignment of any object in it...
void setHasCopyImplyingStackAdjustment(bool B)
bool isImmutableObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to an immutable object.
unsigned getNumFixedObjects() const
Return the number of fixed objects.
void setObjectSExt(int ObjectIdx, bool IsSExt)
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack 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 setStackSize(uint64_t Size)
Set the size of the stack.
bool hasVAStart() const
Returns true if the function calls the llvm.va_start intrinsic.
void setHasVAStart(bool B)
void computeMaxCallFrameSize(const MachineFunction &MF)
Computes the maximum size of a callframe and the AdjustsStack property.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
MachineFrameInfo(unsigned StackAlignment, bool StackRealignable, bool ForcedRealign)
void setObjectSize(int ObjectIdx, int64_t Size)
Change the size of the specified stack object.
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void markAsStatepointSpillSlotObjectIndex(int ObjectIdx)
bool hasCalls() const
Return true if the current function has any function calls.
bool hasTailCall() const
Returns true if the function contains a tail call.
bool isMaxCallFrameSizeComputed() const
CalleeSavedInfo(unsigned R, int FI=0)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
bool isObjectSExt(int ObjectIdx) const
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
void setAdjustsStack(bool V)
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
void setIsImmutableObjectIndex(int ObjectIdx, bool Immutable)
Marks the immutability of an object.
int getStackProtectorIndex() const
Return the index for the stack protector object.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
MachineBasicBlock * getSavePoint() const
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
void setMaxCallFrameSize(unsigned S)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
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 hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool hasMustTailInVarArgFunc() const
Returns true if the function is variadic and contains a musttail call.
an instruction to allocate memory on the stack