[Mlir-commits] [mlir] ffb8b7b - [MLIR][Presburger] Provide functions to convert between arrays of MPInt and int64_t

Arjun P llvmlistbot at llvm.org
Mon Jul 18 09:34:41 PDT 2022


Author: Arjun P
Date: 2022-07-18T17:34:50+01:00
New Revision: ffb8b7b2a0b9e765a74aec87106dd3e83e71ff77

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

LOG: [MLIR][Presburger] Provide functions to convert between arrays of MPInt and int64_t

Reviewed By: Groverkss

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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/MPInt.h
    mlir/include/mlir/Analysis/Presburger/Utils.h
    mlir/lib/Analysis/Presburger/Utils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/MPInt.h b/mlir/include/mlir/Analysis/Presburger/MPInt.h
index 0017715adcaac..e7c2de0a504ad 100644
--- a/mlir/include/mlir/Analysis/Presburger/MPInt.h
+++ b/mlir/include/mlir/Analysis/Presburger/MPInt.h
@@ -260,6 +260,9 @@ llvm::hash_code hash_value(const MPInt &x); // NOLINT
 LLVM_ATTRIBUTE_ALWAYS_INLINE int64_t int64FromMPInt(const MPInt &x) {
   return int64_t(x);
 }
+LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mpintFromInt64(int64_t x) {
+  return MPInt(x);
+}
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const MPInt &x);
 

diff  --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h
index e322cb9189396..bc3006abe7ca4 100644
--- a/mlir/include/mlir/Analysis/Presburger/Utils.h
+++ b/mlir/include/mlir/Analysis/Presburger/Utils.h
@@ -13,6 +13,7 @@
 #ifndef MLIR_ANALYSIS_PRESBURGER_UTILS_H
 #define MLIR_ANALYSIS_PRESBURGER_UTILS_H
 
+#include "mlir/Analysis/Presburger/MPInt.h"
 #include "mlir/Support/LLVM.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallBitVector.h"
@@ -204,6 +205,10 @@ llvm::SmallBitVector getSubrangeBitVector(unsigned len, unsigned setOffset,
 /// function of other variables (where the divisor is a positive constant).
 /// `foundRepr` contains a boolean for each variable indicating if the
 /// explicit representation for that variable has already been computed.
+/// Return the given array as an array of MPInts.
+SmallVector<MPInt, 8> getMPIntVec(ArrayRef<int64_t> range);
+/// Return the given array as an array of int64_t.
+SmallVector<int64_t, 8> getInt64Vec(ArrayRef<MPInt> range);
 /// Returns the `MaybeLocalRepr` struct which contains the indices of the
 /// constraints that can be expressed as a floordiv of an affine function. If
 /// the representation could be computed, `dividend` and `denominator` are set.

diff  --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index 978ced1a967f8..54dcfad166032 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -412,3 +412,15 @@ void DivisionRepr::print(raw_ostream &os) const {
 }
 
 void DivisionRepr::dump() const { print(llvm::errs()); }
+
+SmallVector<MPInt, 8> presburger::getMPIntVec(ArrayRef<int64_t> range) {
+  SmallVector<MPInt, 8> result(range.size());
+  std::transform(range.begin(), range.end(), result.begin(), mpintFromInt64);
+  return result;
+}
+
+SmallVector<int64_t, 8> presburger::getInt64Vec(ArrayRef<MPInt> range) {
+  SmallVector<int64_t, 8> result(range.size());
+  std::transform(range.begin(), range.end(), result.begin(), int64FromMPInt);
+  return result;
+}


        


More information about the Mlir-commits mailing list