| 1 |
//===- llvm/unittests/Frontend/OpenMPCompositionTest.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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "llvm/ADT/ArrayRef.h" |
| 10 |
#include "llvm/ADT/SmallVector.h" |
| 11 |
#include "llvm/Frontend/OpenMP/OMP.h" |
| 12 |
#include "gtest/gtest.h" |
| 13 |
|
| 14 |
using namespace llvm; |
| 15 |
using namespace llvm::omp; |
| 16 |
|
| 17 |
TEST(Composition, GetLeafConstructs) { |
| 18 |
ArrayRef<Directive> L1 = getLeafConstructs(OMPD_loop); |
| 19 |
ASSERT_EQ(L1, (ArrayRef<Directive>{})); |
| 20 |
ArrayRef<Directive> L2 = getLeafConstructs(OMPD_parallel_for); |
| 21 |
ASSERT_EQ(L2, (ArrayRef<Directive>{OMPD_parallel, OMPD_for})); |
| 22 |
ArrayRef<Directive> L3 = getLeafConstructs(OMPD_parallel_for_simd); |
| 23 |
ASSERT_EQ(L3, (ArrayRef<Directive>{OMPD_parallel, OMPD_for, OMPD_simd})); |
| 24 |
} |
| 25 |
|
| 26 |
TEST(Composition, GetLeafConstructsOrSelf) { |
| 27 |
ArrayRef<Directive> L1 = getLeafConstructsOrSelf(OMPD_loop); |
| 28 |
ASSERT_EQ(L1, (ArrayRef<Directive>{OMPD_loop})); |
| 29 |
ArrayRef<Directive> L2 = getLeafConstructsOrSelf(OMPD_parallel_for); |
| 30 |
ASSERT_EQ(L2, (ArrayRef<Directive>{OMPD_parallel, OMPD_for})); |
| 31 |
ArrayRef<Directive> L3 = getLeafConstructsOrSelf(OMPD_parallel_for_simd); |
| 32 |
ASSERT_EQ(L3, (ArrayRef<Directive>{OMPD_parallel, OMPD_for, OMPD_simd})); |
| 33 |
} |
| 34 |
|
| 35 |
TEST(Composition, GetCompoundConstruct) { |
| 36 |
Directive C1 = |
| 37 |
getCompoundConstruct({OMPD_target, OMPD_teams, OMPD_distribute}); |
| 38 |
ASSERT_EQ(C1, OMPD_target_teams_distribute); |
| 39 |
Directive C2 = getCompoundConstruct({OMPD_target}); |
| 40 |
ASSERT_EQ(C2, OMPD_target); |
| 41 |
Directive C3 = getCompoundConstruct({OMPD_target, OMPD_masked}); |
| 42 |
ASSERT_EQ(C3, OMPD_unknown); |
| 43 |
Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute}); |
| 44 |
ASSERT_EQ(C4, OMPD_target_teams_distribute); |
| 45 |
Directive C5 = getCompoundConstruct({}); |
| 46 |
ASSERT_EQ(C5, OMPD_unknown); |
| 47 |
Directive C6 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd}); |
| 48 |
ASSERT_EQ(C6, OMPD_parallel_for_simd); |
| 49 |
Directive C7 = getCompoundConstruct({OMPD_do, OMPD_simd}); |
| 50 |
ASSERT_EQ(C7, OMPD_do_simd); // Make sure it's not OMPD_end_do_simd |
| 51 |
} |
| 52 |
|
| 53 |
TEST(Composition, GetLeafOrCompositeConstructs) { |
| 54 |
SmallVector<Directive> Out1; |
| 55 |
auto Ret1 = getLeafOrCompositeConstructs( |
| 56 |
OMPD_target_teams_distribute_parallel_for, Out1); |
| 57 |
ASSERT_EQ(Ret1, ArrayRef<Directive>(Out1)); |
| 58 |
ASSERT_EQ((ArrayRef<Directive>(Out1)), |
| 59 |
(ArrayRef<Directive>{OMPD_target, OMPD_teams, |
| 60 |
OMPD_distribute_parallel_for})); |
| 61 |
|
| 62 |
SmallVector<Directive> Out2; |
| 63 |
auto Ret2 = |
| 64 |
getLeafOrCompositeConstructs(OMPD_parallel_masked_taskloop_simd, Out2); |
| 65 |
ASSERT_EQ(Ret2, ArrayRef<Directive>(Out2)); |
| 66 |
ASSERT_EQ( |
| 67 |
(ArrayRef<Directive>(Out2)), |
| 68 |
(ArrayRef<Directive>{OMPD_parallel, OMPD_masked, OMPD_taskloop_simd})); |
| 69 |
|
| 70 |
SmallVector<Directive> Out3; |
| 71 |
auto Ret3 = |
| 72 |
getLeafOrCompositeConstructs(OMPD_distribute_parallel_do_simd, Out3); |
| 73 |
ASSERT_EQ(Ret3, ArrayRef<Directive>(Out3)); |
| 74 |
ASSERT_EQ((ArrayRef<Directive>(Out3)), |
| 75 |
(ArrayRef<Directive>{OMPD_distribute_parallel_do_simd})); |
| 76 |
|
| 77 |
SmallVector<Directive> Out4; |
| 78 |
auto Ret4 = getLeafOrCompositeConstructs(OMPD_target_parallel_loop, Out4); |
| 79 |
ASSERT_EQ(Ret4, ArrayRef<Directive>(Out4)); |
| 80 |
ASSERT_EQ((ArrayRef<Directive>(Out4)), |
| 81 |
(ArrayRef<Directive>{OMPD_target, OMPD_parallel, OMPD_loop})); |
| 82 |
} |
| 83 |
|
| 84 |
TEST(Composition, IsLeafConstruct) { |
| 85 |
ASSERT_TRUE(isLeafConstruct(OMPD_loop)); |
| 86 |
ASSERT_TRUE(isLeafConstruct(OMPD_teams)); |
| 87 |
ASSERT_FALSE(isLeafConstruct(OMPD_for_simd)); |
| 88 |
ASSERT_FALSE(isLeafConstruct(OMPD_distribute_simd)); |
| 89 |
ASSERT_FALSE(isLeafConstruct(OMPD_parallel_for)); |
| 90 |
} |
| 91 |
|
| 92 |
TEST(Composition, IsCompositeConstruct) { |
| 93 |
ASSERT_TRUE(isCompositeConstruct(OMPD_distribute_simd)); |
| 94 |
ASSERT_FALSE(isCompositeConstruct(OMPD_for)); |
| 95 |
ASSERT_TRUE(isCompositeConstruct(OMPD_for_simd)); |
| 96 |
// directive-name-A = "parallel", directive-name-B = "for simd", |
| 97 |
// only directive-name-B is loop-associated, so this is not a |
| 98 |
// composite construct, even though "for simd" is. |
| 99 |
ASSERT_FALSE(isCompositeConstruct(OMPD_parallel_for_simd)); |
| 100 |
} |
| 101 |
|
| 102 |
TEST(Composition, IsCombinedConstruct) { |
| 103 |
// "parallel for simd" is a combined construct, see comment in |
| 104 |
// IsCompositeConstruct. |
| 105 |
ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for_simd)); |
| 106 |
ASSERT_FALSE(isCombinedConstruct(OMPD_for_simd)); |
| 107 |
ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for)); |
| 108 |
ASSERT_FALSE(isCombinedConstruct(OMPD_parallel)); |
| 109 |
} |