From 37bad565bf616d755cb44a267c8d61ea34fe9817 Mon Sep 17 00:00:00 2001 From: Prashant Kumar Date: Fri, 4 Feb 2022 21:27:01 +0530 Subject: [PATCH] Revert "[MLIR][Presburger] Use `SmallVector` instead of `std::vector` in `getLocalRepr`" This reverts commit 3cc544772848682bc77ff63db659a5aa4b3d4e6b. SmallVector inside SmallVector are not optimized. Reviewed By: arjunp Differential Revision: https://reviews.llvm.org/D119005 --- .../Analysis/Presburger/IntegerPolyhedron.h | 14 ++++++-------- mlir/include/mlir/Analysis/Presburger/Utils.h | 2 +- .../Analysis/Presburger/IntegerPolyhedron.cpp | 19 +++++++++---------- .../lib/Analysis/Presburger/PresburgerSet.cpp | 2 +- mlir/lib/Analysis/Presburger/Utils.cpp | 12 ++++++------ .../Presburger/IntegerPolyhedronTest.cpp | 2 +- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h index 42e274305a07..8156b7b71f3a 100644 --- a/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerPolyhedron.h @@ -285,14 +285,12 @@ public: /// 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(SmallVectorImpl> ÷nds, - SmallVectorImpl &denominators, - SmallVectorImpl &repr) const; - void - getLocalReprs(SmallVectorImpl &repr) const; - void getLocalReprs(SmallVectorImpl> ÷nds, - SmallVectorImpl &denominators) const; + void getLocalReprs(std::vector> ÷nds, + SmallVector &denominators, + std::vector &repr) const; + void getLocalReprs(std::vector &repr) const; + void getLocalReprs(std::vector> ÷nds, + SmallVector &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 9e5edc0c6436..8e57ac151d25 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( - SmallVectorImpl> &divs, + std::vector> &divs, SmallVectorImpl &denoms, unsigned localOffset, llvm::function_ref merge); diff --git a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp index 4ebf674bc520..578f85472970 100644 --- a/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerPolyhedron.cpp @@ -829,24 +829,23 @@ bool IntegerPolyhedron::containsPoint(ArrayRef point) const { return true; } -void IntegerPolyhedron::getLocalReprs( - SmallVectorImpl &repr) const { - SmallVector> dividends(getNumLocalIds()); +void IntegerPolyhedron::getLocalReprs(std::vector &repr) const { + std::vector> dividends(getNumLocalIds()); SmallVector denominators(getNumLocalIds()); getLocalReprs(dividends, denominators, repr); } void IntegerPolyhedron::getLocalReprs( - SmallVectorImpl> ÷nds, - SmallVectorImpl &denominators) const { - SmallVector repr(getNumLocalIds()); + std::vector> ÷nds, + SmallVector &denominators) const { + std::vector repr(getNumLocalIds()); getLocalReprs(dividends, denominators, repr); } void IntegerPolyhedron::getLocalReprs( - SmallVectorImpl> ÷nds, - SmallVectorImpl &denominators, - SmallVectorImpl &repr) const { + std::vector> ÷nds, + SmallVector &denominators, + std::vector &repr) const { repr.resize(getNumLocalIds()); dividends.resize(getNumLocalIds()); @@ -1104,7 +1103,7 @@ void IntegerPolyhedron::mergeLocalIds(IntegerPolyhedron &other) { polyB.insertLocalId(0, initLocals); // Get division representations from each poly. - SmallVector> divsA, divsB; + std::vector> divsA, divsB; SmallVector 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 981bd563e117..3a7be6efa5bb 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. - SmallVector repr(sI.getNumLocalIds()); + std::vector 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 a06304b1a266..7dc7a26e0b5c 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 `tempDiv` != 0. - int64_t tempDiv = cst.atEq(eqInd, pos); - if (tempDiv == 0) + // Equality must involve the pos-th variable and hence `temp_div` != 0. + int64_t temp_div = cst.atEq(eqInd, pos); + if (temp_div == 0) return failure(); - int64_t signDiv = tempDiv < 0 ? -1 : 1; + int64_t signDiv = temp_div < 0 ? -1 : 1; // The divisor is always a positive integer. - divisor = tempDiv * signDiv; + divisor = temp_div * 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( - SmallVectorImpl> &divs, + std::vector> &divs, SmallVectorImpl &denoms, unsigned localOffset, llvm::function_ref merge) { diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp index 365d6dbe317c..ccb8f3ea043d 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> &expectedDividends, const SmallVectorImpl &expectedDenominators) { - SmallVector> dividends; + std::vector> dividends; SmallVector denominators; poly.getLocalReprs(dividends, denominators);