1//===-- OMPDescriptors.cpp - OpenMP descriptors ------------------- C++ -*-===//
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// This file contains descriptors of OpenMP elements.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Frontend/OpenMP/OMPDescriptors.h"
14
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/Frontend/OpenMP/OMP.h"
17
18namespace llvm::omp {
19const DescriptorMap<Clause, descriptor::Clause> &getClauseMap() {
20 static const DescriptorMap<Clause, descriptor::Clause> Map{
21#define GEN_OMP_CLAUSE_DESCRIPTORS
22#include "OMPDescriptors.inc"
23#undef GEN_OMP_CLAUSE_DESCRIPTORS
24 };
25 return Map;
26}
27
28const DescriptorMap<Modifier, descriptor::Modifier> &getModifierMap() {
29 static const DescriptorMap<Modifier, descriptor::Modifier> Map{
30#define GEN_OMP_MODIFIER_DESCRIPTORS
31#include "OMPDescriptors.inc"
32#undef GEN_OMP_MODIFIER_DESCRIPTORS
33 };
34 return Map;
35}
36
37#define GET_THING_OR_EMPTY(Thing, Member) \
38 template <typename DetailsTy> \
39 static Thing get##Thing##OrEmpty(const DetailsTy &D, unsigned V) { \
40 V = std::max(V, 45u); \
41 if (auto Found = D.find(V); Found != D.end()) \
42 return Found->second.Member; \
43 return Thing{}; \
44 }
45
46GET_THING_OR_EMPTY(Clauses, Cls)
47GET_THING_OR_EMPTY(Directives, Dirs)
48GET_THING_OR_EMPTY(Modifiers, Mods)
49GET_THING_OR_EMPTY(Properties, Props)
50
51#undef GET_THING_OR_EMPTY
52
53Properties descriptor::Clause::getProperties(unsigned V) const {
54 return getPropertiesOrEmpty(D: Details, V);
55}
56Directives descriptor::Clause::getDirectives(unsigned V) const {
57 return getDirectivesOrEmpty(D: Details, V);
58}
59Modifiers descriptor::Clause::getModifiers(unsigned V) const {
60 return getModifiersOrEmpty(D: Details, V);
61}
62Properties descriptor::Modifier::getProperties(unsigned V) const {
63 return getPropertiesOrEmpty(D: Details, V);
64}
65Clauses descriptor::Modifier::getClauses(unsigned V) const {
66 return getClausesOrEmpty(D: Details, V);
67}
68
69const descriptor::Clause &getDescriptor(llvm::omp::Clause C) {
70 return getClauseMap().at(Val: C);
71}
72
73const descriptor::Modifier &getDescriptor(llvm::omp::Modifier M) {
74 return getModifierMap().at(Val: M);
75}
76
77Properties getProperties(Clause C, unsigned Version) {
78 return getDescriptor(C).getProperties(V: std::max(a: Version, b: 45u));
79}
80} // namespace llvm::omp
81