[llvm] r341247 - [NFC] Pre-calculate loop IR counts in size remarks.

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


Author: paquette
Date: Fri Aug 31 13:20:54 2018
New Revision: 341247

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

Another commit reducing compile time in size remarks.

Cache the size of the module and loop, and update values based
off of deltas instead. Avoid recalculating the size of the
whole module whenever possible.

3/6

Modified:
    llvm/trunk/lib/Analysis/LoopPass.cpp

Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=341247&r1=341246&r2=341247&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Fri Aug 31 13:20:54 2018
@@ -194,8 +194,13 @@ bool LPPassManager::runOnFunction(Functi
   }
 
   // Walk Loops
-  unsigned InstrCount = 0;
+  unsigned InstrCount, FunctionSize = 0;
   bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
+  // Collect the initial size of the module and the function we're looking at.
+  if (EmitICRemark) {
+    InstrCount = initSizeRemarkInfo(M);
+    FunctionSize = F.getInstructionCount();
+  }
   while (!LQ.empty()) {
     CurrentLoopDeleted = false;
     CurrentLoop = LQ.back();
@@ -213,11 +218,19 @@ bool LPPassManager::runOnFunction(Functi
       {
         PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
         TimeRegion PassTimer(getPassTimer(P));
-        if (EmitICRemark)
-          InstrCount = initSizeRemarkInfo(M);
         Changed |= P->runOnLoop(CurrentLoop, *this);
-        if (EmitICRemark)
-          emitInstrCountChangedRemark(P, M, InstrCount);
+        if (EmitICRemark) {
+          unsigned NewSize = F.getInstructionCount();
+          // Update the size of the function, emit a remark, and update the
+          // size of the module.
+          if (NewSize != FunctionSize) {
+            emitInstrCountChangedRemark(P, M, InstrCount);
+            int64_t Delta = static_cast<int64_t>(NewSize) -
+                            static_cast<int64_t>(FunctionSize);
+            InstrCount = static_cast<int64_t>(InstrCount) + Delta;
+            FunctionSize = NewSize;
+          }
+        }
       }
 
       if (Changed)




More information about the llvm-commits mailing list