Add a method to build affine maps with zero or more results.
authorUlysse Beaugnon <ulysse@google.com>
Wed, 1 Apr 2020 08:47:06 +0000 (10:47 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 1 Apr 2020 08:47:18 +0000 (10:47 +0200)
Summary:
The commit provides a single method to build affine maps with zero or more
results. Users of mlir::AffineMap previously had to dispatch between two methods
depending on the number of results.

At the same time, this commit fixes the method for building affine map with zero
results that was previously ignoring its `symbolCount` argument.

Differential Revision: https://reviews.llvm.org/D77126

mlir/include/mlir/IR/AffineMap.h
mlir/lib/IR/MLIRContext.cpp

index 14deb85..1553427 100644 (file)
@@ -49,9 +49,16 @@ public:
   static AffineMap get(unsigned dimCount, unsigned symbolCount,
                        MLIRContext *context);
 
+  /// Returns an affine map with `dimCount` dimensions and `symbolCount` symbols
+  /// mapping to the given results. The array of results cannot be empty.
   static AffineMap get(unsigned dimCount, unsigned symbolCount,
                        ArrayRef<AffineExpr> results);
 
+  /// Returns an affine map with `dimCount` dimensions and `symbolCount` mapping
+  /// to the given results, where the number of results can be zero.
+  static AffineMap get(unsigned dimCount, unsigned symbolCount,
+                       ArrayRef<AffineExpr> results, MLIRContext *context);
+
   /// Returns a single constant result affine map.
   static AffineMap getConstantMap(int64_t val, MLIRContext *context);
 
index df4ea9b..3875b57 100644 (file)
@@ -630,7 +630,7 @@ AffineMap AffineMap::get(MLIRContext *context) {
 
 AffineMap AffineMap::get(unsigned dimCount, unsigned symbolCount,
                          MLIRContext *context) {
-  return getImpl(dimCount, /*symbolCount=*/0, /*results=*/{}, context);
+  return getImpl(dimCount, symbolCount, /*results=*/{}, context);
 }
 
 AffineMap AffineMap::get(unsigned dimCount, unsigned symbolCount,
@@ -640,6 +640,11 @@ AffineMap AffineMap::get(unsigned dimCount, unsigned symbolCount,
   return getImpl(dimCount, symbolCount, results, results[0].getContext());
 }
 
+AffineMap AffineMap::get(unsigned dimCount, unsigned symbolCount,
+                         ArrayRef<AffineExpr> results, MLIRContext *context) {
+  return getImpl(dimCount, symbolCount, results, context);
+}
+
 //===----------------------------------------------------------------------===//
 // Integer Sets: these are allocated into the bump pointer, and are immutable.
 // Unlike AffineMap's, these are uniqued only if they are small.