[llvm] 904e8f9 - [PassManager] Reuse StackTraceEntry across passes (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 07:00:35 PDT 2024


Author: Nikita Popov
Date: 2024-07-02T16:00:22+02:00
New Revision: 904e8f936495207cbb36a52fb8ca8183b44d6838

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

LOG: [PassManager] Reuse StackTraceEntry across passes (NFC)

As suggested by aengelke, create the stack frame before the loop
and only update the pass inside it. This reduces the overhead
of repeatedly registering and unregistering the stack frames.

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassManagerImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PassManagerImpl.h b/llvm/include/llvm/IR/PassManagerImpl.h
index 78877199e614f..67e3fbe4f3068 100644
--- a/llvm/include/llvm/IR/PassManagerImpl.h
+++ b/llvm/include/llvm/IR/PassManagerImpl.h
@@ -30,20 +30,24 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
     IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs) {
   class StackTraceEntry : public PrettyStackTraceEntry {
     const PassInstrumentation &PI;
-    PassConceptT &Pass;
     IRUnitT &IR;
+    PassConceptT *Pass = nullptr;
 
   public:
-    explicit StackTraceEntry(const PassInstrumentation &PI, PassConceptT &Pass,
-                             IRUnitT &IR)
-        : PI(PI), Pass(Pass), IR(IR) {}
+    explicit StackTraceEntry(const PassInstrumentation &PI, IRUnitT &IR)
+        : PI(PI), IR(IR) {}
+
+    void setPass(PassConceptT *P) { Pass = P; }
 
     void print(raw_ostream &OS) const override {
       OS << "Running pass \"";
-      Pass.printPipeline(OS, [this](StringRef ClassName) {
-        auto PassName = PI.getPassNameForClassName(ClassName);
-        return PassName.empty() ? ClassName : PassName;
-      });
+      if (Pass)
+        Pass->printPipeline(OS, [this](StringRef ClassName) {
+          auto PassName = PI.getPassNameForClassName(ClassName);
+          return PassName.empty() ? ClassName : PassName;
+        });
+      else
+        OS << "unknown";
       OS << "\" on ";
       printIRUnitNameForStackTrace(OS, IR);
       OS << "\n";
@@ -64,14 +68,16 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
   // for duration of these passes.
   ScopedDbgInfoFormatSetter FormatSetter(IR, UseNewDbgInfoFormat);
 
+  StackTraceEntry Entry(PI, IR);
   for (auto &Pass : Passes) {
+    Entry.setPass(&*Pass);
+
     // Check the PassInstrumentation's BeforePass callbacks before running the
     // pass, skip its execution completely if asked to (callback returns
     // false).
     if (!PI.runBeforePass<IRUnitT>(*Pass, IR))
       continue;
 
-    StackTraceEntry Entry(PI, *Pass, IR);
     PreservedAnalyses PassPA = Pass->run(IR, AM, ExtraArgs...);
 
     // Update the analysis manager as each pass runs and potentially


        


More information about the llvm-commits mailing list