MLIR  15.0.0git
AffineMap.h
Go to the documentation of this file.
1 //===- AffineMap.h - MLIR Affine 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 // Affine maps are mathematical functions which map a list of dimension
10 // identifiers and symbols, to multidimensional affine expressions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_IR_AFFINEMAP_H
15 #define MLIR_IR_AFFINEMAP_H
16 
17 #include "mlir/IR/AffineExpr.h"
18 #include "mlir/Support/LLVM.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMapInfo.h"
21 
22 namespace llvm {
23 class SmallBitVector;
24 } // namespace llvm
25 
26 namespace mlir {
27 
28 namespace detail {
29 struct AffineMapStorage;
30 } // namespace detail
31 
32 class Attribute;
33 struct LogicalResult;
34 class MLIRContext;
35 
36 /// A multi-dimensional affine map
37 /// Affine map's are immutable like Type's, and they are uniqued.
38 /// Eg: (d0, d1) -> (d0/128, d0 mod 128, d1)
39 /// The names used (d0, d1) don't matter - it's the mathematical function that
40 /// is unique to this affine map.
41 class AffineMap {
42 public:
44 
45  constexpr AffineMap() = default;
46  explicit AffineMap(ImplType *map) : map(map) {}
47 
48  /// Returns a zero result affine map with no dimensions or symbols: () -> ().
49  static AffineMap get(MLIRContext *context);
50 
51  /// Returns a zero result affine map with `dimCount` dimensions and
52  /// `symbolCount` symbols, e.g.: `(...) -> ()`.
53  static AffineMap get(unsigned dimCount, unsigned symbolCount,
54  MLIRContext *context);
55 
56  /// Returns an affine map with `dimCount` dimensions and `symbolCount` mapping
57  /// to a single output dimension
58  static AffineMap get(unsigned dimCount, unsigned symbolCount,
59  AffineExpr result);
60 
61  /// Returns an affine map with `dimCount` dimensions and `symbolCount` mapping
62  /// to the given results.
63  static AffineMap get(unsigned dimCount, unsigned symbolCount,
64  ArrayRef<AffineExpr> results, MLIRContext *context);
65 
66  /// Returns a single constant result affine map.
67  static AffineMap getConstantMap(int64_t val, MLIRContext *context);
68 
69  /// Returns an AffineMap with 'numDims' identity result dim exprs.
70  static AffineMap getMultiDimIdentityMap(unsigned numDims,
71  MLIRContext *context);
72 
73  /// Returns an identity affine map (d0, ..., dn) -> (dp, ..., dn) on the most
74  /// minor dimensions.
75  static AffineMap getMinorIdentityMap(unsigned dims, unsigned results,
76  MLIRContext *context);
77 
78  /// Returns an AffineMap representing a permutation.
79  /// The permutation is expressed as a non-empty vector of integers.
80  /// E.g. the permutation `(i,j,k) -> (j,k,i)` will be expressed with
81  /// `permutation = [1,2,0]`. All values in `permutation` must be
82  /// integers, in the range 0..`permutation.size()-1` without duplications
83  /// (i.e. `[1,1,2]` is an invalid permutation).
84  static AffineMap getPermutationMap(ArrayRef<unsigned> permutation,
85  MLIRContext *context);
86 
87  /// Returns a vector of AffineMaps; each with as many results as
88  /// `exprs.size()`, as many dims as the largest dim in `exprs` and as many
89  /// symbols as the largest symbol in `exprs`.
94 
95  MLIRContext *getContext() const;
96 
97  explicit operator bool() const { return map != nullptr; }
98  bool operator==(AffineMap other) const { return other.map == map; }
99  bool operator!=(AffineMap other) const { return !(other.map == map); }
100 
101  /// Returns true if this affine map is an identity affine map.
102  /// An identity affine map corresponds to an identity affine function on the
103  /// dimensional identifiers.
104  bool isIdentity() const;
105 
106  /// Returns true if this affine map is a minor identity, i.e. an identity
107  /// affine map (d0, ..., dn) -> (dp, ..., dn) on the most minor dimensions.
108  bool isMinorIdentity() const;
109 
110  /// Returns true if this affine map is a minor identity up to broadcasted
111  /// dimensions which are indicated by value 0 in the result. If
112  /// `broadcastedDims` is not null, it will be populated with the indices of
113  /// the broadcasted dimensions in the result array.
114  /// Example: affine_map<(d0, d1, d2, d3, d4) -> (0, d2, 0, d4)>
115  /// (`broadcastedDims` will contain [0, 2])
116  bool isMinorIdentityWithBroadcasting(
117  SmallVectorImpl<unsigned> *broadcastedDims = nullptr) const;
118 
119  /// Return true if this affine map can be converted to a minor identity with
120  /// broadcast by doing a permute. Return a permutation (there may be
121  /// several) to apply to get to a minor identity with broadcasts.
122  /// Ex:
123  /// * (d0, d1, d2) -> (0, d1) maps to minor identity (d1, 0 = d2) with
124  /// perm = [1, 0] and broadcast d2
125  /// * (d0, d1, d2) -> (d0, 0) cannot be mapped to a minor identity by
126  /// permutation + broadcast
127  /// * (d0, d1, d2, d3) -> (0, d1, d3) maps to minor identity (d1, 0 = d2, d3)
128  /// with perm = [1, 0, 2] and broadcast d2
129  /// * (d0, d1) -> (d1, 0, 0, d0) maps to minor identity (d0, d1) with extra
130  /// leading broadcat dimensions. The map returned would be (0, 0, d0, d1)
131  /// with perm = [3, 0, 1, 2]
132  bool isPermutationOfMinorIdentityWithBroadcasting(
133  SmallVectorImpl<unsigned> &permutedDims) const;
134 
135  /// Returns true if this affine map is an empty map, i.e., () -> ().
136  bool isEmpty() const;
137 
138  /// Returns true if this affine map is a single result constant function.
139  bool isSingleConstant() const;
140 
141  /// Returns true if this affine map has only constant results.
142  bool isConstant() const;
143 
144  /// Returns the constant result of this map. This methods asserts that the map
145  /// has a single constant result.
146  int64_t getSingleConstantResult() const;
147 
148  /// Returns the constant results of this map. This method asserts that the map
149  /// has all constant results.
150  SmallVector<int64_t> getConstantResults() const;
151 
152  // Prints affine map to 'os'.
153  void print(raw_ostream &os) const;
154  void dump() const;
155 
156  unsigned getNumDims() const;
157  unsigned getNumSymbols() const;
158  unsigned getNumResults() const;
159  unsigned getNumInputs() const;
160 
161  ArrayRef<AffineExpr> getResults() const;
162  AffineExpr getResult(unsigned idx) const;
163 
164  /// Extracts the position of the dimensional expression at the given result,
165  /// when the caller knows it is safe to do so.
166  unsigned getDimPosition(unsigned idx) const;
167 
168  /// Extracts the permuted position where given input index resides.
169  /// Fails when called on a non-permutation.
170  unsigned getPermutedPosition(unsigned input) const;
171 
172  /// Return true if any affine expression involves AffineDimExpr `position`.
173  bool isFunctionOfDim(unsigned position) const {
174  return llvm::any_of(getResults(), [&](AffineExpr e) {
175  return e.isFunctionOfDim(position);
176  });
177  }
178 
179  /// Return true if any affine expression involves AffineSymbolExpr `position`.
180  bool isFunctionOfSymbol(unsigned position) const {
181  return llvm::any_of(getResults(), [&](AffineExpr e) {
182  return e.isFunctionOfSymbol(position);
183  });
184  }
185 
186  /// Walk all of the AffineExpr's in this mapping. Each node in an expression
187  /// tree is visited in postorder.
188  void walkExprs(llvm::function_ref<void(AffineExpr)> callback) const;
189 
190  /// This method substitutes any uses of dimensions and symbols (e.g.
191  /// dim#0 with dimReplacements[0]) in subexpressions and returns the modified
192  /// expression mapping. Because this can be used to eliminate dims and
193  /// symbols, the client needs to specify the number of dims and symbols in
194  /// the result. The returned map always has the same number of results.
195  AffineMap replaceDimsAndSymbols(ArrayRef<AffineExpr> dimReplacements,
196  ArrayRef<AffineExpr> symReplacements,
197  unsigned numResultDims,
198  unsigned numResultSyms) const;
199 
200  /// Sparse replace method. Apply AffineExpr::replace(`expr`, `replacement`) to
201  /// each of the results and return a new AffineMap with the new results and
202  /// with the specified number of dims and symbols.
203  AffineMap replace(AffineExpr expr, AffineExpr replacement,
204  unsigned numResultDims, unsigned numResultSyms) const;
205 
206  /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
207  /// results and return a new AffineMap with the new results and with inferred
208  /// number of dims and symbols.
209  AffineMap replace(const DenseMap<AffineExpr, AffineExpr> &map) const;
210 
211  /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
212  /// results and return a new AffineMap with the new results and with the
213  /// specified number of dims and symbols.
214  AffineMap replace(const DenseMap<AffineExpr, AffineExpr> &map,
215  unsigned numResultDims, unsigned numResultSyms) const;
216 
217  /// Replace dims[offset ... numDims)
218  /// by dims[offset + shift ... shift + numDims).
219  AffineMap shiftDims(unsigned shift, unsigned offset = 0) const {
220  assert(offset <= getNumDims());
221  return AffineMap::get(getNumDims() + shift, getNumSymbols(),
222  llvm::to_vector<4>(llvm::map_range(
223  getResults(),
224  [&](AffineExpr e) {
225  return e.shiftDims(getNumDims(), shift, offset);
226  })),
227  getContext());
228  }
229 
230  /// Replace symbols[offset ... numSymbols)
231  /// by symbols[offset + shift ... shift + numSymbols).
232  AffineMap shiftSymbols(unsigned shift, unsigned offset = 0) const {
233  return AffineMap::get(getNumDims(), getNumSymbols() + shift,
234  llvm::to_vector<4>(llvm::map_range(
235  getResults(),
236  [&](AffineExpr e) {
237  return e.shiftSymbols(getNumSymbols(), shift,
238  offset);
239  })),
240  getContext());
241  }
242 
243  /// Folds the results of the application of an affine map on the provided
244  /// operands to a constant if possible.
245  LogicalResult constantFold(ArrayRef<Attribute> operandConstants,
246  SmallVectorImpl<Attribute> &results) const;
247 
248  /// Propagates the constant operands into this affine map. Operands are
249  /// allowed to be null, at which point they are treated as non-constant. This
250  /// does not change the number of symbols and dimensions. Returns a new map,
251  /// which may be equal to the old map if no folding happened. If `results` is
252  /// provided and if all expressions in the map were folded to constants,
253  /// `results` will contain the values of these constants.
254  AffineMap
255  partialConstantFold(ArrayRef<Attribute> operandConstants,
256  SmallVectorImpl<int64_t> *results = nullptr) const;
257 
258  /// Returns the AffineMap resulting from composing `this` with `map`.
259  /// The resulting AffineMap has as many AffineDimExpr as `map` and as many
260  /// AffineSymbolExpr as the concatenation of `this` and `map` (in which case
261  /// the symbols of `this` map come first).
262  ///
263  /// Prerequisites:
264  /// The maps are composable, i.e. that the number of AffineDimExpr of `this`
265  /// matches the number of results of `map`.
266  ///
267  /// Example:
268  /// map1: `(d0, d1)[s0, s1] -> (d0 + 1 + s1, d1 - 1 - s0)`
269  /// map2: `(d0)[s0] -> (d0 + s0, d0 - s0)`
270  /// map1.compose(map2):
271  /// `(d0)[s0, s1, s2] -> (d0 + s1 + s2 + 1, d0 - s0 - s2 - 1)`
272  AffineMap compose(AffineMap map) const;
273 
274  /// Applies composition by the dims of `this` to the integer `values` and
275  /// returns the resulting values. `this` must be symbol-less.
276  SmallVector<int64_t, 4> compose(ArrayRef<int64_t> values) const;
277 
278  /// Returns true if the AffineMap represents a subset (i.e. a projection) of a
279  /// symbol-less permutation map. `allowZeroInResults` allows projected
280  /// permutation maps with constant zero result expressions.
281  /// TODO: Remove `allowZeroInResults` when constant zero result expressions
282  /// are broadly supported.
283  bool isProjectedPermutation(bool allowZeroInResults = false) const;
284 
285  /// Returns true if the AffineMap represents a symbol-less permutation map.
286  bool isPermutation() const;
287 
288  /// Returns the map consisting of the `resultPos` subset.
289  AffineMap getSubMap(ArrayRef<unsigned> resultPos) const;
290 
291  /// Returns the map consisting of `length` expressions starting from `start`.
292  AffineMap getSliceMap(unsigned start, unsigned length) const;
293 
294  /// Returns the map consisting of the most major `numResults` results.
295  /// Returns the null AffineMap if `numResults` == 0.
296  /// Returns `*this` if `numResults` >= `this->getNumResults()`.
297  AffineMap getMajorSubMap(unsigned numResults) const;
298 
299  /// Returns the map consisting of the most minor `numResults` results.
300  /// Returns the null AffineMap if `numResults` == 0.
301  /// Returns `*this` if `numResults` >= `this->getNumResults()`.
302  AffineMap getMinorSubMap(unsigned numResults) const;
303 
304  friend ::llvm::hash_code hash_value(AffineMap arg);
305 
306  /// Methods supporting C API.
307  const void *getAsOpaquePointer() const {
308  return static_cast<const void *>(map);
309  }
310  static AffineMap getFromOpaquePointer(const void *pointer) {
311  return AffineMap(reinterpret_cast<ImplType *>(const_cast<void *>(pointer)));
312  }
313 
314 private:
315  ImplType *map{nullptr};
316 
317  static AffineMap getImpl(unsigned dimCount, unsigned symbolCount,
318  ArrayRef<AffineExpr> results, MLIRContext *context);
319 };
320 
321 // Make AffineExpr hashable.
322 inline ::llvm::hash_code hash_value(AffineMap arg) {
323  return ::llvm::hash_value(arg.map);
324 }
325 
326 /// A mutable affine map. Its affine expressions are however unique.
328 public:
329  MutableAffineMap() = default;
331 
332  ArrayRef<AffineExpr> getResults() const { return results; }
333  AffineExpr getResult(unsigned idx) const { return results[idx]; }
334  void setResult(unsigned idx, AffineExpr result) { results[idx] = result; }
335  unsigned getNumResults() const { return results.size(); }
336  unsigned getNumDims() const { return numDims; }
337  void setNumDims(unsigned d) { numDims = d; }
338  unsigned getNumSymbols() const { return numSymbols; }
339  void setNumSymbols(unsigned d) { numSymbols = d; }
340  MLIRContext *getContext() const { return context; }
341 
342  /// Returns true if the idx'th result expression is a multiple of factor.
343  bool isMultipleOf(unsigned idx, int64_t factor) const;
344 
345  /// Resets this MutableAffineMap with 'map'.
346  void reset(AffineMap map);
347 
348  /// Simplify the (result) expressions in this map using analysis (used by
349  //-simplify-affine-expr pass).
350  void simplify();
351  /// Get the AffineMap corresponding to this MutableAffineMap. Note that an
352  /// AffineMap will be uniqued and stored in context, while a mutable one
353  /// isn't.
354  AffineMap getAffineMap() const;
355 
356 private:
357  // Same meaning as AffineMap's fields.
359  unsigned numDims = 0;
360  unsigned numSymbols = 0;
361  /// A pointer to the IR's context to store all newly created
362  /// AffineExprStorage's.
363  MLIRContext *context = nullptr;
364 };
365 
366 /// Simplifies an affine map by simplifying its underlying AffineExpr results.
368 
369 /// Drop the dims that are not used.
371 
372 /// Drop the dims that are not used by any of the individual maps in `maps`.
373 /// Asserts that all maps in `maps` are normalized to the same number of
374 /// dims and symbols.
376 
377 /// Drop the dims that are not listed in `unusedDims`.
378 AffineMap compressDims(AffineMap map, const llvm::SmallBitVector &unusedDims);
379 
380 /// Drop the symbols that are not used.
382 
383 /// Drop the symbols that are not used by any of the individual maps in `maps`.
384 /// Asserts that all maps in `maps` are normalized to the same number of
385 /// dims and symbols.
387 
388 /// Drop the symbols that are not listed in `unusedSymbols`.
390  const llvm::SmallBitVector &unusedSymbols);
391 
392 /// Returns a map with the same dimension and symbol count as `map`, but whose
393 /// results are the unique affine expressions of `map`.
395 
396 /// Returns a map of codomain to domain dimensions such that the first codomain
397 /// dimension for a particular domain dimension is selected.
398 /// Returns an empty map if the input map is empty.
399 /// Returns null map (not empty map) if `map` is not invertible (i.e. `map` does
400 /// not contain a subset that is a permutation of full domain rank).
401 ///
402 /// Prerequisites:
403 /// 1. `map` has no symbols.
404 ///
405 /// Example 1:
406 ///
407 /// ```mlir
408 /// (d0, d1, d2) -> (d1, d1, d0, d2, d1, d2, d1, d0)
409 /// 0 2 3
410 /// ```
411 ///
412 /// returns:
413 ///
414 /// ```mlir
415 /// (d0, d1, d2, d3, d4, d5, d6, d7) -> (d2, d0, d3)
416 /// ```
417 ///
418 /// Example 2:
419 ///
420 /// ```mlir
421 /// (d0, d1, d2) -> (d1, d0 + d1, d0, d2, d1, d2, d1, d0)
422 /// 0 2 3
423 /// ```
424 ///
425 /// returns:
426 ///
427 /// ```mlir
428 /// (d0, d1, d2, d3, d4, d5, d6, d7) -> (d2, d0, d3)
429 /// ```
431 
432 /// Return the reverse map of a projected permutation where the projected
433 /// dimensions are transformed into 0s.
434 ///
435 /// Prerequisites: `map` must be a projected permuation.
436 ///
437 /// Example 1:
438 ///
439 /// ```mlir
440 /// affine_map<(d0, d1, d2, d3) -> (d2, d0)>
441 /// ```
442 ///
443 /// returns:
444 ///
445 /// ```mlir
446 /// affine_map<(d0, d1) -> (d1, 0, d0, 0)>
447 /// ```
448 ///
449 /// Example 2:
450 ///
451 /// ```mlir
452 /// affine_map<(d0, d1, d2, d3) -> (d0, d3)>
453 /// ```
454 ///
455 /// returns:
456 ///
457 /// ```mlir
458 /// affine_map<(d0, d1) -> (d0, 0, 0, d1)>
459 /// ```
460 ///
461 /// Example 3:
462 ///
463 /// ```mlir
464 /// affine_map<(d0, d1, d2, d3) -> (d2)>
465 /// ```
466 ///
467 /// returns:
468 ///
469 /// ```mlir
470 /// affine_map<(d0) -> (0, 0, d0, 0)>
471 /// ```
472 /// Example 4:
473 ///
474 /// ```mlir
475 /// affine_map<(d0, d1, d2) -> (d0, 0)>
476 /// ```
477 ///
478 /// returns:
479 ///
480 /// ```mlir
481 /// affine_map<(d0, d1) -> (d0, 0, 0)>
482 /// ```
484 
485 /// Concatenates a list of `maps` into a single AffineMap, stepping over
486 /// potentially empty maps. Assumes each of the underlying map has 0 symbols.
487 /// The resulting map has a number of dims equal to the max of `maps`' dims and
488 /// the concatenated results as its results.
489 /// Returns an empty map if all input `maps` are empty.
490 ///
491 /// Example:
492 /// When applied to the following list of 3 affine maps,
493 ///
494 /// ```mlir
495 /// {
496 /// (i, j, k) -> (i, k),
497 /// (i, j, k) -> (k, j),
498 /// (i, j, k) -> (i, j)
499 /// }
500 /// ```
501 ///
502 /// Returns the map:
503 ///
504 /// ```mlir
505 /// (i, j, k) -> (i, k, k, j, i, j)
506 /// ```
508 
509 /// Returns the map that results from projecting out the dimensions specified in
510 /// `projectedDimensions`. The projected dimensions are set to 0.
511 ///
512 /// Example:
513 /// 1) map : affine_map<(d0, d1, d2) -> (d0, d1)>
514 /// projected_dimensions : {2}
515 /// result : affine_map<(d0, d1) -> (d0, d1)>
516 ///
517 /// 2) map : affine_map<(d0, d1) -> (d0 + d1)>
518 /// projected_dimensions : {1}
519 /// result : affine_map<(d0) -> (d0)>
520 ///
521 /// 3) map : affine_map<(d0, d1, d2) -> (d0, d1)>
522 /// projected_dimensions : {1}
523 /// result : affine_map<(d0, d1) -> (d0, 0)>
524 ///
525 /// This function also compresses unused symbols away.
527  const llvm::SmallBitVector &projectedDimensions);
528 
529 /// Apply a permutation from `map` to `source` and return the result.
530 template <typename T>
532  assert(map.isProjectedPermutation());
533  assert(map.getNumInputs() == source.size());
534  SmallVector<T> result;
535  result.reserve(map.getNumResults());
536  for (AffineExpr expr : map.getResults()) {
537  if (auto dimExpr = expr.dyn_cast<AffineDimExpr>()) {
538  result.push_back(source[dimExpr.getPosition()]);
539  } else if (auto constExpr = expr.dyn_cast<AffineConstantExpr>()) {
540  assert(constExpr.getValue() == 0 &&
541  "Unexpected constant in projected permutation map");
542  result.push_back(0);
543  } else {
544  llvm_unreachable("Unexpected result in projected permutation map");
545  }
546  }
547  return result;
548 }
549 
550 /// Calculates maxmimum dimension and symbol positions from the expressions
551 /// in `exprsLists` and stores them in `maxDim` and `maxSym` respectively.
552 template <typename AffineExprContainer>
554  int64_t &maxDim, int64_t &maxSym) {
555  for (const auto &exprs : exprsList) {
556  for (auto expr : exprs) {
557  expr.walk([&maxDim, &maxSym](AffineExpr e) {
558  if (auto d = e.dyn_cast<AffineDimExpr>())
559  maxDim = std::max(maxDim, static_cast<int64_t>(d.getPosition()));
560  if (auto s = e.dyn_cast<AffineSymbolExpr>())
561  maxSym = std::max(maxSym, static_cast<int64_t>(s.getPosition()));
562  });
563  }
564  }
565 }
566 
567 inline raw_ostream &operator<<(raw_ostream &os, AffineMap map) {
568  map.print(os);
569  return os;
570 }
571 } // namespace mlir
572 
573 namespace llvm {
574 
575 // AffineExpr hash just like pointers
576 template <>
577 struct DenseMapInfo<mlir::AffineMap> {
579  auto *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
580  return mlir::AffineMap(static_cast<mlir::AffineMap::ImplType *>(pointer));
581  }
584  return mlir::AffineMap(static_cast<mlir::AffineMap::ImplType *>(pointer));
585  }
586  static unsigned getHashValue(mlir::AffineMap val) {
587  return mlir::hash_value(val);
588  }
589  static bool isEqual(mlir::AffineMap LHS, mlir::AffineMap RHS) {
590  return LHS == RHS;
591  }
592 };
593 
594 } // namespace llvm
595 
596 #endif // MLIR_IR_AFFINEMAP_H
Include the generated interface declarations.
AffineMap inversePermutation(AffineMap map)
Returns a map of codomain to domain dimensions such that the first codomain dimension for a particula...
Definition: AffineMap.cpp:658
static bool isEqual(mlir::AffineMap LHS, mlir::AffineMap RHS)
Definition: AffineMap.h:589
Explicitly register a set of "builtin" types.
Definition: CallGraph.h:221
static void getMaxDimAndSymbol(ArrayRef< AffineExprContainer > exprsList, int64_t &maxDim, int64_t &maxSym)
Calculates maxmimum dimension and symbol positions from the expressions in exprsLists and stores them...
Definition: AffineMap.h:553
bool isFunctionOfDim(unsigned position) const
Return true if the affine expression involves AffineDimExpr position.
Definition: AffineExpr.cpp:280
AffineExpr shiftSymbols(unsigned numSymbols, unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
Definition: AffineExpr.cpp:120
AffineExpr shiftDims(unsigned numDims, unsigned shift, unsigned offset=0) const
Replace dims[offset ...
Definition: AffineExpr.cpp:108
unsigned getNumResults() const
Definition: AffineMap.h:335
AffineMap shiftSymbols(unsigned shift, unsigned offset=0) const
Replace symbols[offset ...
Definition: AffineMap.h:232
void setNumDims(unsigned d)
Definition: AffineMap.h:337
bool operator!=(AffineMap other) const
Definition: AffineMap.h:99
static bool isPermutation(std::vector< PermutationTy > permutation)
Definition: IRAffine.cpp:57
AffineMap shiftDims(unsigned shift, unsigned offset=0) const
Replace dims[offset ...
Definition: AffineMap.h:219
bool isFunctionOfSymbol(unsigned position) const
Return true if any affine expression involves AffineSymbolExpr position.
Definition: AffineMap.h:180
An integer constant appearing in affine expression.
Definition: AffineExpr.h:232
AffineMap compressSymbols(AffineMap map, const llvm::SmallBitVector &unusedSymbols)
Drop the symbols that are not listed in unusedSymbols.
Definition: AffineMap.cpp:606
unsigned getNumInputs() const
Definition: AffineMap.cpp:303
static mlir::AffineMap getEmptyKey()
Definition: AffineMap.h:578
U dyn_cast() const
Definition: AffineExpr.h:281
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
AffineMap removeDuplicateExprs(AffineMap map)
Returns a map with the same dimension and symbol count as map, but whose results are the unique affin...
Definition: AffineMap.cpp:649
bool operator==(AffineMap other) const
Definition: AffineMap.h:98
A mutable affine map. Its affine expressions are however unique.
Definition: AffineMap.h:327
SmallVector< T > applyPermutationMap(AffineMap map, llvm::ArrayRef< T > source)
Apply a permutation from map to source and return the result.
Definition: AffineMap.h:531
bool isProjectedPermutation(bool allowZeroInResults=false) const
Returns true if the AffineMap represents a subset (i.e.
Definition: AffineMap.cpp:478
AffineMap concatAffineMaps(ArrayRef< AffineMap > maps)
Concatenates a list of maps into a single AffineMap, stepping over potentially empty maps...
Definition: AffineMap.cpp:703
inline ::llvm::hash_code hash_value(AffineMap arg)
Definition: AffineMap.h:322
unsigned getNumSymbols() const
Definition: AffineMap.h:338
Base type for affine expression.
Definition: AffineExpr.h:68
static mlir::AffineMap getTombstoneKey()
Definition: AffineMap.h:582
unsigned getNumResults() const
Definition: AffineMap.cpp:302
A multi-dimensional affine map Affine map&#39;s are immutable like Type&#39;s, and they are uniqued...
Definition: AffineMap.h:41
ArrayRef< AffineExpr > getResults() const
Definition: AffineMap.cpp:307
bool isFunctionOfSymbol(unsigned position) const
Return true if the affine expression involves AffineSymbolExpr position.
Definition: AffineExpr.cpp:291
AffineMap inverseAndBroadcastProjectedPermutation(AffineMap map)
Return the reverse map of a projected permutation where the projected dimensions are transformed into...
Definition: AffineMap.cpp:682
static void print(ArrayType type, DialectAsmPrinter &os)
static unsigned getHashValue(mlir::AffineMap val)
Definition: AffineMap.h:586
MLIRContext * getContext() const
Definition: AffineMap.h:340
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
Definition: AffineExpr.h:240
const void * getAsOpaquePointer() const
Methods supporting C API.
Definition: AffineMap.h:307
void print(raw_ostream &os) const
AffineExpr getResult(unsigned idx) const
Definition: AffineMap.h:333
void setResult(unsigned idx, AffineExpr result)
Definition: AffineMap.h:334
void setNumSymbols(unsigned d)
Definition: AffineMap.h:339
unsigned getNumDims() const
Definition: AffineMap.h:336
AffineMap simplifyAffineMap(AffineMap map)
Simplifies an affine map by simplifying its underlying AffineExpr results.
Definition: AffineMap.cpp:639
std::ostream & operator<<(std::ostream &out, const llvm::Twine &twine)
ArrayRef< AffineExpr > getResults() const
Definition: AffineMap.h:332
AffineMap compressDims(AffineMap map, const llvm::SmallBitVector &unusedDims)
Drop the dims that are not listed in unusedDims.
Definition: AffineMap.cpp:543
AffineMap getProjectedMap(AffineMap map, const llvm::SmallBitVector &projectedDimensions)
Returns the map that results from projecting out the dimensions specified in projectedDimensions.
Definition: AffineMap.cpp:720
A dimensional identifier appearing in an affine expression.
Definition: AffineExpr.h:216
bool isFunctionOfDim(unsigned position) const
Return true if any affine expression involves AffineDimExpr position.
Definition: AffineMap.h:173
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:55
SmallVector< AffineMap > compressUnusedSymbols(ArrayRef< AffineMap > maps)
Drop the symbols that are not used by any of the individual maps in maps.
Definition: AffineMap.cpp:634
static AffineMap getFromOpaquePointer(const void *pointer)
Definition: AffineMap.h:310
AffineMap(ImplType *map)
Definition: AffineMap.h:46
SmallVector< AffineMap > compressUnusedDims(ArrayRef< AffineMap > maps)
Drop the dims that are not used by any of the individual maps in maps.
Definition: AffineMap.cpp:601
static llvm::Optional< unsigned > getDimPosition(AffineMap map, unsigned dim)
Look for a given dimension in an affine map and return its position.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
A symbolic identifier appearing in an affine expression.
Definition: AffineExpr.h:224
static SmallVector< AffineMap, 4 > inferFromExprList(ArrayRef< AffineExprContainer > exprsList)
Definition: AffineMap.cpp:220