[Mlir-commits] [mlir] [MLIR][Presburger] Shift GeneratingFunction.h to includes (PR #77114)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jan 6 02:45:23 PST 2024
https://github.com/Abhinav271828 updated https://github.com/llvm/llvm-project/pull/77114
>From 8fe3212272ed113eebeac99a35f8a3f9a97f2d3f Mon Sep 17 00:00:00 2001
From: Abhinav271828 <abhinav.m at research.iiit.ac.in>
Date: Fri, 5 Jan 2024 21:55:19 +0530
Subject: [PATCH 1/5] Shift GF and make namespace
---
.../mlir}/Analysis/Presburger/GeneratingFunction.h | 2 ++
1 file changed, 2 insertions(+)
rename mlir/{lib => include/mlir}/Analysis/Presburger/GeneratingFunction.h (99%)
diff --git a/mlir/lib/Analysis/Presburger/GeneratingFunction.h b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
similarity index 99%
rename from mlir/lib/Analysis/Presburger/GeneratingFunction.h
rename to mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
index f7deba921ea51e..318f1a6429a6c0 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
@@ -128,6 +129,7 @@ class GeneratingFunction {
std::vector<std::vector<Point>> denominators;
};
+} // namespace detail
} // namespace presburger
} // namespace mlir
>From f28ec4a9ac4035e8a784f393ce92a84e3616b1a8 Mon Sep 17 00:00:00 2001
From: Abhinav271828 <abhinav.m at research.iiit.ac.in>
Date: Sat, 6 Jan 2024 16:04:20 +0530
Subject: [PATCH 2/5] Add GF test
---
.../Analysis/Presburger/GeneratingFunction.h | 2 +-
.../Analysis/Presburger/CMakeLists.txt | 1 +
.../Presburger/GeneratingFunctionTest.cpp | 30 +++++++++++++++++
mlir/unittests/Analysis/Presburger/Utils.h | 32 +++++++++++++++++++
4 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
diff --git a/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
index 318f1a6429a6c0..0ef095dc80e604 100644
--- a/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
@@ -84,7 +84,7 @@ 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 {
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..bb3345db6240a0
--- /dev/null
+++ b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
@@ -0,0 +1,30 @@
+//===- 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}}}));
+}
\ No newline at end of file
diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h
index 2a9966c7ce2ea5..38c44aec4047f0 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,6 +73,37 @@ 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) {
>From 364ca80e2988abd3b521bb7886a17b0088dce8f7 Mon Sep 17 00:00:00 2001
From: Abhinav271828 <abhinav.m at research.iiit.ac.in>
Date: Sat, 6 Jan 2024 16:05:25 +0530
Subject: [PATCH 3/5] Formatting
---
.../Presburger/GeneratingFunctionTest.cpp | 21 +++++++++++++------
mlir/unittests/Analysis/Presburger/Utils.h | 6 ++++--
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
index bb3345db6240a0..c2701a441efd04 100644
--- a/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
@@ -17,14 +17,23 @@ 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}})},
+ {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}})},
+ {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}}}));
+ 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}}}));
}
\ No newline at end of file
diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h
index 38c44aec4047f0..6b00898a7e2749 100644
--- a/mlir/unittests/Analysis/Presburger/Utils.h
+++ b/mlir/unittests/Analysis/Presburger/Utils.h
@@ -75,7 +75,8 @@ inline void EXPECT_EQ_FRAC_MATRIX(FracMatrix a, FracMatrix b) {
// 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) {
+inline void EXPECT_EQ_REPR_GENERATINGFUNCTION(detail::GeneratingFunction a,
+ detail::GeneratingFunction b) {
EXPECT_EQ(a.getNumParams(), b.getNumParams());
SmallVector<int> aSigns = a.getSigns();
@@ -106,7 +107,8 @@ inline void EXPECT_EQ_REPR_GENERATINGFUNCTION(detail::GeneratingFunction a, deta
// 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(),
>From bfda840eaca761f091b42027203d3cacdc6a4e90 Mon Sep 17 00:00:00 2001
From: Abhinav271828 <abhinav.m at research.iiit.ac.in>
Date: Sat, 6 Jan 2024 16:08:16 +0530
Subject: [PATCH 4/5] Formatting
---
mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
index 0ef095dc80e604..4dd692c251563b 100644
--- a/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
@@ -84,7 +84,8 @@ class GeneratingFunction {
std::vector<std::vector<Point>> sumDenominators = denominators;
sumDenominators.insert(sumDenominators.end(), gf.denominators.begin(),
gf.denominators.end());
- return GeneratingFunction(numParam, sumSigns, sumNumerators, sumDenominators);
+ return GeneratingFunction(numParam, sumSigns, sumNumerators,
+ sumDenominators);
}
llvm::raw_ostream &print(llvm::raw_ostream &os) const {
>From dad5d41652fbfccaf6da6d41981bf0fe7307d69b Mon Sep 17 00:00:00 2001
From: Abhinav271828 <abhinav.m at research.iiit.ac.in>
Date: Sat, 6 Jan 2024 16:15:08 +0530
Subject: [PATCH 5/5] Newline
---
mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
index c2701a441efd04..5df1a5a0f64c05 100644
--- a/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
@@ -36,4 +36,4 @@ TEST(GeneratingFunctionTest, sum) {
{{2, 8}, {6, 3}},
{{3, 7}, {5, 1}},
{{5, 2}, {6, 2}}}));
-}
\ No newline at end of file
+}
More information about the Mlir-commits
mailing list