[llvm] 7a5332b - [opt] Remove support for using -O[0|1|2|3|s|z] with legacy PM in opt
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 11 00:18:35 PST 2022
Author: Bjorn Pettersson
Date: 2022-11-11T09:17:05+01:00
New Revision: 7a5332b9b5584cec4517196ee86f8f3af2b78cd9
URL: https://github.com/llvm/llvm-project/commit/7a5332b9b5584cec4517196ee86f8f3af2b78cd9
DIFF: https://github.com/llvm/llvm-project/commit/7a5332b9b5584cec4517196ee86f8f3af2b78cd9.diff
LOG: [opt] Remove support for using -O[0|1|2|3|s|z] with legacy PM in opt
When running a default pipeline (for a specific O-level) in opt it is
now expected that the new PM should be used. Only reason to use the
legacy PM is when testing a pass that is locked to the legacy PM (or
when testing single passes, for example used by the llc backend).
If a test should run both a default pipeline plus some other passes,
the solution would be to invoke opt twice (separating the default
pipeline execution from the execution of individual passes).
Starting with this patch "opt -O0" etc. will result in an error.
Differential Revision: https://reviews.llvm.org/D137663
Added:
Modified:
llvm/test/Other/opt-On.ll
llvm/tools/opt/opt.cpp
Removed:
################################################################################
diff --git a/llvm/test/Other/opt-On.ll b/llvm/test/Other/opt-On.ll
index c0e61695e008d..ffd785ade744f 100644
--- 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
index 8dac02a356b18..702eee3535cd0 100644
--- 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 @@ static inline void addPass(legacy::PassManagerBase &PM, Pass *P) {
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 @@ int main(int argc, char **argv) {
: 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 @@ int main(int argc, char **argv) {
}
std::unique_ptr<legacy::FunctionPassManager> 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 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
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)
More information about the llvm-commits
mailing list