Dynamically Registering a Pass in PassBuilder
Call registerVectorizerStartEPCallback and PM.addPass, and replace the pass in PM.addPass() with the pass implemented by yourself. Then, you can add an instance of the implemented pass to FunctionPassManager. In this way, the dynamic registration is successful.
1 2 3 4 5 6 7 8 9 10 | extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo() { return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING, [](PassBuilder &PB) { PB.registerVectorizerStartEPCallback( [](llvm::FunctionPassManager &PM, OptimizationLevel Level) { PM.addPass(Bye()); }); }}; } |
Parent topic: Using Custom Passes in BiSheng Compiler