@@ -60,15 +60,15 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
60
60
int Slot;
61
61
int Size;
62
62
int Align;
63
- int Offset;
63
+ StackOffset Offset;
64
64
SlotType SlotTy;
65
65
bool Scalable;
66
66
67
- SlotData (const MachineFrameInfo &MFI, const int ValOffset, const int Idx)
67
+ SlotData (const MachineFrameInfo &MFI, const StackOffset Offset,
68
+ const int Idx)
68
69
: Slot(Idx), Size(MFI.getObjectSize(Idx)),
69
- Align (MFI.getObjectAlign(Idx).value()),
70
- Offset(MFI.getObjectOffset(Idx) - ValOffset), SlotTy(Invalid),
71
- Scalable(false ) {
70
+ Align (MFI.getObjectAlign(Idx).value()), Offset(Offset),
71
+ SlotTy(Invalid), Scalable(false ) {
72
72
Scalable = MFI.getStackID (Idx) == TargetStackID::ScalableVector;
73
73
if (MFI.isSpillSlotObjectIndex (Idx))
74
74
SlotTy = SlotType::Spill;
@@ -79,10 +79,10 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
79
79
}
80
80
81
81
// We use this to sort in reverse order, so that the layout is displayed
82
- // correctly. Scalable slots are sorted to the end of the list.
82
+ // correctly.
83
83
bool operator <(const SlotData &Rhs) const {
84
- return std::make_tuple (!Scalable, Offset) >
85
- std::make_tuple (! Rhs.Scalable , Rhs.Offset );
84
+ return (Offset. getFixed () + Offset. getScalable () ) >
85
+ ( Rhs.Offset . getFixed () + Rhs.Offset . getScalable () );
86
86
}
87
87
};
88
88
@@ -149,15 +149,27 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
149
149
// For example we store the Offset in YAML as:
150
150
// ...
151
151
// - Offset: -8
152
+ // - ScalableOffset: -16
153
+ // Note: the ScalableOffset entries are added only for slots with non-zero
154
+ // scalable offsets.
152
155
//
153
- // But we print it to the CLI as
156
+ // But we print it to the CLI as:
154
157
// Offset: [SP-8]
158
+ //
159
+ // Or with non-zero scalable offset:
160
+ // Offset: [SP-8-16 x vscale]
155
161
156
162
// Negative offsets will print a leading `-`, so only add `+`
157
163
std::string Prefix =
158
- formatv (" \n Offset: [SP{0}" , (D.Offset < 0 ) ? " " : " +" ).str ();
159
- Rem << Prefix << ore::NV (" Offset" , D.Offset )
160
- << " ], Type: " << ore::NV (" Type" , getTypeString (D.SlotTy ))
164
+ formatv (" \n Offset: [SP{0}" , (D.Offset .getFixed () < 0 ) ? " " : " +" ).str ();
165
+ Rem << Prefix << ore::NV (" Offset" , D.Offset .getFixed ());
166
+
167
+ if (D.Offset .getScalable ()) {
168
+ Rem << ((D.Offset .getScalable () < 0 ) ? " " : " +" )
169
+ << ore::NV (" ScalableOffset" , D.Offset .getScalable ()) << " x vscale" ;
170
+ }
171
+
172
+ Rem << " ], Type: " << ore::NV (" Type" , getTypeString (D.SlotTy ))
161
173
<< " , Align: " << ore::NV (" Align" , D.Align )
162
174
<< " , Size: " << ore::NV (" Size" , ElementCount::get (D.Size , D.Scalable ));
163
175
}
@@ -170,17 +182,22 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
170
182
Rem << " \n " << ore::NV (" DataLoc" , Loc);
171
183
}
172
184
185
+ StackOffset getStackOffset (const MachineFunction &MF,
186
+ const MachineFrameInfo &MFI,
187
+ const TargetFrameLowering *FI, int FrameIdx) {
188
+ if (!FI)
189
+ return StackOffset::getFixed (MFI.getObjectOffset (FrameIdx));
190
+
191
+ return FI->getFrameIndexReferenceFromSP (MF, FrameIdx);
192
+ }
193
+
173
194
void emitStackFrameLayoutRemarks (MachineFunction &MF,
174
195
MachineOptimizationRemarkAnalysis &Rem) {
175
196
const MachineFrameInfo &MFI = MF.getFrameInfo ();
176
197
if (!MFI.hasStackObjects ())
177
198
return ;
178
199
179
- // ValOffset is the offset to the local area from the SP at function entry.
180
- // To display the true offset from SP, we need to subtract ValOffset from
181
- // MFI's ObjectOffset.
182
200
const TargetFrameLowering *FI = MF.getSubtarget ().getFrameLowering ();
183
- const int ValOffset = (FI ? FI->getOffsetOfLocalArea () : 0 );
184
201
185
202
LLVM_DEBUG (dbgs () << " getStackProtectorIndex =="
186
203
<< MFI.getStackProtectorIndex () << " \n " );
@@ -194,7 +211,7 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
194
211
Idx != EndIdx; ++Idx) {
195
212
if (MFI.isDeadObjectIndex (Idx))
196
213
continue ;
197
- SlotInfo.emplace_back (MFI, ValOffset , Idx);
214
+ SlotInfo.emplace_back (MFI, getStackOffset (MF, MFI, FI, Idx) , Idx);
198
215
}
199
216
200
217
// sort the ordering, to match the actual layout in memory
0 commit comments