[llvm] [Draft] Support save/restore point splitting in shrink-wrap (PR #119359)

Nathan Corbyn via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 02:25:57 PST 2025


================
@@ -651,6 +682,57 @@ static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
   }
 }
 
+static void fillCSInfoPerBB(
+    SaveRestorePoints SRPoints,
+    DenseMap<Register, CalleeSavedInfo *> &RegToInfo,
+    DenseMap<MachineBasicBlock *, std::vector<CalleeSavedInfo>> &CSInfoPerBB,
+    bool isSave, MBBVector &PrologEpilogBlocks) {
+  std::vector<CalleeSavedInfo> CSIV = {};
+  std::vector<CalleeSavedInfo> GCSIV = {};
+  for (auto [BB, Regs] : SRPoints) {
+    CSIV.clear();
+    for (auto &Reg : Regs) {
+      auto It = RegToInfo.find(Reg);
+      if (It == RegToInfo.end())
+        continue;
+      CalleeSavedInfo *CSI = It->second;
+      if (isSave)
+        CSI->addSpilledIn(BB);
+      else
+        CSI->addRestoredIn(BB);
+      CSIV.push_back(*RegToInfo.at(Reg));
+      GCSIV.push_back(*RegToInfo.at(Reg));
+    }
+    std::sort(CSIV.begin(), CSIV.end(),
+              [](const CalleeSavedInfo &Lhs, const CalleeSavedInfo &Rhs) {
+                return Lhs.getFrameIdx() < Rhs.getFrameIdx();
+              });
+    CSInfoPerBB.insert(std::make_pair(BB, CSIV));
+  }
+
+  if (GCSIV.size() >= RegToInfo.size())
+    return;
+
+  for (auto &RTI : RegToInfo) {
+    if (find_if(GCSIV, [&RTI](const CalleeSavedInfo &CSI) {
+          return CSI.getReg() == RTI.first;
+        }) != std::end(GCSIV))
+      continue;
+    for (auto BB : PrologEpilogBlocks) {
+      if (CSInfoPerBB.contains(BB)) {
+        CSInfoPerBB[BB].push_back(*RTI.second);
+        std::sort(CSInfoPerBB[BB].begin(), CSInfoPerBB[BB].end(),
+                  [](const CalleeSavedInfo &Lhs, const CalleeSavedInfo &Rhs) {
+                    return Lhs.getFrameIdx() < Rhs.getFrameIdx();
+                  });
----------------
cofibrant wrote:

Are you missing a `continue` here?

https://github.com/llvm/llvm-project/pull/119359


More information about the llvm-commits mailing list