MLIR  19.0.0git
AffineCanonicalizationUtils.h
Go to the documentation of this file.
1 //===- AffineCanonicalizationUtils.h ----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header file defines utility functions to canonicalize affine ops
10 // within SCF op regions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_SCF_UTILS_AFFINECANONICALIZATIONUTILS_H_
15 #define MLIR_DIALECT_SCF_UTILS_AFFINECANONICALIZATIONUTILS_H_
16 
17 #include "mlir/Support/LLVM.h"
19 
20 namespace mlir {
21 class AffineMap;
22 struct LogicalResult;
23 class Operation;
24 class OpFoldResult;
25 class RewriterBase;
26 class Value;
27 class ValueRange;
28 
29 namespace affine {
30 class FlatAffineValueConstraints;
31 } // namespace affine
32 
33 namespace scf {
34 class IfOp;
35 
36 /// Match "for loop"-like operations: If the first parameter is an iteration
37 /// variable, return lower/upper bounds via the second/third parameter and the
38 /// step size via the last parameter. The function should return `success` in
39 /// that case. If the first parameter is not an iteration variable, return
40 /// `failure`.
43 
44 /// Match "for loop"-like operations from the SCF dialect.
46  OpFoldResult &step);
47 
48 /// Populate the given constraint set with induction variable constraints of a
49 /// "for" loop with the given range and step.
51  Value iv, OpFoldResult lb,
52  OpFoldResult ub, OpFoldResult step);
53 
54 /// Try to canonicalize the given affine.min/max operation in the context of
55 /// for `loops` with a known range.
56 ///
57 /// `loopMatcher` is used to retrieve loop bounds and the step size for a given
58 /// iteration variable.
59 ///
60 /// Note: `loopMatcher` allows this function to be used with any "for loop"-like
61 /// operation (scf.for, scf.parallel and even ops defined in other dialects).
63  LoopMatcherFn loopMatcher);
64 
65 /// Try to simplify the given affine.min/max operation `op` after loop peeling.
66 /// This function can simplify min/max operations such as (ub is the previous
67 /// upper bound of the unpeeled loop):
68 /// ```
69 /// #map = affine_map<(d0)[s0, s1] -> (s0, -d0 + s1)>
70 /// %r = affine.min #map(%iv)[%step, %ub]
71 /// ```
72 /// and rewrites them into (in the case the peeled loop):
73 /// ```
74 /// %r = %step
75 /// ```
76 /// min/max operations inside the partial iteration are rewritten in a similar
77 /// way.
79  Value iv, Value ub, Value step,
80  bool insideLoop);
81 
82 } // namespace scf
83 } // namespace mlir
84 
85 #endif // MLIR_DIALECT_SCF_UTILS_AFFINECANONICALIZATIONUTILS_H_
This class represents a single result from folding an operation.
Definition: OpDefinition.h:268
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:400
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
FlatAffineValueConstraints is an extension of FlatLinearValueConstraints with helper functions for Af...
LogicalResult matchForLikeLoop(Value iv, OpFoldResult &lb, OpFoldResult &ub, OpFoldResult &step)
Match "for loop"-like operations from the SCF dialect.
LogicalResult canonicalizeMinMaxOpInLoop(RewriterBase &rewriter, Operation *op, LoopMatcherFn loopMatcher)
Try to canonicalize the given affine.min/max operation in the context of for loops with a known range...
LogicalResult rewritePeeledMinMaxOp(RewriterBase &rewriter, Operation *op, Value iv, Value ub, Value step, bool insideLoop)
Try to simplify the given affine.min/max operation op after loop peeling.
LogicalResult addLoopRangeConstraints(affine::FlatAffineValueConstraints &cstr, Value iv, OpFoldResult lb, OpFoldResult ub, OpFoldResult step)
Populate the given constraint set with induction variable constraints of a "for" loop with the given ...
Include the generated interface declarations.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26