14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H 15 #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,
unsigned 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),
189 StackID(StackID), Alloca(Alloca), isAliased(IsAliased),
190 SSPLayout(SSPLK_None) {}
194 unsigned StackAlignment;
207 bool StackRealignable;
213 std::vector<StackObject> Objects;
218 unsigned NumFixedObjects = 0;
222 bool HasVarSizedObjects =
false;
226 bool FrameAddressTaken =
false;
230 bool ReturnAddressTaken =
false;
234 bool HasStackMap =
false;
238 bool HasPatchPoint =
false;
244 uint64_t StackSize = 0;
255 int OffsetAdjustment = 0;
264 unsigned MaxAlignment = 0;
269 bool AdjustsStack =
false;
275 int StackProtectorIdx = -1;
278 int FunctionContextIdx = -1;
284 unsigned MaxCallFrameSize = ~0u;
288 unsigned CVBytesOfCalleeSavedRegisters = 0;
294 std::vector<CalleeSavedInfo> CSInfo;
297 bool CSIValid =
false;
304 int64_t LocalFrameSize = 0;
308 unsigned LocalFrameMaxAlign = 0;
313 bool UseLocalStackAllocationBlock =
false;
317 bool HasOpaqueSPAdjustment =
false;
321 bool HasCopyImplyingStackAdjustment =
false;
324 bool HasVAStart =
false;
327 bool HasMustTailInVarArgFunc =
false;
332 bool HasTailCall =
false;
342 : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
343 ForcedRealign(ForcedRealign) {}
401 LocalFrameObjects.
push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
402 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
407 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.
size() &&
408 "Invalid local object reference!");
409 return LocalFrameObjects[i];
431 return UseLocalStackAllocationBlock;
438 UseLocalStackAllocationBlock = v;
443 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444 "Invalid Object Idx!");
445 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
450 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
451 "Invalid Object Idx!");
452 return Objects[ObjectIdx+NumFixedObjects].Size;
457 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
458 "Invalid Object Idx!");
459 Objects[ObjectIdx+NumFixedObjects].Size =
Size;
464 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
465 "Invalid Object Idx!");
466 return Objects[ObjectIdx+NumFixedObjects].Alignment;
471 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
472 "Invalid Object Idx!");
473 Objects[ObjectIdx+NumFixedObjects].Alignment =
Align;
474 ensureMaxAlignment(Align);
480 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
481 "Invalid Object Idx!");
482 return Objects[ObjectIdx+NumFixedObjects].Alloca;
488 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
489 "Invalid Object Idx!");
490 assert(!isDeadObjectIndex(ObjectIdx) &&
491 "Getting frame offset for a dead object?");
492 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
496 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
497 "Invalid Object Idx!");
498 return Objects[ObjectIdx+NumFixedObjects].isZExt;
502 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
503 "Invalid Object Idx!");
504 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
508 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
509 "Invalid Object Idx!");
510 return Objects[ObjectIdx+NumFixedObjects].isSExt;
514 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
515 "Invalid Object Idx!");
516 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
522 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
523 "Invalid Object Idx!");
524 assert(!isDeadObjectIndex(ObjectIdx) &&
525 "Setting frame offset for a dead object?");
526 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
530 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
531 "Invalid Object Idx!");
532 return (
SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
536 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
537 "Invalid Object Idx!");
538 assert(!isDeadObjectIndex(ObjectIdx) &&
539 "Setting SSP layout for a dead object?");
540 Objects[ObjectIdx+NumFixedObjects].SSPLayout =
Kind;
565 void ensureMaxAlignment(
unsigned Align);
584 return HasCopyImplyingStackAdjustment;
587 HasCopyImplyingStackAdjustment =
B;
618 if (!isMaxCallFrameSizeComputed())
620 return MaxCallFrameSize;
623 return MaxCallFrameSize != ~0u;
630 return CVBytesOfCalleeSavedRegisters;
633 CVBytesOfCalleeSavedRegisters = S;
640 int CreateFixedObject(uint64_t
Size, int64_t SPOffset,
bool IsImmutable,
641 bool isAliased =
false);
645 int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset,
646 bool IsImmutable =
false);
650 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
656 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
657 "Invalid Object Idx!");
658 return Objects[ObjectIdx+NumFixedObjects].isAliased;
666 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
667 "Invalid Object Idx!");
668 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
673 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
674 "Invalid Object Idx!");
675 Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
680 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
681 "Invalid Object Idx!");
682 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
686 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
687 "Invalid Object Idx!");
688 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
693 return Objects[ObjectIdx+NumFixedObjects].StackID;
698 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
699 "Invalid Object Idx!");
700 Objects[ObjectIdx+NumFixedObjects].StackID =
ID;
705 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
706 "Invalid Object Idx!");
707 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
713 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
714 "Invalid Object Idx!");
715 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
719 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
720 "Invalid Object Idx!");
721 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
722 assert(isStatepointSpillSlotObjectIndex(ObjectIdx) &&
"inconsistent");
727 int CreateStackObject(uint64_t Size,
unsigned Alignment,
bool isSpillSlot,
732 int CreateSpillStackObject(uint64_t Size,
unsigned Alignment);
737 Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
743 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.
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)
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
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.
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 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.
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 setCVBytesOfCalleeSavedRegisters(unsigned S)
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)
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