[llvm] 1d56510 - [opt] Exposing the parameters of LoopRotate to the -passes interface
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 11:09:48 PDT 2023
Author: Yann Girsberger
Date: 2023-06-22T11:09:23-07:00
New Revision: 1d5651060e14eeee1323bb8ca4fb34d452c3db89
URL: https://github.com/llvm/llvm-project/commit/1d5651060e14eeee1323bb8ca4fb34d452c3db89
DIFF: https://github.com/llvm/llvm-project/commit/1d5651060e14eeee1323bb8ca4fb34d452c3db89.diff
LOG: [opt] Exposing the parameters of LoopRotate to the -passes interface
There is a gap between running opt -Oz and running opt -passes="OZ_PASSES" where OZ_PASSES is taken from running opt -Oz -print-pipeline-passes.
One of the reasons causing this is that -Oz uses non-default setting for LoopRotate but LoopRotate does not expose its settings when printing the pipeline.
This commit fixes this by exposing LoopRotates parameters.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D153437
Added:
Modified:
llvm/include/llvm/Transforms/Scalar/LoopRotation.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/Scalar/LoopRotation.cpp
llvm/test/Other/new-pm-print-pipeline.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopRotation.h b/llvm/include/llvm/Transforms/Scalar/LoopRotation.h
index c0e6f105a4124..cd108f7383e4c 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopRotation.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopRotation.h
@@ -28,6 +28,9 @@ class LoopRotatePass : public PassInfoMixin<LoopRotatePass> {
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR, LPMUpdater &U);
+ void printPipeline(raw_ostream &OS,
+ function_ref<StringRef(StringRef)> MapClassName2PassName);
+
private:
const bool EnableHeaderDuplication;
const bool PrepareForLTO;
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 7fd8b578ac3f9..a4972c8713486 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -897,6 +897,26 @@ Expected<LICMOptions> parseLICMOptions(StringRef Params) {
return Result;
}
+Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
+ std::pair<bool, bool> Result = {true, false};
+ while (!Params.empty()) {
+ StringRef ParamName;
+ std::tie(ParamName, Params) = Params.split(';');
+
+ bool Enable = !ParamName.consume_front("no-");
+ if (ParamName == "header-duplication") {
+ Result.first = Enable;
+ } else if (ParamName == "prepare-for-lto") {
+ Result.second = Enable;
+ } else {
+ return make_error<StringError>(
+ formatv("invalid LoopRotate pass parameter '{0}' ", ParamName).str(),
+ inconvertibleErrorCode());
+ }
+ }
+ return Result;
+}
+
Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
bool Result = false;
while (!Params.empty()) {
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 2c760adc1a409..7a2035cf07b3d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -565,7 +565,6 @@ LOOP_PASS("dot-ddg", DDGDotPrinterPass())
LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
LOOP_PASS("loop-instsimplify", LoopInstSimplifyPass())
-LOOP_PASS("loop-rotate", LoopRotatePass())
LOOP_PASS("no-op-loop", NoOpLoopPass())
LOOP_PASS("print", PrintLoopPass(dbgs()))
LOOP_PASS("loop-deletion", LoopDeletionPass())
@@ -608,4 +607,12 @@ LOOP_PASS_WITH_PARAMS("lnicm", "LNICMPass",
},
parseLICMOptions,
"allowspeculation");
+
+LOOP_PASS_WITH_PARAMS("loop-rotate",
+ "LoopRotatePass",
+ [](std::pair<bool, bool> Params) {
+ return LoopRotatePass(Params.first, Params.second);
+ },
+ parseLoopRotateOptions,
+ "no-header-duplication;header-duplication;no-prepare-for-lto;prepare-for-lto")
#undef LOOP_PASS_WITH_PARAMS
diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
index ba735adc5b274..eee8550587064 100644
--- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
@@ -43,6 +43,21 @@ LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication, bool PrepareForLTO)
: EnableHeaderDuplication(EnableHeaderDuplication),
PrepareForLTO(PrepareForLTO) {}
+void LoopRotatePass::printPipeline(
+ raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
+ static_cast<PassInfoMixin<LoopRotatePass> *>(this)->printPipeline(
+ OS, MapClassName2PassName);
+ OS << "<";
+ if (!EnableHeaderDuplication)
+ OS << "no-";
+ OS << "header-duplication;";
+
+ if (!PrepareForLTO)
+ OS << "no-";
+ OS << "prepare-for-lto";
+ OS << ">";
+}
+
PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR,
LPMUpdater &) {
diff --git a/llvm/test/Other/new-pm-print-pipeline.ll b/llvm/test/Other/new-pm-print-pipeline.ll
index 637e29fb1b48b..94091c4879759 100644
--- a/llvm/test/Other/new-pm-print-pipeline.ll
+++ b/llvm/test/Other/new-pm-print-pipeline.ll
@@ -4,7 +4,7 @@
; CHECK-0: function(adce),function(adce)
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='module(rpo-function-attrs,require<globals-aa>,function(float2int,lower-constant-intrinsics,loop(loop-rotate)),invalidate<globals-aa>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-1
-; CHECK-1: rpo-function-attrs,require<globals-aa>,function(float2int,lower-constant-intrinsics,loop(loop-rotate)),invalidate<globals-aa>
+; CHECK-1: rpo-function-attrs,require<globals-aa>,function(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>)),invalidate<globals-aa>
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='repeat<5>(function(mem2reg)),invalidate<all>' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-2
; CHECK-2: repeat<5>(function(mem2reg)),invalidate<all>
@@ -69,7 +69,7 @@
;; Test that the loop-nest-pass lnicm is printed with the other loop-passes in the pipeline.
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop-mssa(licm,loop-rotate,loop-deletion,lnicm,loop-rotate))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-23
-; CHECK-23: function(loop-mssa(licm<allowspeculation>,loop-rotate,loop-deletion,lnicm<allowspeculation>,loop-rotate))
+; CHECK-23: function(loop-mssa(licm<allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion,lnicm<allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>))
;; Test that -debugify and -check-debugify is printed correctly.
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='debugify,no-op-function,check-debugify' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-24
@@ -111,3 +111,6 @@
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='cgscc(function<no-rerun>(no-op-function))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-32
; CHECK-32: cgscc(function<no-rerun>(no-op-function))
+
+; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop(loop-rotate<no-header-duplication;no-prepare-for-lto>))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-33
+; CHECK-33: function(loop(loop-rotate<no-header-duplication;no-prepare-for-lto>))
More information about the llvm-commits
mailing list