我要评分
获取效率
正确性
完整性
易理解

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());
                });
          }};
}