Skip to content

Commit 95f51f1

Browse files
[AArch64] NFC: Rename LastPopI in emitEpilogue (#156884)
LastPopI suggests it is an iterator to the last stack pop instruction, which is not what it actually points to. Instead, in one instance it points to the homogenous epilogue instruction, in the other it points to the first GPR reload.
1 parent c5e6d56 commit 95f51f1

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,15 +2548,15 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
25482548
AFI->setLocalStackSize(NumBytes - PrologueSaveSize);
25492549
if (homogeneousPrologEpilog(MF, &MBB)) {
25502550
assert(!NeedsWinCFI);
2551-
auto LastPopI = MBB.getFirstTerminator();
2552-
if (LastPopI != MBB.begin()) {
2553-
auto HomogeneousEpilog = std::prev(LastPopI);
2551+
auto FirstHomogenousEpilogI = MBB.getFirstTerminator();
2552+
if (FirstHomogenousEpilogI != MBB.begin()) {
2553+
auto HomogeneousEpilog = std::prev(FirstHomogenousEpilogI);
25542554
if (HomogeneousEpilog->getOpcode() == AArch64::HOM_Epilog)
2555-
LastPopI = HomogeneousEpilog;
2555+
FirstHomogenousEpilogI = HomogeneousEpilog;
25562556
}
25572557

25582558
// Adjust local stack
2559-
emitFrameOffset(MBB, LastPopI, DL, AArch64::SP, AArch64::SP,
2559+
emitFrameOffset(MBB, FirstHomogenousEpilogI, DL, AArch64::SP, AArch64::SP,
25602560
StackOffset::getFixed(AFI->getLocalStackSize()), TII,
25612561
MachineInstr::FrameDestroy, false, NeedsWinCFI, &HasWinCFI);
25622562

@@ -2602,17 +2602,17 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26022602
// Move past the restores of the callee-saved registers.
26032603
// If we plan on combining the sp bump of the local stack size and the callee
26042604
// save stack size, we might need to adjust the CSR save and restore offsets.
2605-
MachineBasicBlock::iterator LastPopI = MBB.getFirstTerminator();
2605+
MachineBasicBlock::iterator FirstGPRRestoreI = MBB.getFirstTerminator();
26062606
MachineBasicBlock::iterator Begin = MBB.begin();
2607-
while (LastPopI != Begin) {
2608-
--LastPopI;
2609-
if (!LastPopI->getFlag(MachineInstr::FrameDestroy) ||
2610-
(!FPAfterSVECalleeSaves && IsSVECalleeSave(LastPopI))) {
2611-
++LastPopI;
2607+
while (FirstGPRRestoreI != Begin) {
2608+
--FirstGPRRestoreI;
2609+
if (!FirstGPRRestoreI->getFlag(MachineInstr::FrameDestroy) ||
2610+
(!FPAfterSVECalleeSaves && IsSVECalleeSave(FirstGPRRestoreI))) {
2611+
++FirstGPRRestoreI;
26122612
break;
26132613
} else if (CombineSPBump)
2614-
fixupCalleeSaveRestoreStackOffset(*LastPopI, AFI->getLocalStackSize(),
2615-
NeedsWinCFI, &HasWinCFI);
2614+
fixupCalleeSaveRestoreStackOffset(
2615+
*FirstGPRRestoreI, AFI->getLocalStackSize(), NeedsWinCFI, &HasWinCFI);
26162616
}
26172617

26182618
if (NeedsWinCFI) {
@@ -2622,9 +2622,9 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26222622
// arguments. Insert the SEH_EpilogStart and remove it later if it
26232623
// we didn't emit any SEH opcodes to avoid generating WinCFI for
26242624
// functions that don't need it.
2625-
BuildMI(MBB, LastPopI, DL, TII->get(AArch64::SEH_EpilogStart))
2625+
BuildMI(MBB, FirstGPRRestoreI, DL, TII->get(AArch64::SEH_EpilogStart))
26262626
.setMIFlag(MachineInstr::FrameDestroy);
2627-
EpilogStartI = LastPopI;
2627+
EpilogStartI = FirstGPRRestoreI;
26282628
--EpilogStartI;
26292629
}
26302630

@@ -2665,7 +2665,7 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26652665

26662666
// When we are about to restore the CSRs, the CFA register is SP again.
26672667
if (EmitCFI && hasFP(MF))
2668-
CFIInstBuilder(MBB, LastPopI, MachineInstr::FrameDestroy)
2668+
CFIInstBuilder(MBB, FirstGPRRestoreI, MachineInstr::FrameDestroy)
26692669
.buildDefCFA(AArch64::SP, NumBytes);
26702670

26712671
emitFrameOffset(MBB, MBB.getFirstTerminator(), DL, AArch64::SP, AArch64::SP,
@@ -2681,7 +2681,8 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26812681
// Process the SVE callee-saves to determine what space needs to be
26822682
// deallocated.
26832683
StackOffset DeallocateBefore = {}, DeallocateAfter = SVEStackSize;
2684-
MachineBasicBlock::iterator RestoreBegin = LastPopI, RestoreEnd = LastPopI;
2684+
MachineBasicBlock::iterator RestoreBegin = FirstGPRRestoreI,
2685+
RestoreEnd = FirstGPRRestoreI;
26852686
if (int64_t CalleeSavedSize = AFI->getSVECalleeSavedStackSize()) {
26862687
if (FPAfterSVECalleeSaves)
26872688
RestoreEnd = MBB.getFirstTerminator();
@@ -2706,7 +2707,7 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
27062707
// deallocates non-callee-save SVE allocations. Otherwise, deallocate
27072708
// them explicitly.
27082709
if (!AFI->isStackRealigned() && !MFI.hasVarSizedObjects()) {
2709-
emitFrameOffset(MBB, LastPopI, DL, AArch64::SP, AArch64::SP,
2710+
emitFrameOffset(MBB, FirstGPRRestoreI, DL, AArch64::SP, AArch64::SP,
27102711
DeallocateBefore, TII, MachineInstr::FrameDestroy, false,
27112712
NeedsWinCFI, &HasWinCFI);
27122713
}
@@ -2796,7 +2797,7 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
27962797
StackRestoreBytes += AfterCSRPopSize;
27972798

27982799
emitFrameOffset(
2799-
MBB, LastPopI, DL, AArch64::SP, AArch64::SP,
2800+
MBB, FirstGPRRestoreI, DL, AArch64::SP, AArch64::SP,
28002801
StackOffset::getFixed(StackRestoreBytes), TII,
28012802
MachineInstr::FrameDestroy, false, NeedsWinCFI, &HasWinCFI, EmitCFI,
28022803
StackOffset::getFixed((RedZone ? 0 : NumBytes) + PrologueSaveSize));
@@ -2816,17 +2817,17 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
28162817
// be able to save any instructions.
28172818
if (!IsFunclet && (MFI.hasVarSizedObjects() || AFI->isStackRealigned())) {
28182819
emitFrameOffset(
2819-
MBB, LastPopI, DL, AArch64::SP, AArch64::FP,
2820+
MBB, FirstGPRRestoreI, DL, AArch64::SP, AArch64::FP,
28202821
StackOffset::getFixed(-AFI->getCalleeSaveBaseToFrameRecordOffset()),
28212822
TII, MachineInstr::FrameDestroy, false, NeedsWinCFI, &HasWinCFI);
28222823
} else if (NumBytes)
2823-
emitFrameOffset(MBB, LastPopI, DL, AArch64::SP, AArch64::SP,
2824+
emitFrameOffset(MBB, FirstGPRRestoreI, DL, AArch64::SP, AArch64::SP,
28242825
StackOffset::getFixed(NumBytes), TII,
28252826
MachineInstr::FrameDestroy, false, NeedsWinCFI, &HasWinCFI);
28262827

28272828
// When we are about to restore the CSRs, the CFA register is SP again.
28282829
if (EmitCFI && hasFP(MF))
2829-
CFIInstBuilder(MBB, LastPopI, MachineInstr::FrameDestroy)
2830+
CFIInstBuilder(MBB, FirstGPRRestoreI, MachineInstr::FrameDestroy)
28302831
.buildDefCFA(AArch64::SP, PrologueSaveSize);
28312832

28322833
// This must be placed after the callee-save restore code because that code

0 commit comments

Comments
 (0)