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

source code of llvm/unittests/Frontend/OpenMPCompositionTest.cpp