MLIR  20.0.0git
AffineExpr.h
Go to the documentation of this file.
1 //===- AffineExpr.h - MLIR Affine Expr 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 affine expression is an affine combination of dimension identifiers and
10 // symbols, including ceildiv/floordiv/mod by a constant integer.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_IR_AFFINEEXPR_H
15 #define MLIR_IR_AFFINEEXPR_H
16 
17 #include "mlir/IR/Visitors.h"
18 #include "mlir/Support/LLVM.h"
19 #include "llvm/ADT/DenseMapInfo.h"
20 #include "llvm/ADT/Hashing.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/Support/Casting.h"
23 #include <type_traits>
24 
25 namespace mlir {
26 
27 class MLIRContext;
28 class AffineMap;
29 class IntegerSet;
30 
31 namespace detail {
32 
33 struct AffineExprStorage;
34 struct AffineBinaryOpExprStorage;
35 struct AffineDimExprStorage;
36 struct AffineConstantExprStorage;
37 
38 } // namespace detail
39 
40 enum class AffineExprKind {
41  Add,
42  /// RHS of mul is always a constant or a symbolic expression.
43  Mul,
44  /// RHS of mod is always a constant or a symbolic expression with a positive
45  /// value.
46  Mod,
47  /// RHS of floordiv is always a constant or a symbolic expression.
48  FloorDiv,
49  /// RHS of ceildiv is always a constant or a symbolic expression.
50  CeilDiv,
51 
52  /// This is a marker for the last affine binary op. The range of binary
53  /// op's is expected to be this element and earlier.
55 
56  /// Constant integer.
57  Constant,
58  /// Dimensional identifier.
59  DimId,
60  /// Symbolic identifier.
61  SymbolId,
62 };
63 
64 /// Base type for affine expression.
65 /// AffineExpr's are immutable value types with intuitive operators to
66 /// operate on chainable, lightweight compositions.
67 /// An AffineExpr is an interface to the underlying storage type pointer.
68 class AffineExpr {
69 public:
71 
72  constexpr AffineExpr() {}
73  /* implicit */ AffineExpr(const ImplType *expr)
74  : expr(const_cast<ImplType *>(expr)) {}
75 
76  bool operator==(AffineExpr other) const { return expr == other.expr; }
77  bool operator!=(AffineExpr other) const { return !(*this == other); }
78  bool operator==(int64_t v) const;
79  bool operator!=(int64_t v) const { return !(*this == v); }
80  explicit operator bool() const { return expr; }
81 
82  bool operator!() const { return expr == nullptr; }
83 
84  template <typename U>
85  [[deprecated("Use llvm::isa<U>() instead")]] constexpr bool isa() const;
86 
87  template <typename U>
88  [[deprecated("Use llvm::dyn_cast<U>() instead")]] U dyn_cast() const;
89 
90  template <typename U>
91  [[deprecated("Use llvm::dyn_cast_or_null<U>() instead")]] U
92  dyn_cast_or_null() const;
93 
94  template <typename U>
95  [[deprecated("Use llvm::cast<U>() instead")]] U cast() const;
96 
97  MLIRContext *getContext() const;
98 
99  /// Return the classification for this type.
100  AffineExprKind getKind() const;
101 
102  void print(raw_ostream &os) const;
103  void dump() const;
104 
105  /// Returns true if this expression is made out of only symbols and
106  /// constants, i.e., it does not involve dimensional identifiers.
107  bool isSymbolicOrConstant() const;
108 
109  /// Returns true if this is a pure affine expression, i.e., multiplication,
110  /// floordiv, ceildiv, and mod is only allowed w.r.t constants.
111  bool isPureAffine() const;
112 
113  /// Returns the greatest known integral divisor of this affine expression. The
114  /// result is always positive.
115  int64_t getLargestKnownDivisor() const;
116 
117  /// Return true if the affine expression is a multiple of 'factor'.
118  bool isMultipleOf(int64_t factor) const;
119 
120  /// Return true if the affine expression involves AffineDimExpr `position`.
121  bool isFunctionOfDim(unsigned position) const;
122 
123  /// Return true if the affine expression involves AffineSymbolExpr `position`.
124  bool isFunctionOfSymbol(unsigned position) const;
125 
126  /// Walk all of the AffineExpr's in this expression in postorder. This allows
127  /// a lambda walk function that can either return `void` or a WalkResult. With
128  /// a WalkResult, interrupting is supported.
129  template <typename FnT, typename RetT = detail::walkResultType<FnT>>
130  RetT walk(FnT &&callback) const {
131  return walk<RetT>(*this, callback);
132  }
133 
134  /// This method substitutes any uses of dimensions and symbols (e.g.
135  /// dim#0 with dimReplacements[0]) and returns the modified expression tree.
136  /// This is a dense replacement method: a replacement must be specified for
137  /// every single dim and symbol.
139  ArrayRef<AffineExpr> symReplacements) const;
140 
141  /// Dim-only version of replaceDimsAndSymbols.
142  AffineExpr replaceDims(ArrayRef<AffineExpr> dimReplacements) const;
143 
144  /// Symbol-only version of replaceDimsAndSymbols.
145  AffineExpr replaceSymbols(ArrayRef<AffineExpr> symReplacements) const;
146 
147  /// Sparse replace method. Replace `expr` by `replacement` and return the
148  /// modified expression tree.
149  AffineExpr replace(AffineExpr expr, AffineExpr replacement) const;
150 
151  /// Sparse replace method. If `*this` appears in `map` replaces it by
152  /// `map[*this]` and return the modified expression tree. Otherwise traverse
153  /// `*this` and apply replace with `map` on its subexpressions.
155 
156  /// Replace dims[offset ... numDims)
157  /// by dims[offset + shift ... shift + numDims).
158  AffineExpr shiftDims(unsigned numDims, unsigned shift,
159  unsigned offset = 0) const;
160 
161  /// Replace symbols[offset ... numSymbols)
162  /// by symbols[offset + shift ... shift + numSymbols).
163  AffineExpr shiftSymbols(unsigned numSymbols, unsigned shift,
164  unsigned offset = 0) const;
165 
166  AffineExpr operator+(int64_t v) const;
167  AffineExpr operator+(AffineExpr other) const;
168  AffineExpr operator-() const;
169  AffineExpr operator-(int64_t v) const;
170  AffineExpr operator-(AffineExpr other) const;
171  AffineExpr operator*(int64_t v) const;
172  AffineExpr operator*(AffineExpr other) const;
173  AffineExpr floorDiv(uint64_t v) const;
174  AffineExpr floorDiv(AffineExpr other) const;
175  AffineExpr ceilDiv(uint64_t v) const;
176  AffineExpr ceilDiv(AffineExpr other) const;
177  AffineExpr operator%(uint64_t v) const;
178  AffineExpr operator%(AffineExpr other) const;
179 
180  /// Compose with an AffineMap.
181  /// Returns the composition of this AffineExpr with `map`.
182  ///
183  /// Prerequisites:
184  /// `this` and `map` are composable, i.e. that the number of AffineDimExpr of
185  /// `this` is smaller than the number of results of `map`. If a result of a
186  /// map does not have a corresponding AffineDimExpr, that result simply does
187  /// not appear in the produced AffineExpr.
188  ///
189  /// Example:
190  /// expr: `d0 + d2`
191  /// map: `(d0, d1, d2)[s0, s1] -> (d0 + s1, d1 + s0, d0 + d1 + d2)`
192  /// returned expr: `d0 * 2 + d1 + d2 + s1`
193  AffineExpr compose(AffineMap map) const;
194 
195  friend ::llvm::hash_code hash_value(AffineExpr arg);
196 
197  /// Methods supporting C API.
198  const void *getAsOpaquePointer() const {
199  return static_cast<const void *>(expr);
200  }
201  static AffineExpr getFromOpaquePointer(const void *pointer) {
202  return AffineExpr(
203  reinterpret_cast<ImplType *>(const_cast<void *>(pointer)));
204  }
205 
206  ImplType *getImpl() const { return expr; }
207 
208 protected:
209  ImplType *expr{nullptr};
210 
211 private:
212  /// A trampoline for the templated non-static AffineExpr::walk method to
213  /// dispatch lambda `callback`'s of either a void result type or a
214  /// WalkResult type. Walk all of the AffineExprs in `e` in postorder. Users
215  /// should use the regular (non-static) `walk` method.
216  template <typename WalkRetTy>
217  static WalkRetTy walk(AffineExpr e,
218  function_ref<WalkRetTy(AffineExpr)> callback);
219 };
220 
221 /// Affine binary operation expression. An affine binary operation could be an
222 /// add, mul, floordiv, ceildiv, or a modulo operation. (Subtraction is
223 /// represented through a multiply by -1 and add.) These expressions are always
224 /// constructed in a simplified form. For eg., the LHS and RHS operands can't
225 /// both be constants. There are additional canonicalizing rules depending on
226 /// the op type: see checks in the constructor.
228 public:
230  /* implicit */ AffineBinaryOpExpr(AffineExpr::ImplType *ptr);
231  AffineExpr getLHS() const;
232  AffineExpr getRHS() const;
233 };
234 
235 /// A dimensional identifier appearing in an affine expression.
236 class AffineDimExpr : public AffineExpr {
237 public:
239  /* implicit */ AffineDimExpr(AffineExpr::ImplType *ptr);
240  unsigned getPosition() const;
241 };
242 
243 /// A symbolic identifier appearing in an affine expression.
244 class AffineSymbolExpr : public AffineExpr {
245 public:
247  /* implicit */ AffineSymbolExpr(AffineExpr::ImplType *ptr);
248  unsigned getPosition() const;
249 };
250 
251 /// An integer constant appearing in affine expression.
253 public:
255  /* implicit */ AffineConstantExpr(AffineExpr::ImplType *ptr = nullptr);
256  int64_t getValue() const;
257 };
258 
259 /// Make AffineExpr hashable.
260 inline ::llvm::hash_code hash_value(AffineExpr arg) {
262 }
263 
264 inline AffineExpr operator+(int64_t val, AffineExpr expr) { return expr + val; }
265 inline AffineExpr operator*(int64_t val, AffineExpr expr) { return expr * val; }
266 inline AffineExpr operator-(int64_t val, AffineExpr expr) {
267  return expr * (-1) + val;
268 }
269 
270 /// These free functions allow clients of the API to not use classes in detail.
271 AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context);
272 AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context);
273 AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context);
274 SmallVector<AffineExpr> getAffineConstantExprs(ArrayRef<int64_t> constants,
275  MLIRContext *context);
276 AffineExpr getAffineBinaryOpExpr(AffineExprKind kind, AffineExpr lhs,
277  AffineExpr rhs);
278 
279 /// Constructs an affine expression from a flat ArrayRef. If there are local
280 /// identifiers (neither dimensional nor symbolic) that appear in the sum of
281 /// products expression, 'localExprs' is expected to have the AffineExpr
282 /// for it, and is substituted into. The ArrayRef 'eq' is expected to be in the
283 /// format [dims, symbols, locals, constant term].
284 AffineExpr getAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
285  unsigned numDims, unsigned numSymbols,
286  ArrayRef<AffineExpr> localExprs,
287  MLIRContext *context);
288 
289 raw_ostream &operator<<(raw_ostream &os, AffineExpr expr);
290 
291 template <typename U>
292 constexpr bool AffineExpr::isa() const {
293  if constexpr (std::is_same_v<U, AffineBinaryOpExpr>)
295  if constexpr (std::is_same_v<U, AffineDimExpr>)
296  return getKind() == AffineExprKind::DimId;
297  if constexpr (std::is_same_v<U, AffineSymbolExpr>)
298  return getKind() == AffineExprKind::SymbolId;
299  if constexpr (std::is_same_v<U, AffineConstantExpr>)
300  return getKind() == AffineExprKind::Constant;
301 }
302 template <typename U>
304  return llvm::dyn_cast<U>(*this);
305 }
306 template <typename U>
308  return llvm::dyn_cast_or_null<U>(*this);
309 }
310 template <typename U>
311 U AffineExpr::cast() const {
312  return llvm::cast<U>(*this);
313 }
314 
315 /// Simplify an affine expression by flattening and some amount of simple
316 /// analysis. This has complexity linear in the number of nodes in 'expr'.
317 /// Returns the simplified expression, which is the same as the input expression
318 /// if it can't be simplified. When `expr` is semi-affine, a simplified
319 /// semi-affine expression is constructed in the sorted order of dimension and
320 /// symbol positions.
321 AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims,
322  unsigned numSymbols);
323 
324 namespace detail {
325 template <int N>
326 void bindDims(MLIRContext *ctx) {}
327 
328 template <int N, typename AffineExprTy, typename... AffineExprTy2>
329 void bindDims(MLIRContext *ctx, AffineExprTy &e, AffineExprTy2 &...exprs) {
330  e = getAffineDimExpr(N, ctx);
331  bindDims<N + 1, AffineExprTy2 &...>(ctx, exprs...);
332 }
333 
334 template <int N>
336 
337 template <int N, typename AffineExprTy, typename... AffineExprTy2>
338 void bindSymbols(MLIRContext *ctx, AffineExprTy &e, AffineExprTy2 &...exprs) {
339  e = getAffineSymbolExpr(N, ctx);
340  bindSymbols<N + 1, AffineExprTy2 &...>(ctx, exprs...);
341 }
342 
343 } // namespace detail
344 
345 /// Bind a list of AffineExpr references to DimExpr at positions:
346 /// [0 .. sizeof...(exprs)]
347 template <typename... AffineExprTy>
348 void bindDims(MLIRContext *ctx, AffineExprTy &...exprs) {
349  detail::bindDims<0>(ctx, exprs...);
350 }
351 
352 template <typename AffineExprTy>
354  int idx = 0;
355  for (AffineExprTy &e : exprs)
356  e = getAffineDimExpr(idx++, ctx);
357 }
358 
359 /// Bind a list of AffineExpr references to SymbolExpr at positions:
360 /// [0 .. sizeof...(exprs)]
361 template <typename... AffineExprTy>
362 void bindSymbols(MLIRContext *ctx, AffineExprTy &...exprs) {
363  detail::bindSymbols<0>(ctx, exprs...);
364 }
365 
366 template <typename AffineExprTy>
368  int idx = 0;
369  for (AffineExprTy &e : exprs)
370  e = getAffineSymbolExpr(idx++, ctx);
371 }
372 
373 /// Get a lower or upper (depending on `isUpper`) bound for `expr` while using
374 /// the constant lower and upper bounds for its inputs provided in
375 /// `constLowerBounds` and `constUpperBounds`. Return std::nullopt if such a
376 /// bound can't be computed. This method only handles simple sum of product
377 /// expressions (w.r.t constant coefficients) so as to not depend on anything
378 /// heavyweight in `Analysis`. Expressions of the form: c0*d0 + c1*d1 + c2*s0 +
379 /// ... + c_n are handled. Expressions involving floordiv, ceildiv, mod or
380 /// semi-affine ones will lead a none being returned.
381 std::optional<int64_t>
382 getBoundForAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols,
383  ArrayRef<std::optional<int64_t>> constLowerBounds,
384  ArrayRef<std::optional<int64_t>> constUpperBounds,
385  bool isUpper);
386 
387 } // namespace mlir
388 
389 namespace llvm {
390 
391 // AffineExpr hash just like pointers
392 template <>
393 struct DenseMapInfo<mlir::AffineExpr> {
395  auto *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
396  return mlir::AffineExpr(static_cast<mlir::AffineExpr::ImplType *>(pointer));
397  }
400  return mlir::AffineExpr(static_cast<mlir::AffineExpr::ImplType *>(pointer));
401  }
402  static unsigned getHashValue(mlir::AffineExpr val) {
403  return mlir::hash_value(val);
404  }
405  static bool isEqual(mlir::AffineExpr LHS, mlir::AffineExpr RHS) {
406  return LHS == RHS;
407  }
408 };
409 
410 /// Add support for llvm style casts. We provide a cast between To and From if
411 /// From is mlir::AffineExpr or derives from it.
412 template <typename To, typename From>
413 struct CastInfo<To, From,
414  std::enable_if_t<std::is_same_v<mlir::AffineExpr,
415  std::remove_const_t<From>> ||
416  std::is_base_of_v<mlir::AffineExpr, From>>>
418  DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
419 
420  static inline bool isPossible(mlir::AffineExpr expr) {
421  /// Return a constant true instead of a dynamic true when casting to self or
422  /// up the hierarchy.
423  if constexpr (std::is_base_of_v<To, From>) {
424  return true;
425  } else {
426  if constexpr (std::is_same_v<To, ::mlir::AffineBinaryOpExpr>)
427  return expr.getKind() <= ::mlir::AffineExprKind::LAST_AFFINE_BINARY_OP;
428  if constexpr (std::is_same_v<To, ::mlir::AffineDimExpr>)
429  return expr.getKind() == ::mlir::AffineExprKind::DimId;
430  if constexpr (std::is_same_v<To, ::mlir::AffineSymbolExpr>)
431  return expr.getKind() == ::mlir::AffineExprKind::SymbolId;
432  if constexpr (std::is_same_v<To, ::mlir::AffineConstantExpr>)
433  return expr.getKind() == ::mlir::AffineExprKind::Constant;
434  }
435  }
436  static inline To doCast(mlir::AffineExpr expr) { return To(expr.getImpl()); }
437 };
438 
439 } // namespace llvm
440 
441 #endif // MLIR_IR_AFFINEEXPR_H
Affine binary operation expression.
Definition: AffineExpr.h:227
AffineExpr getLHS() const
Definition: AffineExpr.cpp:340
AffineBinaryOpExpr(AffineExpr::ImplType *ptr)
Definition: AffineExpr.cpp:338
AffineExpr getRHS() const
Definition: AffineExpr.cpp:343
An integer constant appearing in affine expression.
Definition: AffineExpr.h:252
AffineConstantExpr(AffineExpr::ImplType *ptr=nullptr)
Definition: AffineExpr.cpp:631
int64_t getValue() const
Definition: AffineExpr.cpp:633
A dimensional identifier appearing in an affine expression.
Definition: AffineExpr.h:236
AffineDimExpr(AffineExpr::ImplType *ptr)
Definition: AffineExpr.cpp:347
unsigned getPosition() const
Definition: AffineExpr.cpp:348
Base type for affine expression.
Definition: AffineExpr.h:68
static AffineExpr getFromOpaquePointer(const void *pointer)
Definition: AffineExpr.h:201
AffineExpr replaceDimsAndSymbols(ArrayRef< AffineExpr > dimReplacements, ArrayRef< AffineExpr > symReplacements) const
This method substitutes any uses of dimensions and symbols (e.g.
Definition: AffineExpr.cpp:89
AffineExpr shiftDims(unsigned numDims, unsigned shift, unsigned offset=0) const
Replace dims[offset ...
Definition: AffineExpr.cpp:133
ImplType * getImpl() const
Definition: AffineExpr.h:206
AffineExpr operator+(int64_t v) const
Definition: AffineExpr.cpp:783
U dyn_cast_or_null() const
Definition: AffineExpr.h:307
friend ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:260
bool isSymbolicOrConstant() const
Returns true if this expression is made out of only symbols and constants, i.e., it does not involve ...
Definition: AffineExpr.cpp:188
AffineExpr operator*(int64_t v) const
Definition: AffineExpr.cpp:848
constexpr AffineExpr()
Definition: AffineExpr.h:72
bool operator==(AffineExpr other) const
Definition: AffineExpr.h:76
bool isPureAffine() const
Returns true if this is a pure affine expression, i.e., multiplication, floordiv, ceildiv,...
Definition: AffineExpr.cpp:212
AffineExpr shiftSymbols(unsigned numSymbols, unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
Definition: AffineExpr.cpp:145
AffineExpr operator-() const
Definition: AffineExpr.cpp:861
U cast() const
Definition: AffineExpr.h:311
AffineExpr floorDiv(uint64_t v) const
Definition: AffineExpr.cpp:917
ImplType * expr
Definition: AffineExpr.h:209
RetT walk(FnT &&callback) const
Walk all of the AffineExpr's in this expression in postorder.
Definition: AffineExpr.h:130
bool operator!=(int64_t v) const
Definition: AffineExpr.h:79
AffineExprKind getKind() const
Return the classification for this type.
Definition: AffineExpr.cpp:35
bool isMultipleOf(int64_t factor) const
Return true if the affine expression is a multiple of 'factor'.
Definition: AffineExpr.cpp:283
bool operator!() const
Definition: AffineExpr.h:82
int64_t getLargestKnownDivisor() const
Returns the greatest known integral divisor of this affine expression.
Definition: AffineExpr.cpp:243
AffineExpr compose(AffineMap map) const
Compose with an AffineMap.
constexpr bool isa() const
Definition: AffineExpr.h:292
bool isFunctionOfDim(unsigned position) const
Return true if the affine expression involves AffineDimExpr position.
Definition: AffineExpr.cpp:316
const void * getAsOpaquePointer() const
Methods supporting C API.
Definition: AffineExpr.h:198
bool isFunctionOfSymbol(unsigned position) const
Return true if the affine expression involves AffineSymbolExpr position.
Definition: AffineExpr.cpp:327
AffineExpr replaceDims(ArrayRef< AffineExpr > dimReplacements) const
Dim-only version of replaceDimsAndSymbols.
Definition: AffineExpr.cpp:122
bool operator!=(AffineExpr other) const
Definition: AffineExpr.h:77
AffineExpr operator%(uint64_t v) const
MLIRContext * getContext() const
Definition: AffineExpr.cpp:33
AffineExpr replace(AffineExpr expr, AffineExpr replacement) const
Sparse replace method.
Definition: AffineExpr.cpp:181
AffineExpr replaceSymbols(ArrayRef< AffineExpr > symReplacements) const
Symbol-only version of replaceDimsAndSymbols.
Definition: AffineExpr.cpp:127
AffineExpr(const ImplType *expr)
Definition: AffineExpr.h:73
void dump() const
AffineExpr ceilDiv(uint64_t v) const
Definition: AffineExpr.cpp:964
void print(raw_ostream &os) const
U dyn_cast() const
Definition: AffineExpr.h:303
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition: AffineMap.h:46
A symbolic identifier appearing in an affine expression.
Definition: AffineExpr.h:244
AffineSymbolExpr(AffineExpr::ImplType *ptr)
Definition: AffineExpr.cpp:621
unsigned getPosition() const
Definition: AffineExpr.cpp:623
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
void bindDims(MLIRContext *ctx)
Definition: AffineExpr.h:326
void bindSymbols(MLIRContext *ctx)
Definition: AffineExpr.h:335
Include the generated interface declarations.
std::optional< int64_t > getBoundForAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols, ArrayRef< std::optional< int64_t >> constLowerBounds, ArrayRef< std::optional< int64_t >> constUpperBounds, bool isUpper)
Get a lower or upper (depending on isUpper) bound for expr while using the constant lower and upper b...
void bindDimsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
Definition: AffineExpr.h:353
void bindDims(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to DimExpr at positions: [0 .
Definition: AffineExpr.h:348
AffineExprKind
Definition: AffineExpr.h:40
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ LAST_AFFINE_BINARY_OP
This is a marker for the last affine binary op.
@ Mul
RHS of mul is always a constant or a symbolic expression.
@ Mod
RHS of mod is always a constant or a symbolic expression with a positive value.
@ DimId
Dimensional identifier.
@ FloorDiv
RHS of floordiv is always a constant or a symbolic expression.
@ Constant
Constant integer.
@ SymbolId
Symbolic identifier.
AffineExpr getAffineBinaryOpExpr(AffineExprKind kind, AffineExpr lhs, AffineExpr rhs)
Definition: AffineExpr.cpp:70
AffineExpr operator-(int64_t val, AffineExpr expr)
Definition: AffineExpr.h:266
AffineExpr getAffineExprFromFlatForm(ArrayRef< int64_t > flatExprs, unsigned numDims, unsigned numSymbols, ArrayRef< AffineExpr > localExprs, MLIRContext *context)
Constructs an affine expression from a flat ArrayRef.
void bindSymbols(MLIRContext *ctx, AffineExprTy &...exprs)
Bind a list of AffineExpr references to SymbolExpr at positions: [0 .
Definition: AffineExpr.h:362
AffineExpr operator+(int64_t val, AffineExpr expr)
Definition: AffineExpr.h:264
AffineExpr operator*(int64_t val, AffineExpr expr)
Definition: AffineExpr.h:265
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
Definition: AffineExpr.cpp:641
AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols)
Simplify an affine expression by flattening and some amount of simple analysis.
SmallVector< AffineExpr > getAffineConstantExprs(ArrayRef< int64_t > constants, MLIRContext *context)
Definition: AffineExpr.cpp:651
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:260
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
Definition: AffineExpr.cpp:617
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
Definition: AffineExpr.cpp:627
void bindSymbolsList(MLIRContext *ctx, MutableArrayRef< AffineExprTy > exprs)
Definition: AffineExpr.h:367
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
Definition: AliasAnalysis.h:78
static unsigned getHashValue(mlir::AffineExpr val)
Definition: AffineExpr.h:402
static mlir::AffineExpr getEmptyKey()
Definition: AffineExpr.h:394
static mlir::AffineExpr getTombstoneKey()
Definition: AffineExpr.h:398
static bool isEqual(mlir::AffineExpr LHS, mlir::AffineExpr RHS)
Definition: AffineExpr.h:405
A binary operation appearing in an affine expression.
An integer constant appearing in affine expression.
A dimensional or symbolic identifier appearing in an affine expression.
Base storage class appearing in an affine expression.