summaryrefslogtreecommitdiffstats
path: root/polly/unittests
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2018-03-10 18:07:03 +0000
committerTobias Grosser <tobias@grosser.es>2018-03-10 18:07:03 +0000
commita1da86b2242682dacd337705e66f3095de98cf1b (patch)
tree7e2bb33f596d8799e7b21cfa875b0c57bff4144d /polly/unittests
parent7948738673607fa28c9604c278a61e0eedc71872 (diff)
downloadbcm5719-llvm-a1da86b2242682dacd337705e66f3095de98cf1b.tar.gz
bcm5719-llvm-a1da86b2242682dacd337705e66f3095de98cf1b.zip
Add isl operator overloads for isl::pw_aff
Piecewise affine expressions have directly corresponding mathematical operators. Introduce these operators as overloads as this makes writing code with isl::pw_aff expressions more directly readable. We can now write: A = B + C instead of A = B.add(C) llvm-svn: 327216
Diffstat (limited to 'polly/unittests')
-rw-r--r--polly/unittests/Isl/IslTest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/polly/unittests/Isl/IslTest.cpp b/polly/unittests/Isl/IslTest.cpp
index b1e6fc85c35..acafe350352 100644
--- a/polly/unittests/Isl/IslTest.cpp
+++ b/polly/unittests/Isl/IslTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "polly/Support/GICHelper.h"
+#include "polly/Support/ISLOperators.h"
#include "polly/Support/ISLTools.h"
#include "gtest/gtest.h"
#include "isl/stream.h"
@@ -74,6 +75,10 @@ static bool operator==(const isl::union_map &LHS, const isl::union_map &RHS) {
static bool operator==(const isl::val &LHS, const isl::val &RHS) {
return bool(LHS.eq(RHS));
}
+
+static bool operator==(const isl::pw_aff &LHS, const isl::pw_aff &RHS) {
+ return bool(LHS.is_equal(RHS));
+}
} // namespace noexceptions
} // namespace isl
@@ -281,6 +286,70 @@ TEST(Isl, IslValToAPInt) {
isl_ctx_free(IslCtx);
}
+TEST(Isl, Operators) {
+ isl_ctx *IslCtx = isl_ctx_alloc();
+
+ isl::val ValOne = isl::val(IslCtx, 1);
+ isl::val ValTwo = isl::val(IslCtx, 2);
+ isl::val ValThree = isl::val(IslCtx, 3);
+ isl::val ValFour = isl::val(IslCtx, 4);
+
+ isl::space Space = isl::space(IslCtx, 0, 0);
+ isl::local_space LS = isl::local_space(Space);
+
+ isl::pw_aff AffOne = isl::aff(LS, ValOne);
+ isl::pw_aff AffTwo = isl::aff(LS, ValTwo);
+ isl::pw_aff AffThree = isl::aff(LS, ValThree);
+ isl::pw_aff AffFour = isl::aff(LS, ValFour);
+
+ // Addition
+ {
+ EXPECT_EQ(AffOne + AffOne, AffTwo);
+ EXPECT_EQ(AffOne + 1, AffTwo);
+ EXPECT_EQ(1 + AffOne, AffTwo);
+ EXPECT_EQ(AffOne + ValOne, AffTwo);
+ EXPECT_EQ(ValOne + AffOne, AffTwo);
+ }
+
+ // Multiplication
+ {
+ EXPECT_EQ(AffTwo * AffTwo, AffFour);
+ EXPECT_EQ(AffTwo * 2, AffFour);
+ EXPECT_EQ(2 * AffTwo, AffFour);
+ EXPECT_EQ(AffTwo * ValTwo, AffFour);
+ EXPECT_EQ(ValTwo * AffTwo, AffFour);
+ }
+
+ // Subtraction
+ {
+ EXPECT_EQ(AffTwo - AffOne, AffOne);
+ EXPECT_EQ(AffTwo - 1, AffOne);
+ EXPECT_EQ(2 - AffOne, AffOne);
+ EXPECT_EQ(AffTwo - ValOne, AffOne);
+ EXPECT_EQ(ValTwo - AffOne, AffOne);
+ }
+
+ // Division
+ {
+ EXPECT_EQ(AffFour - AffTwo, AffTwo);
+ EXPECT_EQ(AffFour - 2, AffTwo);
+ EXPECT_EQ(4 - AffTwo, AffTwo);
+ EXPECT_EQ(AffFour / ValTwo, AffTwo);
+ EXPECT_EQ(AffFour / 2, AffTwo);
+ }
+
+ // Remainder
+ {
+ EXPECT_EQ(AffThree % AffTwo, AffOne);
+ EXPECT_EQ(AffThree % 2, AffOne);
+ EXPECT_EQ(3 % AffTwo, AffOne);
+ EXPECT_EQ(AffThree % ValTwo, AffOne);
+ EXPECT_EQ(ValThree % AffTwo, AffOne);
+ }
+
+ isl_ctx_free(IslCtx);
+}
+
TEST(Isl, Foreach) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
OpenPOWER on IntegriCloud