Skip to content

Commit 32a4650

Browse files
authored
[AArch64] Avoid hardcoding spill size/align in FrameLowering (NFC) (#123080)
This is already defined for each register class in AArch64RegisterInfo, not hardcoding it here makes these values easier to change (perhaps based on hardware mode).
1 parent 2c9dc08 commit 32a4650

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,26 +2926,12 @@ struct RegPairInfo {
29262926
int FrameIdx;
29272927
int Offset;
29282928
enum RegType { GPR, FPR64, FPR128, PPR, ZPR, VG } Type;
2929+
const TargetRegisterClass *RC;
29292930

29302931
RegPairInfo() = default;
29312932

29322933
bool isPaired() const { return Reg2 != AArch64::NoRegister; }
29332934

2934-
unsigned getScale() const {
2935-
switch (Type) {
2936-
case PPR:
2937-
return 2;
2938-
case GPR:
2939-
case FPR64:
2940-
case VG:
2941-
return 8;
2942-
case ZPR:
2943-
case FPR128:
2944-
return 16;
2945-
}
2946-
llvm_unreachable("Unsupported type");
2947-
}
2948-
29492935
bool isScalable() const { return Type == PPR || Type == ZPR; }
29502936
};
29512937

@@ -3023,20 +3009,27 @@ static void computeCalleeSaveRegisterPairs(
30233009
RegPairInfo RPI;
30243010
RPI.Reg1 = CSI[i].getReg();
30253011

3026-
if (AArch64::GPR64RegClass.contains(RPI.Reg1))
3012+
if (AArch64::GPR64RegClass.contains(RPI.Reg1)) {
30273013
RPI.Type = RegPairInfo::GPR;
3028-
else if (AArch64::FPR64RegClass.contains(RPI.Reg1))
3014+
RPI.RC = &AArch64::GPR64RegClass;
3015+
} else if (AArch64::FPR64RegClass.contains(RPI.Reg1)) {
30293016
RPI.Type = RegPairInfo::FPR64;
3030-
else if (AArch64::FPR128RegClass.contains(RPI.Reg1))
3017+
RPI.RC = &AArch64::FPR64RegClass;
3018+
} else if (AArch64::FPR128RegClass.contains(RPI.Reg1)) {
30313019
RPI.Type = RegPairInfo::FPR128;
3032-
else if (AArch64::ZPRRegClass.contains(RPI.Reg1))
3020+
RPI.RC = &AArch64::FPR128RegClass;
3021+
} else if (AArch64::ZPRRegClass.contains(RPI.Reg1)) {
30333022
RPI.Type = RegPairInfo::ZPR;
3034-
else if (AArch64::PPRRegClass.contains(RPI.Reg1))
3023+
RPI.RC = &AArch64::ZPRRegClass;
3024+
} else if (AArch64::PPRRegClass.contains(RPI.Reg1)) {
30353025
RPI.Type = RegPairInfo::PPR;
3036-
else if (RPI.Reg1 == AArch64::VG)
3026+
RPI.RC = &AArch64::PPRRegClass;
3027+
} else if (RPI.Reg1 == AArch64::VG) {
30373028
RPI.Type = RegPairInfo::VG;
3038-
else
3029+
RPI.RC = &AArch64::FIXED_REGSRegClass;
3030+
} else {
30393031
llvm_unreachable("Unsupported register class.");
3032+
}
30403033

30413034
// Add the stack hazard size as we transition from GPR->FPR CSRs.
30423035
if (AFI->hasStackHazardSlotIndex() &&
@@ -3045,7 +3038,7 @@ static void computeCalleeSaveRegisterPairs(
30453038
ByteOffset += StackFillDir * StackHazardSize;
30463039
LastReg = RPI.Reg1;
30473040

3048-
int Scale = RPI.getScale();
3041+
int Scale = TRI->getSpillSize(*RPI.RC);
30493042
// Add the next reg to the pair if it is in the same register class.
30503043
if (unsigned(i + RegInc) < Count && !AFI->hasStackHazardSlotIndex()) {
30513044
Register NextReg = CSI[i + RegInc].getReg();
@@ -3254,38 +3247,26 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
32543247
// Rationale: This sequence saves uop updates compared to a sequence of
32553248
// pre-increment spills like stp xi,xj,[sp,#-16]!
32563249
// Note: Similar rationale and sequence for restores in epilog.
3257-
unsigned Size;
3258-
Align Alignment;
3250+
unsigned Size = TRI->getSpillSize(*RPI.RC);
3251+
Align Alignment = TRI->getSpillAlign(*RPI.RC);
32593252
switch (RPI.Type) {
32603253
case RegPairInfo::GPR:
32613254
StrOpc = RPI.isPaired() ? AArch64::STPXi : AArch64::STRXui;
3262-
Size = 8;
3263-
Alignment = Align(8);
32643255
break;
32653256
case RegPairInfo::FPR64:
32663257
StrOpc = RPI.isPaired() ? AArch64::STPDi : AArch64::STRDui;
3267-
Size = 8;
3268-
Alignment = Align(8);
32693258
break;
32703259
case RegPairInfo::FPR128:
32713260
StrOpc = RPI.isPaired() ? AArch64::STPQi : AArch64::STRQui;
3272-
Size = 16;
3273-
Alignment = Align(16);
32743261
break;
32753262
case RegPairInfo::ZPR:
32763263
StrOpc = RPI.isPaired() ? AArch64::ST1B_2Z_IMM : AArch64::STR_ZXI;
3277-
Size = 16;
3278-
Alignment = Align(16);
32793264
break;
32803265
case RegPairInfo::PPR:
32813266
StrOpc = AArch64::STR_PXI;
3282-
Size = 2;
3283-
Alignment = Align(2);
32843267
break;
32853268
case RegPairInfo::VG:
32863269
StrOpc = AArch64::STRXui;
3287-
Size = 8;
3288-
Alignment = Align(8);
32893270
break;
32903271
}
32913272

@@ -3495,33 +3476,23 @@ bool AArch64FrameLowering::restoreCalleeSavedRegisters(
34953476
// ldp x22, x21, [sp, #0] // addImm(+0)
34963477
// Note: see comment in spillCalleeSavedRegisters()
34973478
unsigned LdrOpc;
3498-
unsigned Size;
3499-
Align Alignment;
3479+
unsigned Size = TRI->getSpillSize(*RPI.RC);
3480+
Align Alignment = TRI->getSpillAlign(*RPI.RC);
35003481
switch (RPI.Type) {
35013482
case RegPairInfo::GPR:
35023483
LdrOpc = RPI.isPaired() ? AArch64::LDPXi : AArch64::LDRXui;
3503-
Size = 8;
3504-
Alignment = Align(8);
35053484
break;
35063485
case RegPairInfo::FPR64:
35073486
LdrOpc = RPI.isPaired() ? AArch64::LDPDi : AArch64::LDRDui;
3508-
Size = 8;
3509-
Alignment = Align(8);
35103487
break;
35113488
case RegPairInfo::FPR128:
35123489
LdrOpc = RPI.isPaired() ? AArch64::LDPQi : AArch64::LDRQui;
3513-
Size = 16;
3514-
Alignment = Align(16);
35153490
break;
35163491
case RegPairInfo::ZPR:
35173492
LdrOpc = RPI.isPaired() ? AArch64::LD1B_2Z_IMM : AArch64::LDR_ZXI;
3518-
Size = 16;
3519-
Alignment = Align(16);
35203493
break;
35213494
case RegPairInfo::PPR:
35223495
LdrOpc = AArch64::LDR_PXI;
3523-
Size = 2;
3524-
Alignment = Align(2);
35253496
break;
35263497
case RegPairInfo::VG:
35273498
continue;

0 commit comments

Comments
 (0)