[Mlir-commits] [mlir] f349abc - [mlir] Add `const` qualifiers to `AffineMap` methods

Vladislav Vinogradov llvmlistbot at llvm.org
Fri Feb 5 04:22:25 PST 2021


Author: Vladislav Vinogradov
Date: 2021-02-05T15:22:16+03:00
New Revision: f349abc265ebbd2acdc6b6332f475f81aca49d48

URL: https://github.com/llvm/llvm-project/commit/f349abc265ebbd2acdc6b6332f475f81aca49d48
DIFF: https://github.com/llvm/llvm-project/commit/f349abc265ebbd2acdc6b6332f475f81aca49d48.diff

LOG: [mlir] Add `const` qualifiers to `AffineMap` methods

The `AffineMap` class follows the same semantic as Type and Attribute.
It is immutable object, so it make sence to mark its methods as const.
Also part of its API is already marked as const, this change just make the API consistent.

Reviewed By: ftynse, bondhugula

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/AffineMap.h
    mlir/lib/IR/AffineMap.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h
index bf87bcf55a7f..7884cb5ca8bf 100644
--- a/mlir/include/mlir/IR/AffineMap.h
+++ b/mlir/include/mlir/IR/AffineMap.h
@@ -90,7 +90,7 @@ class AffineMap {
 
   MLIRContext *getContext() const;
 
-  explicit operator bool() { return map != nullptr; }
+  explicit operator bool() const { return map != nullptr; }
   bool operator==(AffineMap other) const { return other.map == map; }
   bool operator!=(AffineMap other) const { return !(other.map == map); }
 
@@ -220,31 +220,31 @@ class AffineMap {
   ///   map2: `(d0)[s0] -> (d0 + s0, d0 - s0)`
   ///   map1.compose(map2):
   ///     `(d0)[s0, s1, s2] -> (d0 + s1 + s2 + 1, d0 - s0 - s2 - 1)`
-  AffineMap compose(AffineMap map);
+  AffineMap compose(AffineMap map) const;
 
   /// Applies composition by the dims of `this` to the integer `values` and
   /// returns the resulting values. `this` must be symbol-less.
-  SmallVector<int64_t, 4> compose(ArrayRef<int64_t> values);
+  SmallVector<int64_t, 4> compose(ArrayRef<int64_t> values) const;
 
   /// Returns true if the AffineMap represents a subset (i.e. a projection) of a
   /// symbol-less permutation map.
-  bool isProjectedPermutation();
+  bool isProjectedPermutation() const;
 
   /// Returns true if the AffineMap represents a symbol-less permutation map.
-  bool isPermutation();
+  bool isPermutation() const;
 
   /// Returns the map consisting of the `resultPos` subset.
-  AffineMap getSubMap(ArrayRef<unsigned> resultPos);
+  AffineMap getSubMap(ArrayRef<unsigned> resultPos) const;
 
   /// Returns the map consisting of the most major `numResults` results.
   /// Returns the null AffineMap if `numResults` == 0.
   /// Returns `*this` if `numResults` >= `this->getNumResults()`.
-  AffineMap getMajorSubMap(unsigned numResults);
+  AffineMap getMajorSubMap(unsigned numResults) const;
 
   /// Returns the map consisting of the most minor `numResults` results.
   /// Returns the null AffineMap if `numResults` == 0.
   /// Returns `*this` if `numResults` >= `this->getNumResults()`.
-  AffineMap getMinorSubMap(unsigned numResults);
+  AffineMap getMinorSubMap(unsigned numResults) const;
 
   friend ::llvm::hash_code hash_value(AffineMap arg);
 

diff  --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp
index 9455b9de3199..37fb3b18da74 100644
--- a/mlir/lib/IR/AffineMap.cpp
+++ b/mlir/lib/IR/AffineMap.cpp
@@ -334,7 +334,7 @@ AffineMap AffineMap::replace(const DenseMap<AffineExpr, AffineExpr> &map,
   return AffineMap::get(numResultDims, numResultSyms, newResults, getContext());
 }
 
-AffineMap AffineMap::compose(AffineMap map) {
+AffineMap AffineMap::compose(AffineMap map) const {
   assert(getNumDims() == map.getNumResults() && "Number of results mismatch");
   // Prepare `map` by concatenating the symbols and rewriting its exprs.
   unsigned numDims = map.getNumDims();
@@ -358,7 +358,7 @@ AffineMap AffineMap::compose(AffineMap map) {
   return AffineMap::get(numDims, numSymbols, exprs, map.getContext());
 }
 
-SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) {
+SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) const {
   assert(getNumSymbols() == 0 && "Expected symbol-less map");
   SmallVector<AffineExpr, 4> exprs;
   exprs.reserve(values.size());
@@ -373,7 +373,7 @@ SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) {
   return res;
 }
 
-bool AffineMap::isProjectedPermutation() {
+bool AffineMap::isProjectedPermutation() const {
   if (getNumSymbols() > 0)
     return false;
   SmallVector<bool, 8> seen(getNumInputs(), false);
@@ -389,13 +389,13 @@ bool AffineMap::isProjectedPermutation() {
   return true;
 }
 
-bool AffineMap::isPermutation() {
+bool AffineMap::isPermutation() const {
   if (getNumDims() != getNumResults())
     return false;
   return isProjectedPermutation();
 }
 
-AffineMap AffineMap::getSubMap(ArrayRef<unsigned> resultPos) {
+AffineMap AffineMap::getSubMap(ArrayRef<unsigned> resultPos) const {
   SmallVector<AffineExpr, 4> exprs;
   exprs.reserve(resultPos.size());
   for (auto idx : resultPos)
@@ -403,7 +403,7 @@ AffineMap AffineMap::getSubMap(ArrayRef<unsigned> resultPos) {
   return AffineMap::get(getNumDims(), getNumSymbols(), exprs, getContext());
 }
 
-AffineMap AffineMap::getMajorSubMap(unsigned numResults) {
+AffineMap AffineMap::getMajorSubMap(unsigned numResults) const {
   if (numResults == 0)
     return AffineMap();
   if (numResults > getNumResults())
@@ -411,7 +411,7 @@ AffineMap AffineMap::getMajorSubMap(unsigned numResults) {
   return getSubMap(llvm::to_vector<4>(llvm::seq<unsigned>(0, numResults)));
 }
 
-AffineMap AffineMap::getMinorSubMap(unsigned numResults) {
+AffineMap AffineMap::getMinorSubMap(unsigned numResults) const {
   if (numResults == 0)
     return AffineMap();
   if (numResults > getNumResults())


        


More information about the Mlir-commits mailing list