41#define DEBUG_TYPE "stack-frame-layout"
73 SlotTy(
Invalid), Scalable(
false) {
76 SlotTy = SlotType::Spill;
78 SlotTy = SlotType::Fixed;
80 SlotTy = SlotType::VariableSized;
83 SlotTy = SlotType::StackProtector;
85 SlotTy = SlotType::Variable;
88 bool isVarSize()
const {
return SlotTy == SlotType::VariableSized; }
95 bool operator<(
const SlotData &Rhs)
const {
96 return std::make_tuple(!isVarSize(),
97 Offset.getFixed() + Offset.getScalable(), Slot) >
98 std::make_tuple(!Rhs.isVarSize(),
99 Rhs.Offset.getFixed() + Rhs.Offset.getScalable(),
107 return "Stack Frame Layout Analysis";
129 Rem << (
"\nFunction: " + MF.
getName()).str();
130 emitStackFrameLayoutRemarks(MF, Rem);
131 getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE().emit(Rem);
137 case SlotType::Spill:
139 case SlotType::Fixed:
141 case SlotType::VariableSized:
142 return "VariableSized";
143 case SlotType::StackProtector:
145 case SlotType::Variable:
183 formatv(
"\nOffset: [SP{0}", (
D.Offset.getFixed() < 0) ?
"" :
"+").str();
184 Rem << Prefix <<
ore::NV(
"Offset",
D.Offset.getFixed());
186 if (
D.Offset.getScalable()) {
187 Rem << ((
D.Offset.getScalable() < 0) ?
"" :
"+")
188 <<
ore::NV(
"ScalableOffset",
D.Offset.getScalable()) <<
" x vscale";
192 <<
", Align: " <<
ore::NV(
"Align",
D.Align)
199 formatv(
"{0} @ {1}:{2}",
N->getName(),
N->getFilename(),
N->getLine())
201 Rem <<
"\n " <<
ore::NV(
"DataLoc", Loc);
224 std::vector<SlotData> SlotInfo;
227 SlotInfo.reserve(NumObj);
239 SlotDbgMap SlotMap = genSlotDbgMapping(MF);
241 for (
const SlotData &
Info : SlotInfo) {
242 emitStackSlotRemark(MF,
Info, Rem);
244 emitSourceLocRemark(MF,
N, Rem);
252 SlotDbgMap SlotDebugMap;
257 SlotDebugMap[DI.getStackSlot()].insert(DI.Var);
265 auto *FI = dyn_cast_or_null<FixedStackPseudoSourceValue>(
266 MO->getPseudoValue());
269 int FrameIdx = FI->getFrameIndex();
271 MI.collectDebugValues(Dbg);
274 SlotDebugMap[FrameIdx].insert(
MI->getDebugVariable());
283char StackFrameLayoutAnalysisPass::ID = 0;
288 "Stack Frame Layout",
false,
false)
293 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)
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
MachineFunctionPass * createStackFrameLayoutAnalysisPass()
StackFramePrinter pass - This pass prints out the machine function's stack frame to the given stream ...
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.