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
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/Bitset.h"
21#include "llvm/ADT/Sequence.h"
23#include "llvm/ADT/StringRef.h"
25
26#include "llvm/Frontend/OpenMP/OMP.h.inc"
27
28namespace llvm::omp {
29template <typename Enum, size_t Size> struct EnumSet;
30
31namespace detail {
32template <size_t Size>
33static constexpr inline size_t findFirstSet(size_t Begin, size_t End,
34 const llvm::Bitset<Size> &Set) {
35 unsigned BeginWord = Begin / 64;
36 unsigned EndWord = (End + 63) / 64;
37
38 for (unsigned I = BeginWord; I < EndWord; ++I) {
39 uint64_t Word = Set.getWord64(I);
40 if (I == BeginWord && Begin % 64 != 0) {
41 Word &= ~uint64_t() << (Begin % 64);
42 }
43 auto Count = static_cast<unsigned>(llvm::countr_zero_constexpr(Word));
44 if (Count < 64) {
45 unsigned Idx = I * 64 + Count;
46 if (Idx >= Begin && Idx < End)
47 return Idx;
48 }
49 }
50 return Size;
51}
52
53template <typename Enum, size_t Size> struct EnumSetIterator {
54 using value_type = Enum;
55 static constexpr size_t enum_size = Size;
56
57 constexpr EnumSetIterator(const EnumSet<Enum, Size> &Set, size_t At)
58 : Set(Set), At(At) {}
59
60 constexpr Enum operator*() const;
61 constexpr auto &operator++();
62
63 constexpr bool operator==(const EnumSetIterator<Enum, Size> &Other) const {
64 return &Set == &Other.Set && At == Other.At;
65 }
66 constexpr bool operator!=(const EnumSetIterator<Enum, Size> &Other) const {
67 return !operator==(Other);
68 }
69
70private:
71 const EnumSet<Enum, Size> &Set;
72 size_t At;
73};
74} // namespace detail
75
76template <typename Enum, size_t Size>
77struct EnumSet : public llvm::Bitset<Size> {
78 using value_type = Enum;
80 using Base::Base;
82
83 constexpr EnumSet(Base &&B) : Base(std::move(B)) {}
84 constexpr EnumSet(std::initializer_list<value_type> Init) {
85 for (value_type E : Init) {
86 auto Value = static_cast<unsigned>(E);
87 assert(Value < Base::size() && "Invalid enumeration value");
89 }
90 }
91
92 constexpr bool empty() const { return Base::none(); }
93 constexpr size_t size() const { return Base::count(); }
94 constexpr size_t max_size() const { return Size; }
95
96 constexpr bool test(Enum E) const {
97 return Base::test(static_cast<unsigned>(E));
98 }
99 constexpr bool operator[](Enum E) const {
100 return Base::operator[](static_cast<unsigned>(E));
101 }
102 constexpr EnumSet &flip(Enum E) {
103 Base::flip(static_cast<unsigned>(E));
104 return *this;
105 }
106 constexpr EnumSet &reset(Enum E) {
107 Base::reset(static_cast<unsigned>(E));
108 return *this;
109 }
110 constexpr EnumSet &set(Enum E) {
111 Base::set(static_cast<unsigned>(E));
112 return *this;
113 }
114
115 constexpr EnumSet &operator|=(const EnumSet &S) {
117 return *this;
118 }
119 constexpr EnumSet &operator&=(const EnumSet &S) {
121 return *this;
122 }
123 constexpr EnumSet operator|(const EnumSet &S) const {
124 EnumSet T{*this};
125 return T |= S;
126 }
127 constexpr EnumSet operator&(const EnumSet &S) const {
128 EnumSet T{*this};
129 return T &= S;
130 }
131
132 constexpr iterator begin() const {
133 return iterator(*this, detail::findFirstSet<Size>(0, Size, *this));
134 }
135 constexpr iterator end() const { return iterator(*this, Size); }
136};
137
138namespace detail {
139template <typename Enum, size_t Size>
141 // Older gcc doesn't like assert(Set.Base::test(At));
142 assert((static_cast<const llvm::Bitset<Size> &>(Set).test(At)));
143 return static_cast<Enum>(At);
144}
145
146template <typename Enum, size_t Size>
148 At = findFirstSet<Size>(At + 1, Size, Set);
149 return *this;
150}
151} // namespace detail
152
156
159
162
164
168
169static constexpr inline auto clauses() {
170 return llvm::enum_seq_inclusive(Clause::First_, Clause::Last_);
171}
172
173static constexpr inline auto directives() {
174 return llvm::enum_seq_inclusive(Directive::First_, Directive::Last_);
175}
176
177/// Can clause C have an iterator-modifier.
178static constexpr inline bool canHaveIterator(Clause C) {
179 // [5.2:67:5]
180 switch (C) {
181 case OMPC_affinity:
182 case OMPC_depend:
183 case OMPC_from:
184 case OMPC_map:
185 case OMPC_to:
186 return true;
187 default:
188 return false;
189 }
190}
191
192// Can clause C create a private copy of a variable.
193static constexpr inline bool isPrivatizingClause(Clause C, Version V) {
194 switch (C) {
195 case OMPC_firstprivate:
196 case OMPC_in_reduction:
197 case OMPC_lastprivate:
198 case OMPC_linear:
199 case OMPC_private:
200 case OMPC_reduction:
201 case OMPC_task_reduction:
202 return true;
203 case OMPC_detach:
204 case OMPC_induction:
205 case OMPC_is_device_ptr:
206 case OMPC_use_device_ptr:
207 return V >= 60;
208 default:
209 return false;
210 }
211}
212
213static constexpr inline bool isDataSharingAttributeClause(Clause C, Version V) {
214 // The "Version" parameter is in case the result is version-depenent
215 // in the future.
216 (void)V;
217 switch (C) {
218 case OMPC_detach:
219 case OMPC_firstprivate:
220 case OMPC_has_device_addr:
221 case OMPC_induction:
222 case OMPC_in_reduction:
223 case OMPC_is_device_ptr:
224 case OMPC_lastprivate:
225 case OMPC_linear:
226 case OMPC_private:
227 case OMPC_reduction:
228 case OMPC_shared:
229 case OMPC_task_reduction:
230 case OMPC_use_device_addr:
231 case OMPC_use_device_ptr:
232 case OMPC_uses_allocators:
233 return true;
234 default:
235 return false;
236 }
237}
238
239static constexpr inline bool isEndClause(Clause C) {
240 switch (C) {
241 case OMPC_copyprivate:
242 case OMPC_nowait:
243 return true;
244 default:
245 return false;
246 }
247}
248
249static constexpr Version FallbackVersion(52);
251
252/// Can directive D, under some circumstances, create a private copy
253/// of a variable in given OpenMP version?
255
257
258/// Create a nicer version of a function name for humans to look at.
259LLVM_ABI std::string prettifyFunctionName(StringRef FunctionName);
260
261/// Deconstruct an OpenMP kernel name into the parent function name and the line
262/// number.
263LLVM_ABI std::string deconstructOpenMPKernelName(StringRef KernelName,
264 unsigned &LineNo);
265
266} // namespace llvm::omp
267
268#endif // LLVM_FRONTEND_OPENMP_OMP_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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
This file defines DenseMapInfo traits for DenseMap.
#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
static constexpr size_t findFirstSet(size_t Begin, size_t End, const llvm::Bitset< Size > &Set)
Definition OMP.h:33
static constexpr auto clauses()
Definition OMP.h:169
LLVM_ABI bool isCombinedConstruct(Directive D)
Definition OMP.cpp:205
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:239
LLVM_ABI ArrayRef< Directive > getLeafOrCompositeConstructs(Directive D, SmallVectorImpl< Directive > &Output)
Definition OMP.cpp:117
static constexpr bool canHaveIterator(Clause C)
Can clause C have an iterator-modifier.
Definition OMP.h:178
LLVM_ABI bool isCompositeConstruct(Directive D)
Definition OMP.cpp:197
static constexpr Version FallbackVersion(52)
LLVM_ABI bool isPrivatizingConstruct(Directive D, Version V)
Can directive D, under some circumstances, create a private copy of a variable in given OpenMP versio...
Definition OMP.cpp:217
EnumSet< llvm::omp::Clause, llvm::omp::Clause_enumSize > ClauseSet
Definition OMP.h:153
LLVM_ABI Directive getCompoundConstruct(ArrayRef< Directive > Parts)
Definition OMP.cpp:144
LLVM_ABI ArrayRef< Version > getOpenMPVersions()
Definition OMP.cpp:211
LLVM_ABI ArrayRef< StringRef > getReservedLocatorNames()
Definition OMP.cpp:229
LLVM_ABI bool isLeafConstruct(Directive D)
Definition OMP.cpp:195
LLVM_ABI ArrayRef< Directive > getLeafConstructsOrSelf(Directive D)
Definition OMP.cpp:106
static constexpr bool isPrivatizingClause(Clause C, Version V)
Definition OMP.h:193
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:173
EnumSet< llvm::omp::Directive, llvm::omp::Directive_enumSize > DirectiveSet
Definition OMP.h:154
LLVM_ABI ArrayRef< Directive > getLeafConstructs(Directive D)
Definition OMP.cpp:98
static constexpr bool isDataSharingAttributeClause(Clause C, Version V)
Definition OMP.h:213
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:99
detail::EnumSetIterator< Enum, Size > iterator
Definition OMP.h:81
constexpr EnumSet(std::initializer_list< value_type > Init)
Definition OMP.h:84
constexpr size_t max_size() const
Definition OMP.h:94
constexpr bool test(Enum E) const
Definition OMP.h:96
constexpr EnumSet(Base &&B)
Definition OMP.h:83
constexpr EnumSet & set(Enum E)
Definition OMP.h:110
constexpr EnumSet & reset(Enum E)
Definition OMP.h:106
constexpr EnumSet & operator|=(const EnumSet &S)
Definition OMP.h:115
constexpr iterator begin() const
Definition OMP.h:132
constexpr EnumSet operator&(const EnumSet &S) const
Definition OMP.h:127
constexpr size_t size() const
Definition OMP.h:93
constexpr EnumSet & operator&=(const EnumSet &S)
Definition OMP.h:119
constexpr bool empty() const
Definition OMP.h:92
Enum value_type
Definition OMP.h:78
constexpr EnumSet operator|(const EnumSet &S) const
Definition OMP.h:123
llvm::Bitset< Size > Base
Definition OMP.h:79
constexpr EnumSet & flip(Enum E)
Definition OMP.h:102
constexpr iterator end() const
Definition OMP.h:135
constexpr bool operator==(const EnumSetIterator< Enum, Size > &Other) const
Definition OMP.h:63
static constexpr size_t enum_size
Definition OMP.h:55
constexpr Enum operator*() const
Definition OMP.h:140
constexpr auto & operator++()
Definition OMP.h:147
constexpr EnumSetIterator(const EnumSet< Enum, Size > &Set, size_t At)
Definition OMP.h:57
constexpr bool operator!=(const EnumSetIterator< Enum, Size > &Other) const
Definition OMP.h:66