[llvm] [Kaleidoscope] Switch to the new PassManager. (PR #69032)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 14:41:33 PST 2023


aemerson wrote:

I reverted this because it was breaking the expensive checks bot: https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/26026/

I know it's been a while but it's only just come to our attention as it was probably failing for a different reason as well, and since this is just the examples I'd like to revert to green.

I tried a quick go at fixing it but the only way I could get one to work was to do this:

```
diff --git a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
index 19ec70efd5e1..81f58d4f023c 100644
--- a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -426,8 +426,10 @@ static std::unique_ptr<IRBuilder<>> Builder;
 static std::map<std::string, Value *> NamedValues;
 static std::unique_ptr<KaleidoscopeJIT> TheJIT;
 static std::unique_ptr<FunctionPassManager> TheFPM;
+static std::unique_ptr<LoopAnalysisManager> TheLAM;
 static std::unique_ptr<FunctionAnalysisManager> TheFAM;
 static std::unique_ptr<ModuleAnalysisManager> TheMAM;
+static std::unique_ptr<CGSCCAnalysisManager> TheCGAM;
 static std::unique_ptr<PassInstrumentationCallbacks> ThePIC;
 static std::unique_ptr<StandardInstrumentations> TheSI;
 static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos;
@@ -575,8 +577,10 @@ static void InitializeModuleAndManagers() {
 
   // Create new pass and analysis managers.
   TheFPM = std::make_unique<FunctionPassManager>();
+  TheLAM = std::make_unique<LoopAnalysisManager>();
   TheFAM = std::make_unique<FunctionAnalysisManager>();
   TheMAM = std::make_unique<ModuleAnalysisManager>();
+  TheCGAM = std::make_unique<CGSCCAnalysisManager>();
   ThePIC = std::make_unique<PassInstrumentationCallbacks>();
   TheSI = std::make_unique<StandardInstrumentations>(*TheContext,
                                                      /*DebugLogging*/ true);
@@ -592,23 +596,11 @@ static void InitializeModuleAndManagers() {
   // Simplify the control flow graph (deleting unreachable blocks, etc).
   TheFPM->addPass(SimplifyCFGPass());
 
+  PassBuilder PB;
   // Register analysis passes used in these transform passes.
-  TheFAM->registerPass([&] { return AAManager(); });
-  TheFAM->registerPass([&] { return AssumptionAnalysis(); });
-  TheFAM->registerPass([&] { return DominatorTreeAnalysis(); });
-  TheFAM->registerPass([&] { return LoopAnalysis(); });
-  TheFAM->registerPass([&] { return MemoryDependenceAnalysis(); });
-  TheFAM->registerPass([&] { return MemorySSAAnalysis(); });
-  TheFAM->registerPass([&] { return OptimizationRemarkEmitterAnalysis(); });
-  TheFAM->registerPass([&] {
-    return OuterAnalysisManagerProxy<ModuleAnalysisManager, Function>(*TheMAM);
-  });
-  TheFAM->registerPass(
-      [&] { return PassInstrumentationAnalysis(ThePIC.get()); });
-  TheFAM->registerPass([&] { return TargetIRAnalysis(); });
-  TheFAM->registerPass([&] { return TargetLibraryAnalysis(); });
-
-  TheMAM->registerPass([&] { return ProfileSummaryAnalysis(); });
+  PB.registerModuleAnalyses(*TheMAM);
+  PB.registerFunctionAnalyses(*TheFAM);
+  PB.crossRegisterProxies(*TheLAM, *TheFAM, *TheCGAM, *TheMAM);
 }
 
 static void HandleDefinition() {
```

but I'm not sure what the right solution is.

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


More information about the llvm-commits mailing list