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 @@ -486,6 +486,35 @@ } }; +// For use in NPM transition. +// TODO: use a codegen version of PassRegistry.def/PassBuilder::is*Pass() once +// it exists. +static bool IsCodegenPass(StringRef Pass) { + return Pass.startswith("x86-") || Pass.startswith("xcore-") || + Pass.startswith("wasm-") || Pass.startswith("systemz-") || + Pass.startswith("ppc-") || Pass.startswith("nvvm-") || + Pass.startswith("nvptx-") || Pass.startswith("mips-") || + Pass.startswith("lanai-") || Pass.startswith("hexagon-") || + Pass.startswith("bpf-") || Pass.startswith("avr-") || + Pass.startswith("thumb2-") || Pass.startswith("arm-") || + Pass.startswith("si-") || Pass.startswith("gcn-") || + Pass.startswith("amdgpu-") || Pass.startswith("aarch64-") || + Pass.contains("ehprepare") || Pass == "safe-stack" || + Pass == "cost-model" || Pass == "codegenprepare" || + Pass == "interleaved-load-combine" || Pass == "unreachableblockelim" || + Pass == "scalarize-masked-mem-intrin"; +} + +// For use in NPM transition. +static bool CodegenPassSpecifiedInPassList() { + for (const auto &P : PassList) { + StringRef Arg = P->getPassArgument(); + if (IsCodegenPass(Arg)) + return true; + } + return false; +} + //===----------------------------------------------------------------------===// // main for opt // @@ -685,7 +714,8 @@ if (OutputThinLTOBC) M->addModuleFlag(Module::Error, "EnableSplitLTOUnit", SplitLTOUnit); - if (EnableNewPassManager || PassPipeline.getNumOccurrences() > 0) { + if ((EnableNewPassManager && !CodegenPassSpecifiedInPassList()) || + PassPipeline.getNumOccurrences() > 0) { if (PassPipeline.getNumOccurrences() > 0 && PassList.size() > 0) { errs() << "Cannot specify passes via both -foo-pass and --passes=foo-pass";