-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AArch64] Avoid hardcoding spill size/align in FrameLowering (NFC) #123080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).
@llvm/pr-subscribers-backend-aarch64 Author: Benjamin Maxwell (MacDue) ChangesThis is already defined for each register class in AArch64RegisterInfo, not hardcoding it here makes these values easier to change (perhaps based on hardware mode). Full diff: https://github.com/llvm/llvm-project/pull/123080.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 206e410047db56..66a3266f989fe8 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -2926,26 +2926,12 @@ struct RegPairInfo {
int FrameIdx;
int Offset;
enum RegType { GPR, FPR64, FPR128, PPR, ZPR, VG } Type;
+ const TargetRegisterClass *RC;
RegPairInfo() = default;
bool isPaired() const { return Reg2 != AArch64::NoRegister; }
- unsigned getScale() const {
- switch (Type) {
- case PPR:
- return 2;
- case GPR:
- case FPR64:
- case VG:
- return 8;
- case ZPR:
- case FPR128:
- return 16;
- }
- llvm_unreachable("Unsupported type");
- }
-
bool isScalable() const { return Type == PPR || Type == ZPR; }
};
@@ -3023,20 +3009,27 @@ static void computeCalleeSaveRegisterPairs(
RegPairInfo RPI;
RPI.Reg1 = CSI[i].getReg();
- if (AArch64::GPR64RegClass.contains(RPI.Reg1))
+ if (AArch64::GPR64RegClass.contains(RPI.Reg1)) {
RPI.Type = RegPairInfo::GPR;
- else if (AArch64::FPR64RegClass.contains(RPI.Reg1))
+ RPI.RC = &AArch64::GPR64RegClass;
+ } else if (AArch64::FPR64RegClass.contains(RPI.Reg1)) {
RPI.Type = RegPairInfo::FPR64;
- else if (AArch64::FPR128RegClass.contains(RPI.Reg1))
+ RPI.RC = &AArch64::FPR64RegClass;
+ } else if (AArch64::FPR128RegClass.contains(RPI.Reg1)) {
RPI.Type = RegPairInfo::FPR128;
- else if (AArch64::ZPRRegClass.contains(RPI.Reg1))
+ RPI.RC = &AArch64::FPR128RegClass;
+ } else if (AArch64::ZPRRegClass.contains(RPI.Reg1)) {
RPI.Type = RegPairInfo::ZPR;
- else if (AArch64::PPRRegClass.contains(RPI.Reg1))
+ RPI.RC = &AArch64::ZPRRegClass;
+ } else if (AArch64::PPRRegClass.contains(RPI.Reg1)) {
RPI.Type = RegPairInfo::PPR;
- else if (RPI.Reg1 == AArch64::VG)
+ RPI.RC = &AArch64::PPRRegClass;
+ } else if (RPI.Reg1 == AArch64::VG) {
RPI.Type = RegPairInfo::VG;
- else
+ RPI.RC = &AArch64::FIXED_REGSRegClass;
+ } else {
llvm_unreachable("Unsupported register class.");
+ }
// Add the stack hazard size as we transition from GPR->FPR CSRs.
if (AFI->hasStackHazardSlotIndex() &&
@@ -3045,7 +3038,7 @@ static void computeCalleeSaveRegisterPairs(
ByteOffset += StackFillDir * StackHazardSize;
LastReg = RPI.Reg1;
- int Scale = RPI.getScale();
+ int Scale = TRI->getSpillSize(*RPI.RC);
// Add the next reg to the pair if it is in the same register class.
if (unsigned(i + RegInc) < Count && !AFI->hasStackHazardSlotIndex()) {
Register NextReg = CSI[i + RegInc].getReg();
@@ -3254,38 +3247,26 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
// Rationale: This sequence saves uop updates compared to a sequence of
// pre-increment spills like stp xi,xj,[sp,#-16]!
// Note: Similar rationale and sequence for restores in epilog.
- unsigned Size;
- Align Alignment;
+ unsigned Size = TRI->getSpillSize(*RPI.RC);
+ Align Alignment = TRI->getSpillAlign(*RPI.RC);
switch (RPI.Type) {
case RegPairInfo::GPR:
StrOpc = RPI.isPaired() ? AArch64::STPXi : AArch64::STRXui;
- Size = 8;
- Alignment = Align(8);
break;
case RegPairInfo::FPR64:
StrOpc = RPI.isPaired() ? AArch64::STPDi : AArch64::STRDui;
- Size = 8;
- Alignment = Align(8);
break;
case RegPairInfo::FPR128:
StrOpc = RPI.isPaired() ? AArch64::STPQi : AArch64::STRQui;
- Size = 16;
- Alignment = Align(16);
break;
case RegPairInfo::ZPR:
StrOpc = RPI.isPaired() ? AArch64::ST1B_2Z_IMM : AArch64::STR_ZXI;
- Size = 16;
- Alignment = Align(16);
break;
case RegPairInfo::PPR:
StrOpc = AArch64::STR_PXI;
- Size = 2;
- Alignment = Align(2);
break;
case RegPairInfo::VG:
StrOpc = AArch64::STRXui;
- Size = 8;
- Alignment = Align(8);
break;
}
@@ -3495,33 +3476,23 @@ bool AArch64FrameLowering::restoreCalleeSavedRegisters(
// ldp x22, x21, [sp, #0] // addImm(+0)
// Note: see comment in spillCalleeSavedRegisters()
unsigned LdrOpc;
- unsigned Size;
- Align Alignment;
+ unsigned Size = TRI->getSpillSize(*RPI.RC);
+ Align Alignment = TRI->getSpillAlign(*RPI.RC);
switch (RPI.Type) {
case RegPairInfo::GPR:
LdrOpc = RPI.isPaired() ? AArch64::LDPXi : AArch64::LDRXui;
- Size = 8;
- Alignment = Align(8);
break;
case RegPairInfo::FPR64:
LdrOpc = RPI.isPaired() ? AArch64::LDPDi : AArch64::LDRDui;
- Size = 8;
- Alignment = Align(8);
break;
case RegPairInfo::FPR128:
LdrOpc = RPI.isPaired() ? AArch64::LDPQi : AArch64::LDRQui;
- Size = 16;
- Alignment = Align(16);
break;
case RegPairInfo::ZPR:
LdrOpc = RPI.isPaired() ? AArch64::LD1B_2Z_IMM : AArch64::LDR_ZXI;
- Size = 16;
- Alignment = Align(16);
break;
case RegPairInfo::PPR:
LdrOpc = AArch64::LDR_PXI;
- Size = 2;
- Alignment = Align(2);
break;
case RegPairInfo::VG:
continue;
|
sdesmalen-arm
approved these changes
Jan 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).