1 //===- FlattenTest.cpp ----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "polly/FlattenAlgo.h"
10 #include "polly/Support/GICHelper.h"
11 #include "gtest/gtest.h"
12 #include "isl/union_map.h"
15 using namespace polly
;
19 /// Flatten a schedule and compare to the expected result.
21 /// @param ScheduleStr The schedule to flatten as string.
22 /// @param ExpectedStr The expected result as string.
24 /// @result Whether the flattened schedule is the same as the expected schedule.
25 bool checkFlatten(const char *ScheduleStr
, const char *ExpectedStr
) {
26 auto *Ctx
= isl_ctx_alloc();
30 auto Schedule
= isl::union_map(Ctx
, ScheduleStr
);
31 auto Expected
= isl::union_map(Ctx
, ExpectedStr
);
33 auto Result
= flattenSchedule(std::move(Schedule
));
34 Success
= Result
.is_equal(Expected
);
41 TEST(Flatten
, FlattenTrivial
) {
42 EXPECT_TRUE(checkFlatten("{ A[] -> [0] }", "{ A[] -> [0] }"));
43 EXPECT_TRUE(checkFlatten("{ A[i] -> [i, 0] : 0 <= i < 10 }",
44 "{ A[i] -> [i] : 0 <= i < 10 }"));
45 EXPECT_TRUE(checkFlatten("{ A[i] -> [0, i] : 0 <= i < 10 }",
46 "{ A[i] -> [i] : 0 <= i < 10 }"));
49 TEST(Flatten
, FlattenSequence
) {
50 EXPECT_TRUE(checkFlatten(
51 "[n] -> { A[i] -> [0, i] : 0 <= i < n; B[i] -> [1, i] : 0 <= i < n }",
52 "[n] -> { A[i] -> [i] : 0 <= i < n; B[i] -> [n + i] : 0 <= i < n }"));
54 EXPECT_TRUE(checkFlatten(
55 "{ A[i] -> [0, i] : 0 <= i < 10; B[i] -> [1, i] : 0 <= i < 10 }",
56 "{ A[i] -> [i] : 0 <= i < 10; B[i] -> [10 + i] : 0 <= i < 10 }"));
59 TEST(Flatten
, FlattenLoop
) {
60 EXPECT_TRUE(checkFlatten(
61 "[n] -> { A[i] -> [i, 0] : 0 <= i < n; B[i] -> [i, 1] : 0 <= i < n }",
62 "[n] -> { A[i] -> [2i] : 0 <= i < n; B[i] -> [2i + 1] : 0 <= i < n }"));
64 EXPECT_TRUE(checkFlatten(
65 "{ A[i] -> [i, 0] : 0 <= i < 10; B[i] -> [i, 1] : 0 <= i < 10 }",
66 "{ A[i] -> [2i] : 0 <= i < 10; B[i] -> [2i + 1] : 0 <= i < 10 }"));
68 } // anonymous namespace