diff --git a/llvm/test/Other/opt-On.ll b/llvm/test/Other/opt-On.ll --- a/llvm/test/Other/opt-On.ll +++ b/llvm/test/Other/opt-On.ll @@ -18,3 +18,17 @@ define void @f() { unreachable } + + +; Legacy PM deprecation tests (tests should be removed in the future). +; +; RUN: not opt -enable-new-pm=0 -O0 < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -enable-new-pm=0 -O1 < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -enable-new-pm=0 -O2 < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -enable-new-pm=0 -O3 < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -enable-new-pm=0 -Os < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -enable-new-pm=0 -Oz < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -O1 -codegenprepare < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR +; RUN: not opt -codegenprepare -O2 < %s -S 2>&1 | FileCheck %s --check-prefix=LEGACYPM-ERROR + +; LEGACYPM-ERROR: Cannot use -O# with legacy PM 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 @@ -52,8 +52,6 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Transforms/IPO/AlwaysInliner.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Debugify.h" @@ -324,40 +322,6 @@ PM.add(createVerifierPass()); } -/// This routine adds optimization passes based on selected optimization level, -/// OptLevel. -/// -/// OptLevel - Optimization Level -static void AddOptimizationPasses(legacy::PassManagerBase &MPM, - legacy::FunctionPassManager &FPM, - TargetMachine *TM, unsigned OptLevel, - unsigned SizeLevel) { - if (!NoVerify || VerifyEach) - FPM.add(createVerifierPass()); // Verify that input is correct - - PassManagerBuilder Builder; - Builder.OptLevel = OptLevel; - Builder.SizeLevel = SizeLevel; - - if (OptLevel > 1) { - Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false); - } else { - Builder.Inliner = createAlwaysInlinerLegacyPass(); - } - Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ? - DisableLoopUnrolling : OptLevel == 0; - - Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2; - - Builder.SLPVectorize = OptLevel > 1 && SizeLevel < 2; - - if (TM) - TM->adjustPassManager(Builder); - - Builder.populateFunctionPassManager(FPM); - Builder.populateModulePassManager(MPM); -} - //===----------------------------------------------------------------------===// // CodeGen-related helper functions. // @@ -791,6 +755,12 @@ : 1; } + if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || + OptLevelO3) { + errs() << "Cannot use -O# with legacy PM.\n"; + return 1; + } + // Create a PassManager to hold and optimize the collection of passes we are // about to build. If the -debugify-each option is set, wrap each pass with // the (-check)-debugify passes. @@ -830,12 +800,6 @@ } std::unique_ptr FPasses; - if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || - OptLevelO3) { - FPasses.reset(new legacy::FunctionPassManager(M.get())); - FPasses->add(createTargetTransformInfoWrapperPass( - TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); - } if (PrintBreakpoints) { // Default to standard output. @@ -864,36 +828,6 @@ // Create a new optimization pass for each one specified on the command line for (unsigned i = 0; i < PassList.size(); ++i) { - if (OptLevelO0 && OptLevelO0.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); - OptLevelO0 = false; - } - - if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); - OptLevelO1 = false; - } - - if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); - OptLevelO2 = false; - } - - if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); - OptLevelOs = false; - } - - if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); - OptLevelOz = false; - } - - if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); - OptLevelO3 = false; - } - const PassInfo *PassInf = PassList[i]; Pass *P = nullptr; if (PassInf->getNormalCtor()) @@ -905,24 +839,6 @@ addPass(Passes, P); } - if (OptLevelO0) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); - - if (OptLevelO1) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); - - if (OptLevelO2) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); - - if (OptLevelOs) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); - - if (OptLevelOz) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); - - if (OptLevelO3) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); - if (FPasses) { FPasses->doInitialization(); for (Function &F : *M)