diff options
author | Elizaveta Noskova <159026035+enoskova-sc@users.noreply.github.com> | 2025-08-12 16:34:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-12 16:34:29 +0300 |
commit | bbde6be841b22667179c6e75682c40e1484a4bf2 (patch) | |
tree | 247974ba5dc1ade8beafbd4aadbb6a4d907d2036 /llvm/lib/CodeGen/PrologEpilogInserter.cpp | |
parent | ef5e65d27b940a2a2ce1d4ff20c38105d52d23b6 (diff) | |
download | llvm-bbde6be841b22667179c6e75682c40e1484a4bf2.zip llvm-bbde6be841b22667179c6e75682c40e1484a4bf2.tar.gz llvm-bbde6be841b22667179c6e75682c40e1484a4bf2.tar.bz2 |
[llvm] Support multiple save/restore points in mir (#119357)
Currently mir supports only one save and one restore point
specification:
```
savePoint: '%bb.1'
restorePoint: '%bb.2'
```
This patch provide possibility to have multiple save and multiple
restore points in mir:
```
savePoints:
- point: '%bb.1'
restorePoints:
- point: '%bb.2'
```
Shrink-Wrap points split Part 3.
RFC:
https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581
Part 1: https://github.com/llvm/llvm-project/pull/117862
Part 2: https://github.com/llvm/llvm-project/pull/119355
Part 4: https://github.com/llvm/llvm-project/pull/119358
Part 5: https://github.com/llvm/llvm-project/pull/119359
Diffstat (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 7b751ba..8fc0748 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -351,8 +351,8 @@ bool PEIImpl::run(MachineFunction &MF) { delete RS; SaveBlocks.clear(); RestoreBlocks.clear(); - MFI.setSavePoint(nullptr); - MFI.setRestorePoint(nullptr); + MFI.setSavePoints({}); + MFI.setRestorePoints({}); return true; } @@ -423,16 +423,18 @@ void PEIImpl::calculateCallFrameInfo(MachineFunction &MF) { /// callee-saved registers, and placing prolog and epilog code. void PEIImpl::calculateSaveRestoreBlocks(MachineFunction &MF) { const MachineFrameInfo &MFI = MF.getFrameInfo(); - // Even when we do not change any CSR, we still want to insert the // prologue and epilogue of the function. // So set the save points for those. // Use the points found by shrink-wrapping, if any. - if (MFI.getSavePoint()) { - SaveBlocks.push_back(MFI.getSavePoint()); - assert(MFI.getRestorePoint() && "Both restore and save must be set"); - MachineBasicBlock *RestoreBlock = MFI.getRestorePoint(); + if (!MFI.getSavePoints().empty()) { + assert(MFI.getSavePoints().size() == 1 && + "Multiple save points are not yet supported!"); + SaveBlocks.push_back(MFI.getSavePoints().front()); + assert(MFI.getRestorePoints().size() == 1 && + "Multiple restore points are not yet supported!"); + MachineBasicBlock *RestoreBlock = MFI.getRestorePoints().front(); // If RestoreBlock does not have any successor and is not a return block // then the end point is unreachable and we do not need to insert any // epilogue. @@ -558,7 +560,11 @@ static void updateLiveness(MachineFunction &MF) { SmallPtrSet<MachineBasicBlock *, 8> Visited; SmallVector<MachineBasicBlock *, 8> WorkList; MachineBasicBlock *Entry = &MF.front(); - MachineBasicBlock *Save = MFI.getSavePoint(); + + assert(MFI.getSavePoints().size() < 2 && + "Multiple save points not yet supported!"); + MachineBasicBlock *Save = + MFI.getSavePoints().empty() ? nullptr : MFI.getSavePoints().front(); if (!Save) Save = Entry; @@ -569,7 +575,10 @@ static void updateLiveness(MachineFunction &MF) { } Visited.insert(Save); - MachineBasicBlock *Restore = MFI.getRestorePoint(); + assert(MFI.getRestorePoints().size() < 2 && + "Multiple restore points not yet supported!"); + MachineBasicBlock *Restore = + MFI.getRestorePoints().empty() ? nullptr : MFI.getRestorePoints().front(); if (Restore) // By construction Restore cannot be visited, otherwise it // means there exists a path to Restore that does not go |