[flang] Fix length handling in character kind implicit conversion (#74586)
[llvm-project.git] / polly / unittests / Flatten / FlattenTest.cpp
blob6668403193996fce8773c37304d23a27f33fd84e
1 //===- FlattenTest.cpp ----------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "polly/FlattenAlgo.h"
10 #include "polly/Support/GICHelper.h"
11 #include "gtest/gtest.h"
12 #include "isl/union_map.h"
14 using namespace llvm;
15 using namespace polly;
17 namespace {
19 /// Flatten a schedule and compare to the expected result.
20 ///
21 /// @param ScheduleStr The schedule to flatten as string.
22 /// @param ExpectedStr The expected result as string.
23 ///
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();
27 bool Success;
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);
37 isl_ctx_free(Ctx);
38 return Success;
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