[llvm] Fix issue with running the same PassManager twice (58939) (PR #92823)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 14:21:06 PDT 2024


https://github.com/modiking created https://github.com/llvm/llvm-project/pull/92823

Fix by re-initializing the moved from passmanagers in the inliner

Testing:
ninja check with new test

>From 4d6ceeb4d63df3eada3434f28c12d5191c91ccb6 Mon Sep 17 00:00:00 2001
From: modimo <modimo at fb.com>
Date: Thu, 16 May 2024 10:11:08 -0700
Subject: [PATCH] fix double pass manager run issue

---
 llvm/lib/Transforms/IPO/Inliner.cpp        |  5 +++++
 llvm/unittests/CodeGen/PassManagerTest.cpp | 24 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index a9747aebf67bb..33aeee4a0d100 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -628,6 +628,11 @@ PreservedAnalyses ModuleInlinerWrapperPass::run(Module &M,
         createDevirtSCCRepeatedPass(std::move(PM), MaxDevirtIterations)));
 
   MPM.addPass(std::move(AfterCGMPM));
+
+  // If this is run again (e.g. same PassManager invoked twice)
+  // these need to be re-initialized after being moved.
+  PM = CGSCCPassManager();
+  AfterCGMPM = ModulePassManager();
   MPM.run(M, MAM);
 
   // Discard the InlineAdvisor, a subsequent inlining session should construct
diff --git a/llvm/unittests/CodeGen/PassManagerTest.cpp b/llvm/unittests/CodeGen/PassManagerTest.cpp
index d3a410f5450cc..8905ee7e1b338 100644
--- a/llvm/unittests/CodeGen/PassManagerTest.cpp
+++ b/llvm/unittests/CodeGen/PassManagerTest.cpp
@@ -264,4 +264,28 @@ TEST_F(PassManagerTest, DiagnosticHandler) {
               std::string::npos);
 }
 
+TEST_F(PassManagerTest, RunTwice) {
+  if (!TM)
+    GTEST_SKIP();
+
+  M->setDataLayout(TM->createDataLayout());
+
+  LoopAnalysisManager LAM;
+  FunctionAnalysisManager FAM;
+  CGSCCAnalysisManager CGAM;
+  ModuleAnalysisManager MAM;
+  PassBuilder PB(TM.get());
+  PB.registerModuleAnalyses(MAM);
+  PB.registerCGSCCAnalyses(CGAM);
+  PB.registerFunctionAnalyses(FAM);
+  PB.registerLoopAnalyses(LAM);
+  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+
+  ModulePassManager MPM;
+  MPM.addPass(PB.buildPerModuleDefaultPipeline(OptimizationLevel::O2));
+
+  MPM.run(*M, MAM);
+  MPM.run(*M, MAM);
+}
+
 } // namespace



More information about the llvm-commits mailing list