From 523914c20d974f20dcff463b40855f2cdd463313 Mon Sep 17 00:00:00 2001 From: Arjun P Date: Fri, 18 Mar 2022 14:51:00 +0000 Subject: [PATCH] [MLIR][Presburger] Deduplicate and move getNegatedCoeffs and getComplementIneq into Utils --- mlir/include/mlir/Analysis/Presburger/Utils.h | 10 ++++++++++ .../lib/Analysis/Presburger/PresburgerRelation.cpp | 23 ---------------------- mlir/lib/Analysis/Presburger/Utils.cpp | 17 ++++++++++++++++ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h index 1f5b571..06298f6 100644 --- a/mlir/include/mlir/Analysis/Presburger/Utils.h +++ b/mlir/include/mlir/Analysis/Presburger/Utils.h @@ -130,6 +130,16 @@ void removeDuplicateDivs( SmallVectorImpl &denoms, unsigned localOffset, llvm::function_ref merge); +/// Return `coeffs` with all the elements negated. +SmallVector getNegatedCoeffs(ArrayRef coeffs); + +/// Return the complement of the given inequality. +/// +/// The complement of a_1 x_1 + ... + a_n x_ + c >= 0 is +/// a_1 x_1 + ... + a_n x_ + c < 0, i.e., -a_1 x_1 - ... - a_n x_ - c - 1 >= 0, +/// since all the variables are constrained to be integers. +SmallVector getComplementIneq(ArrayRef ineq); + } // namespace presburger } // namespace mlir diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp index 1b5aa0f..6f035aa 100644 --- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp @@ -107,29 +107,6 @@ PresburgerRelation::intersect(const PresburgerRelation &set) const { return result; } -/// Return `coeffs` with all the elements negated. -static SmallVector getNegatedCoeffs(ArrayRef coeffs) { - SmallVector negatedCoeffs; - negatedCoeffs.reserve(coeffs.size()); - for (int64_t coeff : coeffs) - negatedCoeffs.emplace_back(-coeff); - return negatedCoeffs; -} - -/// Return the complement of the given inequality. -/// -/// The complement of a_1 x_1 + ... + a_n x_ + c >= 0 is -/// a_1 x_1 + ... + a_n x_ + c < 0, i.e., -a_1 x_1 - ... - a_n x_ - c - 1 >= 0, -/// since all the variables are constrained to be integers. -static SmallVector getComplementIneq(ArrayRef ineq) { - SmallVector coeffs; - coeffs.reserve(ineq.size()); - for (int64_t coeff : ineq) - coeffs.emplace_back(-coeff); - --coeffs.back(); - return coeffs; -} - /// Return the set difference b \ s and accumulate the result into `result`. /// `simplex` must correspond to b. /// diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp index 96fcafa..4cd7670 100644 --- a/mlir/lib/Analysis/Presburger/Utils.cpp +++ b/mlir/lib/Analysis/Presburger/Utils.cpp @@ -303,3 +303,20 @@ void presburger::removeDuplicateDivs( } } } + +SmallVector presburger::getNegatedCoeffs(ArrayRef coeffs) { + SmallVector negatedCoeffs; + negatedCoeffs.reserve(coeffs.size()); + for (int64_t coeff : coeffs) + negatedCoeffs.emplace_back(-coeff); + return negatedCoeffs; +} + +SmallVector presburger::getComplementIneq(ArrayRef ineq) { + SmallVector coeffs; + coeffs.reserve(ineq.size()); + for (int64_t coeff : ineq) + coeffs.emplace_back(-coeff); + --coeffs.back(); + return coeffs; +} -- 2.7.4