[llvm] 5e8700c - Load pass plugins during option processing, so that plugin options are registered and live.
Wael Yehia via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 05:44:03 PDT 2022
Author: Wael Yehia
Date: 2022-03-15T12:43:49Z
New Revision: 5e8700ce8bf58bdf0a59eef99c85185a74177555
URL: https://github.com/llvm/llvm-project/commit/5e8700ce8bf58bdf0a59eef99c85185a74177555
DIFF: https://github.com/llvm/llvm-project/commit/5e8700ce8bf58bdf0a59eef99c85185a74177555.diff
LOG: Load pass plugins during option processing, so that plugin options are registered and live.
Added:
Modified:
llvm/test/Feature/load_extension.ll
llvm/tools/opt/NewPMDriver.cpp
llvm/tools/opt/NewPMDriver.h
llvm/tools/opt/opt.cpp
Removed:
################################################################################
diff --git a/llvm/test/Feature/load_extension.ll b/llvm/test/Feature/load_extension.ll
index 2e1080ceaf97c..18f6775fbb4a1 100644
--- a/llvm/test/Feature/load_extension.ll
+++ b/llvm/test/Feature/load_extension.ll
@@ -1,6 +1,7 @@
; REQUIRES: x86-registered-target
; RUN: opt %s %loadbye -goodbye -wave-goodbye -disable-output -enable-new-pm=0 2>&1 | FileCheck %s
; RUN: opt %s %loadnewpmbye %loadbye -passes="goodbye" -wave-goodbye -disable-output 2>&1 | FileCheck %s
+; RUN: opt %s %loadnewpmbye -passes="goodbye" -wave-goodbye -disable-output 2>&1 | FileCheck %s
; RUN: opt -module-summary %s -o %t.o
; 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
@@ -17,3 +18,6 @@ define i32* @somefunk() {
ret i32* @junk
}
+; Specifying a new PM pass plugin with the old PM is an error.
+; RUN: ! opt %s %loadnewpmbye -goodbye -wave-goodbye -disable-output -enable-new-pm=0 2>&1 | FileCheck %s --check-prefix=ERROR
+; ERROR: load-pass-plugin specified with legacy PM.
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index d6ddad437983a..8bcd8ff2efd30 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -66,10 +66,6 @@ static cl::opt<DebugLogging> DebugPM(
DebugLogging::Verbose, "verbose",
"Print extra information about adaptors and pass managers")));
-static cl::list<std::string>
- PassPlugins("load-pass-plugin",
- cl::desc("Load passes from plugin library"));
-
// This flag specifies a textual description of the alias analysis pipeline to
// use when querying for aliasing information. It only works in concert with
// the "passes" flag above.
@@ -269,6 +265,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
ToolOutputFile *ThinLTOLinkOut,
ToolOutputFile *OptRemarkFile,
StringRef PassPipeline, ArrayRef<StringRef> Passes,
+ ArrayRef<PassPlugin> PassPlugins,
OutputKind OK, VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder,
@@ -341,17 +338,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
PassBuilder PB(TM, PTO, P, &PIC);
registerEPCallbacks(PB);
- // Load requested pass plugins and let them register pass builder callbacks
- for (auto &PluginFN : PassPlugins) {
- auto PassPlugin = PassPlugin::Load(PluginFN);
- if (!PassPlugin) {
- errs() << "Failed to load passes from '" << PluginFN
- << "'. Request ignored.\n";
- continue;
- }
-
- PassPlugin->registerPassBuilderCallbacks(PB);
- }
+ // For any loaded plugins, let them register pass builder callbacks.
+ for (auto &PassPlugin : PassPlugins)
+ PassPlugin.registerPassBuilderCallbacks(PB);
PB.registerPipelineParsingCallback(
[](StringRef Name, ModulePassManager &MPM,
diff --git a/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h
index 056f7d6a9b80b..40f40a0bc8c1f 100644
--- a/llvm/tools/opt/NewPMDriver.h
+++ b/llvm/tools/opt/NewPMDriver.h
@@ -26,6 +26,7 @@
namespace llvm {
class StringRef;
class Module;
+class PassPlugin;
class TargetMachine;
class ToolOutputFile;
class TargetLibraryInfoImpl;
@@ -69,7 +70,8 @@ bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
TargetLibraryInfoImpl *TLII, ToolOutputFile *Out,
ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile,
StringRef PassPipeline, ArrayRef<StringRef> PassInfos,
- opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
+ ArrayRef<PassPlugin> PassPlugins, opt_tool::OutputKind OK,
+ opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder,
bool EmitSummaryIndex, bool EmitModuleHash,
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index da5e582e06954..347a4b72f2f2e 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -39,6 +39,7 @@
#include "llvm/LinkAllPasses.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Passes/PassPlugin.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
@@ -300,6 +301,10 @@ static cl::opt<std::string> RemarksFormat(
cl::desc("The format used for serializing remarks (default: YAML)"),
cl::value_desc("format"), cl::init("yaml"));
+static cl::list<std::string>
+ PassPlugins("load-pass-plugin",
+ cl::desc("Load passes from plugin library"));
+
namespace llvm {
cl::opt<PGOKind>
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
@@ -581,6 +586,17 @@ int main(int argc, char **argv) {
initializeExampleIRTransforms(Registry);
#endif
+ SmallVector<PassPlugin, 1> PluginList;
+ PassPlugins.setCallback([&](const std::string &PluginPath) {
+ auto Plugin = PassPlugin::Load(PluginPath);
+ if (!Plugin) {
+ errs() << "Failed to load passes from '" << PluginPath
+ << "'. Request ignored.\n";
+ return;
+ }
+ PluginList.emplace_back(Plugin.get());
+ });
+
cl::ParseCommandLineOptions(argc, argv,
"llvm .bc -> .bc modular optimizer and analysis printer\n");
@@ -591,6 +607,19 @@ int main(int argc, char **argv) {
return 1;
}
+ // If `-passes=` is specified, use NPM.
+ // If `-enable-new-pm` is specified and there are no codegen passes, use NPM.
+ // e.g. `-enable-new-pm -sroa` will use NPM.
+ // but `-enable-new-pm -codegenprepare` will still revert to legacy PM.
+ const bool UseNPM = (EnableNewPassManager && !shouldForceLegacyPM()) ||
+ PassPipeline.getNumOccurrences() > 0;
+
+ if (!UseNPM && PluginList.size()) {
+ errs() << argv[0] << ": " << PassPlugins.ArgStr
+ << " specified with legacy PM.\n";
+ return 1;
+ }
+
// FIXME: once the legacy PM code is deleted, move runPassPipeline() here and
// construct the PassBuilder before parsing IR so we can reuse the same
// PassBuilder for print passes.
@@ -752,12 +781,7 @@ int main(int argc, char **argv) {
}
}
- // If `-passes=` is specified, use NPM.
- // If `-enable-new-pm` is specified and there are no codegen passes, use NPM.
- // e.g. `-enable-new-pm -sroa` will use NPM.
- // but `-enable-new-pm -codegenprepare` will still revert to legacy PM.
- if ((EnableNewPassManager && !shouldForceLegacyPM()) ||
- PassPipeline.getNumOccurrences() > 0) {
+ if (UseNPM) {
if (AnalyzeOnly) {
errs() << "Cannot specify -analyze under new pass manager, either "
"specify '-enable-new-pm=0', or use the corresponding new pass "
@@ -821,7 +845,7 @@ int main(int argc, char **argv) {
// layer.
return runPassPipeline(argv[0], *M, TM.get(), &TLII, Out.get(),
ThinLinkOut.get(), RemarksFile.get(), Pipeline,
- Passes, OK, VK, PreserveAssemblyUseListOrder,
+ Passes, PluginList, OK, VK, PreserveAssemblyUseListOrder,
PreserveBitcodeUseListOrder, EmitSummaryIndex,
EmitModuleHash, EnableDebugify)
? 0
More information about the llvm-commits
mailing list