Skip to content

Commit 1d56510

Browse files
Quarubaeubanks
authored andcommitted
[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
1 parent 3099505 commit 1d56510

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

llvm/include/llvm/Transforms/Scalar/LoopRotation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class LoopRotatePass : public PassInfoMixin<LoopRotatePass> {
2828
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
2929
LoopStandardAnalysisResults &AR, LPMUpdater &U);
3030

31+
void printPipeline(raw_ostream &OS,
32+
function_ref<StringRef(StringRef)> MapClassName2PassName);
33+
3134
private:
3235
const bool EnableHeaderDuplication;
3336
const bool PrepareForLTO;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,26 @@ Expected<LICMOptions> parseLICMOptions(StringRef Params) {
897897
return Result;
898898
}
899899

900+
Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
901+
std::pair<bool, bool> Result = {true, false};
902+
while (!Params.empty()) {
903+
StringRef ParamName;
904+
std::tie(ParamName, Params) = Params.split(';');
905+
906+
bool Enable = !ParamName.consume_front("no-");
907+
if (ParamName == "header-duplication") {
908+
Result.first = Enable;
909+
} else if (ParamName == "prepare-for-lto") {
910+
Result.second = Enable;
911+
} else {
912+
return make_error<StringError>(
913+
formatv("invalid LoopRotate pass parameter '{0}' ", ParamName).str(),
914+
inconvertibleErrorCode());
915+
}
916+
}
917+
return Result;
918+
}
919+
900920
Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
901921
bool Result = false;
902922
while (!Params.empty()) {

llvm/lib/Passes/PassRegistry.def

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ LOOP_PASS("dot-ddg", DDGDotPrinterPass())
565565
LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
566566
LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
567567
LOOP_PASS("loop-instsimplify", LoopInstSimplifyPass())
568-
LOOP_PASS("loop-rotate", LoopRotatePass())
569568
LOOP_PASS("no-op-loop", NoOpLoopPass())
570569
LOOP_PASS("print", PrintLoopPass(dbgs()))
571570
LOOP_PASS("loop-deletion", LoopDeletionPass())
@@ -608,4 +607,12 @@ LOOP_PASS_WITH_PARAMS("lnicm", "LNICMPass",
608607
},
609608
parseLICMOptions,
610609
"allowspeculation");
610+
611+
LOOP_PASS_WITH_PARAMS("loop-rotate",
612+
"LoopRotatePass",
613+
[](std::pair<bool, bool> Params) {
614+
return LoopRotatePass(Params.first, Params.second);
615+
},
616+
parseLoopRotateOptions,
617+
"no-header-duplication;header-duplication;no-prepare-for-lto;prepare-for-lto")
611618
#undef LOOP_PASS_WITH_PARAMS

llvm/lib/Transforms/Scalar/LoopRotation.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ LoopRotatePass::LoopRotatePass(bool EnableHeaderDuplication, bool PrepareForLTO)
4343
: EnableHeaderDuplication(EnableHeaderDuplication),
4444
PrepareForLTO(PrepareForLTO) {}
4545

46+
void LoopRotatePass::printPipeline(
47+
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
48+
static_cast<PassInfoMixin<LoopRotatePass> *>(this)->printPipeline(
49+
OS, MapClassName2PassName);
50+
OS << "<";
51+
if (!EnableHeaderDuplication)
52+
OS << "no-";
53+
OS << "header-duplication;";
54+
55+
if (!PrepareForLTO)
56+
OS << "no-";
57+
OS << "prepare-for-lto";
58+
OS << ">";
59+
}
60+
4661
PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM,
4762
LoopStandardAnalysisResults &AR,
4863
LPMUpdater &) {

llvm/test/Other/new-pm-print-pipeline.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; CHECK-0: function(adce),function(adce)
55

66
; 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
7-
; CHECK-1: rpo-function-attrs,require<globals-aa>,function(float2int,lower-constant-intrinsics,loop(loop-rotate)),invalidate<globals-aa>
7+
; 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>
88

99
; 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
1010
; CHECK-2: repeat<5>(function(mem2reg)),invalidate<all>
@@ -69,7 +69,7 @@
6969

7070
;; Test that the loop-nest-pass lnicm is printed with the other loop-passes in the pipeline.
7171
; 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
72-
; CHECK-23: function(loop-mssa(licm<allowspeculation>,loop-rotate,loop-deletion,lnicm<allowspeculation>,loop-rotate))
72+
; 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>))
7373

7474
;; Test that -debugify and -check-debugify is printed correctly.
7575
; 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 @@
111111

112112
; 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
113113
; CHECK-32: cgscc(function<no-rerun>(no-op-function))
114+
115+
; 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
116+
; CHECK-33: function(loop(loop-rotate<no-header-duplication;no-prepare-for-lto>))

0 commit comments

Comments
 (0)