From 39765fa3ed74922102d2bae64a8b397dd91aea37 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Fri, 19 Jun 2020 16:22:00 -0700 Subject: [PATCH] [NewPM] Attempt to run opt passes specified via -foo-pass under NPM Summary: In order to enable mass testing of opt under NPM, specifically passes specified via -foo-pass. This is gated under a new opt flag -enable-new-pm. Currently the pass flag parser looks for legacy PM passes with the name "foo" (for opt arg "-foo") and creates a PassInfo for each one. Here we take the (legacy PM) pass name and try to match it with one defined in (NPM) PassRegistry.def. Ultimately if we want all tests to pass like this, we'll need to port all passes to NPM and register them in PassRegistry.def under the same name as they were reigstered in the legacy PM. Maybe at some point we'll migrate all -foo to --passes=foo, but that would be after the NPM switch. Flipping on the flag causes 2XXX failures under check-llvm. By far most of them are passes either not ported to NPM or don't have the same name in PassRegistry.def as their old name. Reviewers: hans, echristo, asbirlea, leonardchan Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82320 --- test/Other/opt-npm.ll | 6 ++++++ tools/opt/NewPMDriver.cpp | 21 +++++++++++++++------ tools/opt/NewPMDriver.h | 5 ++++- tools/opt/opt.cpp | 14 +++++++++++--- 4 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 test/Other/opt-npm.ll diff --git a/test/Other/opt-npm.ll b/test/Other/opt-npm.ll new file mode 100644 index 00000000000..0b1e651b41f --- /dev/null +++ b/test/Other/opt-npm.ll @@ -0,0 +1,6 @@ +; RUN: opt -dce -enable-new-pm -disable-output -debug-pass-manager %s 2>&1 | FileCheck %s + +; CHECK: DCEPass +define void @foo() { + ret void +} diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index ce86c3d6158..cdde8a1f014 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -214,8 +214,8 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, ToolOutputFile *OptRemarkFile, - StringRef PassPipeline, OutputKind OK, - VerifierKind VK, + StringRef PassPipeline, ArrayRef Passes, + OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash, @@ -332,10 +332,19 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, if (EnableDebugify) MPM.addPass(NewPMDebugifyPass()); - if (auto Err = - PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { - errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; - return false; + if (!PassPipeline.empty()) { + if (auto Err = + PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { + errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; + return false; + } + } + for (auto PassName : Passes) { + if (auto Err = + PB.parsePassPipeline(MPM, PassName, VerifyEachPass, DebugPM)) { + errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; + return false; + } } if (VK > VK_NoVerifier) diff --git a/tools/opt/NewPMDriver.h b/tools/opt/NewPMDriver.h index 707522cec4b..7ae273a2c1f 100644 --- a/tools/opt/NewPMDriver.h +++ b/tools/opt/NewPMDriver.h @@ -20,6 +20,8 @@ #ifndef LLVM_TOOLS_OPT_NEWPMDRIVER_H #define LLVM_TOOLS_OPT_NEWPMDRIVER_H +#include "llvm/ADT/ArrayRef.h" + namespace llvm { class StringRef; class Module; @@ -59,7 +61,8 @@ enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse }; bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, ToolOutputFile *Out, ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile, StringRef PassPipeline, - opt_tool::OutputKind OK, opt_tool::VerifierKind VK, + ArrayRef PassInfos, opt_tool::OutputKind OK, + opt_tool::VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash, diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 5b8fa26a3d3..96c835e1aff 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -71,6 +71,10 @@ static codegen::RegisterCodeGenFlags CFG; static cl::list PassList(cl::desc("Optimizations available:")); +static cl::opt + EnableNewPassManager("enable-new-pm", + cl::desc("Enable the new pass manager")); + // This flag specifies a textual description of the optimization pass pipeline // to run over the module. This flag switches opt to use the new pass manager // infrastructure, completely disabling all of the flags specific to the old @@ -734,12 +738,16 @@ int main(int argc, char **argv) { if (OutputThinLTOBC) M->addModuleFlag(Module::Error, "EnableSplitLTOUnit", SplitLTOUnit); - if (PassPipeline.getNumOccurrences() > 0) { - if (PassList.size()) { + if (EnableNewPassManager || PassPipeline.getNumOccurrences() > 0) { + if (PassPipeline.getNumOccurrences() > 0 && PassList.size() > 0) { errs() << "Cannot specify passes via both -foo-pass and --passes=foo-pass"; return 1; } + SmallVector Passes; + for (const auto &P : PassList) { + Passes.push_back(P->getPassArgument()); + } OutputKind OK = OK_NoOutput; if (!NoOutput) OK = OutputAssembly @@ -756,7 +764,7 @@ int main(int argc, char **argv) { // string. Hand off the rest of the functionality to the new code for that // layer. return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(), - RemarksFile.get(), PassPipeline, OK, VK, + RemarksFile.get(), PassPipeline, Passes, OK, VK, PreserveAssemblyUseListOrder, PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash, EnableDebugify, Coroutines)