MLIR 24.0.0git
AffineValueMap.h
Go to the documentation of this file.
1//===- AffineValueMap.h - MLIR Affine Value Map Class -----------*- 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// An AffineValueMap is an affine map plus its ML value operands and results for
10// analysis purposes.
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
14#define MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
15
16#include "mlir/IR/AffineMap.h"
18#include "mlir/IR/Value.h"
19
20namespace mlir {
21namespace affine {
22/// An AffineValueMap is an affine map plus its ML value operands and
23/// results for analysis purposes. The structure is still a tree form that is
24/// same as that of an affine map or an AffineApplyOp. However, its operands,
25/// results, and its map can themselves change as a result of
26/// substitutions, simplifications, and other analysis.
27// An affine value map can readily be constructed from an AffineApplyOp, or an
28// AffineBound of a AffineForOp. It can be further transformed, substituted
29// into, or simplified. Unlike AffineMap's, AffineValueMap's are created and
30// destroyed during analysis. Only the AffineMap expressions that are pointed by
31// them are unique'd. An affine value map, and the operations on it, maintain
32// the invariant that operands are always positionally aligned with the
33// AffineDimExpr and AffineSymbolExpr in the underlying AffineMap.
35public:
36 // Creates an empty AffineValueMap (users should call 'reset' to reset map
37 // and operands).
38 AffineValueMap() = default;
39 AffineValueMap(AffineMap map, ValueRange operands, ValueRange results = {});
40
42
43 // Resets this AffineValueMap with 'map', 'operands', and 'results'.
44 void reset(AffineMap map, ValueRange operands, ValueRange results = {});
45
46 /// Composes all incoming affine.apply ops and then simplifies and
47 /// canonicalizes the map and operands. This can change the number of
48 /// operands, but the result count remains the same.
50
51 /// Combine results from 'a' and 'b' using 'expr'. If 'pairwise' is true (the
52 /// default), apply 'expr' to the results of 'a' and 'b' at each matching
53 /// index; the result counts must be equal. Otherwise, apply 'expr' to the
54 /// Cartesian product of the results. The expression may refer only to d0 and
55 /// d1, which stand for the results of 'a' and 'b', respectively. The output
56 /// map and operands are composed, canonicalized, and simplified.
57 static void combine(const AffineValueMap &a, const AffineValueMap &b,
58 AffineExpr expr, AffineValueMap *res,
59 bool pairwise = true);
60
61 /// Subtract each result of 'b' from the result of 'a' at the same index; the
62 /// result counts must be equal. The output map and operands are composed,
63 /// canonicalized, and simplified.
64 static void difference(const AffineValueMap &a, const AffineValueMap &b,
65 AffineValueMap *res);
66
67 /// Subtract results of 'b' from results of 'a' over their Cartesian product.
68 /// The output map and operands are composed, canonicalized, and simplified.
69 static void cartesianProductDifference(const AffineValueMap &a,
70 const AffineValueMap &b,
71 AffineValueMap *res);
72
73 /// Return true if the idx^th result can be proved to be a multiple of
74 /// 'factor', false otherwise.
75 inline bool isMultipleOf(unsigned idx, int64_t factor) const;
76
77 /// Return true if the idx^th result depends on 'value', false otherwise.
78 bool isFunctionOf(unsigned idx, Value value) const;
79
80 /// Return true if the result at 'idx' is a constant, false
81 /// otherwise.
82 bool isConstant(unsigned idx) const;
83
84 /// Return true if this is an identity map.
85 bool isIdentity() const;
86
87 void setResult(unsigned i, AffineExpr e) { map.setResult(i, e); }
88 AffineExpr getResult(unsigned i) { return map.getResult(i); }
89 inline unsigned getNumOperands() const { return operands.size(); }
90 inline unsigned getNumDims() const { return map.getNumDims(); }
91 inline unsigned getNumSymbols() const { return map.getNumSymbols(); }
92 inline unsigned getNumResults() const { return map.getNumResults(); }
93
94 Value getOperand(unsigned i) const;
96 AffineMap getAffineMap() const;
97
98 /// Attempts to canonicalize the map and operands. Return success if the map
99 /// and/or operands have been modified.
100 LogicalResult canonicalize();
101
102 /// Checks if the application of this map to its operands is semantically
103 /// equal to `other`'s.
104 bool operator==(const AffineValueMap &other) const;
105 bool operator!=(const AffineValueMap &other) const {
106 return !(*this == other);
107 }
108
109private:
110 // A mutable affine map.
112
113 // TODO: make these trailing objects?
114 /// The SSA operands binding to the dim's and symbols of 'map'.
115 SmallVector<Value, 4> operands;
116 /// The SSA results binding to the results of 'map'.
117 SmallVector<Value, 4> results;
118};
119} // namespace affine
120} // namespace mlir
121
122#endif // MLIR_DIALECT_AFFINE_IR_AFFINEVALUEMAP_H
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
Base type for affine expression.
Definition AffineExpr.h:68
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:392
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
An AffineValueMap is an affine map plus its ML value operands and results for analysis purposes.
Value getOperand(unsigned i) const
bool isConstant(unsigned idx) const
Return true if the result at 'idx' is a constant, false otherwise.
static void cartesianProductDifference(const AffineValueMap &a, const AffineValueMap &b, AffineValueMap *res)
Subtract results of 'b' from results of 'a' over their Cartesian product.
bool isIdentity() const
Return true if this is an identity map.
bool operator==(const AffineValueMap &other) const
Checks if the application of this map to its operands is semantically equal to other's.
LogicalResult canonicalize()
Attempts to canonicalize the map and operands.
bool isMultipleOf(unsigned idx, int64_t factor) const
Return true if the idx^th result can be proved to be a multiple of 'factor', false otherwise.
static void combine(const AffineValueMap &a, const AffineValueMap &b, AffineExpr expr, AffineValueMap *res, bool pairwise=true)
Combine results from 'a' and 'b' using 'expr'.
void composeSimplifyAndCanonicalize()
Composes all incoming affine.apply ops and then simplifies and canonicalizes the map and operands.
ArrayRef< Value > getOperands() const
AffineExpr getResult(unsigned i)
bool operator!=(const AffineValueMap &other) const
unsigned getNumOperands() const
bool isFunctionOf(unsigned idx, Value value) const
Return true if the idx^th result depends on 'value', false otherwise.
void setResult(unsigned i, AffineExpr e)
void reset(AffineMap map, ValueRange operands, ValueRange results={})
static void difference(const AffineValueMap &a, const AffineValueMap &b, AffineValueMap *res)
Subtract each result of 'b' from the result of 'a' at the same index; the result counts must be equal...
Include the generated interface declarations.
A mutable affine map. Its affine expressions are however unique.
Definition AffineMap.h:432