LLVM 24.0.0git
OMP.h
Go to the documentation of this file.
1//===-- OMP.h - Core OpenMP definitions and declarations ---------- 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 the core set of OpenMP definitions and declarations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_FRONTEND_OPENMP_OMP_H
14#define LLVM_FRONTEND_OPENMP_OMP_H
15
16#include "llvm/Frontend/OpenMP/OMP.h.inc"
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/Bitset.h"
21#include "llvm/ADT/Sequence.h"
23#include "llvm/ADT/StringRef.h"
24
25namespace llvm::omp {
26template <typename Enum, size_t Size> struct EnumSet;
27
28namespace detail {
29template <size_t Size>
30static constexpr inline size_t findFirstSet(size_t Begin, size_t End,
31 const llvm::Bitset<Size> &Set) {
32 unsigned BeginWord = Begin / 64;
33 unsigned EndWord = (End + 63) / 64;
34
35 for (unsigned I = BeginWord; I < EndWord; ++I) {
36 uint64_t Word = Set.getWord64(I);
37 if (I == BeginWord && Begin % 64 != 0) {
38 Word &= ~uint64_t() << (Begin % 64);
39 }
40 auto Count = static_cast<unsigned>(llvm::countr_zero_constexpr(Word));
41 if (Count < 64) {
42 unsigned Idx = I * 64 + Count;
43 if (Idx >= Begin && Idx < End)
44 return Idx;
45 }
46 }
47 return Size;
48}
49
50template <typename Enum, size_t Size> struct EnumSetIterator {
51 using value_type = Enum;
52 static constexpr size_t enum_size = Size;
53
54 constexpr EnumSetIterator(const EnumSet<Enum, Size> &Set, size_t At)
55 : Set(Set), At(At) {}
56
57 constexpr Enum operator*() const;
58 constexpr auto &operator++();
59
60 constexpr bool operator==(const EnumSetIterator<Enum, Size> &Other) const {
61 return &Set == &Other.Set && At == Other.At;
62 }
63 constexpr bool operator!=(const EnumSetIterator<Enum, Size> &Other) const {
64 return !operator==(Other);
65 }
66
67private:
68 const EnumSet<Enum, Size> &Set;
69 size_t At;
70};
71} // namespace detail
72
73template <typename Enum, size_t Size>
74struct EnumSet : public llvm::Bitset<Size> {
75 using value_type = Enum;
77 using Base::Base;
79
80 constexpr EnumSet(Base &&B) : Base(std::move(B)) {}
81 constexpr EnumSet(std::initializer_list<value_type> Init) {
82 for (value_type E : Init) {
83 auto Value = static_cast<unsigned>(E);
84 assert(Value < Base::size() && "Invalid enumeration value");
86 }
87 }
88
89 constexpr bool empty() const { return Base::none(); }
90 constexpr size_t size() const { return Base::count(); }
91 constexpr size_t max_size() const { return Size; }
92
93 constexpr bool test(Enum E) const {
94 return Base::test(static_cast<unsigned>(E));
95 }
96 constexpr bool operator[](Enum E) const {
97 return Base::operator[](static_cast<unsigned>(E));
98 }
99 constexpr EnumSet &flip(Enum E) {
100 Base::flip(static_cast<unsigned>(E));
101 return *this;
102 }
103 constexpr EnumSet &reset(Enum E) {
104 Base::reset(static_cast<unsigned>(E));
105 return *this;
106 }
107 constexpr EnumSet &set(Enum E) {
108 Base::set(static_cast<unsigned>(E));
109 return *this;
110 }
111
112 constexpr EnumSet &operator|=(const EnumSet &S) {
114 return *this;
115 }
116 constexpr EnumSet &operator&=(const EnumSet &S) {
118 return *this;
119 }
120 constexpr EnumSet operator|(const EnumSet &S) const {
121 EnumSet T{*this};
122 return T |= S;
123 }
124 constexpr EnumSet operator&(const EnumSet &S) const {
125 EnumSet T{*this};
126 return T &= S;
127 }
128
129 constexpr iterator begin() const {
130 return iterator(*this, detail::findFirstSet<Size>(0, Size, *this));
131 }
132 constexpr iterator end() const { return iterator(*this, Size); }
133};
134
135namespace detail {
136template <typename Enum, size_t Size>
138 // Older gcc doesn't like assert(Set.Base::test(At));
139 assert((static_cast<const llvm::Bitset<Size> &>(Set).test(At)));
140 return static_cast<Enum>(At);
141}
142
143template <typename Enum, size_t Size>
145 At = findFirstSet<Size>(At + 1, Size, Set);
146 return *this;
147}
148} // namespace detail
149
153
156
159
161
165
166static constexpr inline auto clauses() {
167 return llvm::enum_seq_inclusive(Clause::First_, Clause::Last_);
168}
169
170static constexpr inline auto directives() {
171 return llvm::enum_seq_inclusive(Directive::First_, Directive::Last_);
172}
173
174/// Can clause C have an iterator-modifier.
175static constexpr inline bool canHaveIterator(Clause C) {
176 // [5.2:67:5]
177 switch (C) {
178 case OMPC_affinity:
179 case OMPC_depend:
180 case OMPC_from:
181 case OMPC_map:
182 case OMPC_to:
183 return true;
184 default:
185 return false;
186 }
187}
188
189// Can clause C create a private copy of a variable.
190static constexpr inline bool isPrivatizingClause(Clause C, unsigned Version) {
191 switch (C) {
192 case OMPC_firstprivate:
193 case OMPC_in_reduction:
194 case OMPC_lastprivate:
195 case OMPC_linear:
196 case OMPC_private:
197 case OMPC_reduction:
198 case OMPC_task_reduction:
199 return true;
200 case OMPC_detach:
201 case OMPC_induction:
202 case OMPC_is_device_ptr:
203 case OMPC_use_device_ptr:
204 return Version >= 60;
205 default:
206 return false;
207 }
208}
209
210static constexpr inline bool isDataSharingAttributeClause(Clause C,
211 unsigned Version) {
212 // The "Version" parameter is in case the result is version-depenent
213 // in the future.
214 (void)Version;
215 switch (C) {
216 case OMPC_detach:
217 case OMPC_firstprivate:
218 case OMPC_has_device_addr:
219 case OMPC_induction:
220 case OMPC_in_reduction:
221 case OMPC_is_device_ptr:
222 case OMPC_lastprivate:
223 case OMPC_linear:
224 case OMPC_private:
225 case OMPC_reduction:
226 case OMPC_shared:
227 case OMPC_task_reduction:
228 case OMPC_use_device_addr:
229 case OMPC_use_device_ptr:
230 case OMPC_uses_allocators:
231 return true;
232 default:
233 return false;
234 }
235}
236
237static constexpr inline bool isEndClause(Clause C) {
238 switch (C) {
239 case OMPC_copyprivate:
240 case OMPC_nowait:
241 return true;
242 default:
243 return false;
244 }
245}
246
247static constexpr unsigned FallbackVersion = 52;
249
250/// Can directive D, under some circumstances, create a private copy
251/// of a variable in given OpenMP version?
253
255
256/// Create a nicer version of a function name for humans to look at.
257LLVM_ABI std::string prettifyFunctionName(StringRef FunctionName);
258
259/// Deconstruct an OpenMP kernel name into the parent function name and the line
260/// number.
261LLVM_ABI std::string deconstructOpenMPKernelName(StringRef KernelName,
262 unsigned &LineNo);
263
264} // namespace llvm::omp
265
266#endif // LLVM_FRONTEND_OPENMP_OMP_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
#define I(x, y, z)
Definition MD5.cpp:57
#define T
modulo schedule test
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This is a constexpr reimplementation of a subset of std::bitset.
Definition Bitset.h:30
constexpr size_t count() const
Definition Bitset.h:130
constexpr Bitset & flip(unsigned I)
Definition Bitset.h:99
constexpr Bitset & set()
Definition Bitset.h:81
constexpr bool none() const
Definition Bitset.h:120
constexpr bool operator[](unsigned I) const
Definition Bitset.h:104
constexpr size_t size() const
Definition Bitset.h:111
constexpr Bitset & operator|=(const Bitset &RHS)
Definition Bitset.h:160
constexpr Bitset & operator&=(const Bitset &RHS)
Definition Bitset.h:149
constexpr bool test(unsigned I) const
Definition Bitset.h:109
constexpr Bitset & reset(unsigned I)
Definition Bitset.h:94
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
static constexpr size_t findFirstSet(size_t Begin, size_t End, const llvm::Bitset< Size > &Set)
Definition OMP.h:30
static constexpr auto clauses()
Definition OMP.h:166
LLVM_ABI ArrayRef< unsigned > getOpenMPVersions()
Definition OMP.cpp:212
static constexpr bool isDataSharingAttributeClause(Clause C, unsigned Version)
Definition OMP.h:210
LLVM_ABI bool isCombinedConstruct(Directive D)
Definition OMP.cpp:206
LLVM_ABI std::string deconstructOpenMPKernelName(StringRef KernelName, unsigned &LineNo)
Deconstruct an OpenMP kernel name into the parent function name and the line number.
Definition OMP.cpp:249
static constexpr bool isEndClause(Clause C)
Definition OMP.h:237
LLVM_ABI ArrayRef< Directive > getLeafOrCompositeConstructs(Directive D, SmallVectorImpl< Directive > &Output)
Definition OMP.cpp:118
LLVM_ABI bool isPrivatizingConstruct(Directive D, unsigned Version)
Can directive D, under some circumstances, create a private copy of a variable in given OpenMP versio...
Definition OMP.cpp:217
static constexpr bool canHaveIterator(Clause C)
Can clause C have an iterator-modifier.
Definition OMP.h:175
LLVM_ABI bool isCompositeConstruct(Directive D)
Definition OMP.cpp:198
EnumSet< llvm::omp::Clause, llvm::omp::Clause_enumSize > ClauseSet
Definition OMP.h:150
LLVM_ABI Directive getCompoundConstruct(ArrayRef< Directive > Parts)
Definition OMP.cpp:145
static constexpr unsigned FallbackVersion
Definition OMP.h:247
LLVM_ABI ArrayRef< StringRef > getReservedLocatorNames()
Definition OMP.cpp:229
LLVM_ABI bool isLeafConstruct(Directive D)
Definition OMP.cpp:196
LLVM_ABI ArrayRef< Directive > getLeafConstructsOrSelf(Directive D)
Definition OMP.cpp:107
LLVM_ABI std::string prettifyFunctionName(StringRef FunctionName)
Create a nicer version of a function name for humans to look at.
Definition OMP.cpp:235
static constexpr auto directives()
Definition OMP.h:170
EnumSet< llvm::omp::Directive, llvm::omp::Directive_enumSize > DirectiveSet
Definition OMP.h:151
LLVM_ABI ArrayRef< Directive > getLeafConstructs(Directive D)
Definition OMP.cpp:99
static constexpr bool isPrivatizingClause(Clause C, unsigned Version)
Definition OMP.h:190
constexpr auto enum_seq_inclusive(EnumT Begin, EnumT End)
Iterate over an enum type from Begin to End inclusive.
Definition Sequence.h:401
@ Other
Any other memory.
Definition ModRef.h:68
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
constexpr int countr_zero_constexpr(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:190
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
constexpr bool operator[](Enum E) const
Definition OMP.h:96
detail::EnumSetIterator< Enum, Size > iterator
Definition OMP.h:78
constexpr EnumSet(std::initializer_list< value_type > Init)
Definition OMP.h:81
constexpr size_t max_size() const
Definition OMP.h:91
constexpr bool test(Enum E) const
Definition OMP.h:93
constexpr EnumSet(Base &&B)
Definition OMP.h:80
constexpr EnumSet & set(Enum E)
Definition OMP.h:107
constexpr EnumSet & reset(Enum E)
Definition OMP.h:103
constexpr EnumSet & operator|=(const EnumSet &S)
Definition OMP.h:112
constexpr iterator begin() const
Definition OMP.h:129
constexpr EnumSet operator&(const EnumSet &S) const
Definition OMP.h:124
constexpr size_t size() const
Definition OMP.h:90
constexpr EnumSet & operator&=(const EnumSet &S)
Definition OMP.h:116
constexpr bool empty() const
Definition OMP.h:89
Enum value_type
Definition OMP.h:75
constexpr EnumSet operator|(const EnumSet &S) const
Definition OMP.h:120
llvm::Bitset< Size > Base
Definition OMP.h:76
constexpr EnumSet & flip(Enum E)
Definition OMP.h:99
constexpr iterator end() const
Definition OMP.h:132
constexpr bool operator==(const EnumSetIterator< Enum, Size > &Other) const
Definition OMP.h:60
static constexpr size_t enum_size
Definition OMP.h:52
constexpr Enum operator*() const
Definition OMP.h:137
constexpr auto & operator++()
Definition OMP.h:144
constexpr EnumSetIterator(const EnumSet< Enum, Size > &Set, size_t At)
Definition OMP.h:54
constexpr bool operator!=(const EnumSetIterator< Enum, Size > &Other) const
Definition OMP.h:63