Skip to content

Commit bd0dc35

Browse files
[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.
1 parent 0abf3a9 commit bd0dc35

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

mlir/lib/Analysis/Presburger/GeneratingFunction.h renamed to mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
namespace mlir {
2121
namespace presburger {
22+
namespace detail {
2223

2324
// A parametric point is a vector, each of whose elements
2425
// is an affine function of n parameters. Each row
@@ -83,7 +84,8 @@ class GeneratingFunction {
8384
std::vector<std::vector<Point>> sumDenominators = denominators;
8485
sumDenominators.insert(sumDenominators.end(), gf.denominators.begin(),
8586
gf.denominators.end());
86-
return GeneratingFunction(0, sumSigns, sumNumerators, sumDenominators);
87+
return GeneratingFunction(numParam, sumSigns, sumNumerators,
88+
sumDenominators);
8789
}
8890

8991
llvm::raw_ostream &print(llvm::raw_ostream &os) const {
@@ -128,6 +130,7 @@ class GeneratingFunction {
128130
std::vector<std::vector<Point>> denominators;
129131
};
130132

133+
} // namespace detail
131134
} // namespace presburger
132135
} // namespace mlir
133136

mlir/unittests/Analysis/Presburger/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_mlir_unittest(MLIRPresburgerTests
22
FractionTest.cpp
3+
GeneratingFunctionTest.cpp
34
IntegerPolyhedronTest.cpp
45
IntegerRelationTest.cpp
56
LinearTransformTest.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===- MatrixTest.cpp - Tests for QuasiPolynomial -------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir/Analysis/Presburger/GeneratingFunction.h"
10+
#include "./Utils.h"
11+
#include <gmock/gmock.h>
12+
#include <gtest/gtest.h>
13+
14+
using namespace mlir;
15+
using namespace presburger;
16+
using namespace mlir::presburger::detail;
17+
18+
TEST(GeneratingFunctionTest, sum) {
19+
GeneratingFunction gf1(2, {1, -1},
20+
{makeFracMatrix(2, 3, {{1, 2, 5}, {7, 2, 6}}),
21+
makeFracMatrix(2, 3, {{5, 2, 5}, {3, 7, 2}})},
22+
{{{3, 6}, {7, 2}}, {{2, 8}, {6, 3}}});
23+
GeneratingFunction gf2(2, {1, 1},
24+
{makeFracMatrix(2, 3, {{6, 2, 1}, {4, 2, 6}}),
25+
makeFracMatrix(2, 3, {{3, 2, 6}, {9, 2, 5}})},
26+
{{{3, 7}, {5, 1}}, {{5, 2}, {6, 2}}});
27+
28+
GeneratingFunction sum = gf1 + gf2;
29+
EXPECT_EQ_REPR_GENERATINGFUNCTION(
30+
sum, GeneratingFunction(2, {1, -1, 1, 1},
31+
{makeFracMatrix(2, 3, {{1, 2, 5}, {7, 2, 6}}),
32+
makeFracMatrix(2, 3, {{5, 2, 5}, {3, 7, 2}}),
33+
makeFracMatrix(2, 3, {{6, 2, 1}, {4, 2, 6}}),
34+
makeFracMatrix(2, 3, {{3, 2, 6}, {9, 2, 5}})},
35+
{{{3, 6}, {7, 2}},
36+
{{2, 8}, {6, 3}},
37+
{{3, 7}, {5, 1}},
38+
{{5, 2}, {6, 2}}}));
39+
}

mlir/unittests/Analysis/Presburger/Utils.h

+35-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H
1414
#define MLIR_UNITTESTS_ANALYSIS_PRESBURGER_UTILS_H
1515

16+
#include "mlir/Analysis/Presburger/GeneratingFunction.h"
1617
#include "mlir/Analysis/Presburger/IntegerRelation.h"
1718
#include "mlir/Analysis/Presburger/Matrix.h"
1819
#include "mlir/Analysis/Presburger/PWMAFunction.h"
@@ -72,9 +73,42 @@ inline void EXPECT_EQ_FRAC_MATRIX(FracMatrix a, FracMatrix b) {
7273
EXPECT_EQ(a(row, col), b(row, col));
7374
}
7475

76+
// Check the coefficients (in order) of two generating functions.
77+
// Note that this is not a true equality check.
78+
inline void EXPECT_EQ_REPR_GENERATINGFUNCTION(detail::GeneratingFunction a,
79+
detail::GeneratingFunction b) {
80+
EXPECT_EQ(a.getNumParams(), b.getNumParams());
81+
82+
SmallVector<int> aSigns = a.getSigns();
83+
SmallVector<int> bSigns = b.getSigns();
84+
EXPECT_EQ(aSigns.size(), bSigns.size());
85+
for (unsigned i = 0, e = aSigns.size(); i < e; i++)
86+
EXPECT_EQ(aSigns[i], bSigns[i]);
87+
88+
std::vector<detail::ParamPoint> aNums = a.getNumerators();
89+
std::vector<detail::ParamPoint> bNums = b.getNumerators();
90+
EXPECT_EQ(aNums.size(), bNums.size());
91+
for (unsigned i = 0, e = aNums.size(); i < e; i++)
92+
EXPECT_EQ_FRAC_MATRIX(aNums[i], bNums[i]);
93+
94+
std::vector<std::vector<detail::Point>> aDens = a.getDenominators();
95+
std::vector<std::vector<detail::Point>> bDens = b.getDenominators();
96+
EXPECT_EQ(aDens.size(), bDens.size());
97+
for (unsigned i = 0, e = aDens.size(); i < e; i++) {
98+
EXPECT_EQ(aDens[i].size(), bDens[i].size());
99+
for (unsigned j = 0, f = aDens[i].size(); j < f; j++) {
100+
EXPECT_EQ(aDens[i][j].size(), bDens[i][j].size());
101+
for (unsigned k = 0, g = aDens[i][j].size(); k < g; k++) {
102+
EXPECT_EQ(aDens[i][j][k], bDens[i][j][k]);
103+
}
104+
}
105+
}
106+
}
107+
75108
// Check the coefficients (in order) of two quasipolynomials.
76109
// Note that this is not a true equality check.
77-
inline void EXPECT_EQ_REPR_QUASIPOLYNOMIAL(QuasiPolynomial a, QuasiPolynomial b) {
110+
inline void EXPECT_EQ_REPR_QUASIPOLYNOMIAL(QuasiPolynomial a,
111+
QuasiPolynomial b) {
78112
EXPECT_EQ(a.getNumInputs(), b.getNumInputs());
79113

80114
SmallVector<Fraction> aCoeffs = a.getCoefficients(),

0 commit comments

Comments
 (0)