[llvm] r341246 - [NFC] Pre-calculate basic block IR counts in size remarks.

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 13:20:53 PDT 2018


Author: paquette
Date: Fri Aug 31 13:20:53 2018
New Revision: 341246

URL: http://llvm.org/viewvc/llvm-project?rev=341246&view=rev
Log:
[NFC] Pre-calculate basic block IR counts in size remarks.

Size remarks are slow due to lots of recalculation of the module.

This is similar to the previous commit. Cache the size of the module and
update counts in basic block passes based off a less-expensive delta.

2/6

Modified:
    llvm/trunk/lib/IR/LegacyPassManager.cpp

Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=341246&r1=341245&r2=341246&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Fri Aug 31 13:20:53 2018
@@ -1287,9 +1287,15 @@ bool BBPassManager::runOnFunction(Functi
   bool Changed = doInitialization(F);
   Module &M = *F.getParent();
 
-  unsigned InstrCount = 0;
+  unsigned InstrCount, BBSize = 0;
   bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
-  for (BasicBlock &BB : F)
+  if (EmitICRemark)
+    InstrCount = initSizeRemarkInfo(M);
+
+  for (BasicBlock &BB : F) {
+    // Collect the initial size of the basic block.
+    if (EmitICRemark)
+      BBSize = BB.size();
     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
       BasicBlockPass *BP = getContainedPass(Index);
       bool LocalChanged = false;
@@ -1303,11 +1309,19 @@ bool BBPassManager::runOnFunction(Functi
         // If the pass crashes, remember this.
         PassManagerPrettyStackEntry X(BP, BB);
         TimeRegion PassTimer(getPassTimer(BP));
-        if (EmitICRemark)
-          InstrCount = initSizeRemarkInfo(M);
         LocalChanged |= BP->runOnBasicBlock(BB);
-        if (EmitICRemark)
-          emitInstrCountChangedRemark(BP, M, InstrCount);
+        if (EmitICRemark) {
+          unsigned NewSize = BB.size();
+          // Update the size of the basic block, emit a remark, and update the
+          // size of the module.
+          if (NewSize != BBSize) {
+            emitInstrCountChangedRemark(BP, M, InstrCount);
+            int64_t Delta =
+                static_cast<int64_t>(NewSize) - static_cast<int64_t>(BBSize);
+            InstrCount = static_cast<int64_t>(InstrCount) + Delta;
+            BBSize = NewSize;
+          }
+        }
       }
 
       Changed |= LocalChanged;
@@ -1322,6 +1336,7 @@ bool BBPassManager::runOnFunction(Functi
       recordAvailableAnalysis(BP);
       removeDeadPasses(BP, BB.getName(), ON_BASICBLOCK_MSG);
     }
+  }
 
   return doFinalization(F) || Changed;
 }




More information about the llvm-commits mailing list