[llvm] Fix issue with running the same PassManager twice (https://github.com/llvm/llvm-project/issues/58939) (PR #92823)

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (modiking)

<details>
<summary>Changes</summary>

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

Testing:
ninja check with new test

---
Full diff: https://github.com/llvm/llvm-project/pull/92823.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/IPO/Inliner.cpp (+5) 
- (modified) llvm/unittests/CodeGen/PassManagerTest.cpp (+24) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list