1 //===- llvm/unittest/IR/OpenMPIRParsingTest.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/Frontend/OpenMP/OMPConstants.h"
10 #include "gtest/gtest.h"
11 
12 using namespace llvm;
13 using namespace llvm::omp;
14 
15 namespace {
16 
TEST(OpenMPParsingTest,OpenMPDirectiveKind)17 TEST(OpenMPParsingTest, OpenMPDirectiveKind) {
18   EXPECT_EQ(getOpenMPDirectiveKind("foobar"), OMPD_unknown);
19 
20   EXPECT_EQ(getOpenMPDirectiveKind("for"), OMPD_for);
21   EXPECT_EQ(getOpenMPDirectiveKind("simd"), OMPD_simd);
22   EXPECT_EQ(getOpenMPDirectiveKind("for simd"), OMPD_for_simd);
23 }
24 
TEST(OpenMPParsingTest,getOpenMPDirectiveName)25 TEST(OpenMPParsingTest, getOpenMPDirectiveName) {
26   EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown), "unknown");
27 
28   EXPECT_EQ(getOpenMPDirectiveName(OMPD_for), "for");
29   EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd), "simd");
30   EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd), "for simd");
31 }
32 
TEST(OpenMPParsingTest,getOpenMPClauseKind)33 TEST(OpenMPParsingTest, getOpenMPClauseKind) {
34   EXPECT_EQ(getOpenMPClauseKind("foobar"), OMPC_unknown);
35 
36   EXPECT_EQ(getOpenMPClauseKind("schedule"), OMPC_schedule);
37   EXPECT_EQ(getOpenMPClauseKind("if"), OMPC_if);
38 }
39 
TEST(OpenMPParsingTest,getOpenMPClauseName)40 TEST(OpenMPParsingTest, getOpenMPClauseName) {
41   EXPECT_EQ(getOpenMPClauseName(OMPC_unknown), "unknown");
42 
43   EXPECT_EQ(getOpenMPClauseName(OMPC_schedule), "schedule");
44   EXPECT_EQ(getOpenMPClauseName(OMPC_if), "if");
45 }
46 
TEST(OpenMPParsingTest,isAllowedClauseForDirective)47 TEST(OpenMPParsingTest, isAllowedClauseForDirective) {
48   EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_schedule, 30));
49   EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_num_teams, 30));
50 
51   EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 30));
52   EXPECT_FALSE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 45));
53   EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 50));
54   EXPECT_TRUE(isAllowedClauseForDirective(OMPD_for, OMPC_order, 51));
55 }
56 
TEST(OpenMPParsingTest,getOrderKind)57 TEST(OpenMPParsingTest, getOrderKind) {
58   EXPECT_EQ(getOrderKind("foobar"), OMP_ORDER_concurrent);
59   EXPECT_EQ(getOrderKind("default"), OMP_ORDER_concurrent);
60 }
61 
TEST(OpenMPParsingTest,getProcBindKind)62 TEST(OpenMPParsingTest, getProcBindKind) {
63   EXPECT_EQ(getProcBindKind("foobar"), OMP_PROC_BIND_unknown);
64 
65   EXPECT_EQ(getProcBindKind("master"), OMP_PROC_BIND_master);
66   EXPECT_EQ(getProcBindKind("close"), OMP_PROC_BIND_close);
67   EXPECT_EQ(getProcBindKind("spread"), OMP_PROC_BIND_spread);
68   EXPECT_EQ(getProcBindKind("default"), OMP_PROC_BIND_default);
69   EXPECT_EQ(getProcBindKind("unknown"), OMP_PROC_BIND_unknown);
70 }
71 
TEST(OpenMPParsingTest,getScheduleKind)72 TEST(OpenMPParsingTest, getScheduleKind) {
73   EXPECT_EQ(getScheduleKind("foobar"), OMP_SCHEDULE_Default);
74 
75   // FIXME: Why are these not lower case?
76   EXPECT_EQ(getScheduleKind("Static"), OMP_SCHEDULE_Static);
77   EXPECT_EQ(getScheduleKind("Dynamic"), OMP_SCHEDULE_Dynamic);
78   EXPECT_EQ(getScheduleKind("Guided"), OMP_SCHEDULE_Guided);
79   EXPECT_EQ(getScheduleKind("Auto"), OMP_SCHEDULE_Auto);
80   EXPECT_EQ(getScheduleKind("Runtime"), OMP_SCHEDULE_Runtime);
81   EXPECT_EQ(getScheduleKind("Default"), OMP_SCHEDULE_Default);
82 }
83 
84 } // namespace
85