diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -144,6 +144,7 @@ std::vector undefined; std::vector dynamicList; std::vector buildIdVector; + std::vector PassPlugins; llvm::MapVector, uint64_t> callGraphProfile; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1252,6 +1252,10 @@ error(arg->getSpelling() + ": unknown plugin option '" + arg->getValue() + "'"); + for (auto *arg : args.filtered(OPT_load_pass_plugins)) { + config->PassPlugins.push_back(arg->getValue()); + } + // Parse -mllvm options. for (auto *arg : args.filtered(OPT_mllvm)) parseClangOption(arg->getValue(), arg->getSpelling()); diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -144,6 +144,8 @@ c.SampleProfile = std::string(config->ltoSampleProfile); c.UseNewPM = config->ltoNewPassManager; + for (auto &PluginFN : config->PassPlugins) + c.PassPlugins.push_back(PluginFN); c.DebugPassManager = config->ltoDebugPassManager; c.DwoDir = std::string(config->dwoDir); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -714,3 +714,5 @@ "Perform additional validation of the written dynamic relocations", "Do not perform additional validation of the written dynamic relocations">, Flags<[HelpHidden]>; + +defm load_pass_plugins: Eq<"load-pass-plugin", "Load passes from plugin library">; diff --git a/llvm/examples/Bye/Bye.cpp b/llvm/examples/Bye/Bye.cpp --- a/llvm/examples/Bye/Bye.cpp +++ b/llvm/examples/Bye/Bye.cpp @@ -50,6 +50,11 @@ [](const llvm::PassManagerBuilder &Builder, llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); }); +static llvm::RegisterStandardPasses RegisterByeLTO( + llvm::PassManagerBuilder::EP_ModuleOptimizerEarly, + [](const llvm::PassManagerBuilder &Builder, + llvm::legacy::PassManagerBase &PM) { PM.add(new LegacyBye()); }); + /* New PM Registration */ llvm::PassPluginLibraryInfo getByePluginInfo() { return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING, diff --git a/llvm/test/Feature/load_extension.ll b/llvm/test/Feature/load_extension.ll --- a/llvm/test/Feature/load_extension.ll +++ b/llvm/test/Feature/load_extension.ll @@ -5,6 +5,8 @@ ; RUN: llvm-lto2 run %t.o %loadbye -wave-goodbye -use-new-pm=0 -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s ; RUN: llvm-lto2 run %t.o %loadbye %loadnewpmbye -wave-goodbye -use-new-pm -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s ; RUN: llvm-lto2 run %t.o %loadbye %loadnewpmbye -opt-pipeline="goodbye" -wave-goodbye -use-new-pm -o %t -r %t.o,somefunk,plx -r %t.o,junk,plx 2>&1 | FileCheck %s +; RUN: ld.lld -%loadnewpmbye --lto-newpm-passes="goodbye" -mllvm=%loadbye -mllvm=-wave-goodbye %t.o 2>&1 | FileCheck %s +; RUN: ld.lld -mllvm=%loadbye -mllvm=-wave-goodbye -plugin-opt=legacy-pass-manager %t.o 2>&1 | FileCheck %s ; REQUIRES: plugins, examples ; UNSUPPORTED: windows ; CHECK: Bye