[Mlir-commits] [mlir] 3cc5447 - [MLIR][Presburger] Use `SmallVector` instead of `std::vector` in `getLocalRepr`

Prashant Kumar llvmlistbot at llvm.org
Wed Feb 2 06:27:23 PST 2022


Author: Prashant Kumar
Date: 2022-02-02T19:57:15+05:30
New Revision: 3cc544772848682bc77ff63db659a5aa4b3d4e6b

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

LOG: [MLIR][Presburger] Use `SmallVector` instead of `std::vector` in `getLocalRepr`

Use `SmallVector` instead of `std::vector` in `getLocalRepr` function.
 Also, fix the casing of a variable.

Reviewed By: arjunp

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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
    mlir/include/mlir/Analysis/Presburger/Utils.h
    mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
    mlir/lib/Analysis/Presburger/PresburgerSet.cpp
    mlir/lib/Analysis/Presburger/Utils.cpp
    mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
index 8156b7b71f3a2..42e274305a079 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h
@@ -285,12 +285,14 @@ class IntegerPolyhedron {
   /// and the denominators in `denominators`. If no explicit representation
   /// could be found for the `i^th` local identifier, `denominators[i]` is set
   /// to 0.
-  void getLocalReprs(std::vector<SmallVector<int64_t, 8>> &dividends,
-                     SmallVector<unsigned, 4> &denominators,
-                     std::vector<presburger_utils::MaybeLocalRepr> &repr) const;
-  void getLocalReprs(std::vector<presburger_utils::MaybeLocalRepr> &repr) const;
-  void getLocalReprs(std::vector<SmallVector<int64_t, 8>> &dividends,
-                     SmallVector<unsigned, 4> &denominators) const;
+  void
+  getLocalReprs(SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
+                SmallVectorImpl<unsigned> &denominators,
+                SmallVectorImpl<presburger_utils::MaybeLocalRepr> &repr) const;
+  void
+  getLocalReprs(SmallVectorImpl<presburger_utils::MaybeLocalRepr> &repr) const;
+  void getLocalReprs(SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
+                     SmallVectorImpl<unsigned> &denominators) const;
 
   /// The type of bound: equal, lower bound or upper bound.
   enum BoundType { EQ, LB, UB };

diff  --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h
index 8e57ac151d258..9e5edc0c64362 100644
--- a/mlir/include/mlir/Analysis/Presburger/Utils.h
+++ b/mlir/include/mlir/Analysis/Presburger/Utils.h
@@ -65,7 +65,7 @@ MaybeLocalRepr computeSingleVarRepr(const IntegerPolyhedron &cst,
 /// the divisions are not merged. `merge` can also do side effects, For example
 /// it can merge the local identifiers in IntegerPolyhedron.
 void removeDuplicateDivs(
-    std::vector<SmallVector<int64_t, 8>> &divs,
+    SmallVectorImpl<SmallVector<int64_t, 8>> &divs,
     SmallVectorImpl<unsigned> &denoms, unsigned localOffset,
     llvm::function_ref<bool(unsigned i, unsigned j)> merge);
 

diff  --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
index 578f854729707..4ebf674bc5201 100644
--- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp
@@ -829,23 +829,24 @@ bool IntegerPolyhedron::containsPoint(ArrayRef<int64_t> point) const {
   return true;
 }
 
-void IntegerPolyhedron::getLocalReprs(std::vector<MaybeLocalRepr> &repr) const {
-  std::vector<SmallVector<int64_t, 8>> dividends(getNumLocalIds());
+void IntegerPolyhedron::getLocalReprs(
+    SmallVectorImpl<MaybeLocalRepr> &repr) const {
+  SmallVector<SmallVector<int64_t, 8>> dividends(getNumLocalIds());
   SmallVector<unsigned, 4> denominators(getNumLocalIds());
   getLocalReprs(dividends, denominators, repr);
 }
 
 void IntegerPolyhedron::getLocalReprs(
-    std::vector<SmallVector<int64_t, 8>> &dividends,
-    SmallVector<unsigned, 4> &denominators) const {
-  std::vector<MaybeLocalRepr> repr(getNumLocalIds());
+    SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
+    SmallVectorImpl<unsigned> &denominators) const {
+  SmallVector<MaybeLocalRepr> repr(getNumLocalIds());
   getLocalReprs(dividends, denominators, repr);
 }
 
 void IntegerPolyhedron::getLocalReprs(
-    std::vector<SmallVector<int64_t, 8>> &dividends,
-    SmallVector<unsigned, 4> &denominators,
-    std::vector<MaybeLocalRepr> &repr) const {
+    SmallVectorImpl<SmallVector<int64_t, 8>> &dividends,
+    SmallVectorImpl<unsigned> &denominators,
+    SmallVectorImpl<MaybeLocalRepr> &repr) const {
 
   repr.resize(getNumLocalIds());
   dividends.resize(getNumLocalIds());
@@ -1103,7 +1104,7 @@ void IntegerPolyhedron::mergeLocalIds(IntegerPolyhedron &other) {
   polyB.insertLocalId(0, initLocals);
 
   // Get division representations from each poly.
-  std::vector<SmallVector<int64_t, 8>> divsA, divsB;
+  SmallVector<SmallVector<int64_t, 8>> divsA, divsB;
   SmallVector<unsigned, 4> denomsA, denomsB;
   polyA.getLocalReprs(divsA, denomsA);
   polyB.getLocalReprs(divsB, denomsB);

diff  --git a/mlir/lib/Analysis/Presburger/PresburgerSet.cpp b/mlir/lib/Analysis/Presburger/PresburgerSet.cpp
index 3a7be6efa5bbb..981bd563e1172 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSet.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSet.cpp
@@ -213,7 +213,7 @@ static void subtractRecursively(IntegerPolyhedron &b, Simplex &simplex,
 
   // Find out which inequalities of sI correspond to division inequalities for
   // the local variables of sI.
-  std::vector<MaybeLocalRepr> repr(sI.getNumLocalIds());
+  SmallVector<MaybeLocalRepr> repr(sI.getNumLocalIds());
   sI.getLocalReprs(repr);
 
   // Add sI's locals to b, after b's locals. Also add b's locals to sI, before

diff  --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index 63ba4ecfdbf3c..c42e653593bb0 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -160,14 +160,14 @@ static LogicalResult getDivRepr(const IntegerPolyhedron &cst, unsigned pos,
 
   // Extract divisor, the divisor can be negative and hence its sign information
   // is stored in `signDiv` to reverse the sign of dividend's coefficients.
-  // Equality must involve the pos-th variable and hence `temp_div` != 0.
-  int64_t temp_div = cst.atEq(eqInd, pos);
-  if (temp_div == 0)
+  // Equality must involve the pos-th variable and hence `tempDiv` != 0.
+  int64_t tempDiv = cst.atEq(eqInd, pos);
+  if (tempDiv == 0)
     return failure();
-  int64_t signDiv = temp_div < 0 ? -1 : 1;
+  int64_t signDiv = tempDiv < 0 ? -1 : 1;
 
   // The divisor is always a positive integer.
-  divisor = temp_div * signDiv;
+  divisor = tempDiv * signDiv;
 
   expr.resize(cst.getNumCols(), 0);
   for (unsigned i = 0, e = cst.getNumIds(); i < e; ++i)
@@ -254,7 +254,7 @@ MaybeLocalRepr presburger_utils::computeSingleVarRepr(
 }
 
 void presburger_utils::removeDuplicateDivs(
-    std::vector<SmallVector<int64_t, 8>> &divs,
+    SmallVectorImpl<SmallVector<int64_t, 8>> &divs,
     SmallVectorImpl<unsigned> &denoms, unsigned localOffset,
     llvm::function_ref<bool(unsigned i, unsigned j)> merge) {
 

diff  --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
index ccb8f3ea043d1..365d6dbe317c3 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
@@ -624,7 +624,7 @@ static void checkDivisionRepresentation(
     const std::vector<SmallVector<int64_t, 8>> &expectedDividends,
     const SmallVectorImpl<unsigned> &expectedDenominators) {
 
-  std::vector<SmallVector<int64_t, 8>> dividends;
+  SmallVector<SmallVector<int64_t, 8>> dividends;
   SmallVector<unsigned, 4> denominators;
 
   poly.getLocalReprs(dividends, denominators);


        


More information about the Mlir-commits mailing list