diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp --- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/Presburger/IntegerPolyhedron.h" -#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h" +#include "./Utils.h" #include "mlir/IR/MLIRContext.h" #include @@ -98,17 +98,6 @@ } while (std::next_permutation(perm.begin(), perm.end())); } -/// Parses a IntegerPolyhedron from a StringRef. It is expected that the -/// string represents a valid IntegerSet, otherwise it will violate a gtest -/// assertion. -static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) { - FailureOr poly = parseIntegerSetToFAC(str, context); - - EXPECT_TRUE(succeeded(poly)); - - return *poly; -} - TEST(IntegerPolyhedronTest, removeInequality) { IntegerPolyhedron set = makeSetFromConstraints(1, {{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}}, {}); diff --git a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp --- a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp @@ -10,9 +10,11 @@ // //===----------------------------------------------------------------------===// +#include "./Utils.h" + #include "mlir/Analysis/Presburger/PWMAFunction.h" -#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h" #include "mlir/Analysis/Presburger/PresburgerSet.h" +#include "mlir/IR/MLIRContext.h" #include #include @@ -20,15 +22,6 @@ namespace mlir { using testing::ElementsAre; -/// Parses an IntegerPolyhedron from a StringRef. It is expected that the -/// string represents a valid IntegerSet, otherwise it will violate a gtest -/// assertion. -static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) { - FailureOr poly = parseIntegerSetToFAC(str, context); - EXPECT_TRUE(succeeded(poly)); - return *poly; -} - static Matrix makeMatrix(unsigned numRow, unsigned numColumns, ArrayRef> matrix) { Matrix results(numRow, numColumns); diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp --- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp @@ -15,24 +15,14 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/Presburger/PresburgerSet.h" -#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h" +#include "./Utils.h" +#include "mlir/IR/MLIRContext.h" #include #include namespace mlir { -/// Parses an IntegerPolyhedron from a StringRef. It is expected that the -/// string represents a valid IntegerSet, otherwise it will violate a gtest -/// assertion. -static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) { - FailureOr poly = parseIntegerSetToFAC(str, context); - - EXPECT_TRUE(succeeded(poly)); - - return *poly; -} - /// 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 diff --git a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp --- a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp +++ b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp @@ -6,8 +6,10 @@ // //===----------------------------------------------------------------------===// +#include "./Utils.h" + #include "mlir/Analysis/Presburger/Simplex.h" -#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h" +#include "mlir/IR/MLIRContext.h" #include #include @@ -476,18 +478,8 @@ EXPECT_TRUE(simplex.isRedundantEquality({-1, 0, 2})); // x = 2. } -static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) { - FailureOr poly = parseIntegerSetToFAC(str, context); - - EXPECT_TRUE(succeeded(poly)); - - return *poly; -} - TEST(SimplexTest, IsRationalSubsetOf) { - MLIRContext context; - IntegerPolyhedron univ = parsePoly("(x) : ()", &context); IntegerPolyhedron empty = parsePoly("(x) : (x + 0 >= 0, -x - 1 >= 0)", &context); diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h new file mode 100644 --- /dev/null +++ b/mlir/unittests/Analysis/Presburger/Utils.h @@ -0,0 +1,32 @@ +//===- Utils.h - Utils for Presburger Tests ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines helper functions for Presburger unittests. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H +#define MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H + +#include "../../Dialect/Affine/Analysis/AffineStructuresParser.h" +#include "mlir/IR/MLIRContext.h" + +#include + +namespace mlir { +/// Parses a IntegerPolyhedron from a StringRef. It is expected that the +/// string represents a valid IntegerSet, otherwise it will violate a gtest +/// assertion. +static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) { + FailureOr poly = parseIntegerSetToFAC(str, context); + EXPECT_TRUE(succeeded(poly)); + return *poly; +} +} // namespace mlir + +#endif // MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H