Skip to content

Commit ca6c03a

Browse files
author
Serguei Katkov
committed
[NewPM] Add Option handling for LoopVectorize
This patch enables passing options to LoopVectorizePass via the passes pipeline. Reviewers: chandlerc, fedor.sergeev, leonardchan, philip.pfaffe Reviewed By: fedor.sergeev Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D60681 llvm-svn: 358647
1 parent da49faf commit ca6c03a

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,42 @@ class ScalarEvolution;
7676
class TargetLibraryInfo;
7777
class TargetTransformInfo;
7878

79+
struct LoopVectorizeOptions {
80+
/// If false, consider all loops for interleaving.
81+
/// If true, only loops that explicitly request interleaving are considered.
82+
bool InterleaveOnlyWhenForced;
83+
84+
/// If false, consider all loops for vectorization.
85+
/// If true, only loops that explicitly request vectorization are considered.
86+
bool VectorizeOnlyWhenForced;
87+
88+
LoopVectorizeOptions()
89+
: InterleaveOnlyWhenForced(false), VectorizeOnlyWhenForced(false) {}
90+
91+
LoopVectorizeOptions &setInterleaveOnlyWhenForced(bool Value) {
92+
InterleaveOnlyWhenForced = Value;
93+
return *this;
94+
}
95+
96+
LoopVectorizeOptions &setVectorizeOnlyWhenForced(bool Value) {
97+
VectorizeOnlyWhenForced = Value;
98+
return *this;
99+
}
100+
};
101+
79102
/// The LoopVectorize Pass.
80103
struct LoopVectorizePass : public PassInfoMixin<LoopVectorizePass> {
81104
/// If false, consider all loops for interleaving.
82105
/// If true, only loops that explicitly request interleaving are considered.
83-
bool InterleaveOnlyWhenForced = false;
106+
bool InterleaveOnlyWhenForced;
84107

85108
/// If false, consider all loops for vectorization.
86109
/// If true, only loops that explicitly request vectorization are considered.
87-
bool VectorizeOnlyWhenForced = false;
110+
bool VectorizeOnlyWhenForced;
111+
112+
LoopVectorizePass(LoopVectorizeOptions Opts = {})
113+
: InterleaveOnlyWhenForced(Opts.InterleaveOnlyWhenForced),
114+
VectorizeOnlyWhenForced(Opts.VectorizeOnlyWhenForced) {}
88115

89116
ScalarEvolution *SE;
90117
LoopInfo *LI;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,27 @@ Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
14691469
return Result;
14701470
}
14711471

1472+
/// Parser of parameters for LoopVectorize pass.
1473+
Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
1474+
LoopVectorizeOptions Opts;
1475+
while (!Params.empty()) {
1476+
StringRef ParamName;
1477+
std::tie(ParamName, Params) = Params.split(';');
1478+
1479+
bool Enable = !ParamName.consume_front("no-");
1480+
if (ParamName == "interleave-forced-only") {
1481+
Opts.setInterleaveOnlyWhenForced(Enable);
1482+
} else if (ParamName == "vectorize-forced-only") {
1483+
Opts.setVectorizeOnlyWhenForced(Enable);
1484+
} else {
1485+
return make_error<StringError>(
1486+
formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
1487+
inconvertibleErrorCode());
1488+
}
1489+
}
1490+
return Opts;
1491+
}
1492+
14721493
} // namespace
14731494

14741495
/// Tests whether a pass name starts with a valid prefix for a default pipeline

llvm/lib/Passes/PassRegistry.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ FUNCTION_PASS("loop-data-prefetch", LoopDataPrefetchPass())
199199
FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
200200
FUNCTION_PASS("loop-fuse", LoopFusePass())
201201
FUNCTION_PASS("loop-distribute", LoopDistributePass())
202-
FUNCTION_PASS("loop-vectorize", LoopVectorizePass())
203202
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
204203
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
205204
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
@@ -258,6 +257,11 @@ FUNCTION_PASS_WITH_PARAMS("simplify-cfg",
258257
return SimplifyCFGPass(Opts);
259258
},
260259
parseSimplifyCFGOptions)
260+
FUNCTION_PASS_WITH_PARAMS("loop-vectorize",
261+
[](LoopVectorizeOptions Opts) {
262+
return LoopVectorizePass(Opts);
263+
},
264+
parseLoopVectorizeOptions)
261265
#undef FUNCTION_PASS_WITH_PARAMS
262266

263267
#ifndef LOOP_ANALYSIS

0 commit comments

Comments
 (0)