Skip to content

Commit

Permalink
[MLIR][Presburger] factor out duplicated function parsePoly into a …
Browse files Browse the repository at this point in the history
…Utils.h

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119194
  • Loading branch information
Superty committed Feb 8, 2022
1 parent 1468202 commit 6472546
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
13 changes: 1 addition & 12 deletions mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gmock/gmock.h>
Expand Down Expand Up @@ -98,17 +98,6 @@ static void checkPermutationsSample(bool hasSample, unsigned nDim,
} 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<IntegerPolyhedron> 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}}, {});
Expand Down
13 changes: 3 additions & 10 deletions mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,18 @@
//
//===----------------------------------------------------------------------===//

#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 <gmock/gmock.h>
#include <gtest/gtest.h>

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<IntegerPolyhedron> poly = parseIntegerSetToFAC(str, context);
EXPECT_TRUE(succeeded(poly));
return *poly;
}

static Matrix makeMatrix(unsigned numRow, unsigned numColumns,
ArrayRef<SmallVector<int64_t, 8>> matrix) {
Matrix results(numRow, numColumns);
Expand Down
14 changes: 2 additions & 12 deletions mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gmock/gmock.h>
#include <gtest/gtest.h>

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<IntegerPolyhedron> 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
Expand Down
14 changes: 3 additions & 11 deletions mlir/unittests/Analysis/Presburger/SimplexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gmock/gmock.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -476,18 +478,8 @@ TEST(SimplexTest, isRedundantEquality) {
EXPECT_TRUE(simplex.isRedundantEquality({-1, 0, 2})); // x = 2.
}

static IntegerPolyhedron parsePoly(StringRef str, MLIRContext *context) {
FailureOr<IntegerPolyhedron> 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);
Expand Down
32 changes: 32 additions & 0 deletions mlir/unittests/Analysis/Presburger/Utils.h
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

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<IntegerPolyhedron> poly = parseIntegerSetToFAC(str, context);
EXPECT_TRUE(succeeded(poly));
return *poly;
}
} // namespace mlir

#endif // MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H

0 comments on commit 6472546

Please sign in to comment.