[Mlir-commits] [mlir] 6472546 - [MLIR][Presburger] factor out duplicated function `parsePoly` into a Utils.h

Arjun P llvmlistbot at llvm.org
Tue Feb 8 05:35:15 PST 2022


Author: Arjun P
Date: 2022-02-09T00:35:43+05:30
New Revision: 6472546fb72fecc57ee5c4d6094bf5e30e687340

URL: https://github.com/llvm/llvm-project/commit/6472546fb72fecc57ee5c4d6094bf5e30e687340
DIFF: https://github.com/llvm/llvm-project/commit/6472546fb72fecc57ee5c4d6094bf5e30e687340.diff

LOG: [MLIR][Presburger] factor out duplicated function `parsePoly` into a Utils.h

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119194

Added: 
    mlir/unittests/Analysis/Presburger/Utils.h

Modified: 
    mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
    mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
    mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
    mlir/unittests/Analysis/Presburger/SimplexTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp
index ccb8f3ea043d1..8fa00131f255b 100644
--- 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 <gmock/gmock.h>
@@ -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}}, {});

diff  --git a/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp
index 614f19cc58b0e..0a1744db838ac 100644
--- 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 <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -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<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);

diff  --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp
index 2a75a5c84cbe0..c4f4f758376ae 100644
--- 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 <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

diff  --git a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp
index 0791ebeba564c..62f600baf071e 100644
--- 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 <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -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);

diff  --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h
new file mode 100644
index 0000000000000..3578575cfa62e
--- /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 <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


        


More information about the Mlir-commits mailing list