[Mlir-commits] [mlir] 0239976 - [MLIR][Presburger] unittests: move more util functions into Utils.h (NFC)
Arjun P
llvmlistbot at llvm.org
Mon Mar 21 09:24:37 PDT 2022
Author: Arjun P
Date: 2022-03-21T16:24:43Z
New Revision: 0239976bec40f7f4f7c4cfb489b0298c289efd6b
URL: https://github.com/llvm/llvm-project/commit/0239976bec40f7f4f7c4cfb489b0298c289efd6b
DIFF: https://github.com/llvm/llvm-project/commit/0239976bec40f7f4f7c4cfb489b0298c289efd6b.diff
LOG: [MLIR][Presburger] unittests: move more util functions into Utils.h (NFC)
Added:
Modified:
mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
mlir/unittests/Analysis/Presburger/Utils.h
Removed:
################################################################################
diff --git a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
index 02546816e52d0..b8469a8c0174a 100644
--- a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
@@ -24,36 +24,6 @@ using namespace presburger;
using testing::ElementsAre;
-static Matrix makeMatrix(unsigned numRow, unsigned numColumns,
- ArrayRef<SmallVector<int64_t, 8>> matrix) {
- Matrix results(numRow, numColumns);
- assert(matrix.size() == numRow);
- for (unsigned i = 0; i < numRow; ++i) {
- assert(matrix[i].size() == numColumns &&
- "Output expression has incorrect dimensionality!");
- for (unsigned j = 0; j < numColumns; ++j)
- results(i, j) = matrix[i][j];
- }
- return results;
-}
-
-/// Construct a PWMAFunction given the dimensionalities and an array describing
-/// the list of pieces. Each piece is given by a string describing the domain
-/// and a 2D array that represents the output.
-static PWMAFunction parsePWMAF(
- unsigned numInputs, unsigned numOutputs,
- ArrayRef<std::pair<StringRef, SmallVector<SmallVector<int64_t, 8>, 8>>>
- data,
- unsigned numSymbols = 0) {
- PWMAFunction result(numInputs - numSymbols, numSymbols, numOutputs);
- for (const auto &pair : data) {
- IntegerPolyhedron domain = parsePoly(pair.first);
- result.addPiece(
- domain, makeMatrix(numOutputs, domain.getNumIds() + 1, pair.second));
- }
- return result;
-}
-
TEST(PWAFunctionTest, isEqual) {
// The output expressions are
diff erent but it doesn't matter because they are
// equal in this domain.
diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
index ed55abbc706a0..7278a5ec56e48 100644
--- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
@@ -24,18 +24,6 @@
using namespace mlir;
using namespace presburger;
-/// Parse a list of StringRefs to IntegerPolyhedron and combine them into a
-/// PresburgerSet be using the union operation. It is expected that the strings
-/// are all valid IntegerSet representation and that all of them have the same
-/// number of dimensions as is specified by the numDims argument.
-static PresburgerSet
-parsePresburgerSetFromPolyStrings(unsigned numDims, ArrayRef<StringRef> strs) {
- PresburgerSet set = PresburgerSet::getEmpty(numDims);
- for (StringRef str : strs)
- set.unionInPlace(parsePoly(str));
- return set;
-}
-
/// Compute the union of s and t, and check that each of the given points
/// belongs to the union iff it belongs to at least one of s and t.
static void testUnionAtPoints(const PresburgerSet &s, const PresburgerSet &t,
diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h
index ef099b7add109..4ed03c5b97e75 100644
--- a/mlir/unittests/Analysis/Presburger/Utils.h
+++ b/mlir/unittests/Analysis/Presburger/Utils.h
@@ -15,8 +15,10 @@
#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h"
#include "mlir/Analysis/Presburger/IntegerRelation.h"
+#include "mlir/Analysis/Presburger/PWMAFunction.h"
#include "mlir/Analysis/Presburger/PresburgerRelation.h"
#include "mlir/IR/MLIRContext.h"
+#include "mlir/Support/LLVM.h"
#include <gtest/gtest.h>
@@ -33,6 +35,51 @@ inline IntegerPolyhedron parsePoly(StringRef str) {
return *poly;
}
+/// Parse a list of StringRefs to IntegerRelation and combine them into a
+/// PresburgerSet be using the union operation. It is expected that the strings
+/// are all valid IntegerSet representation and that all of them have the same
+/// number of dimensions as is specified by the numDims argument.
+inline PresburgerSet
+parsePresburgerSetFromPolyStrings(unsigned numDims, ArrayRef<StringRef> strs) {
+ PresburgerSet set = PresburgerSet::getEmpty(numDims);
+ for (StringRef str : strs)
+ set.unionInPlace(parsePoly(str));
+ return set;
+}
+
+inline Matrix makeMatrix(unsigned numRow, unsigned numColumns,
+ ArrayRef<SmallVector<int64_t, 8>> matrix) {
+ Matrix results(numRow, numColumns);
+ assert(matrix.size() == numRow);
+ for (unsigned i = 0; i < numRow; ++i) {
+ assert(matrix[i].size() == numColumns &&
+ "Output expression has incorrect dimensionality!");
+ for (unsigned j = 0; j < numColumns; ++j)
+ results(i, j) = matrix[i][j];
+ }
+ return results;
+}
+
+/// Construct a PWMAFunction given the dimensionalities and an array describing
+/// the list of pieces. Each piece is given by a string describing the domain
+/// and a 2D array that represents the output.
+inline PWMAFunction parsePWMAF(
+ unsigned numInputs, unsigned numOutputs,
+ ArrayRef<std::pair<StringRef, SmallVector<SmallVector<int64_t, 8>, 8>>>
+ data,
+ unsigned numSymbols = 0) {
+ static MLIRContext context;
+
+ PWMAFunction result(numInputs - numSymbols, numSymbols, numOutputs);
+ for (const auto &pair : data) {
+ IntegerPolyhedron domain = parsePoly(pair.first);
+
+ result.addPiece(
+ domain, makeMatrix(numOutputs, domain.getNumIds() + 1, pair.second));
+ }
+ return result;
+}
+
/// lhs and rhs represent non-negative integers or positive infinity. The
/// infinity case corresponds to when the Optional is empty.
inline bool infinityOrUInt64LE(Optional<uint64_t> lhs, Optional<uint64_t> rhs) {
More information about the Mlir-commits
mailing list