From ffb8b7b2a0b9e765a74aec87106dd3e83e71ff77 Mon Sep 17 00:00:00 2001 From: Arjun P Date: Mon, 18 Jul 2022 17:34:40 +0100 Subject: [PATCH] [MLIR][Presburger] Provide functions to convert between arrays of MPInt and int64_t Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D129509 --- mlir/include/mlir/Analysis/Presburger/MPInt.h | 3 +++ mlir/include/mlir/Analysis/Presburger/Utils.h | 5 +++++ mlir/lib/Analysis/Presburger/Utils.cpp | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/mlir/include/mlir/Analysis/Presburger/MPInt.h b/mlir/include/mlir/Analysis/Presburger/MPInt.h index 0017715..e7c2de0 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 e322cb9..bc3006a 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 getMPIntVec(ArrayRef range); +/// Return the given array as an array of int64_t. +SmallVector getInt64Vec(ArrayRef 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 978ced1..54dcfad 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 presburger::getMPIntVec(ArrayRef range) { + SmallVector result(range.size()); + std::transform(range.begin(), range.end(), result.begin(), mpintFromInt64); + return result; +} + +SmallVector presburger::getInt64Vec(ArrayRef range) { + SmallVector result(range.size()); + std::transform(range.begin(), range.end(), result.begin(), int64FromMPInt); + return result; +} -- 2.7.4