diff --git a/llvm/test/Other/opt-npm.ll b/llvm/test/Other/opt-npm.ll new file mode 100644 --- /dev/null +++ b/llvm/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/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h --- a/llvm/tools/opt/NewPMDriver.h +++ b/llvm/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 @@ 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/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -214,8 +214,8 @@ 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 @@ 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/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -71,6 +71,10 @@ 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 @@ 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 @@ // 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)