[llvm] r337654 - [ORE] Move loop invariant ORE checks outside the PM loop.

Xin Tong via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 21 22:27:41 PDT 2018


Author: trentxintong
Date: Sat Jul 21 22:27:41 2018
New Revision: 337654

URL: http://llvm.org/viewvc/llvm-project?rev=337654&view=rev
Log:
[ORE] Move loop invariant ORE checks outside the PM loop.

Summary:
This takes 22ms out of ~20s compiling sqlite3.c because we call it
for every unit of compilation and every pass.

Reviewers: paquette, anemet

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D49586

Modified:
    llvm/trunk/include/llvm/IR/Module.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/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=337654&r1=337653&r2=337654&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Module.h (original)
+++ llvm/trunk/include/llvm/IR/Module.h Sat Jul 21 22:27:41 2018
@@ -256,9 +256,16 @@ public:
   /// versions when the pass does not change.
   std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
 
-/// @}
-/// @name Module Level Mutators
-/// @{
+  /// Return true if size-info optimization remark is enabled, false
+  /// otherwise.
+  bool shouldEmitInstrCountChangedRemark() {
+    return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
+        "size-info");
+  }
+
+  /// @}
+  /// @name Module Level Mutators
+  /// @{
 
   /// Set the module identifier.
   void setModuleIdentifier(StringRef ID) { ModuleID = ID; }

Modified: llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp?rev=337654&r1=337653&r2=337654&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp (original)
+++ llvm/trunk/lib/Analysis/CallGraphSCCPass.cpp Sat Jul 21 22:27:41 2018
@@ -130,13 +130,17 @@ bool CGPassManager::RunPassOnSCC(Pass *P
     }
 
     {
+      unsigned InstrCount = 0;
+      bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
       TimeRegion PassTimer(getPassTimer(CGSP));
-      unsigned InstrCount = initSizeRemarkInfo(M);
+      if (EmitICRemark)
+        InstrCount = initSizeRemarkInfo(M);
       Changed = CGSP->runOnSCC(CurSCC);
 
       // If the pass modified the module, it may have modified the instruction
       // count of the module. Try emitting a remark.
-      emitInstrCountChangedRemark(P, M, InstrCount);
+      if (EmitICRemark)
+        emitInstrCountChangedRemark(P, M, InstrCount);
     }
     
     // After the CGSCCPass is done, when assertions are enabled, use

Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=337654&r1=337653&r2=337654&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Sat Jul 21 22:27:41 2018
@@ -193,6 +193,8 @@ bool LPPassManager::runOnFunction(Functi
   }
 
   // Walk Loops
+  unsigned InstrCount = 0;
+  bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
   while (!LQ.empty()) {
     CurrentLoopDeleted = false;
     CurrentLoop = LQ.back();
@@ -210,9 +212,11 @@ bool LPPassManager::runOnFunction(Functi
       {
         PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
         TimeRegion PassTimer(getPassTimer(P));
-        unsigned InstrCount = initSizeRemarkInfo(M);
+        if (EmitICRemark)
+          InstrCount = initSizeRemarkInfo(M);
         Changed |= P->runOnLoop(CurrentLoop, *this);
-        emitInstrCountChangedRemark(P, M, InstrCount);
+        if (EmitICRemark)
+          emitInstrCountChangedRemark(P, M, InstrCount);
       }
 
       if (Changed)

Modified: llvm/trunk/lib/IR/LegacyPassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LegacyPassManager.cpp?rev=337654&r1=337653&r2=337654&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LegacyPassManager.cpp (original)
+++ llvm/trunk/lib/IR/LegacyPassManager.cpp Sat Jul 21 22:27:41 2018
@@ -137,17 +137,11 @@ bool PMDataManager::isPassDebuggingExecu
 
 unsigned PMDataManager::initSizeRemarkInfo(Module &M) {
   // Only calculate getInstructionCount if the size-info remark is requested.
-  if (M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
-    return M.getInstructionCount();
-  return 0;
+  return M.getInstructionCount();
 }
 
 void PMDataManager::emitInstrCountChangedRemark(Pass *P, Module &M,
                                                 unsigned CountBefore) {
-  // Did the user request the remark? If not, quit.
-  if (!M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
-    return;
-
   // 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
   // actually contain a basic block, we have to go and find one that's suitable
@@ -1349,6 +1343,8 @@ bool BBPassManager::runOnFunction(Functi
   bool Changed = doInitialization(F);
   Module &M = *F.getParent();
 
+  unsigned InstrCount = 0;
+  bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
   for (BasicBlock &BB : F)
     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
       BasicBlockPass *BP = getContainedPass(Index);
@@ -1363,9 +1359,11 @@ bool BBPassManager::runOnFunction(Functi
         // If the pass crashes, remember this.
         PassManagerPrettyStackEntry X(BP, BB);
         TimeRegion PassTimer(getPassTimer(BP));
-        unsigned InstrCount = initSizeRemarkInfo(M);
+        if (EmitICRemark)
+          InstrCount = initSizeRemarkInfo(M);
         LocalChanged |= BP->runOnBasicBlock(BB);
-        emitInstrCountChangedRemark(BP, M, InstrCount);
+        if (EmitICRemark)
+          emitInstrCountChangedRemark(BP, M, InstrCount);
       }
 
       Changed |= LocalChanged;
@@ -1569,6 +1567,8 @@ bool FPPassManager::runOnFunction(Functi
   // Collect inherited analysis from Module level pass manager.
   populateInheritedAnalysis(TPM->activeStack);
 
+  unsigned InstrCount = 0;
+  bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
     FunctionPass *FP = getContainedPass(Index);
     bool LocalChanged = false;
@@ -1581,9 +1581,11 @@ bool FPPassManager::runOnFunction(Functi
     {
       PassManagerPrettyStackEntry X(FP, F);
       TimeRegion PassTimer(getPassTimer(FP));
-      unsigned InstrCount = initSizeRemarkInfo(M);
+      if (EmitICRemark)
+        InstrCount = initSizeRemarkInfo(M);
       LocalChanged |= FP->runOnFunction(F);
-      emitInstrCountChangedRemark(FP, M, InstrCount);
+      if (EmitICRemark)
+        emitInstrCountChangedRemark(FP, M, InstrCount);
     }
 
     Changed |= LocalChanged;
@@ -1647,6 +1649,8 @@ MPPassManager::runOnModule(Module &M) {
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
     Changed |= getContainedPass(Index)->doInitialization(M);
 
+  unsigned InstrCount = 0;
+  bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
     ModulePass *MP = getContainedPass(Index);
     bool LocalChanged = false;
@@ -1660,9 +1664,11 @@ MPPassManager::runOnModule(Module &M) {
       PassManagerPrettyStackEntry X(MP, M);
       TimeRegion PassTimer(getPassTimer(MP));
 
-      unsigned InstrCount = initSizeRemarkInfo(M);
+      if (EmitICRemark)
+        InstrCount = initSizeRemarkInfo(M);
       LocalChanged |= MP->runOnModule(M);
-      emitInstrCountChangedRemark(MP, M, InstrCount);
+      if (EmitICRemark)
+        emitInstrCountChangedRemark(MP, M, InstrCount);
     }
 
     Changed |= LocalChanged;




More information about the llvm-commits mailing list