Skip to content

Commit

Permalink
[opt] Exposing the parameters of LoopRotate to the -passes interface
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Quarub authored and aeubanks committed Jun 22, 2023
1 parent 3099505 commit 1d56510
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions llvm/include/llvm/Transforms/Scalar/LoopRotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 8 additions & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions llvm/lib/Transforms/Scalar/LoopRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {
Expand Down
7 changes: 5 additions & 2 deletions llvm/test/Other/new-pm-print-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>))

0 comments on commit 1d56510

Please sign in to comment.