[PATCH] D100013: [Greedy RA] Extract computeNumberOfSplillsReloads to use in different places. NFC.

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 6 21:25:55 PDT 2021


skatkov created this revision.
skatkov added reviewers: reames, MatzeB, anemet.
Herald added subscribers: dantrushin, hiraditya, qcolombet.
skatkov requested review of this revision.
Herald added a project: LLVM.

Extract one basic block handling to introduce stat computation for method scope.


https://reviews.llvm.org/D100013

Files:
  llvm/lib/CodeGen/RegAllocGreedy.cpp


Index: llvm/lib/CodeGen/RegAllocGreedy.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -567,6 +567,9 @@
     void report(MachineOptimizationRemarkMissed &R);
   };
 
+  /// Compute the number of spills and reloads for a basic block.
+  RAGreedyStats computeNumberOfSplillsReloads(MachineBasicBlock &MBB);
+
   /// Compute and report the number of spills and reloads for a loop.
   RAGreedyStats reportNumberOfSplillsReloads(MachineLoop *L);
 
@@ -3137,6 +3140,33 @@
     R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads ";
 }
 
+RAGreedy::RAGreedyStats
+RAGreedy::computeNumberOfSplillsReloads(MachineBasicBlock &MBB) {
+  RAGreedyStats Stats;
+  const MachineFrameInfo &MFI = MF->getFrameInfo();
+  int FI;
+
+  for (MachineInstr &MI : MBB) {
+    SmallVector<const MachineMemOperand *, 2> Accesses;
+    auto isSpillSlotAccess = [&MFI](const MachineMemOperand *A) {
+      return MFI.isSpillSlotObjectIndex(cast<FixedStackPseudoSourceValue>(
+          A->getPseudoValue())->getFrameIndex());
+    };
+
+    if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
+      ++Stats.Reloads;
+    else if (TII->hasLoadFromStackSlot(MI, Accesses) &&
+             llvm::any_of(Accesses, isSpillSlotAccess))
+      ++Stats.FoldedReloads;
+    else if (TII->isStoreToStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
+      ++Stats.Spills;
+    else if (TII->hasStoreToStackSlot(MI, Accesses) &&
+             llvm::any_of(Accesses, isSpillSlotAccess))
+      ++Stats.FoldedSpills;
+  }
+  return Stats;
+}
+
 RAGreedy::RAGreedyStats RAGreedy::reportNumberOfSplillsReloads(MachineLoop *L) {
   RAGreedyStats Stats;
 
@@ -3144,32 +3174,10 @@
   for (MachineLoop *SubLoop : *L)
     Stats.add(reportNumberOfSplillsReloads(SubLoop));
 
-  const MachineFrameInfo &MFI = MF->getFrameInfo();
-  int FI;
-
   for (MachineBasicBlock *MBB : L->getBlocks())
     // Handle blocks that were not included in subloops.
     if (Loops->getLoopFor(MBB) == L)
-      for (MachineInstr &MI : *MBB) {
-        SmallVector<const MachineMemOperand *, 2> Accesses;
-        auto isSpillSlotAccess = [&MFI](const MachineMemOperand *A) {
-          return MFI.isSpillSlotObjectIndex(
-              cast<FixedStackPseudoSourceValue>(A->getPseudoValue())
-                  ->getFrameIndex());
-        };
-
-        if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI))
-          ++Stats.Reloads;
-        else if (TII->hasLoadFromStackSlot(MI, Accesses) &&
-                 llvm::any_of(Accesses, isSpillSlotAccess))
-          ++Stats.FoldedReloads;
-        else if (TII->isStoreToStackSlot(MI, FI) &&
-                 MFI.isSpillSlotObjectIndex(FI))
-          ++Stats.Spills;
-        else if (TII->hasStoreToStackSlot(MI, Accesses) &&
-                 llvm::any_of(Accesses, isSpillSlotAccess))
-          ++Stats.FoldedSpills;
-      }
+      Stats.add(computeNumberOfSplillsReloads(*MBB));
 
   if (!Stats.isEmpty()) {
     using namespace ore;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100013.335714.patch
Type: text/x-patch
Size: 3087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210407/995d7f38/attachment.bin>


More information about the llvm-commits mailing list