Registering passes on a module

Hi all,

I’m trying to build passes with the PassBuilder to optimize the result of MCJIT (I assume, this is a requirement for performance).

So I do this:
llvm::PassBuilder passBuilder;
llvm::ModulePassManager modulePassManager = passBuilder.buildPerModuleDefaultPipeline(llvm::PassBuilder::OptimizationLevel::O3);
llvm::ModuleAnalysisManager moduleAnalysisManager;
passBuilder.registerModuleAnalyses(moduleAnalysisManager);
modulePassManager.run(*module, moduleAnalysisManager);

with module being a pointer to an LLVM module.
Unfortunately, the moduleAnalysisManager has only the module passes, but not the function ones that are wrapped with the proxy class. Is there anything I missed or a up-to-date tutorial on this?
I couldn’t find an answer on Stackoverflow (where a similar question was asked).

Cheers,

Matthieu

Hi Matthieu,

You need to set up the different types of AnalysisManagers as well, just as you did with ModuleAM. Then, you need to cross register them with each other by calling passBuilder.crossRegisterProxies.

Cheers,

Philip

Thanks a lot!
It seems that there is only one piece of code describing this online, and it’s part of clang!

Cheers,

Matthieu

You can also look at how opt sets up the pipeline: https://github.com/llvm-mirror/llvm/blob/master/tools/opt/NewPMDriver.cpp#L257

Cheers,
Philip