xref: /llvm-project/llvm/unittests/Frontend/OpenMPCompositionTest.cpp (revision 70d3ddb280ea47066349eed1cd99bc0348bf4186)
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/Frontend/OpenMP/OMP.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 using namespace llvm::omp;
15 
16 TEST(Composition, GetLeafConstructs) {
17   ArrayRef<Directive> L1 = getLeafConstructs(OMPD_loop);
18   ASSERT_EQ(L1, (ArrayRef<Directive>{}));
19   ArrayRef<Directive> L2 = getLeafConstructs(OMPD_parallel_for);
20   ASSERT_EQ(L2, (ArrayRef<Directive>{OMPD_parallel, OMPD_for}));
21   ArrayRef<Directive> L3 = getLeafConstructs(OMPD_parallel_for_simd);
22   ASSERT_EQ(L3, (ArrayRef<Directive>{OMPD_parallel, OMPD_for, OMPD_simd}));
23 }
24 
25 TEST(Composition, GetCompoundConstruct) {
26   Directive C1 =
27       getCompoundConstruct({OMPD_target, OMPD_teams, OMPD_distribute});
28   ASSERT_EQ(C1, OMPD_target_teams_distribute);
29   Directive C2 = getCompoundConstruct({OMPD_target});
30   ASSERT_EQ(C2, OMPD_target);
31   Directive C3 = getCompoundConstruct({OMPD_target, OMPD_masked});
32   ASSERT_EQ(C3, OMPD_unknown);
33   Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
34   ASSERT_EQ(C4, OMPD_target_teams_distribute);
35   Directive C5 = getCompoundConstruct({});
36   ASSERT_EQ(C5, OMPD_unknown);
37   Directive C6 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd});
38   ASSERT_EQ(C6, OMPD_parallel_for_simd);
39   Directive C7 = getCompoundConstruct({OMPD_do, OMPD_simd});
40   ASSERT_EQ(C7, OMPD_do_simd); // Make sure it's not OMPD_end_do_simd
41 }
42 
43 TEST(Composition, IsLeafConstruct) {
44   ASSERT_TRUE(isLeafConstruct(OMPD_loop));
45   ASSERT_TRUE(isLeafConstruct(OMPD_teams));
46   ASSERT_FALSE(isLeafConstruct(OMPD_for_simd));
47   ASSERT_FALSE(isLeafConstruct(OMPD_distribute_simd));
48   ASSERT_FALSE(isLeafConstruct(OMPD_parallel_for));
49 }
50 
51 TEST(Composition, IsCompositeConstruct) {
52   ASSERT_TRUE(isCompositeConstruct(OMPD_distribute_simd));
53   ASSERT_FALSE(isCompositeConstruct(OMPD_for));
54   ASSERT_TRUE(isCompositeConstruct(OMPD_for_simd));
55   // directive-name-A = "parallel", directive-name-B = "for simd",
56   // only directive-name-B is loop-associated, so this is not a
57   // composite construct, even though "for simd" is.
58   ASSERT_FALSE(isCompositeConstruct(OMPD_parallel_for_simd));
59 }
60 
61 TEST(Composition, IsCombinedConstruct) {
62   // "parallel for simd" is a combined construct, see comment in
63   // IsCompositeConstruct.
64   ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for_simd));
65   ASSERT_FALSE(isCombinedConstruct(OMPD_for_simd));
66   ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for));
67   ASSERT_FALSE(isCombinedConstruct(OMPD_parallel));
68 }
69