[NewPM] Use parameterized syntax for a couple of more passes

A couple of passes that are parameterized in new-PM used different
pass names (in cmd line interface) while using the same pass class
name. This patch updates the PassRegistry to model pass parameters
more properly using PASS_WITH_PARAMS.

Reason for the change is to ensure that we have a 1-1 mapping
between class name and pass name (when disregarding the params).
With a 1-1 mapping it is more obvious which pass name to use in
options such as -debug-only, -print-after etc.

The opt -passes syntax is changed for the following passes:
  early-cse-memssa => early-cse<memssa>
  post-inline-ee-instrument => ee-instrument<post-inline>
  loop-extract-single => loop-extract<single>
  lower-matrix-intrinsics-minimal => lower-matrix-intrinsics<minimal>

This patch is not updating pass names in docs/Passes.rst. Not quite
sure what the status is for that document (e.g. when it comes to
listing pass paramters). It is only loop-extract-single that is
mentioned in Passes.rst today, out of the passes mentioned above.

Differential Revision: https://reviews.llvm.org/D108362
This commit is contained in:
Bjorn Pettersson 2021-08-18 23:22:35 +02:00
parent 65d677435e
commit d52f506192
9 changed files with 90 additions and 16 deletions

View File

@ -2139,6 +2139,41 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
return UnrollOpts;
}
Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
StringRef PassName) {
bool Result = false;
while (!Params.empty()) {
StringRef ParamName;
std::tie(ParamName, Params) = Params.split(';');
if (ParamName == OptionName) {
Result = true;
} else {
return make_error<StringError>(
formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
.str(),
inconvertibleErrorCode());
}
}
return Result;
}
Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
return parseSinglePassOption(Params, "memssa", "EarlyCSE");
}
Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
return parseSinglePassOption(Params, "post-inline", "EntryExitInstrumenter");
}
Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
return parseSinglePassOption(Params, "single", "LoopExtractor");
}
Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
return parseSinglePassOption(Params, "minimal", "LowerMatrixIntrinsics");
}
Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
AddressSanitizerOptions Result;
while (!Params.empty()) {

View File

@ -73,7 +73,6 @@ MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("ipsccp", IPSCCPPass())
MODULE_PASS("iroutliner", IROutlinerPass())
MODULE_PASS("print-ir-similarity", IRSimilarityAnalysisPrinterPass(dbgs()))
MODULE_PASS("loop-extract", LoopExtractorPass())
MODULE_PASS("lowertypetests", LowerTypeTestsPass())
MODULE_PASS("metarenamer", MetaRenamerPass())
MODULE_PASS("mergefunc", MergeFunctionsPass())
@ -99,7 +98,6 @@ MODULE_PASS("rpo-function-attrs", ReversePostOrderFunctionAttrsPass())
MODULE_PASS("sample-profile", SampleProfileLoaderPass())
MODULE_PASS("scc-oz-module-inliner",
buildInlinerPipeline(OptimizationLevel::Oz, ThinOrFullLTOPhase::None))
MODULE_PASS("loop-extract-single", LoopExtractorPass(1))
MODULE_PASS("strip", StripSymbolsPass())
MODULE_PASS("strip-dead-debug-info", StripDeadDebugInfoPass())
MODULE_PASS("pseudo-probe", SampleProfileProbePass(TM))
@ -124,6 +122,15 @@ MODULE_PASS("pseudo-probe-update", PseudoProbeUpdatePass())
#ifndef MODULE_PASS_WITH_PARAMS
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
#endif
MODULE_PASS_WITH_PARAMS("loop-extract",
"LoopExtractorPass",
[](bool Single) {
if (Single)
return LoopExtractorPass(1);
return LoopExtractorPass();
},
parseLoopExtractorPassOptions,
"single")
MODULE_PASS_WITH_PARAMS("hwasan",
"HWAddressSanitizerPass",
[](HWAddressSanitizerOptions Opts) {
@ -227,12 +234,8 @@ FUNCTION_PASS("div-rem-pairs", DivRemPairsPass())
FUNCTION_PASS("dse", DSEPass())
FUNCTION_PASS("dot-cfg", CFGPrinterPass())
FUNCTION_PASS("dot-cfg-only", CFGOnlyPrinterPass())
FUNCTION_PASS("early-cse", EarlyCSEPass(/*UseMemorySSA=*/false))
FUNCTION_PASS("early-cse-memssa", EarlyCSEPass(/*UseMemorySSA=*/true))
FUNCTION_PASS("ee-instrument", EntryExitInstrumenterPass(/*PostInlining=*/false))
FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
FUNCTION_PASS("make-guards-explicit", MakeGuardsExplicitPass())
FUNCTION_PASS("post-inline-ee-instrument", EntryExitInstrumenterPass(/*PostInlining=*/true))
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
FUNCTION_PASS("gvn-sink", GVNSinkPass())
FUNCTION_PASS("helloworld", HelloWorldPass())
@ -252,8 +255,6 @@ FUNCTION_PASS("loweratomic", LowerAtomicPass())
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
FUNCTION_PASS("lower-matrix-intrinsics", LowerMatrixIntrinsicsPass())
FUNCTION_PASS("lower-matrix-intrinsics-minimal", LowerMatrixIntrinsicsPass(true))
FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass())
FUNCTION_PASS("guard-widening", GuardWideningPass())
FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass())
@ -340,6 +341,27 @@ FUNCTION_PASS("memprof", MemProfilerPass())
#ifndef FUNCTION_PASS_WITH_PARAMS
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
#endif
FUNCTION_PASS_WITH_PARAMS("early-cse",
"EarlyCSEPass",
[](bool UseMemorySSA) {
return EarlyCSEPass(UseMemorySSA);
},
parseEarlyCSEPassOptions,
"memssa")
FUNCTION_PASS_WITH_PARAMS("ee-instrument",
"EntryExitInstrumenterPass",
[](bool PostInlining) {
return EntryExitInstrumenterPass(PostInlining);
},
parseEntryExitInstrumenterPassOptions,
"post-inline")
FUNCTION_PASS_WITH_PARAMS("lower-matrix-intrinsics",
"LowerMatrixIntrinsicsPass",
[](bool Minimal) {
return LowerMatrixIntrinsicsPass(Minimal);
},
parseLowerMatrixIntrinsicsPassOptions,
"minimal")
FUNCTION_PASS_WITH_PARAMS("loop-unroll",
"LoopUnrollPass",
[](LoopUnrollOptions Opts) {

View File

@ -1,7 +1,7 @@
; RUN: opt -aa-pipeline=basic-aa -passes='require<memoryssa>,invalidate<aa>,early-cse-memssa' \
; RUN: opt -aa-pipeline=basic-aa -passes='require<memoryssa>,invalidate<aa>,early-cse<memssa>' \
; RUN: -debug-pass-manager -disable-output %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-AA-INVALIDATE
; RUN: opt -aa-pipeline=basic-aa -passes='require<memoryssa>,invalidate<domtree>,early-cse-memssa' \
; RUN: opt -aa-pipeline=basic-aa -passes='require<memoryssa>,invalidate<domtree>,early-cse<memssa>' \
; RUN: -debug-pass-manager -disable-output %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-DT-INVALIDATE

View File

@ -1,7 +1,7 @@
; RUN: opt < %s -S -mtriple=aarch64-none-linux-gnu -mattr=+neon -early-cse -earlycse-debug-hash | FileCheck %s
; RUN: opt < %s -S -mtriple=aarch64-none-linux-gnu -mattr=+neon -basic-aa -early-cse-memssa | FileCheck %s
; RUN: opt < %s -S -mtriple=aarch64-none-linux-gnu -mattr=+neon -passes=early-cse | FileCheck %s
; RUN: opt < %s -S -mtriple=aarch64-none-linux-gnu -mattr=+neon -aa-pipeline=basic-aa -passes=early-cse-memssa | FileCheck %s
; RUN: opt < %s -S -mtriple=aarch64-none-linux-gnu -mattr=+neon -aa-pipeline=basic-aa -passes='early-cse<memssa>' | FileCheck %s
define <4 x i32> @test_cse(i32* %a, [2 x <4 x i32>] %s.coerce, i32 %n) {
entry:

View File

@ -1,7 +1,7 @@
; RUN: opt < %s -S -early-cse -earlycse-debug-hash | FileCheck %s --check-prefix=CHECK-NOMEMSSA
; RUN: opt < %s -S -basic-aa -early-cse-memssa | FileCheck %s
; RUN: opt < %s -S -passes='early-cse' | FileCheck %s --check-prefix=CHECK-NOMEMSSA
; RUN: opt < %s -S -aa-pipeline=basic-aa -passes='early-cse-memssa' | FileCheck %s
; RUN: opt < %s -S -aa-pipeline=basic-aa -passes='early-cse<memssa>' | FileCheck %s
@G1 = global i32 zeroinitializer
@G2 = global i32 zeroinitializer

View File

@ -1,4 +1,4 @@
; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument)" -S < %s | FileCheck %s
; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(ee-instrument<post-inline>)" -S < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,7 +1,7 @@
; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument)" -S < %s | FileCheck %s
; RUN: opt -passes="function(ee-instrument),cgscc(inline),function(ee-instrument<post-inline>)" -S < %s | FileCheck %s
; Running the passes twice should not result in more instrumentation.
; RUN: opt -passes="function(ee-instrument),function(ee-instrument),cgscc(inline),function(post-inline-ee-instrument),function(post-inline-ee-instrument)" -S < %s | FileCheck %s
; RUN: opt -passes="function(ee-instrument),function(ee-instrument),cgscc(inline),function(ee-instrument<post-inline>),function(ee-instrument<post-inline>)" -S < %s | FileCheck %s
target datalayout = "E-m:e-i64:64-n32:64"
target triple = "powerpc64le-unknown-linux"

View File

@ -1,6 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -lower-matrix-intrinsics-minimal -fuse-matrix-tile-size=2 -matrix-allow-contract -force-fuse-matrix -instcombine -verify-dom-info %s -S | FileCheck %s
; RUN: opt -passes='lower-matrix-intrinsics-minimal,instcombine,verify<domtree>' -fuse-matrix-tile-size=2 -matrix-allow-contract -force-fuse-matrix %s -S | FileCheck %s
; RUN: opt -passes='lower-matrix-intrinsics<minimal>,instcombine,verify<domtree>' -fuse-matrix-tile-size=2 -matrix-allow-contract -force-fuse-matrix %s -S | FileCheck %s
; Test for the minimal version of the matrix lowering pass, which does not
; require DT or AA. Make sure no tiling is happening, even though it was

View File

@ -412,6 +412,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
if (EnableDebugify)
MPM.addPass(NewPMDebugifyPass());
// Add passes according to the -passes options.
if (!PassPipeline.empty()) {
assert(Passes.empty() &&
"PassPipeline and Passes should not both contain passes");
@ -420,10 +421,26 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
return false;
}
}
// Add passes specified using the legacy PM syntax (i.e. not using
// -passes). This should be removed later when such support has been
// deprecated, i.e. when all lit tests running opt (and not using
// -enable-new-pm=0) have been updated to use -passes.
for (auto PassName : Passes) {
std::string ModifiedPassName(PassName.begin(), PassName.end());
if (PB.isAnalysisPassName(PassName))
ModifiedPassName = "require<" + ModifiedPassName + ">";
// FIXME: These translations are supposed to be removed when lit tests that
// use these names have been updated to use the -passes syntax (and when the
// support for using the old syntax to specify passes is considered as
// deprecated for the new PM).
if (ModifiedPassName == "early-cse-memssa")
ModifiedPassName = "early-cse<memssa>";
else if (ModifiedPassName == "post-inline-ee-instrument")
ModifiedPassName = "ee-instrument<post-inline>";
else if (ModifiedPassName == "loop-extract-single")
ModifiedPassName = "loop-extract<single>";
else if (ModifiedPassName == "lower-matrix-intrinsics-minimal")
ModifiedPassName = "lower-matrix-intrinsics<minimal>";
if (auto Err = PB.parsePassPipeline(MPM, ModifiedPassName)) {
errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
return false;