[Mlir-commits] [mlir] bd0dc35 - [MLIR][Presburger] Shift GeneratingFunction.h to includes (#77114)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Jan 6 03:38:29 PST 2024


Author: Abhinav271828
Date: 2024-01-06T17:08:25+05:30
New Revision: bd0dc357af453f03770c5d43c66ee5a3584abdca

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

LOG: [MLIR][Presburger] Shift GeneratingFunction.h to includes (#77114)

We shift the GeneratingFunction.h header file to the include/ directory
and wrap it in a `detail` namespace.

Added: 
    mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
    mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp

Modified: 
    mlir/unittests/Analysis/Presburger/CMakeLists.txt
    mlir/unittests/Analysis/Presburger/Utils.h

Removed: 
    mlir/lib/Analysis/Presburger/GeneratingFunction.h


################################################################################
diff  --git a/mlir/lib/Analysis/Presburger/GeneratingFunction.h b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
similarity index 96%
rename from mlir/lib/Analysis/Presburger/GeneratingFunction.h
rename to mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
index f7deba921ea51e..4dd692c251563b 100644
--- a/mlir/lib/Analysis/Presburger/GeneratingFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
@@ -19,6 +19,7 @@
 
 namespace mlir {
 namespace presburger {
+namespace detail {
 
 // A parametric point is a vector, each of whose elements
 // is an affine function of n parameters. Each row
@@ -83,7 +84,8 @@ class GeneratingFunction {
     std::vector<std::vector<Point>> sumDenominators = denominators;
     sumDenominators.insert(sumDenominators.end(), gf.denominators.begin(),
                            gf.denominators.end());
-    return GeneratingFunction(0, sumSigns, sumNumerators, sumDenominators);
+    return GeneratingFunction(numParam, sumSigns, sumNumerators,
+                              sumDenominators);
   }
 
   llvm::raw_ostream &print(llvm::raw_ostream &os) const {
@@ -128,6 +130,7 @@ class GeneratingFunction {
   std::vector<std::vector<Point>> denominators;
 };
 
+} // namespace detail
 } // namespace presburger
 } // namespace mlir
 

diff  --git a/mlir/unittests/Analysis/Presburger/CMakeLists.txt b/mlir/unittests/Analysis/Presburger/CMakeLists.txt
index e37133354e53ca..54a841726cd11f 100644
--- a/mlir/unittests/Analysis/Presburger/CMakeLists.txt
+++ b/mlir/unittests/Analysis/Presburger/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_mlir_unittest(MLIRPresburgerTests
   FractionTest.cpp
+  GeneratingFunctionTest.cpp
   IntegerPolyhedronTest.cpp
   IntegerRelationTest.cpp
   LinearTransformTest.cpp

diff  --git a/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
new file mode 100644
index 00000000000000..5df1a5a0f64c05
--- /dev/null
+++ b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
@@ -0,0 +1,39 @@
+//===- MatrixTest.cpp - Tests for QuasiPolynomial -------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Analysis/Presburger/GeneratingFunction.h"
+#include "./Utils.h"
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace mlir;
+using namespace presburger;
+using namespace mlir::presburger::detail;
+
+TEST(GeneratingFunctionTest, sum) {
+  GeneratingFunction gf1(2, {1, -1},
+                         {makeFracMatrix(2, 3, {{1, 2, 5}, {7, 2, 6}}),
+                          makeFracMatrix(2, 3, {{5, 2, 5}, {3, 7, 2}})},
+                         {{{3, 6}, {7, 2}}, {{2, 8}, {6, 3}}});
+  GeneratingFunction gf2(2, {1, 1},
+                         {makeFracMatrix(2, 3, {{6, 2, 1}, {4, 2, 6}}),
+                          makeFracMatrix(2, 3, {{3, 2, 6}, {9, 2, 5}})},
+                         {{{3, 7}, {5, 1}}, {{5, 2}, {6, 2}}});
+
+  GeneratingFunction sum = gf1 + gf2;
+  EXPECT_EQ_REPR_GENERATINGFUNCTION(
+      sum, GeneratingFunction(2, {1, -1, 1, 1},
+                              {makeFracMatrix(2, 3, {{1, 2, 5}, {7, 2, 6}}),
+                               makeFracMatrix(2, 3, {{5, 2, 5}, {3, 7, 2}}),
+                               makeFracMatrix(2, 3, {{6, 2, 1}, {4, 2, 6}}),
+                               makeFracMatrix(2, 3, {{3, 2, 6}, {9, 2, 5}})},
+                              {{{3, 6}, {7, 2}},
+                               {{2, 8}, {6, 3}},
+                               {{3, 7}, {5, 1}},
+                               {{5, 2}, {6, 2}}}));
+}

diff  --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h
index 2a9966c7ce2ea5..6b00898a7e2749 100644
--- a/mlir/unittests/Analysis/Presburger/Utils.h
+++ b/mlir/unittests/Analysis/Presburger/Utils.h
@@ -13,6 +13,7 @@
 #ifndef MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H
 #define MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H
 
+#include "mlir/Analysis/Presburger/GeneratingFunction.h"
 #include "mlir/Analysis/Presburger/IntegerRelation.h"
 #include "mlir/Analysis/Presburger/Matrix.h"
 #include "mlir/Analysis/Presburger/PWMAFunction.h"
@@ -72,9 +73,42 @@ inline void EXPECT_EQ_FRAC_MATRIX(FracMatrix a, FracMatrix b) {
       EXPECT_EQ(a(row, col), b(row, col));
 }
 
+// Check the coefficients (in order) of two generating functions.
+// Note that this is not a true equality check.
+inline void EXPECT_EQ_REPR_GENERATINGFUNCTION(detail::GeneratingFunction a,
+                                              detail::GeneratingFunction b) {
+  EXPECT_EQ(a.getNumParams(), b.getNumParams());
+
+  SmallVector<int> aSigns = a.getSigns();
+  SmallVector<int> bSigns = b.getSigns();
+  EXPECT_EQ(aSigns.size(), bSigns.size());
+  for (unsigned i = 0, e = aSigns.size(); i < e; i++)
+    EXPECT_EQ(aSigns[i], bSigns[i]);
+
+  std::vector<detail::ParamPoint> aNums = a.getNumerators();
+  std::vector<detail::ParamPoint> bNums = b.getNumerators();
+  EXPECT_EQ(aNums.size(), bNums.size());
+  for (unsigned i = 0, e = aNums.size(); i < e; i++)
+    EXPECT_EQ_FRAC_MATRIX(aNums[i], bNums[i]);
+
+  std::vector<std::vector<detail::Point>> aDens = a.getDenominators();
+  std::vector<std::vector<detail::Point>> bDens = b.getDenominators();
+  EXPECT_EQ(aDens.size(), bDens.size());
+  for (unsigned i = 0, e = aDens.size(); i < e; i++) {
+    EXPECT_EQ(aDens[i].size(), bDens[i].size());
+    for (unsigned j = 0, f = aDens[i].size(); j < f; j++) {
+      EXPECT_EQ(aDens[i][j].size(), bDens[i][j].size());
+      for (unsigned k = 0, g = aDens[i][j].size(); k < g; k++) {
+        EXPECT_EQ(aDens[i][j][k], bDens[i][j][k]);
+      }
+    }
+  }
+}
+
 // Check the coefficients (in order) of two quasipolynomials.
 // Note that this is not a true equality check.
-inline void EXPECT_EQ_REPR_QUASIPOLYNOMIAL(QuasiPolynomial a, QuasiPolynomial b) {
+inline void EXPECT_EQ_REPR_QUASIPOLYNOMIAL(QuasiPolynomial a,
+                                           QuasiPolynomial b) {
   EXPECT_EQ(a.getNumInputs(), b.getNumInputs());
 
   SmallVector<Fraction> aCoeffs = a.getCoefficients(),


        


More information about the Mlir-commits mailing list