diff options
author | Jay Foad <jay.foad@amd.com> | 2023-06-08 14:31:51 +0100 |
---|---|---|
committer | Jay Foad <jay.foad@amd.com> | 2023-08-01 07:56:11 +0100 |
commit | eaca8c2edfb14c4edab61c05562b472225f029e0 (patch) | |
tree | b336387cfb2d07212680f39c90c392105ffa3c3b /llvm/lib/CodeGen/PrologEpilogInserter.cpp | |
parent | 9abc6d9105ca625ee2a03c0ec96a77d9575ca34f (diff) | |
download | llvm-eaca8c2edfb14c4edab61c05562b472225f029e0.zip llvm-eaca8c2edfb14c4edab61c05562b472225f029e0.tar.gz llvm-eaca8c2edfb14c4edab61c05562b472225f029e0.tar.bz2 |
[PEI][PowerPC] Switch to backwards frame index elimination
This adds support for reprocessing new instructions that were generated
by the target's eliminateFrameIndex.
Backwards frame index elimination uses backwards register scavenging,
which is preferred because it does not rely on accurate kill flags.
Differential Revision: https://reviews.llvm.org/D156690
Diffstat (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index c2b2399..d97a0e7 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -1486,7 +1486,9 @@ void PEI::replaceFrameIndicesBackward(MachineBasicBlock *BB, if (LocalRS) LocalRS->enterBasicBlockEnd(*BB); - for (MachineInstr &MI : make_early_inc_range(reverse(*BB))) { + for (MachineBasicBlock::iterator I = BB->end(); I != BB->begin();) { + MachineInstr &MI = *std::prev(I); + if (TII.isFrameInstr(MI)) { SPAdj -= TII.getSPAdjust(MI); TFI.eliminateCallFramePseudoInstr(MF, *BB, &MI); @@ -1497,27 +1499,27 @@ void PEI::replaceFrameIndicesBackward(MachineBasicBlock *BB, if (LocalRS) LocalRS->backward(MI); - for (unsigned i = 0; i != MI.getNumOperands(); ++i) { - if (!MI.getOperand(i).isFI()) + bool RemovedMI = false; + for (const auto &[Idx, Op] : enumerate(MI.operands())) { + if (!Op.isFI()) continue; - if (replaceFrameIndexDebugInstr(MF, MI, i, SPAdj)) + if (replaceFrameIndexDebugInstr(MF, MI, Idx, SPAdj)) continue; // Eliminate this FrameIndex operand. - // - // Save and restore the scavenger's position around the call to - // eliminateFrameIndex in case it erases MI and invalidates the iterator. - MachineBasicBlock::iterator Save; - if (LocalRS) - Save = std::next(LocalRS->getCurrentPosition()); - bool Removed = TRI.eliminateFrameIndex(MI, SPAdj, i, LocalRS); - if (LocalRS) - LocalRS->skipTo(std::prev(Save)); - - if (Removed) + RemovedMI = TRI.eliminateFrameIndex(MI, SPAdj, Idx, LocalRS); + if (RemovedMI) break; } + + // Refresh the scavenger's internal iterator in case MI was removed or more + // instructions were inserted after it. + if (LocalRS) + LocalRS->skipTo(std::prev(I)); + + if (!RemovedMI) + --I; } } |