| 1 |
//===- llvm/unittests/Frontend/OpenMPDirectiveNameTest.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/DenseMap.h" |
| 10 |
#include "llvm/ADT/StringRef.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 |
const DenseMap<Directive, StringRef> &Expected52() { |
| 18 |
static const DenseMap<Directive, StringRef> Names{ |
| 19 |
{OMPD_begin_declare_target, "begin declare target"}, |
| 20 |
{OMPD_begin_declare_variant, "begin declare variant"}, |
| 21 |
{OMPD_cancellation_point, "cancellation point"}, |
| 22 |
{OMPD_declare_mapper, "declare mapper"}, |
| 23 |
{OMPD_declare_reduction, "declare reduction"}, |
| 24 |
{OMPD_declare_simd, "declare simd"}, |
| 25 |
{OMPD_declare_target, "declare target"}, |
| 26 |
{OMPD_declare_variant, "declare variant"}, |
| 27 |
{OMPD_end_declare_target, "end declare target"}, |
| 28 |
{OMPD_end_declare_variant, "end declare variant"}, |
| 29 |
{OMPD_target_data, "target data"}, |
| 30 |
{OMPD_target_enter_data, "target enter data"}, |
| 31 |
{OMPD_target_exit_data, "target exit data"}, |
| 32 |
{OMPD_target_update, "target update"}, |
| 33 |
}; |
| 34 |
return Names; |
| 35 |
} |
| 36 |
|
| 37 |
const DenseMap<Directive, StringRef> &Expected60() { |
| 38 |
static const DenseMap<Directive, StringRef> Names{ |
| 39 |
{OMPD_begin_declare_target, "begin declare_target"}, |
| 40 |
{OMPD_begin_declare_variant, "begin declare_variant"}, |
| 41 |
{OMPD_cancellation_point, "cancellation_point"}, |
| 42 |
{OMPD_declare_mapper, "declare_mapper"}, |
| 43 |
{OMPD_declare_reduction, "declare_reduction"}, |
| 44 |
{OMPD_declare_simd, "declare_simd"}, |
| 45 |
{OMPD_declare_target, "declare_target"}, |
| 46 |
{OMPD_declare_variant, "declare_variant"}, |
| 47 |
{OMPD_end_declare_target, "end declare_target"}, |
| 48 |
{OMPD_end_declare_variant, "end declare_variant"}, |
| 49 |
{OMPD_target_data, "target_data"}, |
| 50 |
{OMPD_target_enter_data, "target_enter_data"}, |
| 51 |
{OMPD_target_exit_data, "target_exit_data"}, |
| 52 |
{OMPD_target_update, "target_update"}, |
| 53 |
}; |
| 54 |
return Names; |
| 55 |
} |
| 56 |
|
| 57 |
class VersionTest : public testing::TestWithParam<unsigned> { |
| 58 |
public: |
| 59 |
void SetUp() override { |
| 60 |
Version = GetParam(); |
| 61 |
|
| 62 |
if (Version < 60) |
| 63 |
KindToName = &Expected52(); |
| 64 |
else |
| 65 |
KindToName = &Expected60(); |
| 66 |
} |
| 67 |
|
| 68 |
const DenseMap<Directive, StringRef> *KindToName; |
| 69 |
unsigned Version; |
| 70 |
}; |
| 71 |
|
| 72 |
INSTANTIATE_TEST_SUITE_P(OpenMPDirectiveNames, VersionTest, |
| 73 |
testing::ValuesIn(getOpenMPVersions())); |
| 74 |
|
| 75 |
TEST_P(VersionTest, DirectiveName) { |
| 76 |
for (auto [Kind, Name] : *KindToName) |
| 77 |
ASSERT_EQ(Name, getOpenMPDirectiveName(Kind, Version)); |
| 78 |
} |
| 79 |
|
| 80 |
TEST(OpenMPDirectiveNames, DirectiveKind52) { |
| 81 |
for (auto [Kind, Name] : Expected52()) { |
| 82 |
auto [K, R] = getOpenMPDirectiveKindAndVersions(Name); |
| 83 |
ASSERT_EQ(K, Kind); |
| 84 |
// Expect the name to be valid in 5.2, but not in 6.0. |
| 85 |
EXPECT_TRUE(52 <= R.Max && R.Max < 60); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
TEST(OpenMPDirectiveNames, DirectiveKind60) { |
| 90 |
for (auto [Kind, Name] : Expected60()) { |
| 91 |
auto [K, R] = getOpenMPDirectiveKindAndVersions(Name); |
| 92 |
ASSERT_EQ(K, Kind); |
| 93 |
// Expect the name to be valid in 6.0 and later. |
| 94 |
EXPECT_TRUE(60 <= R.Min); |
| 95 |
} |
| 96 |
} |