diff --git a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp index 02546816e52d..b8469a8c0174 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> 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, 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 different 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 ed55abbc706a..7278a5ec56e4 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 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 ef099b7add10..4ed03c5b97e7 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 @@ -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 strs) { + PresburgerSet set = PresburgerSet::getEmpty(numDims); + for (StringRef str : strs) + set.unionInPlace(parsePoly(str)); + return set; +} + +inline Matrix makeMatrix(unsigned numRow, unsigned numColumns, + ArrayRef> 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, 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 lhs, Optional rhs) {