39#define DEBUG_TYPE "stack-frame-layout"
71 SlotTy(
Invalid), Scalable(
false) {
74 SlotTy = SlotType::Spill;
76 SlotTy = SlotType::Fixed;
78 SlotTy = SlotType::VariableSized;
81 SlotTy = SlotType::StackProtector;
83 SlotTy = SlotType::Variable;
86 bool isVarSize()
const {
return SlotTy == SlotType::VariableSized; }
93 bool operator<(
const SlotData &Rhs)
const {
94 return std::make_tuple(!isVarSize(),
95 Offset.getFixed() + Offset.getScalable(), Slot) >
96 std::make_tuple(!Rhs.isVarSize(),
97 Rhs.Offset.getFixed() + Rhs.Offset.getScalable(),
105 return "Stack Frame Layout Analysis";
127 Rem << (
"\nFunction: " + MF.
getName()).str();
128 emitStackFrameLayoutRemarks(MF, Rem);
129 getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE().emit(Rem);
135 case SlotType::Spill:
137 case SlotType::Fixed:
139 case SlotType::VariableSized:
140 return "VariableSized";
141 case SlotType::StackProtector:
143 case SlotType::Variable:
181 formatv(
"\nOffset: [SP{0}", (
D.Offset.getFixed() < 0) ?
"" :
"+").str();
182 Rem << Prefix <<
ore::NV(
"Offset",
D.Offset.getFixed());
184 if (
D.Offset.getScalable()) {
185 Rem << ((
D.Offset.getScalable() < 0) ?
"" :
"+")
186 <<
ore::NV(
"ScalableOffset",
D.Offset.getScalable()) <<
" x vscale";
190 <<
", Align: " <<
ore::NV(
"Align",
D.Align)
197 formatv(
"{0} @ {1}:{2}",
N->getName(),
N->getFilename(),
N->getLine())
199 Rem <<
"\n " <<
ore::NV(
"DataLoc", Loc);
222 std::vector<SlotData> SlotInfo;
225 SlotInfo.reserve(NumObj);
237 SlotDbgMap SlotMap = genSlotDbgMapping(MF);
239 for (
const SlotData &
Info : SlotInfo) {
240 emitStackSlotRemark(MF,
Info, Rem);
242 emitSourceLocRemark(MF,
N, Rem);
250 SlotDbgMap SlotDebugMap;
255 SlotDebugMap[DI.getStackSlot()].insert(DI.Var);
263 auto *FI = dyn_cast_or_null<FixedStackPseudoSourceValue>(
264 MO->getPseudoValue());
267 int FrameIdx = FI->getFrameIndex();
269 MI.collectDebugValues(Dbg);
272 SlotDebugMap[FrameIdx].insert(
MI->getDebugVariable());
281char StackFrameLayoutAnalysisPass::ID = 0;
286 "Stack Frame Layout",
false,
false)
291 return new StackFrameLayoutAnalysisPass();
static StackOffset getStackOffset(const MachineFunction &MF, int64_t ObjectOffset)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static std::string getTypeString(Type *T)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
DISubprogram * getSubprogram() const
Get the attached subprogram.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
This is an important class for using LLVM in a threaded context.
const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int getStackProtectorIndex() const
Return the index for the stack protector object.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
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.
unsigned getNumObjects() const
Return the number of objects.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
bool hasStackObjects() const
Return true if there are any stack objects in this function.
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
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.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Description of the location of a variable whose Address is valid and unchanging during function execu...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
Representation of each machine instruction.
A description of a memory reference used in the backend.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
StringRef - Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
virtual StackOffset getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI) const
getFrameIndexReferenceFromSP - This method returns the offset from the stack pointer to the slot of t...
virtual const TargetFrameLowering * getFrameLowering() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
MachineFunctionPass * createStackFrameLayoutAnalysisPass()
StackFramePrinter pass - This pass prints out the machine function's stack frame to the given stream ...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isFunctionInPrintList(StringRef FunctionName)
char & StackFrameLayoutAnalysisPassID
StackFramePrinter - This pass prints the stack frame layout and variable mappings.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.