[llvm] f6e3b4f - [GreedyRA ORE] Re-factor computeNumberOfSplillsReloads.

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 22:57:35 PDT 2021


Author: Serguei Katkov
Date: 2021-04-09T12:44:11+07:00
New Revision: f6e3b4fe582f0598ad3b594ad915431dfb87bf66

URL: https://github.com/llvm/llvm-project/commit/f6e3b4fe582f0598ad3b594ad915431dfb87bf66
DIFF: https://github.com/llvm/llvm-project/commit/f6e3b4fe582f0598ad3b594ad915431dfb87bf66.diff

LOG: [GreedyRA ORE] Re-factor computeNumberOfSplillsReloads.

Replace if-else to if-continue usage.
This simplifies further extension of the collected stats.

Added: 
    

Modified: 
    llvm/lib/CodeGen/RegAllocGreedy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 26ea0166be3e..295483fe4627 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -3146,23 +3146,31 @@ RAGreedy::computeNumberOfSplillsReloads(MachineBasicBlock &MBB) {
   const MachineFrameInfo &MFI = MF->getFrameInfo();
   int FI;
 
+  auto isSpillSlotAccess = [&MFI](const MachineMemOperand *A) {
+    return MFI.isSpillSlotObjectIndex(cast<FixedStackPseudoSourceValue>(
+        A->getPseudoValue())->getFrameIndex());
+  };
   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))
+    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))
+      continue;
+    }
+    if (TII->isStoreToStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI)) {
       ++Stats.Spills;
-    else if (TII->hasStoreToStackSlot(MI, Accesses) &&
-             llvm::any_of(Accesses, isSpillSlotAccess))
+      continue;
+    }
+    if (TII->hasLoadFromStackSlot(MI, Accesses) &&
+        llvm::any_of(Accesses, isSpillSlotAccess)) {
+      ++Stats.FoldedReloads;
+      continue;
+    }
+    Accesses.clear();
+    if (TII->hasStoreToStackSlot(MI, Accesses) &&
+        llvm::any_of(Accesses, isSpillSlotAccess)) {
       ++Stats.FoldedSpills;
+    }
   }
   return Stats;
 }


        


More information about the llvm-commits mailing list