[MLIR][Presburger] Provide functions to convert between arrays of MPInt and int64_t
authorArjun P <arjunpitchanathan@gmail.com>
Mon, 18 Jul 2022 16:34:40 +0000 (17:34 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Mon, 18 Jul 2022 16:34:50 +0000 (17:34 +0100)
Reviewed By: Groverkss

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

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

index 0017715..e7c2de0 100644 (file)
@@ -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);
 
index e322cb9..bc3006a 100644 (file)
@@ -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.
index 978ced1..54dcfad 100644 (file)
@@ -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;
+}