14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H 15 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H 24 class MachineFunction;
25 class MachineBasicBlock;
50 : Reg(R), FrameIdx(FI), Restored(
true) {}
53 unsigned getReg()
const {
return Reg; }
132 bool isStatepointSpillSlot =
false;
151 bool PreAllocated =
false;
167 StackObject(uint64_t Size,
unsigned Alignment, int64_t SPOffset,
168 bool IsImmutable,
bool IsSpillSlot,
const AllocaInst *Alloca,
169 bool IsAliased, uint8_t StackID = 0)
170 : SPOffset(SPOffset),
Size(Size), Alignment(Alignment),
171 isImmutable(IsImmutable), isSpillSlot(IsSpillSlot),
172 StackID(StackID), Alloca(Alloca), isAliased(IsAliased),
173 SSPLayout(SSPLK_None) {}
177 unsigned StackAlignment;
190 bool StackRealignable;
196 std::vector<StackObject> Objects;
201 unsigned NumFixedObjects = 0;
205 bool HasVarSizedObjects =
false;
209 bool FrameAddressTaken =
false;
213 bool ReturnAddressTaken =
false;
217 bool HasStackMap =
false;
221 bool HasPatchPoint =
false;
227 uint64_t StackSize = 0;
238 int OffsetAdjustment = 0;
247 unsigned MaxAlignment = 0;
252 bool AdjustsStack =
false;
258 int StackProtectorIdx = -1;
261 int FunctionContextIdx = -1;
267 unsigned MaxCallFrameSize = ~0u;
273 std::vector<CalleeSavedInfo> CSInfo;
276 bool CSIValid =
false;
283 int64_t LocalFrameSize = 0;
287 unsigned LocalFrameMaxAlign = 0;
292 bool UseLocalStackAllocationBlock =
false;
296 bool HasOpaqueSPAdjustment =
false;
300 bool HasCopyImplyingStackAdjustment =
false;
303 bool HasVAStart =
false;
306 bool HasMustTailInVarArgFunc =
false;
311 bool HasTailCall =
false;
321 : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
322 ForcedRealign(ForcedRealign) {}
380 LocalFrameObjects.
push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
381 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
386 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.
size() &&
387 "Invalid local object reference!");
388 return LocalFrameObjects[i];
410 return UseLocalStackAllocationBlock;
417 UseLocalStackAllocationBlock = v;
422 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
423 "Invalid Object Idx!");
424 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
429 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
430 "Invalid Object Idx!");
431 return Objects[ObjectIdx+NumFixedObjects].Size;
436 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
437 "Invalid Object Idx!");
438 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
443 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444 "Invalid Object Idx!");
445 return Objects[ObjectIdx+NumFixedObjects].Alignment;
450 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
451 "Invalid Object Idx!");
452 Objects[ObjectIdx+NumFixedObjects].Alignment =
Align;
453 ensureMaxAlignment(Align);
459 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
460 "Invalid Object Idx!");
461 return Objects[ObjectIdx+NumFixedObjects].Alloca;
467 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
468 "Invalid Object Idx!");
469 assert(!isDeadObjectIndex(ObjectIdx) &&
470 "Getting frame offset for a dead object?");
471 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
475 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
476 "Invalid Object Idx!");
477 return Objects[ObjectIdx+NumFixedObjects].isZExt;
481 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
482 "Invalid Object Idx!");
483 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
487 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
488 "Invalid Object Idx!");
489 return Objects[ObjectIdx+NumFixedObjects].isSExt;
493 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
494 "Invalid Object Idx!");
495 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
501 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
502 "Invalid Object Idx!");
503 assert(!isDeadObjectIndex(ObjectIdx) &&
504 "Setting frame offset for a dead object?");
505 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
509 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
510 "Invalid Object Idx!");
511 return (
SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
515 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
516 "Invalid Object Idx!");
517 assert(!isDeadObjectIndex(ObjectIdx) &&
518 "Setting SSP layout for a dead object?");
519 Objects[ObjectIdx+NumFixedObjects].SSPLayout =
Kind;
544 void ensureMaxAlignment(
unsigned Align);
563 return HasCopyImplyingStackAdjustment;
566 HasCopyImplyingStackAdjustment =
B;
597 if (!isMaxCallFrameSizeComputed())
599 return MaxCallFrameSize;
602 return MaxCallFrameSize != ~0u;
610 int CreateFixedObject(uint64_t
Size, int64_t SPOffset,
bool IsImmutable,
611 bool isAliased =
false);
615 int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset,
616 bool IsImmutable =
false);
620 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
626 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
627 "Invalid Object Idx!");
628 return Objects[ObjectIdx+NumFixedObjects].isAliased;
636 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
637 "Invalid Object Idx!");
638 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
643 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
644 "Invalid Object Idx!");
645 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
650 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
651 "Invalid Object Idx!");
652 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
656 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
657 "Invalid Object Idx!");
658 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
663 return Objects[ObjectIdx+NumFixedObjects].StackID;
668 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
669 "Invalid Object Idx!");
670 Objects[ObjectIdx+NumFixedObjects].StackID =
ID;
675 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
676 "Invalid Object Idx!");
677 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
683 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
684 "Invalid Object Idx!");
685 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
689 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
690 "Invalid Object Idx!");
691 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
692 assert(isStatepointSpillSlotObjectIndex(ObjectIdx) &&
"inconsistent");
697 int CreateStackObject(uint64_t Size,
unsigned Alignment,
bool isSpillSlot,
702 int CreateSpillStackObject(uint64_t Size,
unsigned Alignment);
707 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
713 int CreateVariableSizedObject(
unsigned Alignment,
const AllocaInst *Alloca);
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
unsigned getNumFixedObjects() const
Return the number of fixed objects.
void push_back(const T &Elt)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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)
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)
Compute iterated dominance frontiers using a linear time algorithm.
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.
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.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
block Block Frequency true
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.
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.
void setLocalFrameMaxAlign(unsigned Align)
Required alignment of the local object blob, which is the strictest alignment of any object in it...
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)
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 getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
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)
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)
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
int getOffsetAdjustment() const
Return the correction for frame offsets.
void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable)
Marks the immutability of an object.
uint8_t getStackID(int ObjectIdx) const
MachineBasicBlock * getSavePoint() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setReturnAddressIsTaken(bool s)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...
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