18
18
19
19
namespace mlir {
20
20
21
- class AffineMinOp ;
21
+ class AffineMap ;
22
22
class ConversionTarget ;
23
23
struct LogicalResult ;
24
24
class MLIRContext ;
@@ -29,6 +29,7 @@ class RewritePatternSet;
29
29
using OwningRewritePatternList = RewritePatternSet;
30
30
class Operation ;
31
31
class Value ;
32
+ class ValueRange ;
32
33
33
34
namespace scf {
34
35
@@ -37,20 +38,28 @@ class ForOp;
37
38
class ParallelOp ;
38
39
class ForOp ;
39
40
40
- // / Try to canonicalize an affine.min operation in the context of `for` loops
41
- // / with a known range.
41
+ // / Match "for loop"-like operations: If the first parameter is an iteration
42
+ // / variable, return lower/upper bounds via the second/third parameter and the
43
+ // / step size via the last parameter. The function should return `success` in
44
+ // / that case. If the first parameter is not an iteration variable, return
45
+ // / `failure`.
46
+ using LoopMatcherFn =
47
+ function_ref<LogicalResult(Value, Value &, Value &, Value &)>;
48
+
49
+ // / Try to canonicalize an min/max operations in the context of for `loops` with
50
+ // / a known range.
42
51
// /
43
- // / `loopMatcher ` is used to retrieve loop bounds and step size for a given
44
- // / iteration variable: If the first parameter is an iteration variable, return
45
- // / lower/upper bounds via the second/third parameter and the step size via the
46
- // / last parameter. The function should return `success` in that case. If the
47
- // / first parameter is not an iteration variable, return `failure` .
52
+ // / `map ` is the body of the min/max operation and `operands` are the SSA values
53
+ // / that the dimensions and symbols are bound to; dimensions are listed first.
54
+ // / If `isMin`, the operation is a min operation; otherwise, a max operation.
55
+ // / `loopMatcher` is used to retrieve loop bounds and the step size for a given
56
+ // / iteration variable.
48
57
// /
49
58
// / Note: `loopMatcher` allows this function to be used with any "for loop"-like
50
59
// / operation (scf.for, scf.parallel and even ops defined in other dialects).
51
- LogicalResult canonicalizeAffineMinOpInLoop (
52
- AffineMinOp minOp, RewriterBase &rewriter ,
53
- function_ref<LogicalResult(Value, Value &, Value &, Value &)> loopMatcher);
60
+ LogicalResult canonicalizeMinMaxOpInLoop (RewriterBase &rewriter, Operation *op,
61
+ AffineMap map, ValueRange operands ,
62
+ bool isMin, LoopMatcherFn loopMatcher);
54
63
55
64
// / Fuses all adjacent scf.parallel operations with identical bounds and step
56
65
// / into one scf.parallel operations. Uses a naive aliasing and dependency
@@ -85,10 +94,10 @@ void naivelyFuseParallelOps(Region ®ion);
85
94
// / ```
86
95
// /
87
96
// / After loop peeling, this function tries to simplify/canonicalize affine.min
88
- // / operations in the body of the loop and the scf.if, taking advantage of the
89
- // / fact that every iteration of the peeled loop is a "full" iteration. This
90
- // / canonicalization is expected to enable further canonicalization
91
- // / opportunities through other patterns.
97
+ // / and affine.max ops in the body of the loop and the scf.if, taking advantage
98
+ // / of the fact that the peeled loop has only "full" iterations and the scf.if
99
+ // / is always a partial iteration (if any). This canonicalization is expected to
100
+ // / enable further canonicalization opportunities through other patterns.
92
101
// /
93
102
// / The return value indicates whether the loop was rewritten or not. Loops are
94
103
// / not rewritten if:
@@ -168,7 +177,7 @@ void populateSCFLoopPipeliningPatterns(RewritePatternSet &patterns,
168
177
const PipeliningOption &options);
169
178
170
179
// / Populate patterns for canonicalizing operations inside SCF loop bodies.
171
- // / At the moment, only affine.min computations with iteration variables,
180
+ // / At the moment, only affine.min/max computations with iteration variables,
172
181
// / loop bounds and loop steps are canonicalized.
173
182
void populateSCFLoopBodyCanonicalizationPatterns (RewritePatternSet &patterns);
174
183
0 commit comments