Skip to content

Commit c80198b

Browse files
author
Wael Yehia
committed
Reland "Load pass plugins during option processing, so that plugin options are registered and live."
Fix Polly failures. Reviewed By: mehdi_amini, Meinersbur Differential Revision: https://reviews.llvm.org/D121566
1 parent aee3684 commit c80198b

33 files changed

+91
-74
lines changed

llvm/test/Feature/load_extension.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
; REQUIRES: x86-registered-target
22
; RUN: opt %s %loadbye -goodbye -wave-goodbye -disable-output -enable-new-pm=0 2>&1 | FileCheck %s
33
; RUN: opt %s %loadnewpmbye %loadbye -passes="goodbye" -wave-goodbye -disable-output 2>&1 | FileCheck %s
4+
; RUN: opt %s %loadnewpmbye -passes="goodbye" -wave-goodbye -disable-output 2>&1 | FileCheck %s
45
; RUN: opt -module-summary %s -o %t.o
56
; 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
67
; 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
78
; 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
89
; REQUIRES: plugins, examples
910
; UNSUPPORTED: windows
1011
; CHECK: Bye
12+
;
13+
; Specifying a new PM pass plugin with the old PM is an error.
14+
; RUN: ! opt %s %loadnewpmbye -goodbye -wave-goodbye -disable-output -enable-new-pm=0 2>&1 | FileCheck %s --check-prefix=ERROR
15+
; ERROR: load-pass-plugin specified with legacy PM.
1116

1217
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1318
target triple = "x86_64-unknown-linux-gnu"

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ static cl::opt<DebugLogging> DebugPM(
6666
DebugLogging::Verbose, "verbose",
6767
"Print extra information about adaptors and pass managers")));
6868

69-
static cl::list<std::string>
70-
PassPlugins("load-pass-plugin",
71-
cl::desc("Load passes from plugin library"));
72-
7369
// This flag specifies a textual description of the alias analysis pipeline to
7470
// use when querying for aliasing information. It only works in concert with
7571
// the "passes" flag above.
@@ -269,6 +265,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
269265
ToolOutputFile *ThinLTOLinkOut,
270266
ToolOutputFile *OptRemarkFile,
271267
StringRef PassPipeline, ArrayRef<StringRef> Passes,
268+
ArrayRef<PassPlugin> PassPlugins,
272269
OutputKind OK, VerifierKind VK,
273270
bool ShouldPreserveAssemblyUseListOrder,
274271
bool ShouldPreserveBitcodeUseListOrder,
@@ -341,17 +338,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
341338
PassBuilder PB(TM, PTO, P, &PIC);
342339
registerEPCallbacks(PB);
343340

344-
// Load requested pass plugins and let them register pass builder callbacks
345-
for (auto &PluginFN : PassPlugins) {
346-
auto PassPlugin = PassPlugin::Load(PluginFN);
347-
if (!PassPlugin) {
348-
errs() << "Failed to load passes from '" << PluginFN
349-
<< "'. Request ignored.\n";
350-
continue;
351-
}
352-
353-
PassPlugin->registerPassBuilderCallbacks(PB);
354-
}
341+
// For any loaded plugins, let them register pass builder callbacks.
342+
for (auto &PassPlugin : PassPlugins)
343+
PassPlugin.registerPassBuilderCallbacks(PB);
355344

356345
PB.registerPipelineParsingCallback(
357346
[](StringRef Name, ModulePassManager &MPM,

llvm/tools/opt/NewPMDriver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace llvm {
2727
class StringRef;
2828
class Module;
29+
class PassPlugin;
2930
class TargetMachine;
3031
class ToolOutputFile;
3132
class TargetLibraryInfoImpl;
@@ -69,7 +70,8 @@ bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
6970
TargetLibraryInfoImpl *TLII, ToolOutputFile *Out,
7071
ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile,
7172
StringRef PassPipeline, ArrayRef<StringRef> PassInfos,
72-
opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
73+
ArrayRef<PassPlugin> PassPlugins, opt_tool::OutputKind OK,
74+
opt_tool::VerifierKind VK,
7375
bool ShouldPreserveAssemblyUseListOrder,
7476
bool ShouldPreserveBitcodeUseListOrder,
7577
bool EmitSummaryIndex, bool EmitModuleHash,

llvm/tools/opt/opt.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/LinkAllPasses.h"
4040
#include "llvm/MC/SubtargetFeature.h"
4141
#include "llvm/MC/TargetRegistry.h"
42+
#include "llvm/Passes/PassPlugin.h"
4243
#include "llvm/Remarks/HotnessThresholdParser.h"
4344
#include "llvm/Support/Debug.h"
4445
#include "llvm/Support/FileSystem.h"
@@ -300,6 +301,10 @@ static cl::opt<std::string> RemarksFormat(
300301
cl::desc("The format used for serializing remarks (default: YAML)"),
301302
cl::value_desc("format"), cl::init("yaml"));
302303

304+
static cl::list<std::string>
305+
PassPlugins("load-pass-plugin",
306+
cl::desc("Load passes from plugin library"));
307+
303308
namespace llvm {
304309
cl::opt<PGOKind>
305310
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
@@ -581,6 +586,17 @@ int main(int argc, char **argv) {
581586
initializeExampleIRTransforms(Registry);
582587
#endif
583588

589+
SmallVector<PassPlugin, 1> PluginList;
590+
PassPlugins.setCallback([&](const std::string &PluginPath) {
591+
auto Plugin = PassPlugin::Load(PluginPath);
592+
if (!Plugin) {
593+
errs() << "Failed to load passes from '" << PluginPath
594+
<< "'. Request ignored.\n";
595+
return;
596+
}
597+
PluginList.emplace_back(Plugin.get());
598+
});
599+
584600
cl::ParseCommandLineOptions(argc, argv,
585601
"llvm .bc -> .bc modular optimizer and analysis printer\n");
586602

@@ -591,6 +607,19 @@ int main(int argc, char **argv) {
591607
return 1;
592608
}
593609

610+
// If `-passes=` is specified, use NPM.
611+
// If `-enable-new-pm` is specified and there are no codegen passes, use NPM.
612+
// e.g. `-enable-new-pm -sroa` will use NPM.
613+
// but `-enable-new-pm -codegenprepare` will still revert to legacy PM.
614+
const bool UseNPM = (EnableNewPassManager && !shouldForceLegacyPM()) ||
615+
PassPipeline.getNumOccurrences() > 0;
616+
617+
if (!UseNPM && PluginList.size()) {
618+
errs() << argv[0] << ": " << PassPlugins.ArgStr
619+
<< " specified with legacy PM.\n";
620+
return 1;
621+
}
622+
594623
// FIXME: once the legacy PM code is deleted, move runPassPipeline() here and
595624
// construct the PassBuilder before parsing IR so we can reuse the same
596625
// PassBuilder for print passes.
@@ -752,12 +781,7 @@ int main(int argc, char **argv) {
752781
}
753782
}
754783

755-
// If `-passes=` is specified, use NPM.
756-
// If `-enable-new-pm` is specified and there are no codegen passes, use NPM.
757-
// e.g. `-enable-new-pm -sroa` will use NPM.
758-
// but `-enable-new-pm -codegenprepare` will still revert to legacy PM.
759-
if ((EnableNewPassManager && !shouldForceLegacyPM()) ||
760-
PassPipeline.getNumOccurrences() > 0) {
784+
if (UseNPM) {
761785
if (AnalyzeOnly) {
762786
errs() << "Cannot specify -analyze under new pass manager, either "
763787
"specify '-enable-new-pm=0', or use the corresponding new pass "
@@ -821,7 +845,7 @@ int main(int argc, char **argv) {
821845
// layer.
822846
return runPassPipeline(argv[0], *M, TM.get(), &TLII, Out.get(),
823847
ThinLinkOut.get(), RemarksFile.get(), Pipeline,
824-
Passes, OK, VK, PreserveAssemblyUseListOrder,
848+
Passes, PluginList, OK, VK, PreserveAssemblyUseListOrder,
825849
PreserveBitcodeUseListOrder, EmitSummaryIndex,
826850
EmitModuleHash, EnableDebugify)
827851
? 0

polly/test/CodeGen/multiple-codegens.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt %loadPolly -polly-scops -polly-opt-isl -polly-codegen -polly-scops -polly-codegen -S < %s | FileCheck %s
2-
; RUN: opt %loadPolly "-passes=scop(polly-opt-isl,polly-codegen,polly-codegen)" -S < %s | FileCheck %s
3-
; RUN: opt %loadPolly "-passes=scop(polly-opt-isl,polly-codegen),scop(polly-codegen)" -S < %s | FileCheck %s
2+
; RUN: opt %loadNPMPolly "-passes=scop(polly-opt-isl,polly-codegen,polly-codegen)" -S < %s | FileCheck %s
3+
; RUN: opt %loadNPMPolly "-passes=scop(polly-opt-isl,polly-codegen),scop(polly-codegen)" -S < %s | FileCheck %s
44
;
55
; llvm.org/PR34441
66
; Properly handle multiple -polly-scops/-polly-codegen in the same

polly/test/DeLICM/map_memset_zero.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-print-delicm -disable-output < %s | FileCheck -match-full-lines %s
2-
; RUN: opt %loadPolly -polly-stmt-granularity=bb "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck -match-full-lines %s
2+
; RUN: opt %loadNPMPolly -polly-stmt-granularity=bb "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck -match-full-lines %s
33
;
44
; Check that PHI mapping works even in presence of a memset whose'
55
; zero value is used.

polly/test/DeLICM/pass_existence.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: opt %loadPolly -polly-delicm -disable-output < %s
22
; RUN: opt %loadPolly -polly-print-delicm -disable-output < %s | FileCheck %s
3-
; RUN: opt %loadPolly "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck %s
3+
; RUN: opt %loadNPMPolly "-passes=scop(print<polly-delicm>)" -disable-output < %s | FileCheck %s
44
;
55
; Simple test for the existence of the DeLICM pass.
66
;

polly/test/DeadCodeElimination/computeout.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: opt -S %loadPolly -basic-aa -polly-dce -polly-print-ast -disable-output < %s | FileCheck %s
2-
; RUN: opt -S %loadPolly "-passes=scop(polly-dce,print<polly-ast>)" < %s | FileCheck %s
2+
; RUN: opt -S %loadNPMPolly "-passes=scop(polly-dce,print<polly-ast>)" < %s | FileCheck %s
33
; RUN: opt -S %loadPolly -basic-aa -polly-dce -polly-print-ast -polly-dependences-computeout=1 -disable-output < %s | FileCheck %s -check-prefix=TIMEOUT
44
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
55

polly/test/DeadCodeElimination/dead_iteration_elimination.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: opt -S %loadPolly -basic-aa -polly-dependences-analysis-type=value-based -polly-dce -polly-dce-precise-steps=2 -polly-print-ast -disable-output < %s | FileCheck %s
2-
; RUN: opt -S %loadPolly "-passes=scop(polly-dce,print<polly-ast>)" -polly-dependences-analysis-type=value-based -polly-dce-precise-steps=2 < %s | FileCheck %s
2+
; RUN: opt -S %loadNPMPolly "-passes=scop(polly-dce,print<polly-ast>)" -polly-dependences-analysis-type=value-based -polly-dce-precise-steps=2 < %s | FileCheck %s
33
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
44
;
55
; for(i = 0; i < 200; i++ )

polly/test/ForwardOpTree/forward_load.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: opt %loadPolly -polly-print-optree -disable-output < %s | FileCheck %s -match-full-lines
2-
; RUN: opt %loadPolly "-passes=scop(print<polly-optree>)" -disable-output < %s | FileCheck %s -match-full-lines
2+
; RUN: opt %loadNPMPolly "-passes=scop(print<polly-optree>)" -disable-output < %s | FileCheck %s -match-full-lines
33
;
44
; Rematerialize a load.
55
;

0 commit comments

Comments
 (0)