14 #ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
15 #define LLVM_CODEGEN_MACHINEFRAMEINFO_H
18 #include "llvm/Support/DataTypes.h"
25 class TargetRegisterClass;
27 class MachineFunction;
28 class MachineBasicBlock;
29 class TargetFrameLowering;
43 : Reg(R), FrameIdx(FI) {}
46 unsigned getReg()
const {
return Reg; }
109 bool isStatepointSpillSlot;
131 StackObject(uint64_t Sz,
unsigned Al, int64_t SP,
bool IM,
133 : SPOffset(SP), Size(Sz), Alignment(Al), isImmutable(IM),
134 isSpillSlot(isSS), isStatepointSpillSlot(
false), Alloca(Val),
135 PreAllocated(
false), isAliased(A), isZExt(
false), isSExt(
false) {}
139 unsigned StackAlignment;
152 bool StackRealignable;
158 std::vector<StackObject> Objects;
163 unsigned NumFixedObjects = 0;
167 bool HasVarSizedObjects =
false;
171 bool FrameAddressTaken =
false;
175 bool ReturnAddressTaken =
false;
179 bool HasStackMap =
false;
183 bool HasPatchPoint =
false;
189 uint64_t StackSize = 0;
200 int OffsetAdjustment = 0;
209 unsigned MaxAlignment = 0;
214 bool AdjustsStack =
false;
217 bool HasCalls =
false;
220 int StackProtectorIdx = -1;
223 int FunctionContextIdx = -1;
229 unsigned MaxCallFrameSize = 0;
235 std::vector<CalleeSavedInfo> CSInfo;
238 bool CSIValid =
false;
245 int64_t LocalFrameSize = 0;
249 unsigned LocalFrameMaxAlign = 0;
254 bool UseLocalStackAllocationBlock =
false;
258 bool HasOpaqueSPAdjustment =
false;
262 bool HasCopyImplyingStackAdjustment =
false;
265 bool HasVAStart =
false;
268 bool HasMustTailInVarArgFunc =
false;
273 bool HasTailCall =
false;
283 : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
284 ForcedRealign(ForcedRealign) {}
342 LocalFrameObjects.
push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
343 Objects[ObjectIndex + NumFixedObjects].PreAllocated =
true;
348 assert (i >= 0 && (
unsigned)i < LocalFrameObjects.
size() &&
349 "Invalid local object reference!");
350 return LocalFrameObjects[
i];
372 return UseLocalStackAllocationBlock;
379 UseLocalStackAllocationBlock = v;
384 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
385 "Invalid Object Idx!");
386 return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
391 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
392 "Invalid Object Idx!");
393 return Objects[ObjectIdx+NumFixedObjects].Size;
398 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
399 "Invalid Object Idx!");
400 Objects[ObjectIdx+NumFixedObjects].Size = Size;
405 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
406 "Invalid Object Idx!");
407 return Objects[ObjectIdx+NumFixedObjects].Alignment;
412 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
413 "Invalid Object Idx!");
414 Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
421 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
422 "Invalid Object Idx!");
423 return Objects[ObjectIdx+NumFixedObjects].Alloca;
429 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
430 "Invalid Object Idx!");
432 "Getting frame offset for a dead object?");
433 return Objects[ObjectIdx+NumFixedObjects].SPOffset;
437 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
438 "Invalid Object Idx!");
439 return Objects[ObjectIdx+NumFixedObjects].isZExt;
443 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444 "Invalid Object Idx!");
445 Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
449 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
450 "Invalid Object Idx!");
451 return Objects[ObjectIdx+NumFixedObjects].isSExt;
455 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
456 "Invalid Object Idx!");
457 Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
463 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
464 "Invalid Object Idx!");
466 "Setting frame offset for a dead object?");
467 Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
511 return HasCopyImplyingStackAdjustment;
514 HasCopyImplyingStackAdjustment =
B;
542 bool isAliased =
false);
547 bool Immutable =
false);
551 return ObjectIdx < 0 && (ObjectIdx >= -(int)NumFixedObjects);
557 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
558 "Invalid Object Idx!");
559 return Objects[ObjectIdx+NumFixedObjects].isAliased;
568 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
569 "Invalid Object Idx!");
570 return Objects[ObjectIdx+NumFixedObjects].isImmutable;
575 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
576 "Invalid Object Idx!");
577 return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
581 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
582 "Invalid Object Idx!");
583 return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
588 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
589 "Invalid Object Idx!");
590 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
596 assert(
unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
597 "Invalid Object Idx!");
598 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
602 assert(
unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
603 "Invalid Object Idx!");
604 Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot =
true;
620 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...
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void setHasCopyImplyingStackAdjustment(bool B)
bool isImmutableObjectIndex(int ObjectIdx) const
isImmutableObjectIndex - 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.
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)
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.
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...
int getStackProtectorIndex() const
Return the index for the stack protector object.
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
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)
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
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. ...
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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