MLIR  19.0.0git
AffineMap.cpp
Go to the documentation of this file.
1 //===- AffineMap.cpp - MLIR Affine Map Classes ----------------------------===//
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 #include "mlir/IR/AffineMap.h"
10 #include "AffineMapDetail.h"
11 #include "mlir/IR/AffineExpr.h"
12 #include "mlir/IR/Builders.h"
14 #include "mlir/IR/BuiltinTypes.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallBitVector.h"
17 #include "llvm/ADT/SmallSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/MathExtras.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include <iterator>
23 #include <numeric>
24 #include <optional>
25 #include <type_traits>
26 
27 using namespace mlir;
28 
29 using llvm::divideCeilSigned;
30 using llvm::divideFloorSigned;
31 using llvm::mod;
32 
33 namespace {
34 
35 // AffineExprConstantFolder evaluates an affine expression using constant
36 // operands passed in 'operandConsts'. Returns an IntegerAttr attribute
37 // representing the constant value of the affine expression evaluated on
38 // constant 'operandConsts', or nullptr if it can't be folded.
39 class AffineExprConstantFolder {
40 public:
41  AffineExprConstantFolder(unsigned numDims, ArrayRef<Attribute> operandConsts)
42  : numDims(numDims), operandConsts(operandConsts) {}
43 
44  /// Attempt to constant fold the specified affine expr, or return null on
45  /// failure.
46  IntegerAttr constantFold(AffineExpr expr) {
47  if (auto result = constantFoldImpl(expr))
48  return IntegerAttr::get(IndexType::get(expr.getContext()), *result);
49  return nullptr;
50  }
51 
52  bool hasPoison() const { return hasPoison_; }
53 
54 private:
55  std::optional<int64_t> constantFoldImpl(AffineExpr expr) {
56  switch (expr.getKind()) {
58  return constantFoldBinExpr(
59  expr, [](int64_t lhs, int64_t rhs) { return lhs + rhs; });
61  return constantFoldBinExpr(
62  expr, [](int64_t lhs, int64_t rhs) { return lhs * rhs; });
64  return constantFoldBinExpr(
65  expr, [this](int64_t lhs, int64_t rhs) -> std::optional<int64_t> {
66  if (rhs < 1) {
67  hasPoison_ = true;
68  return std::nullopt;
69  }
70  return mod(lhs, rhs);
71  });
73  return constantFoldBinExpr(
74  expr, [this](int64_t lhs, int64_t rhs) -> std::optional<int64_t> {
75  if (rhs == 0) {
76  hasPoison_ = true;
77  return std::nullopt;
78  }
79  return divideFloorSigned(lhs, rhs);
80  });
82  return constantFoldBinExpr(
83  expr, [this](int64_t lhs, int64_t rhs) -> std::optional<int64_t> {
84  if (rhs == 0) {
85  hasPoison_ = true;
86  return std::nullopt;
87  }
88  return divideCeilSigned(lhs, rhs);
89  });
91  return cast<AffineConstantExpr>(expr).getValue();
93  if (auto attr = llvm::dyn_cast_or_null<IntegerAttr>(
94  operandConsts[cast<AffineDimExpr>(expr).getPosition()]))
95  return attr.getInt();
96  return std::nullopt;
98  if (auto attr = llvm::dyn_cast_or_null<IntegerAttr>(
99  operandConsts[numDims +
100  cast<AffineSymbolExpr>(expr).getPosition()]))
101  return attr.getInt();
102  return std::nullopt;
103  }
104  llvm_unreachable("Unknown AffineExpr");
105  }
106 
107  // TODO: Change these to operate on APInts too.
108  std::optional<int64_t> constantFoldBinExpr(
109  AffineExpr expr,
110  llvm::function_ref<std::optional<int64_t>(int64_t, int64_t)> op) {
111  auto binOpExpr = cast<AffineBinaryOpExpr>(expr);
112  if (auto lhs = constantFoldImpl(binOpExpr.getLHS()))
113  if (auto rhs = constantFoldImpl(binOpExpr.getRHS()))
114  return op(*lhs, *rhs);
115  return std::nullopt;
116  }
117 
118  // The number of dimension operands in AffineMap containing this expression.
119  unsigned numDims;
120  // The constant valued operands used to evaluate this AffineExpr.
121  ArrayRef<Attribute> operandConsts;
122  bool hasPoison_{false};
123 };
124 
125 } // namespace
126 
127 /// Returns a single constant result affine map.
129  return get(/*dimCount=*/0, /*symbolCount=*/0,
130  {getAffineConstantExpr(val, context)});
131 }
132 
133 /// Returns an identity affine map (d0, ..., dn) -> (dp, ..., dn) on the most
134 /// minor dimensions.
135 AffineMap AffineMap::getMinorIdentityMap(unsigned dims, unsigned results,
136  MLIRContext *context) {
137  assert(dims >= results && "Dimension mismatch");
138  auto id = AffineMap::getMultiDimIdentityMap(dims, context);
139  return AffineMap::get(dims, 0, id.getResults().take_back(results), context);
140 }
141 
143  MLIRContext *ctx, unsigned numDims,
144  llvm::function_ref<bool(AffineDimExpr)> keepDimFilter) {
145  auto identityMap = getMultiDimIdentityMap(numDims, ctx);
146 
147  // Apply filter to results.
148  llvm::SmallBitVector dropDimResults(numDims);
149  for (auto [idx, resultExpr] : llvm::enumerate(identityMap.getResults()))
150  dropDimResults[idx] = !keepDimFilter(cast<AffineDimExpr>(resultExpr));
151 
152  return identityMap.dropResults(dropDimResults);
153 }
154 
156  return getNumDims() >= getNumResults() &&
157  *this ==
159 }
160 
161 /// Returns true if this affine map is a minor identity up to broadcasted
162 /// dimensions which are indicated by value 0 in the result.
164  SmallVectorImpl<unsigned> *broadcastedDims) const {
165  if (broadcastedDims)
166  broadcastedDims->clear();
167  if (getNumDims() < getNumResults())
168  return false;
169  unsigned suffixStart = getNumDims() - getNumResults();
170  for (const auto &idxAndExpr : llvm::enumerate(getResults())) {
171  unsigned resIdx = idxAndExpr.index();
172  AffineExpr expr = idxAndExpr.value();
173  if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
174  // Each result may be either a constant 0 (broadcasted dimension).
175  if (constExpr.getValue() != 0)
176  return false;
177  if (broadcastedDims)
178  broadcastedDims->push_back(resIdx);
179  } else if (auto dimExpr = dyn_cast<AffineDimExpr>(expr)) {
180  // Or it may be the input dimension corresponding to this result position.
181  if (dimExpr.getPosition() != suffixStart + resIdx)
182  return false;
183  } else {
184  return false;
185  }
186  }
187  return true;
188 }
189 
190 /// Return true if this affine map can be converted to a minor identity with
191 /// broadcast by doing a permute. Return a permutation (there may be
192 /// several) to apply to get to a minor identity with broadcasts.
193 /// Ex:
194 /// * (d0, d1, d2) -> (0, d1) maps to minor identity (d1, 0 = d2) with
195 /// perm = [1, 0] and broadcast d2
196 /// * (d0, d1, d2) -> (d0, 0) cannot be mapped to a minor identity by
197 /// permutation + broadcast
198 /// * (d0, d1, d2, d3) -> (0, d1, d3) maps to minor identity (d1, 0 = d2, d3)
199 /// with perm = [1, 0, 2] and broadcast d2
200 /// * (d0, d1) -> (d1, 0, 0, d0) maps to minor identity (d0, d1) with extra
201 /// leading broadcat dimensions. The map returned would be (0, 0, d0, d1) with
202 /// perm = [3, 0, 1, 2]
204  SmallVectorImpl<unsigned> &permutedDims) const {
205  unsigned projectionStart =
207  permutedDims.clear();
208  SmallVector<unsigned> broadcastDims;
209  permutedDims.resize(getNumResults(), 0);
210  // If there are more results than input dimensions we want the new map to
211  // start with broadcast dimensions in order to be a minor identity with
212  // broadcasting.
213  unsigned leadingBroadcast =
215  llvm::SmallBitVector dimFound(std::max(getNumInputs(), getNumResults()),
216  false);
217  for (const auto &idxAndExpr : llvm::enumerate(getResults())) {
218  unsigned resIdx = idxAndExpr.index();
219  AffineExpr expr = idxAndExpr.value();
220  // Each result may be either a constant 0 (broadcast dimension) or a
221  // dimension.
222  if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
223  if (constExpr.getValue() != 0)
224  return false;
225  broadcastDims.push_back(resIdx);
226  } else if (auto dimExpr = dyn_cast<AffineDimExpr>(expr)) {
227  if (dimExpr.getPosition() < projectionStart)
228  return false;
229  unsigned newPosition =
230  dimExpr.getPosition() - projectionStart + leadingBroadcast;
231  permutedDims[resIdx] = newPosition;
232  dimFound[newPosition] = true;
233  } else {
234  return false;
235  }
236  }
237  // Find a permuation for the broadcast dimension. Since they are broadcasted
238  // any valid permutation is acceptable. We just permute the dim into a slot
239  // without an existing dimension.
240  unsigned pos = 0;
241  for (auto dim : broadcastDims) {
242  while (pos < dimFound.size() && dimFound[pos]) {
243  pos++;
244  }
245  permutedDims[dim] = pos++;
246  }
247  return true;
248 }
249 
250 /// Returns an AffineMap representing a permutation.
252  MLIRContext *context) {
253  assert(!permutation.empty() &&
254  "Cannot create permutation map from empty permutation vector");
255  const auto *m = llvm::max_element(permutation);
256  auto permutationMap = getMultiDimMapWithTargets(*m + 1, permutation, context);
257  assert(permutationMap.isPermutation() && "Invalid permutation vector");
258  return permutationMap;
259 }
261  MLIRContext *context) {
262  SmallVector<unsigned> perm = llvm::map_to_vector(
263  permutation, [](int64_t i) { return static_cast<unsigned>(i); });
264  return AffineMap::getPermutationMap(perm, context);
265 }
266 
268  ArrayRef<unsigned> targets,
269  MLIRContext *context) {
271  for (unsigned t : targets)
272  affExprs.push_back(getAffineDimExpr(t, context));
273  AffineMap result = AffineMap::get(/*dimCount=*/numDims, /*symbolCount=*/0,
274  affExprs, context);
275  return result;
276 }
277 
278 /// Creates an affine map each for each list of AffineExpr's in `exprsList`
279 /// while inferring the right number of dimensional and symbolic inputs needed
280 /// based on the maximum dimensional and symbolic identifier appearing in the
281 /// expressions.
282 template <typename AffineExprContainer>
285  MLIRContext *context) {
286  if (exprsList.empty())
287  return {};
288  int64_t maxDim = -1, maxSym = -1;
289  getMaxDimAndSymbol(exprsList, maxDim, maxSym);
291  maps.reserve(exprsList.size());
292  for (const auto &exprs : exprsList)
293  maps.push_back(AffineMap::get(/*dimCount=*/maxDim + 1,
294  /*symbolCount=*/maxSym + 1, exprs, context));
295  return maps;
296 }
297 
300  MLIRContext *context) {
301  return ::inferFromExprList(exprsList, context);
302 }
303 
306  MLIRContext *context) {
307  return ::inferFromExprList(exprsList, context);
308 }
309 
311  uint64_t gcd = 0;
312  for (AffineExpr resultExpr : getResults()) {
313  uint64_t thisGcd = resultExpr.getLargestKnownDivisor();
314  gcd = std::gcd(gcd, thisGcd);
315  }
316  if (gcd == 0)
318  return gcd;
319 }
320 
322  MLIRContext *context) {
324  dimExprs.reserve(numDims);
325  for (unsigned i = 0; i < numDims; ++i)
326  dimExprs.push_back(mlir::getAffineDimExpr(i, context));
327  return get(/*dimCount=*/numDims, /*symbolCount=*/0, dimExprs, context);
328 }
329 
330 MLIRContext *AffineMap::getContext() const { return map->context; }
331 
332 bool AffineMap::isIdentity() const {
333  if (getNumDims() != getNumResults())
334  return false;
335  ArrayRef<AffineExpr> results = getResults();
336  for (unsigned i = 0, numDims = getNumDims(); i < numDims; ++i) {
337  auto expr = dyn_cast<AffineDimExpr>(results[i]);
338  if (!expr || expr.getPosition() != i)
339  return false;
340  }
341  return true;
342 }
343 
345  if (getNumSymbols() != getNumResults())
346  return false;
347  ArrayRef<AffineExpr> results = getResults();
348  for (unsigned i = 0, numSymbols = getNumSymbols(); i < numSymbols; ++i) {
349  auto expr = dyn_cast<AffineDimExpr>(results[i]);
350  if (!expr || expr.getPosition() != i)
351  return false;
352  }
353  return true;
354 }
355 
356 bool AffineMap::isEmpty() const {
357  return getNumDims() == 0 && getNumSymbols() == 0 && getNumResults() == 0;
358 }
359 
361  return getNumResults() == 1 && isa<AffineConstantExpr>(getResult(0));
362 }
363 
364 bool AffineMap::isConstant() const {
365  return llvm::all_of(getResults(), llvm::IsaPred<AffineConstantExpr>);
366 }
367 
369  assert(isSingleConstant() && "map must have a single constant result");
370  return cast<AffineConstantExpr>(getResult(0)).getValue();
371 }
372 
374  assert(isConstant() && "map must have only constant results");
375  SmallVector<int64_t> result;
376  for (auto expr : getResults())
377  result.emplace_back(cast<AffineConstantExpr>(expr).getValue());
378  return result;
379 }
380 
381 unsigned AffineMap::getNumDims() const {
382  assert(map && "uninitialized map storage");
383  return map->numDims;
384 }
385 unsigned AffineMap::getNumSymbols() const {
386  assert(map && "uninitialized map storage");
387  return map->numSymbols;
388 }
389 unsigned AffineMap::getNumResults() const { return getResults().size(); }
390 unsigned AffineMap::getNumInputs() const {
391  assert(map && "uninitialized map storage");
392  return map->numDims + map->numSymbols;
393 }
395  assert(map && "uninitialized map storage");
396  return map->results();
397 }
398 AffineExpr AffineMap::getResult(unsigned idx) const {
399  return getResults()[idx];
400 }
401 
402 unsigned AffineMap::getDimPosition(unsigned idx) const {
403  return cast<AffineDimExpr>(getResult(idx)).getPosition();
404 }
405 
406 std::optional<unsigned> AffineMap::getResultPosition(AffineExpr input) const {
407  if (!isa<AffineDimExpr>(input))
408  return std::nullopt;
409 
410  for (unsigned i = 0, numResults = getNumResults(); i < numResults; i++) {
411  if (getResult(i) == input)
412  return i;
413  }
414 
415  return std::nullopt;
416 }
417 
418 /// Folds the results of the application of an affine map on the provided
419 /// operands to a constant if possible. Returns false if the folding happens,
420 /// true otherwise.
421 LogicalResult AffineMap::constantFold(ArrayRef<Attribute> operandConstants,
423  bool *hasPoison) const {
424  // Attempt partial folding.
425  SmallVector<int64_t, 2> integers;
426  partialConstantFold(operandConstants, &integers, hasPoison);
427 
428  // If all expressions folded to a constant, populate results with attributes
429  // containing those constants.
430  if (integers.empty())
431  return failure();
432 
433  auto range = llvm::map_range(integers, [this](int64_t i) {
435  });
436  results.append(range.begin(), range.end());
437  return success();
438 }
439 
441  SmallVectorImpl<int64_t> *results,
442  bool *hasPoison) const {
443  assert(getNumInputs() == operandConstants.size());
444 
445  // Fold each of the result expressions.
446  AffineExprConstantFolder exprFolder(getNumDims(), operandConstants);
448  exprs.reserve(getNumResults());
449 
450  for (auto expr : getResults()) {
451  auto folded = exprFolder.constantFold(expr);
452  if (exprFolder.hasPoison() && hasPoison) {
453  *hasPoison = true;
454  return {};
455  }
456  // If did not fold to a constant, keep the original expression, and clear
457  // the integer results vector.
458  if (folded) {
459  exprs.push_back(
460  getAffineConstantExpr(folded.getInt(), folded.getContext()));
461  if (results)
462  results->push_back(folded.getInt());
463  } else {
464  exprs.push_back(expr);
465  if (results) {
466  results->clear();
467  results = nullptr;
468  }
469  }
470  }
471 
472  return get(getNumDims(), getNumSymbols(), exprs, getContext());
473 }
474 
475 /// Walk all of the AffineExpr's in this mapping. Each node in an expression
476 /// tree is visited in postorder.
478  for (auto expr : getResults())
479  expr.walk(callback);
480 }
481 
482 /// This method substitutes any uses of dimensions and symbols (e.g.
483 /// dim#0 with dimReplacements[0]) in subexpressions and returns the modified
484 /// expression mapping. Because this can be used to eliminate dims and
485 /// symbols, the client needs to specify the number of dims and symbols in
486 /// the result. The returned map always has the same number of results.
488  ArrayRef<AffineExpr> symReplacements,
489  unsigned numResultDims,
490  unsigned numResultSyms) const {
492  results.reserve(getNumResults());
493  for (auto expr : getResults())
494  results.push_back(
495  expr.replaceDimsAndSymbols(dimReplacements, symReplacements));
496  return get(numResultDims, numResultSyms, results, getContext());
497 }
498 
499 /// Sparse replace method. Apply AffineExpr::replace(`expr`, `replacement`) to
500 /// each of the results and return a new AffineMap with the new results and
501 /// with the specified number of dims and symbols.
503  unsigned numResultDims,
504  unsigned numResultSyms) const {
505  SmallVector<AffineExpr, 4> newResults;
506  newResults.reserve(getNumResults());
507  for (AffineExpr e : getResults())
508  newResults.push_back(e.replace(expr, replacement));
509  return AffineMap::get(numResultDims, numResultSyms, newResults, getContext());
510 }
511 
512 /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
513 /// results and return a new AffineMap with the new results and with the
514 /// specified number of dims and symbols.
516  unsigned numResultDims,
517  unsigned numResultSyms) const {
518  SmallVector<AffineExpr, 4> newResults;
519  newResults.reserve(getNumResults());
520  for (AffineExpr e : getResults())
521  newResults.push_back(e.replace(map));
522  return AffineMap::get(numResultDims, numResultSyms, newResults, getContext());
523 }
524 
525 AffineMap
527  SmallVector<AffineExpr, 4> newResults;
528  newResults.reserve(getNumResults());
529  for (AffineExpr e : getResults())
530  newResults.push_back(e.replace(map));
531  return AffineMap::inferFromExprList(newResults, getContext()).front();
532 }
533 
534 AffineMap AffineMap::dropResults(const llvm::SmallBitVector &positions) const {
535  auto exprs = llvm::to_vector<4>(getResults());
536  // TODO: this is a pretty terrible API .. is there anything better?
537  for (auto pos = positions.find_last(); pos != -1;
538  pos = positions.find_prev(pos))
539  exprs.erase(exprs.begin() + pos);
540  return AffineMap::get(getNumDims(), getNumSymbols(), exprs, getContext());
541 }
542 
544  assert(getNumDims() == map.getNumResults() && "Number of results mismatch");
545  // Prepare `map` by concatenating the symbols and rewriting its exprs.
546  unsigned numDims = map.getNumDims();
547  unsigned numSymbolsThisMap = getNumSymbols();
548  unsigned numSymbols = numSymbolsThisMap + map.getNumSymbols();
549  SmallVector<AffineExpr, 8> newDims(numDims);
550  for (unsigned idx = 0; idx < numDims; ++idx) {
551  newDims[idx] = getAffineDimExpr(idx, getContext());
552  }
553  SmallVector<AffineExpr, 8> newSymbols(numSymbols - numSymbolsThisMap);
554  for (unsigned idx = numSymbolsThisMap; idx < numSymbols; ++idx) {
555  newSymbols[idx - numSymbolsThisMap] =
557  }
558  auto newMap =
559  map.replaceDimsAndSymbols(newDims, newSymbols, numDims, numSymbols);
561  exprs.reserve(getResults().size());
562  for (auto expr : getResults())
563  exprs.push_back(expr.compose(newMap));
564  return AffineMap::get(numDims, numSymbols, exprs, map.getContext());
565 }
566 
568  assert(getNumSymbols() == 0 && "Expected symbol-less map");
570  exprs.reserve(values.size());
571  MLIRContext *ctx = getContext();
572  for (auto v : values)
573  exprs.push_back(getAffineConstantExpr(v, ctx));
574  auto resMap = compose(AffineMap::get(0, 0, exprs, ctx));
576  res.reserve(resMap.getNumResults());
577  for (auto e : resMap.getResults())
578  res.push_back(cast<AffineConstantExpr>(e).getValue());
579  return res;
580 }
581 
582 bool AffineMap::isProjectedPermutation(bool allowZeroInResults) const {
583  if (getNumSymbols() > 0)
584  return false;
585 
586  // Having more results than inputs means that results have duplicated dims or
587  // zeros that can't be mapped to input dims.
588  if (getNumResults() > getNumInputs())
589  return false;
590 
591  SmallVector<bool, 8> seen(getNumInputs(), false);
592  // A projected permutation can have, at most, only one instance of each input
593  // dimension in the result expressions. Zeros are allowed as long as the
594  // number of result expressions is lower or equal than the number of input
595  // expressions.
596  for (auto expr : getResults()) {
597  if (auto dim = dyn_cast<AffineDimExpr>(expr)) {
598  if (seen[dim.getPosition()])
599  return false;
600  seen[dim.getPosition()] = true;
601  } else {
602  auto constExpr = dyn_cast<AffineConstantExpr>(expr);
603  if (!allowZeroInResults || !constExpr || constExpr.getValue() != 0)
604  return false;
605  }
606  }
607 
608  // Results are either dims or zeros and zeros can be mapped to input dims.
609  return true;
610 }
611 
613  if (getNumDims() != getNumResults())
614  return false;
615  return isProjectedPermutation();
616 }
617 
620  exprs.reserve(resultPos.size());
621  for (auto idx : resultPos)
622  exprs.push_back(getResult(idx));
623  return AffineMap::get(getNumDims(), getNumSymbols(), exprs, getContext());
624 }
625 
626 AffineMap AffineMap::getSliceMap(unsigned start, unsigned length) const {
628  getResults().slice(start, length), getContext());
629 }
630 
631 AffineMap AffineMap::getMajorSubMap(unsigned numResults) const {
632  if (numResults == 0)
633  return AffineMap();
634  if (numResults > getNumResults())
635  return *this;
636  return getSliceMap(0, numResults);
637 }
638 
639 AffineMap AffineMap::getMinorSubMap(unsigned numResults) const {
640  if (numResults == 0)
641  return AffineMap();
642  if (numResults > getNumResults())
643  return *this;
644  return getSliceMap(getNumResults() - numResults, numResults);
645 }
646 
647 /// Implementation detail to compress multiple affine maps with a compressionFun
648 /// that is expected to be either compressUnusedDims or compressUnusedSymbols.
649 /// The implementation keeps track of num dims and symbols across the different
650 /// affine maps.
652  ArrayRef<AffineMap> maps,
653  llvm::function_ref<AffineMap(AffineMap)> compressionFun) {
654  if (maps.empty())
655  return SmallVector<AffineMap>();
656  SmallVector<AffineExpr> allExprs;
657  allExprs.reserve(maps.size() * maps.front().getNumResults());
658  unsigned numDims = maps.front().getNumDims(),
659  numSymbols = maps.front().getNumSymbols();
660  for (auto m : maps) {
661  assert(numDims == m.getNumDims() && numSymbols == m.getNumSymbols() &&
662  "expected maps with same num dims and symbols");
663  llvm::append_range(allExprs, m.getResults());
664  }
665  AffineMap unifiedMap = compressionFun(
666  AffineMap::get(numDims, numSymbols, allExprs, maps.front().getContext()));
667  unsigned unifiedNumDims = unifiedMap.getNumDims(),
668  unifiedNumSymbols = unifiedMap.getNumSymbols();
669  ArrayRef<AffineExpr> unifiedResults = unifiedMap.getResults();
671  res.reserve(maps.size());
672  for (auto m : maps) {
673  res.push_back(AffineMap::get(unifiedNumDims, unifiedNumSymbols,
674  unifiedResults.take_front(m.getNumResults()),
675  m.getContext()));
676  unifiedResults = unifiedResults.drop_front(m.getNumResults());
677  }
678  return res;
679 }
680 
682  const llvm::SmallBitVector &unusedDims) {
683  return projectDims(map, unusedDims, /*compressDimsFlag=*/true);
684 }
685 
687  return compressDims(map, getUnusedDimsBitVector({map}));
688 }
689 
691  return compressUnusedListImpl(
692  maps, [](AffineMap m) { return compressUnusedDims(m); });
693 }
694 
696  const llvm::SmallBitVector &unusedSymbols) {
697  return projectSymbols(map, unusedSymbols, /*compressSymbolsFlag=*/true);
698 }
699 
701  return compressSymbols(map, getUnusedSymbolsBitVector({map}));
702 }
703 
705  return compressUnusedListImpl(
706  maps, [](AffineMap m) { return compressUnusedSymbols(m); });
707 }
708 
710  ArrayRef<OpFoldResult> operands,
711  SmallVector<Value> &remainingValues) {
712  SmallVector<AffineExpr> dimReplacements, symReplacements;
713  int64_t numDims = 0;
714  for (int64_t i = 0; i < map.getNumDims(); ++i) {
715  if (auto attr = operands[i].dyn_cast<Attribute>()) {
716  dimReplacements.push_back(
717  b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
718  } else {
719  dimReplacements.push_back(b.getAffineDimExpr(numDims++));
720  remainingValues.push_back(operands[i].get<Value>());
721  }
722  }
723  int64_t numSymbols = 0;
724  for (int64_t i = 0; i < map.getNumSymbols(); ++i) {
725  if (auto attr = operands[i + map.getNumDims()].dyn_cast<Attribute>()) {
726  symReplacements.push_back(
727  b.getAffineConstantExpr(cast<IntegerAttr>(attr).getInt()));
728  } else {
729  symReplacements.push_back(b.getAffineSymbolExpr(numSymbols++));
730  remainingValues.push_back(operands[i + map.getNumDims()].get<Value>());
731  }
732  }
733  return map.replaceDimsAndSymbols(dimReplacements, symReplacements, numDims,
734  numSymbols);
735 }
736 
739  for (auto e : map.getResults()) {
740  exprs.push_back(
741  simplifyAffineExpr(e, map.getNumDims(), map.getNumSymbols()));
742  }
743  return AffineMap::get(map.getNumDims(), map.getNumSymbols(), exprs,
744  map.getContext());
745 }
746 
748  auto results = map.getResults();
749  SmallVector<AffineExpr, 4> uniqueExprs(results.begin(), results.end());
750  uniqueExprs.erase(llvm::unique(uniqueExprs), uniqueExprs.end());
751  return AffineMap::get(map.getNumDims(), map.getNumSymbols(), uniqueExprs,
752  map.getContext());
753 }
754 
756  if (map.isEmpty())
757  return map;
758  assert(map.getNumSymbols() == 0 && "expected map without symbols");
760  for (const auto &en : llvm::enumerate(map.getResults())) {
761  auto expr = en.value();
762  // Skip non-permutations.
763  if (auto d = dyn_cast<AffineDimExpr>(expr)) {
764  if (exprs[d.getPosition()])
765  continue;
766  exprs[d.getPosition()] = getAffineDimExpr(en.index(), d.getContext());
767  }
768  }
769  SmallVector<AffineExpr, 4> seenExprs;
770  seenExprs.reserve(map.getNumDims());
771  for (auto expr : exprs)
772  if (expr)
773  seenExprs.push_back(expr);
774  if (seenExprs.size() != map.getNumInputs())
775  return AffineMap();
776  return AffineMap::get(map.getNumResults(), 0, seenExprs, map.getContext());
777 }
778 
780  assert(map.isProjectedPermutation(/*allowZeroInResults=*/true));
781  MLIRContext *context = map.getContext();
782  AffineExpr zero = mlir::getAffineConstantExpr(0, context);
783  // Start with all the results as 0.
784  SmallVector<AffineExpr, 4> exprs(map.getNumInputs(), zero);
785  for (unsigned i : llvm::seq(unsigned(0), map.getNumResults())) {
786  // Skip zeros from input map. 'exprs' is already initialized to zero.
787  if (auto constExpr = dyn_cast<AffineConstantExpr>(map.getResult(i))) {
788  assert(constExpr.getValue() == 0 &&
789  "Unexpected constant in projected permutation");
790  (void)constExpr;
791  continue;
792  }
793 
794  // Reverse each dimension existing in the original map result.
795  exprs[map.getDimPosition(i)] = getAffineDimExpr(i, context);
796  }
797  return AffineMap::get(map.getNumResults(), /*symbolCount=*/0, exprs, context);
798 }
799 
801  unsigned numResults = 0, numDims = 0, numSymbols = 0;
802  for (auto m : maps)
803  numResults += m.getNumResults();
805  results.reserve(numResults);
806  for (auto m : maps) {
807  for (auto res : m.getResults())
808  results.push_back(res.shiftSymbols(m.getNumSymbols(), numSymbols));
809 
810  numSymbols += m.getNumSymbols();
811  numDims = std::max(m.getNumDims(), numDims);
812  }
813  return AffineMap::get(numDims, numSymbols, results,
814  maps.front().getContext());
815 }
816 
817 /// Common implementation to project out dimensions or symbols from an affine
818 /// map based on the template type.
819 /// Additionally, if 'compress' is true, the projected out dimensions or symbols
820 /// are also dropped from the resulting map.
821 template <typename AffineDimOrSymExpr>
823  const llvm::SmallBitVector &toProject,
824  bool compress) {
825  static_assert(llvm::is_one_of<AffineDimOrSymExpr, AffineDimExpr,
826  AffineSymbolExpr>::value,
827  "expected AffineDimExpr or AffineSymbolExpr");
828 
829  constexpr bool isDim = std::is_same<AffineDimOrSymExpr, AffineDimExpr>::value;
830  int64_t numDimOrSym = (isDim) ? map.getNumDims() : map.getNumSymbols();
831  SmallVector<AffineExpr> replacements;
832  replacements.reserve(numDimOrSym);
833 
834  auto createNewDimOrSym = (isDim) ? getAffineDimExpr : getAffineSymbolExpr;
835 
836  using replace_fn_ty =
837  std::function<AffineExpr(AffineExpr, ArrayRef<AffineExpr>)>;
838  replace_fn_ty replaceDims = [](AffineExpr e,
839  ArrayRef<AffineExpr> replacements) {
840  return e.replaceDims(replacements);
841  };
842  replace_fn_ty replaceSymbols = [](AffineExpr e,
843  ArrayRef<AffineExpr> replacements) {
844  return e.replaceSymbols(replacements);
845  };
846  replace_fn_ty replaceNewDimOrSym = (isDim) ? replaceDims : replaceSymbols;
847 
848  MLIRContext *context = map.getContext();
849  int64_t newNumDimOrSym = 0;
850  for (unsigned dimOrSym = 0; dimOrSym < numDimOrSym; ++dimOrSym) {
851  if (toProject.test(dimOrSym)) {
852  replacements.push_back(getAffineConstantExpr(0, context));
853  continue;
854  }
855  int64_t newPos = compress ? newNumDimOrSym++ : dimOrSym;
856  replacements.push_back(createNewDimOrSym(newPos, context));
857  }
858  SmallVector<AffineExpr> resultExprs;
859  resultExprs.reserve(map.getNumResults());
860  for (auto e : map.getResults())
861  resultExprs.push_back(replaceNewDimOrSym(e, replacements));
862 
863  int64_t numDims = (compress && isDim) ? newNumDimOrSym : map.getNumDims();
864  int64_t numSyms = (compress && !isDim) ? newNumDimOrSym : map.getNumSymbols();
865  return AffineMap::get(numDims, numSyms, resultExprs, context);
866 }
867 
869  const llvm::SmallBitVector &projectedDimensions,
870  bool compressDimsFlag) {
871  return projectCommonImpl<AffineDimExpr>(map, projectedDimensions,
872  compressDimsFlag);
873 }
874 
876  const llvm::SmallBitVector &projectedSymbols,
877  bool compressSymbolsFlag) {
878  return projectCommonImpl<AffineSymbolExpr>(map, projectedSymbols,
879  compressSymbolsFlag);
880 }
881 
883  const llvm::SmallBitVector &projectedDimensions,
884  bool compressDimsFlag,
885  bool compressSymbolsFlag) {
886  map = projectDims(map, projectedDimensions, compressDimsFlag);
887  if (compressSymbolsFlag)
888  map = compressUnusedSymbols(map);
889  return map;
890 }
891 
893  unsigned numDims = maps[0].getNumDims();
894  llvm::SmallBitVector numDimsBitVector(numDims, true);
895  for (AffineMap m : maps) {
896  for (unsigned i = 0; i < numDims; ++i) {
897  if (m.isFunctionOfDim(i))
898  numDimsBitVector.reset(i);
899  }
900  }
901  return numDimsBitVector;
902 }
903 
905  unsigned numSymbols = maps[0].getNumSymbols();
906  llvm::SmallBitVector numSymbolsBitVector(numSymbols, true);
907  for (AffineMap m : maps) {
908  for (unsigned i = 0; i < numSymbols; ++i) {
909  if (m.isFunctionOfSymbol(i))
910  numSymbolsBitVector.reset(i);
911  }
912  }
913  return numSymbolsBitVector;
914 }
915 
916 AffineMap
918  const llvm::SmallBitVector &projectedDimensions) {
919  auto id = AffineMap::getMultiDimIdentityMap(rank, map.getContext());
920  AffineMap proj = id.dropResults(projectedDimensions);
921  return map.compose(proj);
922 }
923 
924 //===----------------------------------------------------------------------===//
925 // MutableAffineMap.
926 //===----------------------------------------------------------------------===//
927 
929  : results(map.getResults().begin(), map.getResults().end()),
930  numDims(map.getNumDims()), numSymbols(map.getNumSymbols()),
931  context(map.getContext()) {}
932 
934  results.clear();
935  numDims = map.getNumDims();
936  numSymbols = map.getNumSymbols();
937  context = map.getContext();
938  llvm::append_range(results, map.getResults());
939 }
940 
941 bool MutableAffineMap::isMultipleOf(unsigned idx, int64_t factor) const {
942  return results[idx].isMultipleOf(factor);
943 }
944 
945 // Simplifies the result affine expressions of this map. The expressions
946 // have to be pure for the simplification implemented.
948  // Simplify each of the results if possible.
949  // TODO: functional-style map
950  for (unsigned i = 0, e = getNumResults(); i < e; i++) {
951  results[i] = simplifyAffineExpr(getResult(i), numDims, numSymbols);
952  }
953 }
954 
956  return AffineMap::get(numDims, numSymbols, results, context);
957 }
static SmallVector< AffineMap > compressUnusedListImpl(ArrayRef< AffineMap > maps, llvm::function_ref< AffineMap(AffineMap)> compressionFun)
Implementation detail to compress multiple affine maps with a compressionFun that is expected to be e...
Definition: AffineMap.cpp:651
static SmallVector< AffineMap, 4 > inferFromExprList(ArrayRef< AffineExprContainer > exprsList, MLIRContext *context)
Creates an affine map each for each list of AffineExpr's in exprsList while inferring the right numbe...
Definition: AffineMap.cpp:284
static AffineMap projectCommonImpl(AffineMap map, const llvm::SmallBitVector &toProject, bool compress)
Common implementation to project out dimensions or symbols from an affine map based on the template t...
Definition: AffineMap.cpp:822
static MLIRContext * getContext(OpFoldResult val)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
A dimensional identifier appearing in an affine expression.
Definition: AffineExpr.h:236
Base type for affine expression.
Definition: AffineExpr.h:68
AffineExpr replaceDimsAndSymbols(ArrayRef< AffineExpr > dimReplacements, ArrayRef< AffineExpr > symReplacements) const
This method substitutes any uses of dimensions and symbols (e.g.
Definition: AffineExpr.cpp:88
RetT walk(FnT &&callback) const
Walk all of the AffineExpr's in this expression in postorder.
Definition: AffineExpr.h:130
AffineExprKind getKind() const
Return the classification for this type.
Definition: AffineExpr.cpp:34
AffineExpr compose(AffineMap map) const
Compose with an AffineMap.
AffineExpr replaceDims(ArrayRef< AffineExpr > dimReplacements) const
Dim-only version of replaceDimsAndSymbols.
Definition: AffineExpr.cpp:121
MLIRContext * getContext() const
Definition: AffineExpr.cpp:32
AffineExpr replaceSymbols(ArrayRef< AffineExpr > symReplacements) const
Symbol-only version of replaceDimsAndSymbols.
Definition: AffineExpr.cpp:126
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition: AffineMap.h:46
int64_t getSingleConstantResult() const
Returns the constant result of this map.
Definition: AffineMap.cpp:368
static AffineMap getMinorIdentityMap(unsigned dims, unsigned results, MLIRContext *context)
Returns an identity affine map (d0, ..., dn) -> (dp, ..., dn) on the most minor dimensions.
Definition: AffineMap.cpp:135
AffineMap dropResults(ArrayRef< int64_t > positions) const
Definition: AffineMap.h:291
AffineMap getSliceMap(unsigned start, unsigned length) const
Returns the map consisting of length expressions starting from start.
Definition: AffineMap.cpp:626
AffineMap getMajorSubMap(unsigned numResults) const
Returns the map consisting of the most major numResults results.
Definition: AffineMap.cpp:631
MLIRContext * getContext() const
Definition: AffineMap.cpp:330
bool isMinorIdentity() const
Returns true if this affine map is a minor identity, i.e.
Definition: AffineMap.cpp:155
unsigned getDimPosition(unsigned idx) const
Extracts the position of the dimensional expression at the given result, when the caller knows it is ...
Definition: AffineMap.cpp:402
bool isConstant() const
Returns true if this affine map has only constant results.
Definition: AffineMap.cpp:364
static AffineMap getMultiDimIdentityMap(unsigned numDims, MLIRContext *context)
Returns an AffineMap with 'numDims' identity result dim exprs.
Definition: AffineMap.cpp:321
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
bool isSingleConstant() const
Returns true if this affine map is a single result constant function.
Definition: AffineMap.cpp:360
bool isProjectedPermutation(bool allowZeroInResults=false) const
Returns true if the AffineMap represents a subset (i.e.
Definition: AffineMap.cpp:582
AffineMap getMinorSubMap(unsigned numResults) const
Returns the map consisting of the most minor numResults results.
Definition: AffineMap.cpp:639
uint64_t getLargestKnownDivisorOfMapExprs()
Get the largest known divisor of all map expressions.
Definition: AffineMap.cpp:310
constexpr AffineMap()=default
bool isEmpty() const
Returns true if this affine map is an empty map, i.e., () -> ().
Definition: AffineMap.cpp:356
std::optional< unsigned > getResultPosition(AffineExpr input) const
Extracts the first result position where input dimension resides.
Definition: AffineMap.cpp:406
unsigned getNumSymbols() const
Definition: AffineMap.cpp:385
bool isMinorIdentityWithBroadcasting(SmallVectorImpl< unsigned > *broadcastedDims=nullptr) const
Returns true if this affine map is a minor identity up to broadcasted dimensions which are indicated ...
Definition: AffineMap.cpp:163
unsigned getNumDims() const
Definition: AffineMap.cpp:381
ArrayRef< AffineExpr > getResults() const
Definition: AffineMap.cpp:394
SmallVector< int64_t > getConstantResults() const
Returns the constant results of this map.
Definition: AffineMap.cpp:373
bool isPermutationOfMinorIdentityWithBroadcasting(SmallVectorImpl< unsigned > &permutedDims) const
Return true if this affine map can be converted to a minor identity with broadcast by doing a permute...
Definition: AffineMap.cpp:203
bool isSymbolIdentity() const
Returns true if this affine map is an identity affine map on the symbol identifiers.
Definition: AffineMap.cpp:344
unsigned getNumResults() const
Definition: AffineMap.cpp:389
AffineMap replaceDimsAndSymbols(ArrayRef< AffineExpr > dimReplacements, ArrayRef< AffineExpr > symReplacements, unsigned numResultDims, unsigned numResultSyms) const
This method substitutes any uses of dimensions and symbols (e.g.
Definition: AffineMap.cpp:487
unsigned getNumInputs() const
Definition: AffineMap.cpp:390
AffineExpr getResult(unsigned idx) const
Definition: AffineMap.cpp:398
static AffineMap getFilteredIdentityMap(MLIRContext *ctx, unsigned numDims, llvm::function_ref< bool(AffineDimExpr)> keepDimFilter)
Returns an identity affine map with numDims input dimensions and filtered results using keepDimFilter...
Definition: AffineMap.cpp:142
AffineMap replace(AffineExpr expr, AffineExpr replacement, unsigned numResultDims, unsigned numResultSyms) const
Sparse replace method.
Definition: AffineMap.cpp:502
static AffineMap getPermutationMap(ArrayRef< unsigned > permutation, MLIRContext *context)
Returns an AffineMap representing a permutation.
Definition: AffineMap.cpp:251
void walkExprs(llvm::function_ref< void(AffineExpr)> callback) const
Walk all of the AffineExpr's in this mapping.
Definition: AffineMap.cpp:477
AffineMap partialConstantFold(ArrayRef< Attribute > operandConstants, SmallVectorImpl< int64_t > *results=nullptr, bool *hasPoison=nullptr) const
Propagates the constant operands into this affine map.
Definition: AffineMap.cpp:440
static AffineMap getConstantMap(int64_t val, MLIRContext *context)
Returns a single constant result affine map.
Definition: AffineMap.cpp:128
static AffineMap getMultiDimMapWithTargets(unsigned numDims, ArrayRef< unsigned > targets, MLIRContext *context)
Returns an affine map with numDims input dimensions and results specified by targets.
Definition: AffineMap.cpp:267
AffineMap getSubMap(ArrayRef< unsigned > resultPos) const
Returns the map consisting of the resultPos subset.
Definition: AffineMap.cpp:618
LogicalResult constantFold(ArrayRef< Attribute > operandConstants, SmallVectorImpl< Attribute > &results, bool *hasPoison=nullptr) const
Folds the results of the application of an affine map on the provided operands to a constant if possi...
Definition: AffineMap.cpp:421
AffineMap compose(AffineMap map) const
Returns the AffineMap resulting from composing this with map.
Definition: AffineMap.cpp:543
bool isIdentity() const
Returns true if this affine map is an identity affine map.
Definition: AffineMap.cpp:332
bool isPermutation() const
Returns true if the AffineMap represents a symbol-less permutation map.
Definition: AffineMap.cpp:612
static SmallVector< AffineMap, 4 > inferFromExprList(ArrayRef< ArrayRef< AffineExpr >> exprsList, MLIRContext *context)
Returns a vector of AffineMaps; each with as many results as exprs.size(), as many dims as the larges...
Definition: AffineMap.cpp:299
A symbolic identifier appearing in an affine expression.
Definition: AffineExpr.h:244
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:50
AffineExpr getAffineSymbolExpr(unsigned position)
Definition: Builders.cpp:375
AffineExpr getAffineConstantExpr(int64_t constant)
Definition: Builders.cpp:379
AffineExpr getAffineDimExpr(unsigned position)
Definition: Builders.cpp:371
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Definition: Matchers.h:285
Include the generated interface declarations.
AffineMap simplifyAffineMap(AffineMap map)
Simplifies an affine map by simplifying its underlying AffineExpr results.
Definition: AffineMap.cpp:737
AffineMap expandDimsToRank(AffineMap map, int64_t rank, const llvm::SmallBitVector &projectedDimensions)
Expand map to operate on rank dims while projecting out the dims in projectedDimensions.
Definition: AffineMap.cpp:917
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:747
llvm::SmallBitVector getUnusedSymbolsBitVector(ArrayRef< AffineMap > maps)
Definition: AffineMap.cpp:904
AffineMap inverseAndBroadcastProjectedPermutation(AffineMap map)
Return the reverse map of a projected permutation where the projected dimensions are transformed into...
Definition: AffineMap.cpp:779
AffineMap inversePermutation(AffineMap map)
Returns a map of codomain to domain dimensions such that the first codomain dimension for a particula...
Definition: AffineMap.cpp:755
AffineMap concatAffineMaps(ArrayRef< AffineMap > maps)
Concatenates a list of maps into a single AffineMap, stepping over potentially empty maps.
Definition: AffineMap.cpp:800
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
@ 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.
AffineMap compressSymbols(AffineMap map, const llvm::SmallBitVector &unusedSymbols)
Drop the symbols that are listed in unusedSymbols.
Definition: AffineMap.cpp:695
static void getMaxDimAndSymbol(ArrayRef< AffineExprContainer > exprsList, int64_t &maxDim, int64_t &maxSym)
Calculates maximum dimension and symbol positions from the expressions in exprsLists and stores them ...
Definition: AffineMap.h:671
AffineMap compressUnusedDims(AffineMap map)
Drop the dims that are not used.
Definition: AffineMap.cpp:686
AffineMap compressDims(AffineMap map, const llvm::SmallBitVector &unusedDims)
Drop the dims that are listed in unusedDims.
Definition: AffineMap.cpp:681
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
Definition: AffineExpr.cpp:630
AffineMap getProjectedMap(AffineMap map, const llvm::SmallBitVector &projectedDimensions, bool compressDimsFlag=true, bool compressSymbolsFlag=true)
Calls projectDims(map, projectedDimensions, compressDimsFlag).
Definition: AffineMap.cpp:882
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
llvm::SmallBitVector getUnusedDimsBitVector(ArrayRef< AffineMap > maps)
Definition: AffineMap.cpp:892
AffineExpr simplifyAffineExpr(AffineExpr expr, unsigned numDims, unsigned numSymbols)
Simplify an affine expression by flattening and some amount of simple analysis.
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
Definition: AffineExpr.cpp:606
AffineMap projectDims(AffineMap map, const llvm::SmallBitVector &projectedDimensions, bool compressDimsFlag=false)
Returns the map that results from projecting out the dimensions specified in projectedDimensions.
Definition: AffineMap.cpp:868
AffineMap compressUnusedSymbols(AffineMap map)
Drop the symbols that are not used.
Definition: AffineMap.cpp:700
AffineMap projectSymbols(AffineMap map, const llvm::SmallBitVector &projectedSymbols, bool compressSymbolsFlag=false)
Symbol counterpart of projectDims.
Definition: AffineMap.cpp:875
AffineMap foldAttributesIntoMap(Builder &b, AffineMap map, ArrayRef< OpFoldResult > operands, SmallVector< Value > &remainingValues)
Fold all attributes among the given operands into the affine map.
Definition: AffineMap.cpp:709
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
Definition: AffineExpr.cpp:616
void reset(AffineMap map)
Resets this MutableAffineMap with 'map'.
Definition: AffineMap.cpp:933
AffineMap getAffineMap() const
Get the AffineMap corresponding to this MutableAffineMap.
Definition: AffineMap.cpp:955
AffineExpr getResult(unsigned idx) const
Definition: AffineMap.h:410
bool isMultipleOf(unsigned idx, int64_t factor) const
Returns true if the idx'th result expression is a multiple of factor.
Definition: AffineMap.cpp:941
unsigned getNumResults() const
Definition: AffineMap.h:412
void simplify()
Simplify the (result) expressions in this map using analysis (used by.
Definition: AffineMap.cpp:947
ArrayRef< AffineExpr > results() const
The affine expressions for this (multi-dimensional) map.