Skip to content

Commit e09032f

Browse files
authored
[StackFrameLayoutAnalysis] Add basic Scalable stack slot output (#99883)
The existing StackFrameLayoutAnalysis details do not do well with Scalable vector stack slots, which are not marked as scalable and intertwined with the other fixed-size slots. This patch adds some very basic support, marking them as scalable and sorting them to the end of the list. The slot addresses are not really correct (for fixed as well as scalable), but this prints something a little better with the limited information curently available.
1 parent e6fdecd commit e09032f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
6262
int Align;
6363
int Offset;
6464
SlotType SlotTy;
65+
bool Scalable;
6566

6667
SlotData(const MachineFrameInfo &MFI, const int ValOffset, const int Idx)
6768
: Slot(Idx), Size(MFI.getObjectSize(Idx)),
6869
Align(MFI.getObjectAlign(Idx).value()),
69-
Offset(MFI.getObjectOffset(Idx) - ValOffset), SlotTy(Invalid) {
70+
Offset(MFI.getObjectOffset(Idx) - ValOffset), SlotTy(Invalid),
71+
Scalable(false) {
72+
Scalable = MFI.getStackID(Idx) == TargetStackID::ScalableVector;
7073
if (MFI.isSpillSlotObjectIndex(Idx))
7174
SlotTy = SlotType::Spill;
7275
else if (Idx == MFI.getStackProtectorIndex())
@@ -75,9 +78,12 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
7578
SlotTy = SlotType::Variable;
7679
}
7780

78-
// we use this to sort in reverse order, so that the layout is displayed
79-
// correctly
80-
bool operator<(const SlotData &Rhs) const { return Offset > Rhs.Offset; }
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.
83+
bool operator<(const SlotData &Rhs) const {
84+
return std::make_tuple(!Scalable, Offset) >
85+
std::make_tuple(!Rhs.Scalable, Rhs.Offset);
86+
}
8187
};
8288

8389
StackFrameLayoutAnalysisPass() : MachineFunctionPass(ID) {}
@@ -153,7 +159,7 @@ struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
153159
Rem << Prefix << ore::NV("Offset", D.Offset)
154160
<< "], Type: " << ore::NV("Type", getTypeString(D.SlotTy))
155161
<< ", Align: " << ore::NV("Align", D.Align)
156-
<< ", Size: " << ore::NV("Size", D.Size);
162+
<< ", Size: " << ore::NV("Size", ElementCount::get(D.Size, D.Scalable));
157163
}
158164

159165
void emitSourceLocRemark(const MachineFunction &MF, const DILocalVariable *N,

llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
; CHECK-FRAMELAYOUT-LABEL: Function: csr_d8_allocnxv4i32i32f64
66
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-8], Type: Spill, Align: 8, Size: 8
7-
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Variable, Align: 16, Size: 16
87
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
98
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-20], Type: Variable, Align: 4, Size: 4
109
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
10+
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Variable, Align: 16, Size: vscale x 16
1111

1212
define i32 @csr_d8_allocnxv4i32i32f64(double %d) "aarch64_pstate_sm_compatible" {
1313
; CHECK-LABEL: csr_d8_allocnxv4i32i32f64:
@@ -46,11 +46,11 @@ entry:
4646

4747
; CHECK-FRAMELAYOUT-LABEL: Function: csr_d8_allocnxv4i32i32f64_fp
4848
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-8], Type: Spill, Align: 8, Size: 8
49-
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Variable, Align: 16, Size: 16
5049
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
5150
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-20], Type: Variable, Align: 4, Size: 4
5251
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-32], Type: Spill, Align: 16, Size: 8
5352
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-40], Type: Variable, Align: 8, Size: 8
53+
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Variable, Align: 16, Size: vscale x 16
5454

5555
define i32 @csr_d8_allocnxv4i32i32f64_fp(double %d) "aarch64_pstate_sm_compatible" "frame-pointer"="all" {
5656
; CHECK-LABEL: csr_d8_allocnxv4i32i32f64_fp:
@@ -92,11 +92,11 @@ entry:
9292

9393
; CHECK-FRAMELAYOUT-LABEL: Function: svecc_z8_allocnxv4i32i32f64_fp
9494
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-8], Type: Spill, Align: 8, Size: 8
95-
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Spill, Align: 16, Size: 16
9695
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
9796
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-20], Type: Variable, Align: 4, Size: 4
98-
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-32], Type: Variable, Align: 16, Size: 16
9997
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
98+
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-16], Type: Spill, Align: 16, Size: vscale x 16
99+
; CHECK-FRAMELAYOUT-NEXT: Offset: [SP-32], Type: Variable, Align: 16, Size: vscale x 16
100100

101101
define i32 @svecc_z8_allocnxv4i32i32f64_fp(double %d, <vscale x 4 x i32> %v) "aarch64_pstate_sm_compatible" "frame-pointer"="all" {
102102
; CHECK-LABEL: svecc_z8_allocnxv4i32i32f64_fp:

0 commit comments

Comments
 (0)