[llvm] fc7604a - Instantiate fewer templates in PassManager::addPass()

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 09:48:12 PDT 2021


Author: Arthur Eubanks
Date: 2021-09-30T09:47:59-07:00
New Revision: fc7604a2c0791d81ca097e935d19784b80bd016d

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

LOG: Instantiate fewer templates in PassManager::addPass()

We create many instantiations of PassManager::addPass() in
PassBuilder.cpp.  vector::emplace_back() and make_unique() are both
templated and would have many instantiations based on the number of
times we instantiate addPass().  Now we directly construct the
unique_ptr with the type as the actual unique_ptr type in the vector we
are adding it to, so we only have one unique_ptr constructor
instantiation across all addPass() instantiations and only the
non-templated push_back().

This makes PassBuilder.cpp slightly faster to build.

Reviewed By: rnk

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassManager.h
    llvm/include/llvm/Transforms/Scalar/LoopPassManager.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 7e429177ebc4e..29f2494bb5548 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -554,7 +554,10 @@ class PassManager : public PassInfoMixin<
         detail::PassModel<IRUnitT, PassT, PreservedAnalyses, AnalysisManagerT,
                           ExtraArgTs...>;
 
-    Passes.emplace_back(new PassModelT(std::forward<PassT>(Pass)));
+    // Do not use make_unique or emplace_back, they cause too many template
+    // instantiations, causing terrible compile times.
+    Passes.push_back(std::unique_ptr<PassConceptT>(
+        new PassModelT(std::forward<PassT>(Pass))));
   }
 
   /// When adding a pass manager pass that has the same type as this pass
@@ -566,7 +569,7 @@ class PassManager : public PassInfoMixin<
   std::enable_if_t<std::is_same<PassT, PassManager>::value>
   addPass(PassT &&Pass) {
     for (auto &P : Pass.Passes)
-      Passes.emplace_back(std::move(P));
+      Passes.push_back(std::move(P));
   }
 
   /// Returns if the pass manager contains any passes.

diff  --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index 26b095e1b1a5e..ad72d28d48716 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -109,7 +109,10 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
         detail::PassModel<Loop, PassT, PreservedAnalyses, LoopAnalysisManager,
                           LoopStandardAnalysisResults &, LPMUpdater &>;
     IsLoopNestPass.push_back(false);
-    LoopPasses.emplace_back(new LoopPassModelT(std::forward<PassT>(Pass)));
+    // Do not use make_unique or emplace_back, they cause too many template
+    // instantiations, causing terrible compile times.
+    LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
+        new LoopPassModelT(std::forward<PassT>(Pass))));
   }
 
   template <typename PassT>
@@ -120,8 +123,8 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LPMUpdater &>;
     IsLoopNestPass.push_back(true);
-    LoopNestPasses.emplace_back(
-        new LoopNestPassModelT(std::forward<PassT>(Pass)));
+    LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
+        new LoopNestPassModelT(std::forward<PassT>(Pass))));
   }
 
   // Specializations of `addPass` for `RepeatedPass`. These are necessary since
@@ -135,7 +138,8 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LPMUpdater &>;
     IsLoopNestPass.push_back(false);
-    LoopPasses.emplace_back(new RepeatedLoopPassModelT(std::move(Pass)));
+    LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
+        new RepeatedLoopPassModelT(std::move(Pass))));
   }
 
   template <typename PassT>
@@ -146,8 +150,8 @@ class PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LoopAnalysisManager, LoopStandardAnalysisResults &,
                           LPMUpdater &>;
     IsLoopNestPass.push_back(true);
-    LoopNestPasses.emplace_back(
-        new RepeatedLoopNestPassModelT(std::move(Pass)));
+    LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
+        new RepeatedLoopNestPassModelT(std::move(Pass))));
   }
 
   bool isEmpty() const { return LoopPasses.empty() && LoopNestPasses.empty(); }


        


More information about the llvm-commits mailing list