[llvm] r341250 - [NFC] Pass the instruction delta to emitInstrCountChangedRemark

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


Author: paquette
Date: Fri Aug 31 13:20:57 2018
New Revision: 341250

URL: http://llvm.org/viewvc/llvm-project?rev=341250&view=rev
Log:
[NFC] Pass the instruction delta to emitInstrCountChangedRemark

Instead of counting the size of the entire module every time we run a pass,
pass along a delta instead and use that to emit the remark.

This means we only have to use (on average) smaller IR units to calculate
instruction counts. E.g, in a BB pass, we only need to look at the delta of
the BB instead of the delta of the entire module.

6/6

(This improved compile time for size remarks on sqlite3 + O2 significantly)

Modified:
    llvm/trunk/include/llvm/IR/LegacyPassManagers.h
    llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
    llvm/trunk/lib/Analysis/LoopPass.cpp
    llvm/trunk/lib/IR/LegacyPassManager.cpp

Modified: llvm/trunk/include/llvm/IR/LegacyPassManagers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LegacyPassManagers.h?rev=341250&r1=341249&r2=341250&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/LegacyPassManagers.h (original)
+++ llvm/trunk/include/llvm/IR/LegacyPassManagers.h Fri Aug 31 13:20:57 2018
@@ -410,7 +410,8 @@ public:
 
   /// Emit a remark signifying that the number of IR instructions in the module
   /// changed.
-  void emitInstrCountChangedRemark(Pass *P, Module &M, unsigned CountBefore);
+  void emitInstrCountChangedRemark(Pass *P, Module &M, int64_t Delta,
+                                   unsigned CountBefore);
 
 protected:
   // Top level manager.

Modified: llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp?rev=341250&r1=341249&r2=341250&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp (original)
+++ llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp Fri Aug 31 13:20:57 2018
@@ -124,7 +124,7 @@ bool CGPassManager::RunPassOnSCC(Pass *P
   Module &M = CG.getModule();
 
   if (!PM) {
-    CallGraphSCCPass *CGSP = (CallGraphSCCPass*)P;
+    CallGraphSCCPass *CGSP = (CallGraphSCCPass *)P;
     if (!CallGraphUpToDate) {
       DevirtualizedCall |= RefreshCallGraph(CurSCC, CG, false);
       CallGraphUpToDate = true;
@@ -140,13 +140,13 @@ bool CGPassManager::RunPassOnSCC(Pass *P
 
       if (EmitICRemark) {
         // FIXME: Add getInstructionCount to CallGraphSCC.
-        // TODO: emitInstrCountChangedRemark should take in the delta between
-        // SCCount and InstrCount.
         SCCCount = M.getInstructionCount();
         // Is there a difference in the number of instructions in the module?
         if (SCCCount != InstrCount) {
           // Yep. Emit a remark and update InstrCount.
-          emitInstrCountChangedRemark(P, M, InstrCount);
+          int64_t Delta =
+              static_cast<int64_t>(SCCCount) - static_cast<int64_t>(InstrCount);
+          emitInstrCountChangedRemark(P, M, Delta, InstrCount);
           InstrCount = SCCCount;
         }
       }

Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=341250&r1=341249&r2=341250&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Fri Aug 31 13:20:57 2018
@@ -224,9 +224,9 @@ bool LPPassManager::runOnFunction(Functi
           // 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);
+            emitInstrCountChangedRemark(P, M, Delta, InstrCount);
             InstrCount = static_cast<int64_t>(InstrCount) + Delta;
             FunctionSize = NewSize;
           }

Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=341250&r1=341249&r2=341250&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Fri Aug 31 13:20:57 2018
@@ -142,6 +142,7 @@ unsigned PMDataManager::initSizeRemarkIn
 }
 
 void PMDataManager::emitInstrCountChangedRemark(Pass *P, Module &M,
+                                                int64_t Delta,
                                                 unsigned CountBefore) {
   // We need a function containing at least one basic block in order to output
   // remarks. Since it's possible that the first function in the module doesn't
@@ -157,25 +158,13 @@ void PMDataManager::emitInstrCountChange
   // We found a function containing at least one basic block.
   Function *F = &*It;
 
-  // How many instructions are in the module now?
-  unsigned CountAfter = M.getInstructionCount();
-
-  // If there was no change, don't emit a remark.
-  if (CountBefore == CountAfter)
-    return;
-
   // If it's a pass manager, don't emit a remark. (This hinges on the assumption
   // that the only passes that return non-null with getAsPMDataManager are pass
   // managers.) The reason we have to do this is to avoid emitting remarks for
   // CGSCC passes.
   if (P->getAsPMDataManager())
     return;
-
-  // Compute a possibly negative delta between the instruction count before
-  // running P, and after running P.
-  int64_t Delta =
-      static_cast<int64_t>(CountAfter) - static_cast<int64_t>(CountBefore);
-
+  int64_t CountAfter = static_cast<int64_t>(CountBefore) + Delta;
   BasicBlock &BB = *F->begin();
   OptimizationRemarkAnalysis R("size-info", "IRSizeChange",
                                DiagnosticLocation(), &BB);
@@ -1315,9 +1304,9 @@ bool BBPassManager::runOnFunction(Functi
           // 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);
+            emitInstrCountChangedRemark(BP, M, Delta, InstrCount);
             InstrCount = static_cast<int64_t>(InstrCount) + Delta;
             BBSize = NewSize;
           }
@@ -1552,9 +1541,9 @@ bool FPPassManager::runOnFunction(Functi
         // Update the size of the function, emit a remark, and update the size
         // of the module.
         if (NewSize != FunctionSize) {
-          emitInstrCountChangedRemark(FP, M, InstrCount);
           int64_t Delta = static_cast<int64_t>(NewSize) -
                           static_cast<int64_t>(FunctionSize);
+          emitInstrCountChangedRemark(FP, M, Delta, InstrCount);
           InstrCount = static_cast<int64_t>(InstrCount) + Delta;
           FunctionSize = NewSize;
         }
@@ -1646,12 +1635,11 @@ MPPassManager::runOnModule(Module &M) {
       LocalChanged |= MP->runOnModule(M);
       if (EmitICRemark) {
         // Update the size of the module.
-        // TODO: emitInstrCountChangedRemark should take in a delta between
-        // the old count and new count. Right now, we're calculating this
-        // twice.
         ModuleCount = M.getInstructionCount();
         if (ModuleCount != InstrCount) {
-          emitInstrCountChangedRemark(MP, M, InstrCount);
+          int64_t Delta = static_cast<int64_t>(ModuleCount) -
+                          static_cast<int64_t>(InstrCount);
+          emitInstrCountChangedRemark(MP, M, Delta, InstrCount);
           ModuleCount = InstrCount;
         }
       }




More information about the llvm-commits mailing list