40#define DEBUG_TYPE "stack-frame-layout"
47struct StackFrameLayoutAnalysis {
74 SlotTy(
Invalid), Scalable(
false) {
77 SlotTy = SlotType::Spill;
79 SlotTy = SlotType::Fixed;
81 SlotTy = SlotType::VariableSized;
84 SlotTy = SlotType::StackProtector;
86 SlotTy = SlotType::Variable;
89 bool isVarSize()
const {
return SlotTy == SlotType::VariableSized; }
96 bool operator<(
const SlotData &Rhs)
const {
97 return std::make_tuple(!isVarSize(),
98 Offset.getFixed() + Offset.getScalable(), Slot) >
99 std::make_tuple(!Rhs.isVarSize(),
100 Rhs.Offset.getFixed() + Rhs.Offset.getScalable(),
118 Rem << (
"\nFunction: " + MF.
getName()).str();
119 emitStackFrameLayoutRemarks(MF, Rem);
126 case SlotType::Spill:
128 case SlotType::Fixed:
130 case SlotType::VariableSized:
131 return "VariableSized";
132 case SlotType::StackProtector:
134 case SlotType::Variable:
172 formatv(
"\nOffset: [SP{0}", (
D.Offset.getFixed() < 0) ?
"" :
"+").str();
173 Rem << Prefix <<
ore::NV(
"Offset",
D.Offset.getFixed());
175 if (
D.Offset.getScalable()) {
176 Rem << ((
D.Offset.getScalable() < 0) ?
"" :
"+")
177 <<
ore::NV(
"ScalableOffset",
D.Offset.getScalable()) <<
" x vscale";
181 <<
", Align: " <<
ore::NV(
"Align",
D.Align)
188 formatv(
"{0} @ {1}:{2}",
N->getName(),
N->getFilename(),
N->getLine())
190 Rem <<
"\n " <<
ore::NV(
"DataLoc", Loc);
213 std::vector<SlotData> SlotInfo;
216 SlotInfo.reserve(NumObj);
228 SlotDbgMap SlotMap = genSlotDbgMapping(MF);
230 for (
const SlotData &
Info : SlotInfo) {
231 emitStackSlotRemark(MF,
Info, Rem);
233 emitSourceLocRemark(MF,
N, Rem);
241 SlotDbgMap SlotDebugMap;
246 SlotDebugMap[DI.getStackSlot()].insert(DI.Var);
254 auto *FI = dyn_cast_or_null<FixedStackPseudoSourceValue>(
255 MO->getPseudoValue());
258 int FrameIdx = FI->getFrameIndex();
260 MI.collectDebugValues(Dbg);
263 SlotDebugMap[FrameIdx].insert(
MI->getDebugVariable());
279 return "Stack Frame Layout Analysis";
289 auto &ORE = getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
290 return StackFrameLayoutAnalysis(ORE).run(MF);
294char StackFrameLayoutAnalysisLegacy::ID = 0;
301 StackFrameLayoutAnalysis(ORE).
run(MF);
307 "Stack Frame Layout",
false,
false)
312 return new StackFrameLayoutAnalysisLegacy();
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.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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.
LLVM_ABI 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.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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)
LLVM_ABI 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)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isFunctionInPrintList(StringRef FunctionName)
LLVM_ABI 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.