[mlir] NFC - Add AffineMap::replace variant with dim/symbol inference
authorNicolas Vasilache <nicolas.vasilache@gmail.com>
Wed, 14 Jul 2021 20:06:16 +0000 (20:06 +0000)
committerNicolas Vasilache <nicolas.vasilache@gmail.com>
Wed, 14 Jul 2021 20:29:12 +0000 (20:29 +0000)
mlir/include/mlir/IR/AffineMap.h
mlir/lib/IR/AffineMap.cpp

index 336e618..b308bea 100644 (file)
@@ -197,6 +197,11 @@ public:
                     unsigned numResultDims, unsigned numResultSyms) const;
 
   /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
+  /// results and return a new AffineMap with the new results and with inferred
+  /// number of dims and symbols.
+  AffineMap replace(const DenseMap<AffineExpr, AffineExpr> &map) const;
+
+  /// Sparse replace method. Apply AffineExpr::replace(`map`) to each of the
   /// results and return a new AffineMap with the new results and with the
   /// specified number of dims and symbols.
   AffineMap replace(const DenseMap<AffineExpr, AffineExpr> &map,
index 2713426..2257617 100644 (file)
@@ -439,6 +439,15 @@ AffineMap AffineMap::replace(const DenseMap<AffineExpr, AffineExpr> &map,
   return AffineMap::get(numResultDims, numResultSyms, newResults, getContext());
 }
 
+AffineMap
+AffineMap::replace(const DenseMap<AffineExpr, AffineExpr> &map) const {
+  SmallVector<AffineExpr, 4> newResults;
+  newResults.reserve(getNumResults());
+  for (AffineExpr e : getResults())
+    newResults.push_back(e.replace(map));
+  return AffineMap::inferFromExprList(newResults).front();
+}
+
 AffineMap AffineMap::compose(AffineMap map) const {
   assert(getNumDims() == map.getNumResults() && "Number of results mismatch");
   // Prepare `map` by concatenating the symbols and rewriting its exprs.