Skip to content

[MLIR][Presburger] Shift GeneratingFunction.h to includes #77114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -128,6 +130,7 @@ class GeneratingFunction {
std::vector<std::vector<Point>> denominators;
};

} // namespace detail
} // namespace presburger
} // namespace mlir

Expand Down
1 change: 1 addition & 0 deletions mlir/unittests/Analysis/Presburger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_mlir_unittest(MLIRPresburgerTests
FractionTest.cpp
GeneratingFunctionTest.cpp
IntegerPolyhedronTest.cpp
IntegerRelationTest.cpp
LinearTransformTest.cpp
Expand Down
39 changes: 39 additions & 0 deletions mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp
Original file line number Diff line number Diff line change
@@ -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}}}));
}
36 changes: 35 additions & 1 deletion mlir/unittests/Analysis/Presburger/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down