MLIR  16.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"
18 
19 namespace mlir {
20 class AffineMap;
21 struct LogicalResult;
22 class Operation;
23 class OpFoldResult;
24 class RewriterBase;
25 class Value;
26 class ValueRange;
27 
28 namespace scf {
29 class IfOp;
30 
31 /// Match "for loop"-like operations: If the first parameter is an iteration
32 /// variable, return lower/upper bounds via the second/third parameter and the
33 /// step size via the last parameter. The function should return `success` in
34 /// that case. If the first parameter is not an iteration variable, return
35 /// `failure`.
36 using LoopMatcherFn = function_ref<LogicalResult(
38 
39 /// Try to canonicalize an min/max operations in the context of for `loops` with
40 /// a known range.
41 ///
42 /// `map` is the body of the min/max operation and `operands` are the SSA values
43 /// that the dimensions and symbols are bound to; dimensions are listed first.
44 /// If `isMin`, the operation is a min operation; otherwise, a max operation.
45 /// `loopMatcher` is used to retrieve loop bounds and the step size for a given
46 /// iteration variable.
47 ///
48 /// Note: `loopMatcher` allows this function to be used with any "for loop"-like
49 /// operation (scf.for, scf.parallel and even ops defined in other dialects).
51  AffineMap map, ValueRange operands,
52  bool isMin, LoopMatcherFn loopMatcher);
53 
54 /// Try to simplify a min/max operation `op` after loop peeling. This function
55 /// can simplify min/max operations such as (ub is the previous upper bound of
56 /// the unpeeled loop):
57 /// ```
58 /// #map = affine_map<(d0)[s0, s1] -> (s0, -d0 + s1)>
59 /// %r = affine.min #affine.min #map(%iv)[%step, %ub]
60 /// ```
61 /// and rewrites them into (in the case the peeled loop):
62 /// ```
63 /// %r = %step
64 /// ```
65 /// min/max operations inside the partial iteration are rewritten in a similar
66 /// way.
68  AffineMap map, ValueRange operands,
69  bool isMin, Value iv, Value ub, Value step,
70  bool insideLoop);
71 
72 } // namespace scf
73 } // namespace mlir
74 
75 #endif // MLIR_DIALECT_SCF_UTILS_AFFINECANONICALIZATIONUTILS_H_
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
llvm::function_ref< Fn > function_ref
Definition: LLVM.h:149
This class represents a single result from folding an operation.
Definition: OpDefinition.h:239
LogicalResult canonicalizeMinMaxOpInLoop(RewriterBase &rewriter, Operation *op, AffineMap map, ValueRange operands, bool isMin, LoopMatcherFn loopMatcher)
Try to canonicalize an min/max operations in the context of for loops with a known range...
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
A multi-dimensional affine map Affine map&#39;s are immutable like Type&#39;s, and they are uniqued...
Definition: AffineMap.h:42
function_ref< LogicalResult(Value, OpFoldResult &, OpFoldResult &, OpFoldResult &)> LoopMatcherFn
Match "for loop"-like operations: If the first parameter is an iteration variable, return lower/upper bounds via the second/third parameter and the step size via the last parameter.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
LogicalResult rewritePeeledMinMaxOp(RewriterBase &rewriter, Operation *op, AffineMap map, ValueRange operands, bool isMin, Value iv, Value ub, Value step, bool insideLoop)
Try to simplify a min/max operation op after loop peeling.
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:345
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:398