/src/llvm-project/clang/lib/AST/OpenMPClause.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- OpenMPClause.cpp - Classes for OpenMP clauses ----------------------===// |
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 implements the subclesses of Stmt class declared in OpenMPClause.h |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/OpenMPClause.h" |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/Attr.h" |
16 | | #include "clang/AST/Decl.h" |
17 | | #include "clang/AST/DeclOpenMP.h" |
18 | | #include "clang/Basic/LLVM.h" |
19 | | #include "clang/Basic/OpenMPKinds.h" |
20 | | #include "clang/Basic/TargetInfo.h" |
21 | | #include "llvm/ADT/SmallPtrSet.h" |
22 | | #include "llvm/Support/Casting.h" |
23 | | #include "llvm/Support/ErrorHandling.h" |
24 | | #include <algorithm> |
25 | | #include <cassert> |
26 | | #include <optional> |
27 | | |
28 | | using namespace clang; |
29 | | using namespace llvm; |
30 | | using namespace omp; |
31 | | |
32 | 0 | OMPClause::child_range OMPClause::children() { |
33 | 0 | switch (getClauseKind()) { |
34 | 0 | default: |
35 | 0 | break; |
36 | 0 | #define GEN_CLANG_CLAUSE_CLASS |
37 | 0 | #define CLAUSE_CLASS(Enum, Str, Class) \ |
38 | 0 | case Enum: \ |
39 | 0 | return static_cast<Class *>(this)->children(); |
40 | 0 | #include "llvm/Frontend/OpenMP/OMP.inc" |
41 | 0 | } |
42 | 0 | llvm_unreachable("unknown OMPClause"); |
43 | 0 | } |
44 | | |
45 | 0 | OMPClause::child_range OMPClause::used_children() { |
46 | 0 | switch (getClauseKind()) { |
47 | 0 | #define GEN_CLANG_CLAUSE_CLASS |
48 | 0 | #define CLAUSE_CLASS(Enum, Str, Class) \ |
49 | 0 | case Enum: \ |
50 | 0 | return static_cast<Class *>(this)->used_children(); |
51 | 0 | #define CLAUSE_NO_CLASS(Enum, Str) \ |
52 | 0 | case Enum: \ |
53 | 0 | break; |
54 | 0 | #include "llvm/Frontend/OpenMP/OMP.inc" |
55 | 0 | } |
56 | 0 | llvm_unreachable("unknown OMPClause"); |
57 | 0 | } |
58 | | |
59 | 0 | OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { |
60 | 0 | auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); |
61 | 0 | return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; |
62 | 0 | } |
63 | | |
64 | 0 | const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { |
65 | 0 | switch (C->getClauseKind()) { |
66 | 0 | case OMPC_schedule: |
67 | 0 | return static_cast<const OMPScheduleClause *>(C); |
68 | 0 | case OMPC_dist_schedule: |
69 | 0 | return static_cast<const OMPDistScheduleClause *>(C); |
70 | 0 | case OMPC_firstprivate: |
71 | 0 | return static_cast<const OMPFirstprivateClause *>(C); |
72 | 0 | case OMPC_lastprivate: |
73 | 0 | return static_cast<const OMPLastprivateClause *>(C); |
74 | 0 | case OMPC_reduction: |
75 | 0 | return static_cast<const OMPReductionClause *>(C); |
76 | 0 | case OMPC_task_reduction: |
77 | 0 | return static_cast<const OMPTaskReductionClause *>(C); |
78 | 0 | case OMPC_in_reduction: |
79 | 0 | return static_cast<const OMPInReductionClause *>(C); |
80 | 0 | case OMPC_linear: |
81 | 0 | return static_cast<const OMPLinearClause *>(C); |
82 | 0 | case OMPC_if: |
83 | 0 | return static_cast<const OMPIfClause *>(C); |
84 | 0 | case OMPC_num_threads: |
85 | 0 | return static_cast<const OMPNumThreadsClause *>(C); |
86 | 0 | case OMPC_num_teams: |
87 | 0 | return static_cast<const OMPNumTeamsClause *>(C); |
88 | 0 | case OMPC_thread_limit: |
89 | 0 | return static_cast<const OMPThreadLimitClause *>(C); |
90 | 0 | case OMPC_device: |
91 | 0 | return static_cast<const OMPDeviceClause *>(C); |
92 | 0 | case OMPC_grainsize: |
93 | 0 | return static_cast<const OMPGrainsizeClause *>(C); |
94 | 0 | case OMPC_num_tasks: |
95 | 0 | return static_cast<const OMPNumTasksClause *>(C); |
96 | 0 | case OMPC_final: |
97 | 0 | return static_cast<const OMPFinalClause *>(C); |
98 | 0 | case OMPC_priority: |
99 | 0 | return static_cast<const OMPPriorityClause *>(C); |
100 | 0 | case OMPC_novariants: |
101 | 0 | return static_cast<const OMPNovariantsClause *>(C); |
102 | 0 | case OMPC_nocontext: |
103 | 0 | return static_cast<const OMPNocontextClause *>(C); |
104 | 0 | case OMPC_filter: |
105 | 0 | return static_cast<const OMPFilterClause *>(C); |
106 | 0 | case OMPC_ompx_dyn_cgroup_mem: |
107 | 0 | return static_cast<const OMPXDynCGroupMemClause *>(C); |
108 | 0 | case OMPC_default: |
109 | 0 | case OMPC_proc_bind: |
110 | 0 | case OMPC_safelen: |
111 | 0 | case OMPC_simdlen: |
112 | 0 | case OMPC_sizes: |
113 | 0 | case OMPC_allocator: |
114 | 0 | case OMPC_allocate: |
115 | 0 | case OMPC_collapse: |
116 | 0 | case OMPC_private: |
117 | 0 | case OMPC_shared: |
118 | 0 | case OMPC_aligned: |
119 | 0 | case OMPC_copyin: |
120 | 0 | case OMPC_copyprivate: |
121 | 0 | case OMPC_ordered: |
122 | 0 | case OMPC_nowait: |
123 | 0 | case OMPC_untied: |
124 | 0 | case OMPC_mergeable: |
125 | 0 | case OMPC_threadprivate: |
126 | 0 | case OMPC_flush: |
127 | 0 | case OMPC_depobj: |
128 | 0 | case OMPC_read: |
129 | 0 | case OMPC_write: |
130 | 0 | case OMPC_update: |
131 | 0 | case OMPC_capture: |
132 | 0 | case OMPC_compare: |
133 | 0 | case OMPC_fail: |
134 | 0 | case OMPC_seq_cst: |
135 | 0 | case OMPC_acq_rel: |
136 | 0 | case OMPC_acquire: |
137 | 0 | case OMPC_release: |
138 | 0 | case OMPC_relaxed: |
139 | 0 | case OMPC_depend: |
140 | 0 | case OMPC_threads: |
141 | 0 | case OMPC_simd: |
142 | 0 | case OMPC_map: |
143 | 0 | case OMPC_nogroup: |
144 | 0 | case OMPC_hint: |
145 | 0 | case OMPC_defaultmap: |
146 | 0 | case OMPC_unknown: |
147 | 0 | case OMPC_uniform: |
148 | 0 | case OMPC_to: |
149 | 0 | case OMPC_from: |
150 | 0 | case OMPC_use_device_ptr: |
151 | 0 | case OMPC_use_device_addr: |
152 | 0 | case OMPC_is_device_ptr: |
153 | 0 | case OMPC_has_device_addr: |
154 | 0 | case OMPC_unified_address: |
155 | 0 | case OMPC_unified_shared_memory: |
156 | 0 | case OMPC_reverse_offload: |
157 | 0 | case OMPC_dynamic_allocators: |
158 | 0 | case OMPC_atomic_default_mem_order: |
159 | 0 | case OMPC_at: |
160 | 0 | case OMPC_severity: |
161 | 0 | case OMPC_message: |
162 | 0 | case OMPC_device_type: |
163 | 0 | case OMPC_match: |
164 | 0 | case OMPC_nontemporal: |
165 | 0 | case OMPC_order: |
166 | 0 | case OMPC_destroy: |
167 | 0 | case OMPC_detach: |
168 | 0 | case OMPC_inclusive: |
169 | 0 | case OMPC_exclusive: |
170 | 0 | case OMPC_uses_allocators: |
171 | 0 | case OMPC_affinity: |
172 | 0 | case OMPC_when: |
173 | 0 | case OMPC_bind: |
174 | 0 | case OMPC_ompx_bare: |
175 | 0 | break; |
176 | 0 | default: |
177 | 0 | break; |
178 | 0 | } |
179 | | |
180 | 0 | return nullptr; |
181 | 0 | } |
182 | | |
183 | 0 | OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { |
184 | 0 | auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); |
185 | 0 | return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; |
186 | 0 | } |
187 | | |
188 | 0 | const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { |
189 | 0 | switch (C->getClauseKind()) { |
190 | 0 | case OMPC_lastprivate: |
191 | 0 | return static_cast<const OMPLastprivateClause *>(C); |
192 | 0 | case OMPC_reduction: |
193 | 0 | return static_cast<const OMPReductionClause *>(C); |
194 | 0 | case OMPC_task_reduction: |
195 | 0 | return static_cast<const OMPTaskReductionClause *>(C); |
196 | 0 | case OMPC_in_reduction: |
197 | 0 | return static_cast<const OMPInReductionClause *>(C); |
198 | 0 | case OMPC_linear: |
199 | 0 | return static_cast<const OMPLinearClause *>(C); |
200 | 0 | case OMPC_schedule: |
201 | 0 | case OMPC_dist_schedule: |
202 | 0 | case OMPC_firstprivate: |
203 | 0 | case OMPC_default: |
204 | 0 | case OMPC_proc_bind: |
205 | 0 | case OMPC_if: |
206 | 0 | case OMPC_final: |
207 | 0 | case OMPC_num_threads: |
208 | 0 | case OMPC_safelen: |
209 | 0 | case OMPC_simdlen: |
210 | 0 | case OMPC_sizes: |
211 | 0 | case OMPC_allocator: |
212 | 0 | case OMPC_allocate: |
213 | 0 | case OMPC_collapse: |
214 | 0 | case OMPC_private: |
215 | 0 | case OMPC_shared: |
216 | 0 | case OMPC_aligned: |
217 | 0 | case OMPC_copyin: |
218 | 0 | case OMPC_copyprivate: |
219 | 0 | case OMPC_ordered: |
220 | 0 | case OMPC_nowait: |
221 | 0 | case OMPC_untied: |
222 | 0 | case OMPC_mergeable: |
223 | 0 | case OMPC_threadprivate: |
224 | 0 | case OMPC_flush: |
225 | 0 | case OMPC_depobj: |
226 | 0 | case OMPC_read: |
227 | 0 | case OMPC_write: |
228 | 0 | case OMPC_update: |
229 | 0 | case OMPC_capture: |
230 | 0 | case OMPC_compare: |
231 | 0 | case OMPC_fail: |
232 | 0 | case OMPC_seq_cst: |
233 | 0 | case OMPC_acq_rel: |
234 | 0 | case OMPC_acquire: |
235 | 0 | case OMPC_release: |
236 | 0 | case OMPC_relaxed: |
237 | 0 | case OMPC_depend: |
238 | 0 | case OMPC_device: |
239 | 0 | case OMPC_threads: |
240 | 0 | case OMPC_simd: |
241 | 0 | case OMPC_map: |
242 | 0 | case OMPC_num_teams: |
243 | 0 | case OMPC_thread_limit: |
244 | 0 | case OMPC_priority: |
245 | 0 | case OMPC_grainsize: |
246 | 0 | case OMPC_nogroup: |
247 | 0 | case OMPC_num_tasks: |
248 | 0 | case OMPC_hint: |
249 | 0 | case OMPC_defaultmap: |
250 | 0 | case OMPC_unknown: |
251 | 0 | case OMPC_uniform: |
252 | 0 | case OMPC_to: |
253 | 0 | case OMPC_from: |
254 | 0 | case OMPC_use_device_ptr: |
255 | 0 | case OMPC_use_device_addr: |
256 | 0 | case OMPC_is_device_ptr: |
257 | 0 | case OMPC_has_device_addr: |
258 | 0 | case OMPC_unified_address: |
259 | 0 | case OMPC_unified_shared_memory: |
260 | 0 | case OMPC_reverse_offload: |
261 | 0 | case OMPC_dynamic_allocators: |
262 | 0 | case OMPC_atomic_default_mem_order: |
263 | 0 | case OMPC_at: |
264 | 0 | case OMPC_severity: |
265 | 0 | case OMPC_message: |
266 | 0 | case OMPC_device_type: |
267 | 0 | case OMPC_match: |
268 | 0 | case OMPC_nontemporal: |
269 | 0 | case OMPC_order: |
270 | 0 | case OMPC_destroy: |
271 | 0 | case OMPC_novariants: |
272 | 0 | case OMPC_nocontext: |
273 | 0 | case OMPC_detach: |
274 | 0 | case OMPC_inclusive: |
275 | 0 | case OMPC_exclusive: |
276 | 0 | case OMPC_uses_allocators: |
277 | 0 | case OMPC_affinity: |
278 | 0 | case OMPC_when: |
279 | 0 | case OMPC_bind: |
280 | 0 | break; |
281 | 0 | default: |
282 | 0 | break; |
283 | 0 | } |
284 | | |
285 | 0 | return nullptr; |
286 | 0 | } |
287 | | |
288 | | /// Gets the address of the original, non-captured, expression used in the |
289 | | /// clause as the preinitializer. |
290 | 0 | static Stmt **getAddrOfExprAsWritten(Stmt *S) { |
291 | 0 | if (!S) |
292 | 0 | return nullptr; |
293 | 0 | if (auto *DS = dyn_cast<DeclStmt>(S)) { |
294 | 0 | assert(DS->isSingleDecl() && "Only single expression must be captured."); |
295 | 0 | if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl())) |
296 | 0 | return OED->getInitAddress(); |
297 | 0 | } |
298 | 0 | return nullptr; |
299 | 0 | } |
300 | | |
301 | 0 | OMPClause::child_range OMPIfClause::used_children() { |
302 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
303 | 0 | return child_range(C, C + 1); |
304 | 0 | return child_range(&Condition, &Condition + 1); |
305 | 0 | } |
306 | | |
307 | 0 | OMPClause::child_range OMPGrainsizeClause::used_children() { |
308 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
309 | 0 | return child_range(C, C + 1); |
310 | 0 | return child_range(&Grainsize, &Grainsize + 1); |
311 | 0 | } |
312 | | |
313 | 0 | OMPClause::child_range OMPNumTasksClause::used_children() { |
314 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
315 | 0 | return child_range(C, C + 1); |
316 | 0 | return child_range(&NumTasks, &NumTasks + 1); |
317 | 0 | } |
318 | | |
319 | 0 | OMPClause::child_range OMPFinalClause::used_children() { |
320 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
321 | 0 | return child_range(C, C + 1); |
322 | 0 | return children(); |
323 | 0 | } |
324 | | |
325 | 0 | OMPClause::child_range OMPPriorityClause::used_children() { |
326 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
327 | 0 | return child_range(C, C + 1); |
328 | 0 | return child_range(&Priority, &Priority + 1); |
329 | 0 | } |
330 | | |
331 | 0 | OMPClause::child_range OMPNovariantsClause::used_children() { |
332 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
333 | 0 | return child_range(C, C + 1); |
334 | 0 | return children(); |
335 | 0 | } |
336 | | |
337 | 0 | OMPClause::child_range OMPNocontextClause::used_children() { |
338 | 0 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
339 | 0 | return child_range(C, C + 1); |
340 | 0 | return children(); |
341 | 0 | } |
342 | | |
343 | | OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, |
344 | | unsigned NumLoops, |
345 | | SourceLocation StartLoc, |
346 | | SourceLocation LParenLoc, |
347 | 0 | SourceLocation EndLoc) { |
348 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); |
349 | 0 | auto *Clause = |
350 | 0 | new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc); |
351 | 0 | for (unsigned I = 0; I < NumLoops; ++I) { |
352 | 0 | Clause->setLoopNumIterations(I, nullptr); |
353 | 0 | Clause->setLoopCounter(I, nullptr); |
354 | 0 | } |
355 | 0 | return Clause; |
356 | 0 | } |
357 | | |
358 | | OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C, |
359 | 0 | unsigned NumLoops) { |
360 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); |
361 | 0 | auto *Clause = new (Mem) OMPOrderedClause(NumLoops); |
362 | 0 | for (unsigned I = 0; I < NumLoops; ++I) { |
363 | 0 | Clause->setLoopNumIterations(I, nullptr); |
364 | 0 | Clause->setLoopCounter(I, nullptr); |
365 | 0 | } |
366 | 0 | return Clause; |
367 | 0 | } |
368 | | |
369 | | void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, |
370 | 0 | Expr *NumIterations) { |
371 | 0 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
372 | 0 | getTrailingObjects<Expr *>()[NumLoop] = NumIterations; |
373 | 0 | } |
374 | | |
375 | 0 | ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { |
376 | 0 | return llvm::ArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); |
377 | 0 | } |
378 | | |
379 | 0 | void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { |
380 | 0 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
381 | 0 | getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter; |
382 | 0 | } |
383 | | |
384 | 0 | Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) { |
385 | 0 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
386 | 0 | return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; |
387 | 0 | } |
388 | | |
389 | 0 | const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const { |
390 | 0 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
391 | 0 | return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; |
392 | 0 | } |
393 | | |
394 | | OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C, |
395 | | SourceLocation StartLoc, |
396 | 0 | SourceLocation EndLoc) { |
397 | 0 | return new (C) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/false); |
398 | 0 | } |
399 | | |
400 | | OMPUpdateClause * |
401 | | OMPUpdateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
402 | | SourceLocation LParenLoc, SourceLocation ArgumentLoc, |
403 | 0 | OpenMPDependClauseKind DK, SourceLocation EndLoc) { |
404 | 0 | void *Mem = |
405 | 0 | C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1), |
406 | 0 | alignof(OMPUpdateClause)); |
407 | 0 | auto *Clause = |
408 | 0 | new (Mem) OMPUpdateClause(StartLoc, EndLoc, /*IsExtended=*/true); |
409 | 0 | Clause->setLParenLoc(LParenLoc); |
410 | 0 | Clause->setArgumentLoc(ArgumentLoc); |
411 | 0 | Clause->setDependencyKind(DK); |
412 | 0 | return Clause; |
413 | 0 | } |
414 | | |
415 | | OMPUpdateClause *OMPUpdateClause::CreateEmpty(const ASTContext &C, |
416 | 0 | bool IsExtended) { |
417 | 0 | if (!IsExtended) |
418 | 0 | return new (C) OMPUpdateClause(/*IsExtended=*/false); |
419 | 0 | void *Mem = |
420 | 0 | C.Allocate(totalSizeToAlloc<SourceLocation, OpenMPDependClauseKind>(2, 1), |
421 | 0 | alignof(OMPUpdateClause)); |
422 | 0 | auto *Clause = new (Mem) OMPUpdateClause(/*IsExtended=*/true); |
423 | 0 | Clause->IsExtended = true; |
424 | 0 | return Clause; |
425 | 0 | } |
426 | | |
427 | 0 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
428 | 0 | assert(VL.size() == varlist_size() && |
429 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
430 | 0 | std::copy(VL.begin(), VL.end(), varlist_end()); |
431 | 0 | } |
432 | | |
433 | | OMPPrivateClause * |
434 | | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
435 | | SourceLocation LParenLoc, SourceLocation EndLoc, |
436 | 0 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
437 | | // Allocate space for private variables and initializer expressions. |
438 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); |
439 | 0 | OMPPrivateClause *Clause = |
440 | 0 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
441 | 0 | Clause->setVarRefs(VL); |
442 | 0 | Clause->setPrivateCopies(PrivateVL); |
443 | 0 | return Clause; |
444 | 0 | } |
445 | | |
446 | | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
447 | 0 | unsigned N) { |
448 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); |
449 | 0 | return new (Mem) OMPPrivateClause(N); |
450 | 0 | } |
451 | | |
452 | 0 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
453 | 0 | assert(VL.size() == varlist_size() && |
454 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
455 | 0 | std::copy(VL.begin(), VL.end(), varlist_end()); |
456 | 0 | } |
457 | | |
458 | 0 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
459 | 0 | assert(VL.size() == varlist_size() && |
460 | 0 | "Number of inits is not the same as the preallocated buffer"); |
461 | 0 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
462 | 0 | } |
463 | | |
464 | | OMPFirstprivateClause * |
465 | | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
466 | | SourceLocation LParenLoc, SourceLocation EndLoc, |
467 | | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
468 | 0 | ArrayRef<Expr *> InitVL, Stmt *PreInit) { |
469 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); |
470 | 0 | OMPFirstprivateClause *Clause = |
471 | 0 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
472 | 0 | Clause->setVarRefs(VL); |
473 | 0 | Clause->setPrivateCopies(PrivateVL); |
474 | 0 | Clause->setInits(InitVL); |
475 | 0 | Clause->setPreInitStmt(PreInit); |
476 | 0 | return Clause; |
477 | 0 | } |
478 | | |
479 | | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
480 | 0 | unsigned N) { |
481 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); |
482 | 0 | return new (Mem) OMPFirstprivateClause(N); |
483 | 0 | } |
484 | | |
485 | 0 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
486 | 0 | assert(PrivateCopies.size() == varlist_size() && |
487 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
488 | 0 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
489 | 0 | } |
490 | | |
491 | 0 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
492 | 0 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
493 | 0 | "not the same as the " |
494 | 0 | "preallocated buffer"); |
495 | 0 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
496 | 0 | } |
497 | | |
498 | 0 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
499 | 0 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
500 | 0 | "expressions is not the same as " |
501 | 0 | "the preallocated buffer"); |
502 | 0 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
503 | 0 | } |
504 | | |
505 | 0 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
506 | 0 | assert(AssignmentOps.size() == varlist_size() && |
507 | 0 | "Number of assignment expressions is not the same as the preallocated " |
508 | 0 | "buffer"); |
509 | 0 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
510 | 0 | getDestinationExprs().end()); |
511 | 0 | } |
512 | | |
513 | | OMPLastprivateClause *OMPLastprivateClause::Create( |
514 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
515 | | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
516 | | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, |
517 | | OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, |
518 | 0 | SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) { |
519 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
520 | 0 | OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause( |
521 | 0 | StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size()); |
522 | 0 | Clause->setVarRefs(VL); |
523 | 0 | Clause->setSourceExprs(SrcExprs); |
524 | 0 | Clause->setDestinationExprs(DstExprs); |
525 | 0 | Clause->setAssignmentOps(AssignmentOps); |
526 | 0 | Clause->setPreInitStmt(PreInit); |
527 | 0 | Clause->setPostUpdateExpr(PostUpdate); |
528 | 0 | return Clause; |
529 | 0 | } |
530 | | |
531 | | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
532 | 0 | unsigned N) { |
533 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
534 | 0 | return new (Mem) OMPLastprivateClause(N); |
535 | 0 | } |
536 | | |
537 | | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
538 | | SourceLocation StartLoc, |
539 | | SourceLocation LParenLoc, |
540 | | SourceLocation EndLoc, |
541 | 0 | ArrayRef<Expr *> VL) { |
542 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
543 | 0 | OMPSharedClause *Clause = |
544 | 0 | new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
545 | 0 | Clause->setVarRefs(VL); |
546 | 0 | return Clause; |
547 | 0 | } |
548 | | |
549 | 0 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { |
550 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
551 | 0 | return new (Mem) OMPSharedClause(N); |
552 | 0 | } |
553 | | |
554 | 0 | void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { |
555 | 0 | assert(PL.size() == varlist_size() && |
556 | 0 | "Number of privates is not the same as the preallocated buffer"); |
557 | 0 | std::copy(PL.begin(), PL.end(), varlist_end()); |
558 | 0 | } |
559 | | |
560 | 0 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
561 | 0 | assert(IL.size() == varlist_size() && |
562 | 0 | "Number of inits is not the same as the preallocated buffer"); |
563 | 0 | std::copy(IL.begin(), IL.end(), getPrivates().end()); |
564 | 0 | } |
565 | | |
566 | 0 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
567 | 0 | assert(UL.size() == varlist_size() && |
568 | 0 | "Number of updates is not the same as the preallocated buffer"); |
569 | 0 | std::copy(UL.begin(), UL.end(), getInits().end()); |
570 | 0 | } |
571 | | |
572 | 0 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
573 | 0 | assert(FL.size() == varlist_size() && |
574 | 0 | "Number of final updates is not the same as the preallocated buffer"); |
575 | 0 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
576 | 0 | } |
577 | | |
578 | 0 | void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) { |
579 | 0 | assert( |
580 | 0 | UE.size() == varlist_size() + 1 && |
581 | 0 | "Number of used expressions is not the same as the preallocated buffer"); |
582 | 0 | std::copy(UE.begin(), UE.end(), getFinals().end() + 2); |
583 | 0 | } |
584 | | |
585 | | OMPLinearClause *OMPLinearClause::Create( |
586 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
587 | | OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, |
588 | | SourceLocation ColonLoc, SourceLocation StepModifierLoc, |
589 | | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PL, |
590 | | ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, |
591 | 0 | Expr *PostUpdate) { |
592 | | // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions |
593 | | // (Step and CalcStep), list of used expression + step. |
594 | 0 | void *Mem = |
595 | 0 | C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1)); |
596 | 0 | OMPLinearClause *Clause = |
597 | 0 | new (Mem) OMPLinearClause(StartLoc, LParenLoc, Modifier, ModifierLoc, |
598 | 0 | ColonLoc, StepModifierLoc, EndLoc, VL.size()); |
599 | 0 | Clause->setVarRefs(VL); |
600 | 0 | Clause->setPrivates(PL); |
601 | 0 | Clause->setInits(IL); |
602 | | // Fill update and final expressions with zeroes, they are provided later, |
603 | | // after the directive construction. |
604 | 0 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
605 | 0 | nullptr); |
606 | 0 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
607 | 0 | nullptr); |
608 | 0 | std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(), |
609 | 0 | nullptr); |
610 | 0 | Clause->setStep(Step); |
611 | 0 | Clause->setCalcStep(CalcStep); |
612 | 0 | Clause->setPreInitStmt(PreInit); |
613 | 0 | Clause->setPostUpdateExpr(PostUpdate); |
614 | 0 | return Clause; |
615 | 0 | } |
616 | | |
617 | | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
618 | 0 | unsigned NumVars) { |
619 | | // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions |
620 | | // (Step and CalcStep), list of used expression + step. |
621 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1)); |
622 | 0 | return new (Mem) OMPLinearClause(NumVars); |
623 | 0 | } |
624 | | |
625 | 0 | OMPClause::child_range OMPLinearClause::used_children() { |
626 | | // Range includes only non-nullptr elements. |
627 | 0 | return child_range( |
628 | 0 | reinterpret_cast<Stmt **>(getUsedExprs().begin()), |
629 | 0 | reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr))); |
630 | 0 | } |
631 | | |
632 | | OMPAlignedClause * |
633 | | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
634 | | SourceLocation LParenLoc, SourceLocation ColonLoc, |
635 | 0 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
636 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
637 | 0 | OMPAlignedClause *Clause = new (Mem) |
638 | 0 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
639 | 0 | Clause->setVarRefs(VL); |
640 | 0 | Clause->setAlignment(A); |
641 | 0 | return Clause; |
642 | 0 | } |
643 | | |
644 | | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
645 | 0 | unsigned NumVars) { |
646 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); |
647 | 0 | return new (Mem) OMPAlignedClause(NumVars); |
648 | 0 | } |
649 | | |
650 | | OMPAlignClause *OMPAlignClause::Create(const ASTContext &C, Expr *A, |
651 | | SourceLocation StartLoc, |
652 | | SourceLocation LParenLoc, |
653 | 0 | SourceLocation EndLoc) { |
654 | 0 | return new (C) OMPAlignClause(A, StartLoc, LParenLoc, EndLoc); |
655 | 0 | } |
656 | | |
657 | 0 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
658 | 0 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
659 | 0 | "not the same as the " |
660 | 0 | "preallocated buffer"); |
661 | 0 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
662 | 0 | } |
663 | | |
664 | 0 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
665 | 0 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
666 | 0 | "expressions is not the same as " |
667 | 0 | "the preallocated buffer"); |
668 | 0 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
669 | 0 | } |
670 | | |
671 | 0 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
672 | 0 | assert(AssignmentOps.size() == varlist_size() && |
673 | 0 | "Number of assignment expressions is not the same as the preallocated " |
674 | 0 | "buffer"); |
675 | 0 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
676 | 0 | getDestinationExprs().end()); |
677 | 0 | } |
678 | | |
679 | | OMPCopyinClause *OMPCopyinClause::Create( |
680 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
681 | | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
682 | 0 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
683 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
684 | 0 | OMPCopyinClause *Clause = |
685 | 0 | new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
686 | 0 | Clause->setVarRefs(VL); |
687 | 0 | Clause->setSourceExprs(SrcExprs); |
688 | 0 | Clause->setDestinationExprs(DstExprs); |
689 | 0 | Clause->setAssignmentOps(AssignmentOps); |
690 | 0 | return Clause; |
691 | 0 | } |
692 | | |
693 | 0 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { |
694 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
695 | 0 | return new (Mem) OMPCopyinClause(N); |
696 | 0 | } |
697 | | |
698 | 0 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
699 | 0 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
700 | 0 | "not the same as the " |
701 | 0 | "preallocated buffer"); |
702 | 0 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
703 | 0 | } |
704 | | |
705 | 0 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
706 | 0 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
707 | 0 | "expressions is not the same as " |
708 | 0 | "the preallocated buffer"); |
709 | 0 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
710 | 0 | } |
711 | | |
712 | 0 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
713 | 0 | assert(AssignmentOps.size() == varlist_size() && |
714 | 0 | "Number of assignment expressions is not the same as the preallocated " |
715 | 0 | "buffer"); |
716 | 0 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
717 | 0 | getDestinationExprs().end()); |
718 | 0 | } |
719 | | |
720 | | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
721 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
722 | | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
723 | 0 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
724 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
725 | 0 | OMPCopyprivateClause *Clause = |
726 | 0 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
727 | 0 | Clause->setVarRefs(VL); |
728 | 0 | Clause->setSourceExprs(SrcExprs); |
729 | 0 | Clause->setDestinationExprs(DstExprs); |
730 | 0 | Clause->setAssignmentOps(AssignmentOps); |
731 | 0 | return Clause; |
732 | 0 | } |
733 | | |
734 | | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
735 | 0 | unsigned N) { |
736 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
737 | 0 | return new (Mem) OMPCopyprivateClause(N); |
738 | 0 | } |
739 | | |
740 | 0 | void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
741 | 0 | assert(Privates.size() == varlist_size() && |
742 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
743 | 0 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
744 | 0 | } |
745 | | |
746 | 0 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
747 | 0 | assert( |
748 | 0 | LHSExprs.size() == varlist_size() && |
749 | 0 | "Number of LHS expressions is not the same as the preallocated buffer"); |
750 | 0 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
751 | 0 | } |
752 | | |
753 | 0 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
754 | 0 | assert( |
755 | 0 | RHSExprs.size() == varlist_size() && |
756 | 0 | "Number of RHS expressions is not the same as the preallocated buffer"); |
757 | 0 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
758 | 0 | } |
759 | | |
760 | 0 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
761 | 0 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
762 | 0 | "expressions is not the same " |
763 | 0 | "as the preallocated buffer"); |
764 | 0 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
765 | 0 | } |
766 | | |
767 | 0 | void OMPReductionClause::setInscanCopyOps(ArrayRef<Expr *> Ops) { |
768 | 0 | assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); |
769 | 0 | assert(Ops.size() == varlist_size() && "Number of copy " |
770 | 0 | "expressions is not the same " |
771 | 0 | "as the preallocated buffer"); |
772 | 0 | llvm::copy(Ops, getReductionOps().end()); |
773 | 0 | } |
774 | | |
775 | | void OMPReductionClause::setInscanCopyArrayTemps( |
776 | 0 | ArrayRef<Expr *> CopyArrayTemps) { |
777 | 0 | assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); |
778 | 0 | assert(CopyArrayTemps.size() == varlist_size() && |
779 | 0 | "Number of copy temp expressions is not the same as the preallocated " |
780 | 0 | "buffer"); |
781 | 0 | llvm::copy(CopyArrayTemps, getInscanCopyOps().end()); |
782 | 0 | } |
783 | | |
784 | | void OMPReductionClause::setInscanCopyArrayElems( |
785 | 0 | ArrayRef<Expr *> CopyArrayElems) { |
786 | 0 | assert(Modifier == OMPC_REDUCTION_inscan && "Expected inscan reduction."); |
787 | 0 | assert(CopyArrayElems.size() == varlist_size() && |
788 | 0 | "Number of copy temp expressions is not the same as the preallocated " |
789 | 0 | "buffer"); |
790 | 0 | llvm::copy(CopyArrayElems, getInscanCopyArrayTemps().end()); |
791 | 0 | } |
792 | | |
793 | | OMPReductionClause *OMPReductionClause::Create( |
794 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
795 | | SourceLocation ModifierLoc, SourceLocation EndLoc, SourceLocation ColonLoc, |
796 | | OpenMPReductionClauseModifier Modifier, ArrayRef<Expr *> VL, |
797 | | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
798 | | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
799 | | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, |
800 | | ArrayRef<Expr *> CopyOps, ArrayRef<Expr *> CopyArrayTemps, |
801 | 0 | ArrayRef<Expr *> CopyArrayElems, Stmt *PreInit, Expr *PostUpdate) { |
802 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>( |
803 | 0 | (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * VL.size())); |
804 | 0 | auto *Clause = new (Mem) |
805 | 0 | OMPReductionClause(StartLoc, LParenLoc, ModifierLoc, EndLoc, ColonLoc, |
806 | 0 | Modifier, VL.size(), QualifierLoc, NameInfo); |
807 | 0 | Clause->setVarRefs(VL); |
808 | 0 | Clause->setPrivates(Privates); |
809 | 0 | Clause->setLHSExprs(LHSExprs); |
810 | 0 | Clause->setRHSExprs(RHSExprs); |
811 | 0 | Clause->setReductionOps(ReductionOps); |
812 | 0 | Clause->setPreInitStmt(PreInit); |
813 | 0 | Clause->setPostUpdateExpr(PostUpdate); |
814 | 0 | if (Modifier == OMPC_REDUCTION_inscan) { |
815 | 0 | Clause->setInscanCopyOps(CopyOps); |
816 | 0 | Clause->setInscanCopyArrayTemps(CopyArrayTemps); |
817 | 0 | Clause->setInscanCopyArrayElems(CopyArrayElems); |
818 | 0 | } else { |
819 | 0 | assert(CopyOps.empty() && |
820 | 0 | "copy operations are expected in inscan reductions only."); |
821 | 0 | assert(CopyArrayTemps.empty() && |
822 | 0 | "copy array temps are expected in inscan reductions only."); |
823 | 0 | assert(CopyArrayElems.empty() && |
824 | 0 | "copy array temps are expected in inscan reductions only."); |
825 | 0 | } |
826 | 0 | return Clause; |
827 | 0 | } |
828 | | |
829 | | OMPReductionClause * |
830 | | OMPReductionClause::CreateEmpty(const ASTContext &C, unsigned N, |
831 | 0 | OpenMPReductionClauseModifier Modifier) { |
832 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>( |
833 | 0 | (Modifier == OMPC_REDUCTION_inscan ? 8 : 5) * N)); |
834 | 0 | auto *Clause = new (Mem) OMPReductionClause(N); |
835 | 0 | Clause->setModifier(Modifier); |
836 | 0 | return Clause; |
837 | 0 | } |
838 | | |
839 | 0 | void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
840 | 0 | assert(Privates.size() == varlist_size() && |
841 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
842 | 0 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
843 | 0 | } |
844 | | |
845 | 0 | void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
846 | 0 | assert( |
847 | 0 | LHSExprs.size() == varlist_size() && |
848 | 0 | "Number of LHS expressions is not the same as the preallocated buffer"); |
849 | 0 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
850 | 0 | } |
851 | | |
852 | 0 | void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
853 | 0 | assert( |
854 | 0 | RHSExprs.size() == varlist_size() && |
855 | 0 | "Number of RHS expressions is not the same as the preallocated buffer"); |
856 | 0 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
857 | 0 | } |
858 | | |
859 | 0 | void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
860 | 0 | assert(ReductionOps.size() == varlist_size() && "Number of task reduction " |
861 | 0 | "expressions is not the same " |
862 | 0 | "as the preallocated buffer"); |
863 | 0 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
864 | 0 | } |
865 | | |
866 | | OMPTaskReductionClause *OMPTaskReductionClause::Create( |
867 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
868 | | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
869 | | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
870 | | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
871 | | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, |
872 | 0 | Expr *PostUpdate) { |
873 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
874 | 0 | OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause( |
875 | 0 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
876 | 0 | Clause->setVarRefs(VL); |
877 | 0 | Clause->setPrivates(Privates); |
878 | 0 | Clause->setLHSExprs(LHSExprs); |
879 | 0 | Clause->setRHSExprs(RHSExprs); |
880 | 0 | Clause->setReductionOps(ReductionOps); |
881 | 0 | Clause->setPreInitStmt(PreInit); |
882 | 0 | Clause->setPostUpdateExpr(PostUpdate); |
883 | 0 | return Clause; |
884 | 0 | } |
885 | | |
886 | | OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C, |
887 | 0 | unsigned N) { |
888 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
889 | 0 | return new (Mem) OMPTaskReductionClause(N); |
890 | 0 | } |
891 | | |
892 | 0 | void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
893 | 0 | assert(Privates.size() == varlist_size() && |
894 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
895 | 0 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
896 | 0 | } |
897 | | |
898 | 0 | void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
899 | 0 | assert( |
900 | 0 | LHSExprs.size() == varlist_size() && |
901 | 0 | "Number of LHS expressions is not the same as the preallocated buffer"); |
902 | 0 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
903 | 0 | } |
904 | | |
905 | 0 | void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
906 | 0 | assert( |
907 | 0 | RHSExprs.size() == varlist_size() && |
908 | 0 | "Number of RHS expressions is not the same as the preallocated buffer"); |
909 | 0 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
910 | 0 | } |
911 | | |
912 | 0 | void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
913 | 0 | assert(ReductionOps.size() == varlist_size() && "Number of in reduction " |
914 | 0 | "expressions is not the same " |
915 | 0 | "as the preallocated buffer"); |
916 | 0 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
917 | 0 | } |
918 | | |
919 | | void OMPInReductionClause::setTaskgroupDescriptors( |
920 | 0 | ArrayRef<Expr *> TaskgroupDescriptors) { |
921 | 0 | assert(TaskgroupDescriptors.size() == varlist_size() && |
922 | 0 | "Number of in reduction descriptors is not the same as the " |
923 | 0 | "preallocated buffer"); |
924 | 0 | std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(), |
925 | 0 | getReductionOps().end()); |
926 | 0 | } |
927 | | |
928 | | OMPInReductionClause *OMPInReductionClause::Create( |
929 | | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
930 | | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
931 | | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
932 | | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
933 | | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, |
934 | 0 | ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) { |
935 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size())); |
936 | 0 | OMPInReductionClause *Clause = new (Mem) OMPInReductionClause( |
937 | 0 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
938 | 0 | Clause->setVarRefs(VL); |
939 | 0 | Clause->setPrivates(Privates); |
940 | 0 | Clause->setLHSExprs(LHSExprs); |
941 | 0 | Clause->setRHSExprs(RHSExprs); |
942 | 0 | Clause->setReductionOps(ReductionOps); |
943 | 0 | Clause->setTaskgroupDescriptors(TaskgroupDescriptors); |
944 | 0 | Clause->setPreInitStmt(PreInit); |
945 | 0 | Clause->setPostUpdateExpr(PostUpdate); |
946 | 0 | return Clause; |
947 | 0 | } |
948 | | |
949 | | OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C, |
950 | 0 | unsigned N) { |
951 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N)); |
952 | 0 | return new (Mem) OMPInReductionClause(N); |
953 | 0 | } |
954 | | |
955 | | OMPSizesClause *OMPSizesClause::Create(const ASTContext &C, |
956 | | SourceLocation StartLoc, |
957 | | SourceLocation LParenLoc, |
958 | | SourceLocation EndLoc, |
959 | 0 | ArrayRef<Expr *> Sizes) { |
960 | 0 | OMPSizesClause *Clause = CreateEmpty(C, Sizes.size()); |
961 | 0 | Clause->setLocStart(StartLoc); |
962 | 0 | Clause->setLParenLoc(LParenLoc); |
963 | 0 | Clause->setLocEnd(EndLoc); |
964 | 0 | Clause->setSizesRefs(Sizes); |
965 | 0 | return Clause; |
966 | 0 | } |
967 | | |
968 | | OMPSizesClause *OMPSizesClause::CreateEmpty(const ASTContext &C, |
969 | 0 | unsigned NumSizes) { |
970 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumSizes)); |
971 | 0 | return new (Mem) OMPSizesClause(NumSizes); |
972 | 0 | } |
973 | | |
974 | | OMPFullClause *OMPFullClause::Create(const ASTContext &C, |
975 | | SourceLocation StartLoc, |
976 | 0 | SourceLocation EndLoc) { |
977 | 0 | OMPFullClause *Clause = CreateEmpty(C); |
978 | 0 | Clause->setLocStart(StartLoc); |
979 | 0 | Clause->setLocEnd(EndLoc); |
980 | 0 | return Clause; |
981 | 0 | } |
982 | | |
983 | 0 | OMPFullClause *OMPFullClause::CreateEmpty(const ASTContext &C) { |
984 | 0 | return new (C) OMPFullClause(); |
985 | 0 | } |
986 | | |
987 | | OMPPartialClause *OMPPartialClause::Create(const ASTContext &C, |
988 | | SourceLocation StartLoc, |
989 | | SourceLocation LParenLoc, |
990 | | SourceLocation EndLoc, |
991 | 0 | Expr *Factor) { |
992 | 0 | OMPPartialClause *Clause = CreateEmpty(C); |
993 | 0 | Clause->setLocStart(StartLoc); |
994 | 0 | Clause->setLParenLoc(LParenLoc); |
995 | 0 | Clause->setLocEnd(EndLoc); |
996 | 0 | Clause->setFactor(Factor); |
997 | 0 | return Clause; |
998 | 0 | } |
999 | | |
1000 | 0 | OMPPartialClause *OMPPartialClause::CreateEmpty(const ASTContext &C) { |
1001 | 0 | return new (C) OMPPartialClause(); |
1002 | 0 | } |
1003 | | |
1004 | | OMPAllocateClause * |
1005 | | OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
1006 | | SourceLocation LParenLoc, Expr *Allocator, |
1007 | | SourceLocation ColonLoc, SourceLocation EndLoc, |
1008 | 0 | ArrayRef<Expr *> VL) { |
1009 | | // Allocate space for private variables and initializer expressions. |
1010 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
1011 | 0 | auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator, |
1012 | 0 | ColonLoc, EndLoc, VL.size()); |
1013 | 0 | Clause->setVarRefs(VL); |
1014 | 0 | return Clause; |
1015 | 0 | } |
1016 | | |
1017 | | OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C, |
1018 | 0 | unsigned N) { |
1019 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
1020 | 0 | return new (Mem) OMPAllocateClause(N); |
1021 | 0 | } |
1022 | | |
1023 | | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
1024 | | SourceLocation StartLoc, |
1025 | | SourceLocation LParenLoc, |
1026 | | SourceLocation EndLoc, |
1027 | 0 | ArrayRef<Expr *> VL) { |
1028 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
1029 | 0 | OMPFlushClause *Clause = |
1030 | 0 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
1031 | 0 | Clause->setVarRefs(VL); |
1032 | 0 | return Clause; |
1033 | 0 | } |
1034 | | |
1035 | 0 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
1036 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
1037 | 0 | return new (Mem) OMPFlushClause(N); |
1038 | 0 | } |
1039 | | |
1040 | | OMPDepobjClause *OMPDepobjClause::Create(const ASTContext &C, |
1041 | | SourceLocation StartLoc, |
1042 | | SourceLocation LParenLoc, |
1043 | | SourceLocation RParenLoc, |
1044 | 0 | Expr *Depobj) { |
1045 | 0 | auto *Clause = new (C) OMPDepobjClause(StartLoc, LParenLoc, RParenLoc); |
1046 | 0 | Clause->setDepobj(Depobj); |
1047 | 0 | return Clause; |
1048 | 0 | } |
1049 | | |
1050 | 0 | OMPDepobjClause *OMPDepobjClause::CreateEmpty(const ASTContext &C) { |
1051 | 0 | return new (C) OMPDepobjClause(); |
1052 | 0 | } |
1053 | | |
1054 | | OMPDependClause * |
1055 | | OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, |
1056 | | SourceLocation LParenLoc, SourceLocation EndLoc, |
1057 | | DependDataTy Data, Expr *DepModifier, |
1058 | 0 | ArrayRef<Expr *> VL, unsigned NumLoops) { |
1059 | 0 | void *Mem = C.Allocate( |
1060 | 0 | totalSizeToAlloc<Expr *>(VL.size() + /*depend-modifier*/ 1 + NumLoops), |
1061 | 0 | alignof(OMPDependClause)); |
1062 | 0 | OMPDependClause *Clause = new (Mem) |
1063 | 0 | OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); |
1064 | 0 | Clause->setDependencyKind(Data.DepKind); |
1065 | 0 | Clause->setDependencyLoc(Data.DepLoc); |
1066 | 0 | Clause->setColonLoc(Data.ColonLoc); |
1067 | 0 | Clause->setOmpAllMemoryLoc(Data.OmpAllMemoryLoc); |
1068 | 0 | Clause->setModifier(DepModifier); |
1069 | 0 | Clause->setVarRefs(VL); |
1070 | 0 | for (unsigned I = 0 ; I < NumLoops; ++I) |
1071 | 0 | Clause->setLoopData(I, nullptr); |
1072 | 0 | return Clause; |
1073 | 0 | } |
1074 | | |
1075 | | OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N, |
1076 | 0 | unsigned NumLoops) { |
1077 | 0 | void *Mem = |
1078 | 0 | C.Allocate(totalSizeToAlloc<Expr *>(N + /*depend-modifier*/ 1 + NumLoops), |
1079 | 0 | alignof(OMPDependClause)); |
1080 | 0 | return new (Mem) OMPDependClause(N, NumLoops); |
1081 | 0 | } |
1082 | | |
1083 | 0 | void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) { |
1084 | 0 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
1085 | 0 | getDependencyKind() == OMPC_DEPEND_source) && |
1086 | 0 | NumLoop < NumLoops && |
1087 | 0 | "Expected sink or source depend + loop index must be less number of " |
1088 | 0 | "loops."); |
1089 | 0 | auto *It = std::next(getVarRefs().end(), NumLoop + 1); |
1090 | 0 | *It = Cnt; |
1091 | 0 | } |
1092 | | |
1093 | 0 | Expr *OMPDependClause::getLoopData(unsigned NumLoop) { |
1094 | 0 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
1095 | 0 | getDependencyKind() == OMPC_DEPEND_source) && |
1096 | 0 | NumLoop < NumLoops && |
1097 | 0 | "Expected sink or source depend + loop index must be less number of " |
1098 | 0 | "loops."); |
1099 | 0 | auto *It = std::next(getVarRefs().end(), NumLoop + 1); |
1100 | 0 | return *It; |
1101 | 0 | } |
1102 | | |
1103 | 0 | const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const { |
1104 | 0 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
1105 | 0 | getDependencyKind() == OMPC_DEPEND_source) && |
1106 | 0 | NumLoop < NumLoops && |
1107 | 0 | "Expected sink or source depend + loop index must be less number of " |
1108 | 0 | "loops."); |
1109 | 0 | const auto *It = std::next(getVarRefs().end(), NumLoop + 1); |
1110 | 0 | return *It; |
1111 | 0 | } |
1112 | | |
1113 | 0 | void OMPDependClause::setModifier(Expr *DepModifier) { |
1114 | 0 | *getVarRefs().end() = DepModifier; |
1115 | 0 | } |
1116 | 0 | Expr *OMPDependClause::getModifier() { return *getVarRefs().end(); } |
1117 | | |
1118 | | unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( |
1119 | 0 | MappableExprComponentListsRef ComponentLists) { |
1120 | 0 | unsigned TotalNum = 0u; |
1121 | 0 | for (auto &C : ComponentLists) |
1122 | 0 | TotalNum += C.size(); |
1123 | 0 | return TotalNum; |
1124 | 0 | } |
1125 | | |
1126 | | unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( |
1127 | 0 | ArrayRef<const ValueDecl *> Declarations) { |
1128 | 0 | unsigned TotalNum = 0u; |
1129 | 0 | llvm::SmallPtrSet<const ValueDecl *, 8> Cache; |
1130 | 0 | for (const ValueDecl *D : Declarations) { |
1131 | 0 | const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; |
1132 | 0 | if (Cache.count(VD)) |
1133 | 0 | continue; |
1134 | 0 | ++TotalNum; |
1135 | 0 | Cache.insert(VD); |
1136 | 0 | } |
1137 | 0 | return TotalNum; |
1138 | 0 | } |
1139 | | |
1140 | | OMPMapClause *OMPMapClause::Create( |
1141 | | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
1142 | | ArrayRef<ValueDecl *> Declarations, |
1143 | | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
1144 | | Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapModifiers, |
1145 | | ArrayRef<SourceLocation> MapModifiersLoc, |
1146 | | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, |
1147 | 0 | OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) { |
1148 | 0 | OMPMappableExprListSizeTy Sizes; |
1149 | 0 | Sizes.NumVars = Vars.size(); |
1150 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1151 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1152 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1153 | | |
1154 | | // We need to allocate: |
1155 | | // 2 x NumVars x Expr* - we have an original list expression and an associated |
1156 | | // user-defined mapper for each clause list entry. |
1157 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1158 | | // with each component list. |
1159 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1160 | | // number of lists for each unique declaration and the size of each component |
1161 | | // list. |
1162 | | // NumComponents x MappableComponent - the total of all the components in all |
1163 | | // the lists. |
1164 | 0 | void *Mem = C.Allocate( |
1165 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1166 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1167 | 0 | 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations, |
1168 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1169 | 0 | Sizes.NumComponents)); |
1170 | 0 | OMPMapClause *Clause = new (Mem) |
1171 | 0 | OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId, |
1172 | 0 | Type, TypeIsImplicit, TypeLoc, Locs, Sizes); |
1173 | |
|
1174 | 0 | Clause->setVarRefs(Vars); |
1175 | 0 | Clause->setUDMapperRefs(UDMapperRefs); |
1176 | 0 | Clause->setIteratorModifier(IteratorModifier); |
1177 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1178 | 0 | Clause->setMapType(Type); |
1179 | 0 | Clause->setMapLoc(TypeLoc); |
1180 | 0 | return Clause; |
1181 | 0 | } |
1182 | | |
1183 | | OMPMapClause * |
1184 | | OMPMapClause::CreateEmpty(const ASTContext &C, |
1185 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1186 | 0 | void *Mem = C.Allocate( |
1187 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1188 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1189 | 0 | 2 * Sizes.NumVars + 1, Sizes.NumUniqueDeclarations, |
1190 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1191 | 0 | Sizes.NumComponents)); |
1192 | 0 | OMPMapClause *Clause = new (Mem) OMPMapClause(Sizes); |
1193 | 0 | Clause->setIteratorModifier(nullptr); |
1194 | 0 | return Clause; |
1195 | 0 | } |
1196 | | |
1197 | | OMPToClause *OMPToClause::Create( |
1198 | | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
1199 | | ArrayRef<ValueDecl *> Declarations, |
1200 | | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
1201 | | ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
1202 | | ArrayRef<SourceLocation> MotionModifiersLoc, |
1203 | 0 | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { |
1204 | 0 | OMPMappableExprListSizeTy Sizes; |
1205 | 0 | Sizes.NumVars = Vars.size(); |
1206 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1207 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1208 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1209 | | |
1210 | | // We need to allocate: |
1211 | | // 2 x NumVars x Expr* - we have an original list expression and an associated |
1212 | | // user-defined mapper for each clause list entry. |
1213 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1214 | | // with each component list. |
1215 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1216 | | // number of lists for each unique declaration and the size of each component |
1217 | | // list. |
1218 | | // NumComponents x MappableComponent - the total of all the components in all |
1219 | | // the lists. |
1220 | 0 | void *Mem = C.Allocate( |
1221 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1222 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1223 | 0 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1224 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1225 | 0 | Sizes.NumComponents)); |
1226 | |
|
1227 | 0 | auto *Clause = new (Mem) OMPToClause(MotionModifiers, MotionModifiersLoc, |
1228 | 0 | UDMQualifierLoc, MapperId, Locs, Sizes); |
1229 | |
|
1230 | 0 | Clause->setVarRefs(Vars); |
1231 | 0 | Clause->setUDMapperRefs(UDMapperRefs); |
1232 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1233 | 0 | return Clause; |
1234 | 0 | } |
1235 | | |
1236 | | OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, |
1237 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1238 | 0 | void *Mem = C.Allocate( |
1239 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1240 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1241 | 0 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1242 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1243 | 0 | Sizes.NumComponents)); |
1244 | 0 | return new (Mem) OMPToClause(Sizes); |
1245 | 0 | } |
1246 | | |
1247 | | OMPFromClause *OMPFromClause::Create( |
1248 | | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
1249 | | ArrayRef<ValueDecl *> Declarations, |
1250 | | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
1251 | | ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
1252 | | ArrayRef<SourceLocation> MotionModifiersLoc, |
1253 | 0 | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { |
1254 | 0 | OMPMappableExprListSizeTy Sizes; |
1255 | 0 | Sizes.NumVars = Vars.size(); |
1256 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1257 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1258 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1259 | | |
1260 | | // We need to allocate: |
1261 | | // 2 x NumVars x Expr* - we have an original list expression and an associated |
1262 | | // user-defined mapper for each clause list entry. |
1263 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1264 | | // with each component list. |
1265 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1266 | | // number of lists for each unique declaration and the size of each component |
1267 | | // list. |
1268 | | // NumComponents x MappableComponent - the total of all the components in all |
1269 | | // the lists. |
1270 | 0 | void *Mem = C.Allocate( |
1271 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1272 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1273 | 0 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1274 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1275 | 0 | Sizes.NumComponents)); |
1276 | |
|
1277 | 0 | auto *Clause = |
1278 | 0 | new (Mem) OMPFromClause(MotionModifiers, MotionModifiersLoc, |
1279 | 0 | UDMQualifierLoc, MapperId, Locs, Sizes); |
1280 | |
|
1281 | 0 | Clause->setVarRefs(Vars); |
1282 | 0 | Clause->setUDMapperRefs(UDMapperRefs); |
1283 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1284 | 0 | return Clause; |
1285 | 0 | } |
1286 | | |
1287 | | OMPFromClause * |
1288 | | OMPFromClause::CreateEmpty(const ASTContext &C, |
1289 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1290 | 0 | void *Mem = C.Allocate( |
1291 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1292 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1293 | 0 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1294 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1295 | 0 | Sizes.NumComponents)); |
1296 | 0 | return new (Mem) OMPFromClause(Sizes); |
1297 | 0 | } |
1298 | | |
1299 | 0 | void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
1300 | 0 | assert(VL.size() == varlist_size() && |
1301 | 0 | "Number of private copies is not the same as the preallocated buffer"); |
1302 | 0 | std::copy(VL.begin(), VL.end(), varlist_end()); |
1303 | 0 | } |
1304 | | |
1305 | 0 | void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) { |
1306 | 0 | assert(VL.size() == varlist_size() && |
1307 | 0 | "Number of inits is not the same as the preallocated buffer"); |
1308 | 0 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
1309 | 0 | } |
1310 | | |
1311 | | OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create( |
1312 | | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
1313 | | ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, |
1314 | | ArrayRef<ValueDecl *> Declarations, |
1315 | 0 | MappableExprComponentListsRef ComponentLists) { |
1316 | 0 | OMPMappableExprListSizeTy Sizes; |
1317 | 0 | Sizes.NumVars = Vars.size(); |
1318 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1319 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1320 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1321 | | |
1322 | | // We need to allocate: |
1323 | | // NumVars x Expr* - we have an original list expression for each clause |
1324 | | // list entry. |
1325 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1326 | | // with each component list. |
1327 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1328 | | // number of lists for each unique declaration and the size of each component |
1329 | | // list. |
1330 | | // NumComponents x MappableComponent - the total of all the components in all |
1331 | | // the lists. |
1332 | 0 | void *Mem = C.Allocate( |
1333 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1334 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1335 | 0 | 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1336 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1337 | 0 | Sizes.NumComponents)); |
1338 | |
|
1339 | 0 | OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes); |
1340 | |
|
1341 | 0 | Clause->setVarRefs(Vars); |
1342 | 0 | Clause->setPrivateCopies(PrivateVars); |
1343 | 0 | Clause->setInits(Inits); |
1344 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1345 | 0 | return Clause; |
1346 | 0 | } |
1347 | | |
1348 | | OMPUseDevicePtrClause * |
1349 | | OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C, |
1350 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1351 | 0 | void *Mem = C.Allocate( |
1352 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1353 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1354 | 0 | 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1355 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1356 | 0 | Sizes.NumComponents)); |
1357 | 0 | return new (Mem) OMPUseDevicePtrClause(Sizes); |
1358 | 0 | } |
1359 | | |
1360 | | OMPUseDeviceAddrClause * |
1361 | | OMPUseDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, |
1362 | | ArrayRef<Expr *> Vars, |
1363 | | ArrayRef<ValueDecl *> Declarations, |
1364 | 0 | MappableExprComponentListsRef ComponentLists) { |
1365 | 0 | OMPMappableExprListSizeTy Sizes; |
1366 | 0 | Sizes.NumVars = Vars.size(); |
1367 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1368 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1369 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1370 | | |
1371 | | // We need to allocate: |
1372 | | // 3 x NumVars x Expr* - we have an original list expression for each clause |
1373 | | // list entry and an equal number of private copies and inits. |
1374 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1375 | | // with each component list. |
1376 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1377 | | // number of lists for each unique declaration and the size of each component |
1378 | | // list. |
1379 | | // NumComponents x MappableComponent - the total of all the components in all |
1380 | | // the lists. |
1381 | 0 | void *Mem = C.Allocate( |
1382 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1383 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1384 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1385 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1386 | 0 | Sizes.NumComponents)); |
1387 | |
|
1388 | 0 | auto *Clause = new (Mem) OMPUseDeviceAddrClause(Locs, Sizes); |
1389 | |
|
1390 | 0 | Clause->setVarRefs(Vars); |
1391 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1392 | 0 | return Clause; |
1393 | 0 | } |
1394 | | |
1395 | | OMPUseDeviceAddrClause * |
1396 | | OMPUseDeviceAddrClause::CreateEmpty(const ASTContext &C, |
1397 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1398 | 0 | void *Mem = C.Allocate( |
1399 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1400 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1401 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1402 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1403 | 0 | Sizes.NumComponents)); |
1404 | 0 | return new (Mem) OMPUseDeviceAddrClause(Sizes); |
1405 | 0 | } |
1406 | | |
1407 | | OMPIsDevicePtrClause * |
1408 | | OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, |
1409 | | ArrayRef<Expr *> Vars, |
1410 | | ArrayRef<ValueDecl *> Declarations, |
1411 | 0 | MappableExprComponentListsRef ComponentLists) { |
1412 | 0 | OMPMappableExprListSizeTy Sizes; |
1413 | 0 | Sizes.NumVars = Vars.size(); |
1414 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1415 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1416 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1417 | | |
1418 | | // We need to allocate: |
1419 | | // NumVars x Expr* - we have an original list expression for each clause list |
1420 | | // entry. |
1421 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1422 | | // with each component list. |
1423 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1424 | | // number of lists for each unique declaration and the size of each component |
1425 | | // list. |
1426 | | // NumComponents x MappableComponent - the total of all the components in all |
1427 | | // the lists. |
1428 | 0 | void *Mem = C.Allocate( |
1429 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1430 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1431 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1432 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1433 | 0 | Sizes.NumComponents)); |
1434 | |
|
1435 | 0 | OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes); |
1436 | |
|
1437 | 0 | Clause->setVarRefs(Vars); |
1438 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1439 | 0 | return Clause; |
1440 | 0 | } |
1441 | | |
1442 | | OMPIsDevicePtrClause * |
1443 | | OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C, |
1444 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1445 | 0 | void *Mem = C.Allocate( |
1446 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1447 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1448 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1449 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1450 | 0 | Sizes.NumComponents)); |
1451 | 0 | return new (Mem) OMPIsDevicePtrClause(Sizes); |
1452 | 0 | } |
1453 | | |
1454 | | OMPHasDeviceAddrClause * |
1455 | | OMPHasDeviceAddrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, |
1456 | | ArrayRef<Expr *> Vars, |
1457 | | ArrayRef<ValueDecl *> Declarations, |
1458 | 0 | MappableExprComponentListsRef ComponentLists) { |
1459 | 0 | OMPMappableExprListSizeTy Sizes; |
1460 | 0 | Sizes.NumVars = Vars.size(); |
1461 | 0 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
1462 | 0 | Sizes.NumComponentLists = ComponentLists.size(); |
1463 | 0 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
1464 | | |
1465 | | // We need to allocate: |
1466 | | // NumVars x Expr* - we have an original list expression for each clause list |
1467 | | // entry. |
1468 | | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
1469 | | // with each component list. |
1470 | | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
1471 | | // number of lists for each unique declaration and the size of each component |
1472 | | // list. |
1473 | | // NumComponents x MappableComponent - the total of all the components in all |
1474 | | // the lists. |
1475 | 0 | void *Mem = C.Allocate( |
1476 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1477 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1478 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1479 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1480 | 0 | Sizes.NumComponents)); |
1481 | |
|
1482 | 0 | auto *Clause = new (Mem) OMPHasDeviceAddrClause(Locs, Sizes); |
1483 | |
|
1484 | 0 | Clause->setVarRefs(Vars); |
1485 | 0 | Clause->setClauseInfo(Declarations, ComponentLists); |
1486 | 0 | return Clause; |
1487 | 0 | } |
1488 | | |
1489 | | OMPHasDeviceAddrClause * |
1490 | | OMPHasDeviceAddrClause::CreateEmpty(const ASTContext &C, |
1491 | 0 | const OMPMappableExprListSizeTy &Sizes) { |
1492 | 0 | void *Mem = C.Allocate( |
1493 | 0 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
1494 | 0 | OMPClauseMappableExprCommon::MappableComponent>( |
1495 | 0 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
1496 | 0 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
1497 | 0 | Sizes.NumComponents)); |
1498 | 0 | return new (Mem) OMPHasDeviceAddrClause(Sizes); |
1499 | 0 | } |
1500 | | |
1501 | | OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C, |
1502 | | SourceLocation StartLoc, |
1503 | | SourceLocation LParenLoc, |
1504 | | SourceLocation EndLoc, |
1505 | 0 | ArrayRef<Expr *> VL) { |
1506 | | // Allocate space for nontemporal variables + private references. |
1507 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); |
1508 | 0 | auto *Clause = |
1509 | 0 | new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
1510 | 0 | Clause->setVarRefs(VL); |
1511 | 0 | return Clause; |
1512 | 0 | } |
1513 | | |
1514 | | OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C, |
1515 | 0 | unsigned N) { |
1516 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); |
1517 | 0 | return new (Mem) OMPNontemporalClause(N); |
1518 | 0 | } |
1519 | | |
1520 | 0 | void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) { |
1521 | 0 | assert(VL.size() == varlist_size() && "Number of private references is not " |
1522 | 0 | "the same as the preallocated buffer"); |
1523 | 0 | std::copy(VL.begin(), VL.end(), varlist_end()); |
1524 | 0 | } |
1525 | | |
1526 | | OMPInclusiveClause *OMPInclusiveClause::Create(const ASTContext &C, |
1527 | | SourceLocation StartLoc, |
1528 | | SourceLocation LParenLoc, |
1529 | | SourceLocation EndLoc, |
1530 | 0 | ArrayRef<Expr *> VL) { |
1531 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
1532 | 0 | auto *Clause = |
1533 | 0 | new (Mem) OMPInclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
1534 | 0 | Clause->setVarRefs(VL); |
1535 | 0 | return Clause; |
1536 | 0 | } |
1537 | | |
1538 | | OMPInclusiveClause *OMPInclusiveClause::CreateEmpty(const ASTContext &C, |
1539 | 0 | unsigned N) { |
1540 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
1541 | 0 | return new (Mem) OMPInclusiveClause(N); |
1542 | 0 | } |
1543 | | |
1544 | | OMPExclusiveClause *OMPExclusiveClause::Create(const ASTContext &C, |
1545 | | SourceLocation StartLoc, |
1546 | | SourceLocation LParenLoc, |
1547 | | SourceLocation EndLoc, |
1548 | 0 | ArrayRef<Expr *> VL) { |
1549 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
1550 | 0 | auto *Clause = |
1551 | 0 | new (Mem) OMPExclusiveClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
1552 | 0 | Clause->setVarRefs(VL); |
1553 | 0 | return Clause; |
1554 | 0 | } |
1555 | | |
1556 | | OMPExclusiveClause *OMPExclusiveClause::CreateEmpty(const ASTContext &C, |
1557 | 0 | unsigned N) { |
1558 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
1559 | 0 | return new (Mem) OMPExclusiveClause(N); |
1560 | 0 | } |
1561 | | |
1562 | | void OMPUsesAllocatorsClause::setAllocatorsData( |
1563 | 0 | ArrayRef<OMPUsesAllocatorsClause::Data> Data) { |
1564 | 0 | assert(Data.size() == NumOfAllocators && |
1565 | 0 | "Size of allocators data is not the same as the preallocated buffer."); |
1566 | 0 | for (unsigned I = 0, E = Data.size(); I < E; ++I) { |
1567 | 0 | const OMPUsesAllocatorsClause::Data &D = Data[I]; |
1568 | 0 | getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + |
1569 | 0 | static_cast<int>(ExprOffsets::Allocator)] = |
1570 | 0 | D.Allocator; |
1571 | 0 | getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + |
1572 | 0 | static_cast<int>( |
1573 | 0 | ExprOffsets::AllocatorTraits)] = |
1574 | 0 | D.AllocatorTraits; |
1575 | 0 | getTrailingObjects< |
1576 | 0 | SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + |
1577 | 0 | static_cast<int>(ParenLocsOffsets::LParen)] = |
1578 | 0 | D.LParenLoc; |
1579 | 0 | getTrailingObjects< |
1580 | 0 | SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + |
1581 | 0 | static_cast<int>(ParenLocsOffsets::RParen)] = |
1582 | 0 | D.RParenLoc; |
1583 | 0 | } |
1584 | 0 | } |
1585 | | |
1586 | | OMPUsesAllocatorsClause::Data |
1587 | 0 | OMPUsesAllocatorsClause::getAllocatorData(unsigned I) const { |
1588 | 0 | OMPUsesAllocatorsClause::Data Data; |
1589 | 0 | Data.Allocator = |
1590 | 0 | getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + |
1591 | 0 | static_cast<int>(ExprOffsets::Allocator)]; |
1592 | 0 | Data.AllocatorTraits = |
1593 | 0 | getTrailingObjects<Expr *>()[I * static_cast<int>(ExprOffsets::Total) + |
1594 | 0 | static_cast<int>( |
1595 | 0 | ExprOffsets::AllocatorTraits)]; |
1596 | 0 | Data.LParenLoc = getTrailingObjects< |
1597 | 0 | SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + |
1598 | 0 | static_cast<int>(ParenLocsOffsets::LParen)]; |
1599 | 0 | Data.RParenLoc = getTrailingObjects< |
1600 | 0 | SourceLocation>()[I * static_cast<int>(ParenLocsOffsets::Total) + |
1601 | 0 | static_cast<int>(ParenLocsOffsets::RParen)]; |
1602 | 0 | return Data; |
1603 | 0 | } |
1604 | | |
1605 | | OMPUsesAllocatorsClause * |
1606 | | OMPUsesAllocatorsClause::Create(const ASTContext &C, SourceLocation StartLoc, |
1607 | | SourceLocation LParenLoc, SourceLocation EndLoc, |
1608 | 0 | ArrayRef<OMPUsesAllocatorsClause::Data> Data) { |
1609 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>( |
1610 | 0 | static_cast<int>(ExprOffsets::Total) * Data.size(), |
1611 | 0 | static_cast<int>(ParenLocsOffsets::Total) * Data.size())); |
1612 | 0 | auto *Clause = new (Mem) |
1613 | 0 | OMPUsesAllocatorsClause(StartLoc, LParenLoc, EndLoc, Data.size()); |
1614 | 0 | Clause->setAllocatorsData(Data); |
1615 | 0 | return Clause; |
1616 | 0 | } |
1617 | | |
1618 | | OMPUsesAllocatorsClause * |
1619 | 0 | OMPUsesAllocatorsClause::CreateEmpty(const ASTContext &C, unsigned N) { |
1620 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *, SourceLocation>( |
1621 | 0 | static_cast<int>(ExprOffsets::Total) * N, |
1622 | 0 | static_cast<int>(ParenLocsOffsets::Total) * N)); |
1623 | 0 | return new (Mem) OMPUsesAllocatorsClause(N); |
1624 | 0 | } |
1625 | | |
1626 | | OMPAffinityClause * |
1627 | | OMPAffinityClause::Create(const ASTContext &C, SourceLocation StartLoc, |
1628 | | SourceLocation LParenLoc, SourceLocation ColonLoc, |
1629 | | SourceLocation EndLoc, Expr *Modifier, |
1630 | 0 | ArrayRef<Expr *> Locators) { |
1631 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Locators.size() + 1)); |
1632 | 0 | auto *Clause = new (Mem) |
1633 | 0 | OMPAffinityClause(StartLoc, LParenLoc, ColonLoc, EndLoc, Locators.size()); |
1634 | 0 | Clause->setModifier(Modifier); |
1635 | 0 | Clause->setVarRefs(Locators); |
1636 | 0 | return Clause; |
1637 | 0 | } |
1638 | | |
1639 | | OMPAffinityClause *OMPAffinityClause::CreateEmpty(const ASTContext &C, |
1640 | 0 | unsigned N) { |
1641 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1)); |
1642 | 0 | return new (Mem) OMPAffinityClause(N); |
1643 | 0 | } |
1644 | | |
1645 | | OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar, |
1646 | | OMPInteropInfo &InteropInfo, |
1647 | | SourceLocation StartLoc, |
1648 | | SourceLocation LParenLoc, |
1649 | | SourceLocation VarLoc, |
1650 | 0 | SourceLocation EndLoc) { |
1651 | |
|
1652 | 0 | void *Mem = |
1653 | 0 | C.Allocate(totalSizeToAlloc<Expr *>(InteropInfo.PreferTypes.size() + 1)); |
1654 | 0 | auto *Clause = new (Mem) OMPInitClause( |
1655 | 0 | InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc, |
1656 | 0 | VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1); |
1657 | 0 | Clause->setInteropVar(InteropVar); |
1658 | 0 | llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1); |
1659 | 0 | return Clause; |
1660 | 0 | } |
1661 | | |
1662 | 0 | OMPInitClause *OMPInitClause::CreateEmpty(const ASTContext &C, unsigned N) { |
1663 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
1664 | 0 | return new (Mem) OMPInitClause(N); |
1665 | 0 | } |
1666 | | |
1667 | | OMPBindClause * |
1668 | | OMPBindClause::Create(const ASTContext &C, OpenMPBindClauseKind K, |
1669 | | SourceLocation KLoc, SourceLocation StartLoc, |
1670 | 0 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
1671 | 0 | return new (C) OMPBindClause(K, KLoc, StartLoc, LParenLoc, EndLoc); |
1672 | 0 | } |
1673 | | |
1674 | 0 | OMPBindClause *OMPBindClause::CreateEmpty(const ASTContext &C) { |
1675 | 0 | return new (C) OMPBindClause(); |
1676 | 0 | } |
1677 | | |
1678 | | OMPDoacrossClause * |
1679 | | OMPDoacrossClause::Create(const ASTContext &C, SourceLocation StartLoc, |
1680 | | SourceLocation LParenLoc, SourceLocation EndLoc, |
1681 | | OpenMPDoacrossClauseModifier DepType, |
1682 | | SourceLocation DepLoc, SourceLocation ColonLoc, |
1683 | 0 | ArrayRef<Expr *> VL, unsigned NumLoops) { |
1684 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops), |
1685 | 0 | alignof(OMPDoacrossClause)); |
1686 | 0 | OMPDoacrossClause *Clause = new (Mem) |
1687 | 0 | OMPDoacrossClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); |
1688 | 0 | Clause->setDependenceType(DepType); |
1689 | 0 | Clause->setDependenceLoc(DepLoc); |
1690 | 0 | Clause->setColonLoc(ColonLoc); |
1691 | 0 | Clause->setVarRefs(VL); |
1692 | 0 | for (unsigned I = 0; I < NumLoops; ++I) |
1693 | 0 | Clause->setLoopData(I, nullptr); |
1694 | 0 | return Clause; |
1695 | 0 | } |
1696 | | |
1697 | | OMPDoacrossClause *OMPDoacrossClause::CreateEmpty(const ASTContext &C, |
1698 | | unsigned N, |
1699 | 0 | unsigned NumLoops) { |
1700 | 0 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops), |
1701 | 0 | alignof(OMPDoacrossClause)); |
1702 | 0 | return new (Mem) OMPDoacrossClause(N, NumLoops); |
1703 | 0 | } |
1704 | | |
1705 | 0 | void OMPDoacrossClause::setLoopData(unsigned NumLoop, Expr *Cnt) { |
1706 | 0 | assert(NumLoop < NumLoops && "Loop index must be less number of loops."); |
1707 | 0 | auto *It = std::next(getVarRefs().end(), NumLoop); |
1708 | 0 | *It = Cnt; |
1709 | 0 | } |
1710 | | |
1711 | 0 | Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) { |
1712 | 0 | assert(NumLoop < NumLoops && "Loop index must be less number of loops."); |
1713 | 0 | auto *It = std::next(getVarRefs().end(), NumLoop); |
1714 | 0 | return *It; |
1715 | 0 | } |
1716 | | |
1717 | 0 | const Expr *OMPDoacrossClause::getLoopData(unsigned NumLoop) const { |
1718 | 0 | assert(NumLoop < NumLoops && "Loop index must be less number of loops."); |
1719 | 0 | const auto *It = std::next(getVarRefs().end(), NumLoop); |
1720 | 0 | return *It; |
1721 | 0 | } |
1722 | | |
1723 | | //===----------------------------------------------------------------------===// |
1724 | | // OpenMP clauses printing methods |
1725 | | //===----------------------------------------------------------------------===// |
1726 | | |
1727 | 0 | void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { |
1728 | 0 | OS << "if("; |
1729 | 0 | if (Node->getNameModifier() != OMPD_unknown) |
1730 | 0 | OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": "; |
1731 | 0 | Node->getCondition()->printPretty(OS, nullptr, Policy, 0); |
1732 | 0 | OS << ")"; |
1733 | 0 | } |
1734 | | |
1735 | 0 | void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) { |
1736 | 0 | OS << "final("; |
1737 | 0 | Node->getCondition()->printPretty(OS, nullptr, Policy, 0); |
1738 | 0 | OS << ")"; |
1739 | 0 | } |
1740 | | |
1741 | 0 | void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) { |
1742 | 0 | OS << "num_threads("; |
1743 | 0 | Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0); |
1744 | 0 | OS << ")"; |
1745 | 0 | } |
1746 | | |
1747 | 0 | void OMPClausePrinter::VisitOMPAlignClause(OMPAlignClause *Node) { |
1748 | 0 | OS << "align("; |
1749 | 0 | Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); |
1750 | 0 | OS << ")"; |
1751 | 0 | } |
1752 | | |
1753 | 0 | void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { |
1754 | 0 | OS << "safelen("; |
1755 | 0 | Node->getSafelen()->printPretty(OS, nullptr, Policy, 0); |
1756 | 0 | OS << ")"; |
1757 | 0 | } |
1758 | | |
1759 | 0 | void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) { |
1760 | 0 | OS << "simdlen("; |
1761 | 0 | Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0); |
1762 | 0 | OS << ")"; |
1763 | 0 | } |
1764 | | |
1765 | 0 | void OMPClausePrinter::VisitOMPSizesClause(OMPSizesClause *Node) { |
1766 | 0 | OS << "sizes("; |
1767 | 0 | bool First = true; |
1768 | 0 | for (auto *Size : Node->getSizesRefs()) { |
1769 | 0 | if (!First) |
1770 | 0 | OS << ", "; |
1771 | 0 | Size->printPretty(OS, nullptr, Policy, 0); |
1772 | 0 | First = false; |
1773 | 0 | } |
1774 | 0 | OS << ")"; |
1775 | 0 | } |
1776 | | |
1777 | 0 | void OMPClausePrinter::VisitOMPFullClause(OMPFullClause *Node) { OS << "full"; } |
1778 | | |
1779 | 0 | void OMPClausePrinter::VisitOMPPartialClause(OMPPartialClause *Node) { |
1780 | 0 | OS << "partial"; |
1781 | |
|
1782 | 0 | if (Expr *Factor = Node->getFactor()) { |
1783 | 0 | OS << '('; |
1784 | 0 | Factor->printPretty(OS, nullptr, Policy, 0); |
1785 | 0 | OS << ')'; |
1786 | 0 | } |
1787 | 0 | } |
1788 | | |
1789 | 0 | void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) { |
1790 | 0 | OS << "allocator("; |
1791 | 0 | Node->getAllocator()->printPretty(OS, nullptr, Policy, 0); |
1792 | 0 | OS << ")"; |
1793 | 0 | } |
1794 | | |
1795 | 0 | void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) { |
1796 | 0 | OS << "collapse("; |
1797 | 0 | Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0); |
1798 | 0 | OS << ")"; |
1799 | 0 | } |
1800 | | |
1801 | 0 | void OMPClausePrinter::VisitOMPDetachClause(OMPDetachClause *Node) { |
1802 | 0 | OS << "detach("; |
1803 | 0 | Node->getEventHandler()->printPretty(OS, nullptr, Policy, 0); |
1804 | 0 | OS << ")"; |
1805 | 0 | } |
1806 | | |
1807 | 0 | void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { |
1808 | 0 | OS << "default(" |
1809 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_default, |
1810 | 0 | unsigned(Node->getDefaultKind())) |
1811 | 0 | << ")"; |
1812 | 0 | } |
1813 | | |
1814 | 0 | void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) { |
1815 | 0 | OS << "proc_bind(" |
1816 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, |
1817 | 0 | unsigned(Node->getProcBindKind())) |
1818 | 0 | << ")"; |
1819 | 0 | } |
1820 | | |
1821 | 0 | void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) { |
1822 | 0 | OS << "unified_address"; |
1823 | 0 | } |
1824 | | |
1825 | | void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause( |
1826 | 0 | OMPUnifiedSharedMemoryClause *) { |
1827 | 0 | OS << "unified_shared_memory"; |
1828 | 0 | } |
1829 | | |
1830 | 0 | void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) { |
1831 | 0 | OS << "reverse_offload"; |
1832 | 0 | } |
1833 | | |
1834 | | void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( |
1835 | 0 | OMPDynamicAllocatorsClause *) { |
1836 | 0 | OS << "dynamic_allocators"; |
1837 | 0 | } |
1838 | | |
1839 | | void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause( |
1840 | 0 | OMPAtomicDefaultMemOrderClause *Node) { |
1841 | 0 | OS << "atomic_default_mem_order(" |
1842 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order, |
1843 | 0 | Node->getAtomicDefaultMemOrderKind()) |
1844 | 0 | << ")"; |
1845 | 0 | } |
1846 | | |
1847 | 0 | void OMPClausePrinter::VisitOMPAtClause(OMPAtClause *Node) { |
1848 | 0 | OS << "at(" << getOpenMPSimpleClauseTypeName(OMPC_at, Node->getAtKind()) |
1849 | 0 | << ")"; |
1850 | 0 | } |
1851 | | |
1852 | 0 | void OMPClausePrinter::VisitOMPSeverityClause(OMPSeverityClause *Node) { |
1853 | 0 | OS << "severity(" |
1854 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_severity, Node->getSeverityKind()) |
1855 | 0 | << ")"; |
1856 | 0 | } |
1857 | | |
1858 | 0 | void OMPClausePrinter::VisitOMPMessageClause(OMPMessageClause *Node) { |
1859 | 0 | OS << "message(\"" |
1860 | 0 | << cast<StringLiteral>(Node->getMessageString())->getString() << "\")"; |
1861 | 0 | } |
1862 | | |
1863 | 0 | void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { |
1864 | 0 | OS << "schedule("; |
1865 | 0 | if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { |
1866 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, |
1867 | 0 | Node->getFirstScheduleModifier()); |
1868 | 0 | if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { |
1869 | 0 | OS << ", "; |
1870 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, |
1871 | 0 | Node->getSecondScheduleModifier()); |
1872 | 0 | } |
1873 | 0 | OS << ": "; |
1874 | 0 | } |
1875 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind()); |
1876 | 0 | if (auto *E = Node->getChunkSize()) { |
1877 | 0 | OS << ", "; |
1878 | 0 | E->printPretty(OS, nullptr, Policy); |
1879 | 0 | } |
1880 | 0 | OS << ")"; |
1881 | 0 | } |
1882 | | |
1883 | 0 | void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) { |
1884 | 0 | OS << "ordered"; |
1885 | 0 | if (auto *Num = Node->getNumForLoops()) { |
1886 | 0 | OS << "("; |
1887 | 0 | Num->printPretty(OS, nullptr, Policy, 0); |
1888 | 0 | OS << ")"; |
1889 | 0 | } |
1890 | 0 | } |
1891 | | |
1892 | 0 | void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { |
1893 | 0 | OS << "nowait"; |
1894 | 0 | } |
1895 | | |
1896 | 0 | void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) { |
1897 | 0 | OS << "untied"; |
1898 | 0 | } |
1899 | | |
1900 | 0 | void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) { |
1901 | 0 | OS << "nogroup"; |
1902 | 0 | } |
1903 | | |
1904 | 0 | void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) { |
1905 | 0 | OS << "mergeable"; |
1906 | 0 | } |
1907 | | |
1908 | 0 | void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; } |
1909 | | |
1910 | 0 | void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; } |
1911 | | |
1912 | 0 | void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *Node) { |
1913 | 0 | OS << "update"; |
1914 | 0 | if (Node->isExtended()) { |
1915 | 0 | OS << "("; |
1916 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), |
1917 | 0 | Node->getDependencyKind()); |
1918 | 0 | OS << ")"; |
1919 | 0 | } |
1920 | 0 | } |
1921 | | |
1922 | 0 | void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { |
1923 | 0 | OS << "capture"; |
1924 | 0 | } |
1925 | | |
1926 | 0 | void OMPClausePrinter::VisitOMPCompareClause(OMPCompareClause *) { |
1927 | 0 | OS << "compare"; |
1928 | 0 | } |
1929 | | |
1930 | 0 | void OMPClausePrinter::VisitOMPFailClause(OMPFailClause *Node) { |
1931 | 0 | OS << "fail"; |
1932 | 0 | if (Node) { |
1933 | 0 | OS << "("; |
1934 | 0 | OS << getOpenMPSimpleClauseTypeName( |
1935 | 0 | Node->getClauseKind(), static_cast<int>(Node->getFailParameter())); |
1936 | 0 | OS << ")"; |
1937 | 0 | } |
1938 | 0 | } |
1939 | | |
1940 | 0 | void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { |
1941 | 0 | OS << "seq_cst"; |
1942 | 0 | } |
1943 | | |
1944 | 0 | void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) { |
1945 | 0 | OS << "acq_rel"; |
1946 | 0 | } |
1947 | | |
1948 | 0 | void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) { |
1949 | 0 | OS << "acquire"; |
1950 | 0 | } |
1951 | | |
1952 | 0 | void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) { |
1953 | 0 | OS << "release"; |
1954 | 0 | } |
1955 | | |
1956 | 0 | void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) { |
1957 | 0 | OS << "relaxed"; |
1958 | 0 | } |
1959 | | |
1960 | 0 | void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) { |
1961 | 0 | OS << "threads"; |
1962 | 0 | } |
1963 | | |
1964 | 0 | void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; } |
1965 | | |
1966 | 0 | void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) { |
1967 | 0 | OS << "device("; |
1968 | 0 | OpenMPDeviceClauseModifier Modifier = Node->getModifier(); |
1969 | 0 | if (Modifier != OMPC_DEVICE_unknown) { |
1970 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) |
1971 | 0 | << ": "; |
1972 | 0 | } |
1973 | 0 | Node->getDevice()->printPretty(OS, nullptr, Policy, 0); |
1974 | 0 | OS << ")"; |
1975 | 0 | } |
1976 | | |
1977 | 0 | void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) { |
1978 | 0 | OS << "num_teams("; |
1979 | 0 | Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0); |
1980 | 0 | OS << ")"; |
1981 | 0 | } |
1982 | | |
1983 | 0 | void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) { |
1984 | 0 | OS << "thread_limit("; |
1985 | 0 | Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0); |
1986 | 0 | OS << ")"; |
1987 | 0 | } |
1988 | | |
1989 | 0 | void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) { |
1990 | 0 | OS << "priority("; |
1991 | 0 | Node->getPriority()->printPretty(OS, nullptr, Policy, 0); |
1992 | 0 | OS << ")"; |
1993 | 0 | } |
1994 | | |
1995 | 0 | void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) { |
1996 | 0 | OS << "grainsize("; |
1997 | 0 | OpenMPGrainsizeClauseModifier Modifier = Node->getModifier(); |
1998 | 0 | if (Modifier != OMPC_GRAINSIZE_unknown) { |
1999 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) |
2000 | 0 | << ": "; |
2001 | 0 | } |
2002 | 0 | Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0); |
2003 | 0 | OS << ")"; |
2004 | 0 | } |
2005 | | |
2006 | 0 | void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) { |
2007 | 0 | OS << "num_tasks("; |
2008 | 0 | OpenMPNumTasksClauseModifier Modifier = Node->getModifier(); |
2009 | 0 | if (Modifier != OMPC_NUMTASKS_unknown) { |
2010 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), Modifier) |
2011 | 0 | << ": "; |
2012 | 0 | } |
2013 | 0 | Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0); |
2014 | 0 | OS << ")"; |
2015 | 0 | } |
2016 | | |
2017 | 0 | void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) { |
2018 | 0 | OS << "hint("; |
2019 | 0 | Node->getHint()->printPretty(OS, nullptr, Policy, 0); |
2020 | 0 | OS << ")"; |
2021 | 0 | } |
2022 | | |
2023 | 0 | void OMPClausePrinter::VisitOMPInitClause(OMPInitClause *Node) { |
2024 | 0 | OS << "init("; |
2025 | 0 | bool First = true; |
2026 | 0 | for (const Expr *E : Node->prefs()) { |
2027 | 0 | if (First) |
2028 | 0 | OS << "prefer_type("; |
2029 | 0 | else |
2030 | 0 | OS << ","; |
2031 | 0 | E->printPretty(OS, nullptr, Policy); |
2032 | 0 | First = false; |
2033 | 0 | } |
2034 | 0 | if (!First) |
2035 | 0 | OS << "), "; |
2036 | 0 | if (Node->getIsTarget()) |
2037 | 0 | OS << "target"; |
2038 | 0 | if (Node->getIsTargetSync()) { |
2039 | 0 | if (Node->getIsTarget()) |
2040 | 0 | OS << ", "; |
2041 | 0 | OS << "targetsync"; |
2042 | 0 | } |
2043 | 0 | OS << " : "; |
2044 | 0 | Node->getInteropVar()->printPretty(OS, nullptr, Policy); |
2045 | 0 | OS << ")"; |
2046 | 0 | } |
2047 | | |
2048 | 0 | void OMPClausePrinter::VisitOMPUseClause(OMPUseClause *Node) { |
2049 | 0 | OS << "use("; |
2050 | 0 | Node->getInteropVar()->printPretty(OS, nullptr, Policy); |
2051 | 0 | OS << ")"; |
2052 | 0 | } |
2053 | | |
2054 | 0 | void OMPClausePrinter::VisitOMPDestroyClause(OMPDestroyClause *Node) { |
2055 | 0 | OS << "destroy"; |
2056 | 0 | if (Expr *E = Node->getInteropVar()) { |
2057 | 0 | OS << "("; |
2058 | 0 | E->printPretty(OS, nullptr, Policy); |
2059 | 0 | OS << ")"; |
2060 | 0 | } |
2061 | 0 | } |
2062 | | |
2063 | 0 | void OMPClausePrinter::VisitOMPNovariantsClause(OMPNovariantsClause *Node) { |
2064 | 0 | OS << "novariants"; |
2065 | 0 | if (Expr *E = Node->getCondition()) { |
2066 | 0 | OS << "("; |
2067 | 0 | E->printPretty(OS, nullptr, Policy, 0); |
2068 | 0 | OS << ")"; |
2069 | 0 | } |
2070 | 0 | } |
2071 | | |
2072 | 0 | void OMPClausePrinter::VisitOMPNocontextClause(OMPNocontextClause *Node) { |
2073 | 0 | OS << "nocontext"; |
2074 | 0 | if (Expr *E = Node->getCondition()) { |
2075 | 0 | OS << "("; |
2076 | 0 | E->printPretty(OS, nullptr, Policy, 0); |
2077 | 0 | OS << ")"; |
2078 | 0 | } |
2079 | 0 | } |
2080 | | |
2081 | | template<typename T> |
2082 | 0 | void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { |
2083 | 0 | for (typename T::varlist_iterator I = Node->varlist_begin(), |
2084 | 0 | E = Node->varlist_end(); |
2085 | 0 | I != E; ++I) { |
2086 | 0 | assert(*I && "Expected non-null Stmt"); |
2087 | 0 | OS << (I == Node->varlist_begin() ? StartSym : ','); |
2088 | 0 | if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) { |
2089 | 0 | if (isa<OMPCapturedExprDecl>(DRE->getDecl())) |
2090 | 0 | DRE->printPretty(OS, nullptr, Policy, 0); |
2091 | 0 | else |
2092 | 0 | DRE->getDecl()->printQualifiedName(OS); |
2093 | 0 | } else |
2094 | 0 | (*I)->printPretty(OS, nullptr, Policy, 0); |
2095 | 0 | } |
2096 | 0 | } Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPAllocateClause>(clang::OMPAllocateClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPPrivateClause>(clang::OMPPrivateClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFirstprivateClause>(clang::OMPFirstprivateClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPLastprivateClause>(clang::OMPLastprivateClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPSharedClause>(clang::OMPSharedClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPReductionClause>(clang::OMPReductionClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPTaskReductionClause>(clang::OMPTaskReductionClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPInReductionClause>(clang::OMPInReductionClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPLinearClause>(clang::OMPLinearClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPAlignedClause>(clang::OMPAlignedClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPCopyinClause>(clang::OMPCopyinClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPCopyprivateClause>(clang::OMPCopyprivateClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFlushClause>(clang::OMPFlushClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPDependClause>(clang::OMPDependClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPMapClause>(clang::OMPMapClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPToClause>(clang::OMPToClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFromClause>(clang::OMPFromClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPUseDevicePtrClause>(clang::OMPUseDevicePtrClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPUseDeviceAddrClause>(clang::OMPUseDeviceAddrClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPIsDevicePtrClause>(clang::OMPIsDevicePtrClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPHasDeviceAddrClause>(clang::OMPHasDeviceAddrClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPNontemporalClause>(clang::OMPNontemporalClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPInclusiveClause>(clang::OMPInclusiveClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPExclusiveClause>(clang::OMPExclusiveClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPAffinityClause>(clang::OMPAffinityClause*, char) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPDoacrossClause>(clang::OMPDoacrossClause*, char) |
2097 | | |
2098 | 0 | void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) { |
2099 | 0 | if (Node->varlist_empty()) |
2100 | 0 | return; |
2101 | 0 | OS << "allocate"; |
2102 | 0 | if (Expr *Allocator = Node->getAllocator()) { |
2103 | 0 | OS << "("; |
2104 | 0 | Allocator->printPretty(OS, nullptr, Policy, 0); |
2105 | 0 | OS << ":"; |
2106 | 0 | VisitOMPClauseList(Node, ' '); |
2107 | 0 | } else { |
2108 | 0 | VisitOMPClauseList(Node, '('); |
2109 | 0 | } |
2110 | 0 | OS << ")"; |
2111 | 0 | } |
2112 | | |
2113 | 0 | void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) { |
2114 | 0 | if (!Node->varlist_empty()) { |
2115 | 0 | OS << "private"; |
2116 | 0 | VisitOMPClauseList(Node, '('); |
2117 | 0 | OS << ")"; |
2118 | 0 | } |
2119 | 0 | } |
2120 | | |
2121 | 0 | void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) { |
2122 | 0 | if (!Node->varlist_empty()) { |
2123 | 0 | OS << "firstprivate"; |
2124 | 0 | VisitOMPClauseList(Node, '('); |
2125 | 0 | OS << ")"; |
2126 | 0 | } |
2127 | 0 | } |
2128 | | |
2129 | 0 | void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) { |
2130 | 0 | if (!Node->varlist_empty()) { |
2131 | 0 | OS << "lastprivate"; |
2132 | 0 | OpenMPLastprivateModifier LPKind = Node->getKind(); |
2133 | 0 | if (LPKind != OMPC_LASTPRIVATE_unknown) { |
2134 | 0 | OS << "(" |
2135 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind()) |
2136 | 0 | << ":"; |
2137 | 0 | } |
2138 | 0 | VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? '(' : ' '); |
2139 | 0 | OS << ")"; |
2140 | 0 | } |
2141 | 0 | } |
2142 | | |
2143 | 0 | void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { |
2144 | 0 | if (!Node->varlist_empty()) { |
2145 | 0 | OS << "shared"; |
2146 | 0 | VisitOMPClauseList(Node, '('); |
2147 | 0 | OS << ")"; |
2148 | 0 | } |
2149 | 0 | } |
2150 | | |
2151 | 0 | void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) { |
2152 | 0 | if (!Node->varlist_empty()) { |
2153 | 0 | OS << "reduction("; |
2154 | 0 | if (Node->getModifierLoc().isValid()) |
2155 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_reduction, Node->getModifier()) |
2156 | 0 | << ", "; |
2157 | 0 | NestedNameSpecifier *QualifierLoc = |
2158 | 0 | Node->getQualifierLoc().getNestedNameSpecifier(); |
2159 | 0 | OverloadedOperatorKind OOK = |
2160 | 0 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
2161 | 0 | if (QualifierLoc == nullptr && OOK != OO_None) { |
2162 | | // Print reduction identifier in C format |
2163 | 0 | OS << getOperatorSpelling(OOK); |
2164 | 0 | } else { |
2165 | | // Use C++ format |
2166 | 0 | if (QualifierLoc != nullptr) |
2167 | 0 | QualifierLoc->print(OS, Policy); |
2168 | 0 | OS << Node->getNameInfo(); |
2169 | 0 | } |
2170 | 0 | OS << ":"; |
2171 | 0 | VisitOMPClauseList(Node, ' '); |
2172 | 0 | OS << ")"; |
2173 | 0 | } |
2174 | 0 | } |
2175 | | |
2176 | | void OMPClausePrinter::VisitOMPTaskReductionClause( |
2177 | 0 | OMPTaskReductionClause *Node) { |
2178 | 0 | if (!Node->varlist_empty()) { |
2179 | 0 | OS << "task_reduction("; |
2180 | 0 | NestedNameSpecifier *QualifierLoc = |
2181 | 0 | Node->getQualifierLoc().getNestedNameSpecifier(); |
2182 | 0 | OverloadedOperatorKind OOK = |
2183 | 0 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
2184 | 0 | if (QualifierLoc == nullptr && OOK != OO_None) { |
2185 | | // Print reduction identifier in C format |
2186 | 0 | OS << getOperatorSpelling(OOK); |
2187 | 0 | } else { |
2188 | | // Use C++ format |
2189 | 0 | if (QualifierLoc != nullptr) |
2190 | 0 | QualifierLoc->print(OS, Policy); |
2191 | 0 | OS << Node->getNameInfo(); |
2192 | 0 | } |
2193 | 0 | OS << ":"; |
2194 | 0 | VisitOMPClauseList(Node, ' '); |
2195 | 0 | OS << ")"; |
2196 | 0 | } |
2197 | 0 | } |
2198 | | |
2199 | 0 | void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) { |
2200 | 0 | if (!Node->varlist_empty()) { |
2201 | 0 | OS << "in_reduction("; |
2202 | 0 | NestedNameSpecifier *QualifierLoc = |
2203 | 0 | Node->getQualifierLoc().getNestedNameSpecifier(); |
2204 | 0 | OverloadedOperatorKind OOK = |
2205 | 0 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
2206 | 0 | if (QualifierLoc == nullptr && OOK != OO_None) { |
2207 | | // Print reduction identifier in C format |
2208 | 0 | OS << getOperatorSpelling(OOK); |
2209 | 0 | } else { |
2210 | | // Use C++ format |
2211 | 0 | if (QualifierLoc != nullptr) |
2212 | 0 | QualifierLoc->print(OS, Policy); |
2213 | 0 | OS << Node->getNameInfo(); |
2214 | 0 | } |
2215 | 0 | OS << ":"; |
2216 | 0 | VisitOMPClauseList(Node, ' '); |
2217 | 0 | OS << ")"; |
2218 | 0 | } |
2219 | 0 | } |
2220 | | |
2221 | 0 | void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) { |
2222 | 0 | if (!Node->varlist_empty()) { |
2223 | 0 | OS << "linear"; |
2224 | 0 | VisitOMPClauseList(Node, '('); |
2225 | 0 | if (Node->getModifierLoc().isValid() || Node->getStep() != nullptr) { |
2226 | 0 | OS << ": "; |
2227 | 0 | } |
2228 | 0 | if (Node->getModifierLoc().isValid()) { |
2229 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); |
2230 | 0 | } |
2231 | 0 | if (Node->getStep() != nullptr) { |
2232 | 0 | if (Node->getModifierLoc().isValid()) { |
2233 | 0 | OS << ", "; |
2234 | 0 | } |
2235 | 0 | OS << "step("; |
2236 | 0 | Node->getStep()->printPretty(OS, nullptr, Policy, 0); |
2237 | 0 | OS << ")"; |
2238 | 0 | } |
2239 | 0 | OS << ")"; |
2240 | 0 | } |
2241 | 0 | } |
2242 | | |
2243 | 0 | void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) { |
2244 | 0 | if (!Node->varlist_empty()) { |
2245 | 0 | OS << "aligned"; |
2246 | 0 | VisitOMPClauseList(Node, '('); |
2247 | 0 | if (Node->getAlignment() != nullptr) { |
2248 | 0 | OS << ": "; |
2249 | 0 | Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); |
2250 | 0 | } |
2251 | 0 | OS << ")"; |
2252 | 0 | } |
2253 | 0 | } |
2254 | | |
2255 | 0 | void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) { |
2256 | 0 | if (!Node->varlist_empty()) { |
2257 | 0 | OS << "copyin"; |
2258 | 0 | VisitOMPClauseList(Node, '('); |
2259 | 0 | OS << ")"; |
2260 | 0 | } |
2261 | 0 | } |
2262 | | |
2263 | 0 | void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) { |
2264 | 0 | if (!Node->varlist_empty()) { |
2265 | 0 | OS << "copyprivate"; |
2266 | 0 | VisitOMPClauseList(Node, '('); |
2267 | 0 | OS << ")"; |
2268 | 0 | } |
2269 | 0 | } |
2270 | | |
2271 | 0 | void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) { |
2272 | 0 | if (!Node->varlist_empty()) { |
2273 | 0 | VisitOMPClauseList(Node, '('); |
2274 | 0 | OS << ")"; |
2275 | 0 | } |
2276 | 0 | } |
2277 | | |
2278 | 0 | void OMPClausePrinter::VisitOMPDepobjClause(OMPDepobjClause *Node) { |
2279 | 0 | OS << "("; |
2280 | 0 | Node->getDepobj()->printPretty(OS, nullptr, Policy, 0); |
2281 | 0 | OS << ")"; |
2282 | 0 | } |
2283 | | |
2284 | 0 | void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) { |
2285 | 0 | OS << "depend("; |
2286 | 0 | if (Expr *DepModifier = Node->getModifier()) { |
2287 | 0 | DepModifier->printPretty(OS, nullptr, Policy); |
2288 | 0 | OS << ", "; |
2289 | 0 | } |
2290 | 0 | OpenMPDependClauseKind DepKind = Node->getDependencyKind(); |
2291 | 0 | OpenMPDependClauseKind PrintKind = DepKind; |
2292 | 0 | bool IsOmpAllMemory = false; |
2293 | 0 | if (PrintKind == OMPC_DEPEND_outallmemory) { |
2294 | 0 | PrintKind = OMPC_DEPEND_out; |
2295 | 0 | IsOmpAllMemory = true; |
2296 | 0 | } else if (PrintKind == OMPC_DEPEND_inoutallmemory) { |
2297 | 0 | PrintKind = OMPC_DEPEND_inout; |
2298 | 0 | IsOmpAllMemory = true; |
2299 | 0 | } |
2300 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), PrintKind); |
2301 | 0 | if (!Node->varlist_empty() || IsOmpAllMemory) |
2302 | 0 | OS << " :"; |
2303 | 0 | VisitOMPClauseList(Node, ' '); |
2304 | 0 | if (IsOmpAllMemory) { |
2305 | 0 | OS << (Node->varlist_empty() ? " " : ","); |
2306 | 0 | OS << "omp_all_memory"; |
2307 | 0 | } |
2308 | 0 | OS << ")"; |
2309 | 0 | } |
2310 | | |
2311 | | template <typename T> |
2312 | | static void PrintMapper(raw_ostream &OS, T *Node, |
2313 | 0 | const PrintingPolicy &Policy) { |
2314 | 0 | OS << '('; |
2315 | 0 | NestedNameSpecifier *MapperNNS = |
2316 | 0 | Node->getMapperQualifierLoc().getNestedNameSpecifier(); |
2317 | 0 | if (MapperNNS) |
2318 | 0 | MapperNNS->print(OS, Policy); |
2319 | 0 | OS << Node->getMapperIdInfo() << ')'; |
2320 | 0 | } Unexecuted instantiation: OpenMPClause.cpp:void PrintMapper<clang::OMPMapClause>(llvm::raw_ostream&, clang::OMPMapClause*, clang::PrintingPolicy const&) Unexecuted instantiation: OpenMPClause.cpp:void PrintMapper<clang::OMPToClause>(llvm::raw_ostream&, clang::OMPToClause*, clang::PrintingPolicy const&) Unexecuted instantiation: OpenMPClause.cpp:void PrintMapper<clang::OMPFromClause>(llvm::raw_ostream&, clang::OMPFromClause*, clang::PrintingPolicy const&) |
2321 | | |
2322 | | template <typename T> |
2323 | | static void PrintIterator(raw_ostream &OS, T *Node, |
2324 | 0 | const PrintingPolicy &Policy) { |
2325 | 0 | if (Expr *IteratorModifier = Node->getIteratorModifier()) |
2326 | 0 | IteratorModifier->printPretty(OS, nullptr, Policy); |
2327 | 0 | } |
2328 | | |
2329 | 0 | void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) { |
2330 | 0 | if (!Node->varlist_empty()) { |
2331 | 0 | OS << "map("; |
2332 | 0 | if (Node->getMapType() != OMPC_MAP_unknown) { |
2333 | 0 | for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) { |
2334 | 0 | if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) { |
2335 | 0 | if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_iterator) { |
2336 | 0 | PrintIterator(OS, Node, Policy); |
2337 | 0 | } else { |
2338 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_map, |
2339 | 0 | Node->getMapTypeModifier(I)); |
2340 | 0 | if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) |
2341 | 0 | PrintMapper(OS, Node, Policy); |
2342 | 0 | } |
2343 | 0 | OS << ','; |
2344 | 0 | } |
2345 | 0 | } |
2346 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType()); |
2347 | 0 | OS << ':'; |
2348 | 0 | } |
2349 | 0 | VisitOMPClauseList(Node, ' '); |
2350 | 0 | OS << ")"; |
2351 | 0 | } |
2352 | 0 | } |
2353 | | |
2354 | 0 | template <typename T> void OMPClausePrinter::VisitOMPMotionClause(T *Node) { |
2355 | 0 | if (Node->varlist_empty()) |
2356 | 0 | return; |
2357 | 0 | OS << getOpenMPClauseName(Node->getClauseKind()); |
2358 | 0 | unsigned ModifierCount = 0; |
2359 | 0 | for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { |
2360 | 0 | if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) |
2361 | 0 | ++ModifierCount; |
2362 | 0 | } |
2363 | 0 | if (ModifierCount) { |
2364 | 0 | OS << '('; |
2365 | 0 | for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { |
2366 | 0 | if (Node->getMotionModifier(I) != OMPC_MOTION_MODIFIER_unknown) { |
2367 | 0 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), |
2368 | 0 | Node->getMotionModifier(I)); |
2369 | 0 | if (Node->getMotionModifier(I) == OMPC_MOTION_MODIFIER_mapper) |
2370 | 0 | PrintMapper(OS, Node, Policy); |
2371 | 0 | if (I < ModifierCount - 1) |
2372 | 0 | OS << ", "; |
2373 | 0 | } |
2374 | 0 | } |
2375 | 0 | OS << ':'; |
2376 | 0 | VisitOMPClauseList(Node, ' '); |
2377 | 0 | } else { |
2378 | 0 | VisitOMPClauseList(Node, '('); |
2379 | 0 | } |
2380 | 0 | OS << ")"; |
2381 | 0 | } Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPMotionClause<clang::OMPToClause>(clang::OMPToClause*) Unexecuted instantiation: void clang::OMPClausePrinter::VisitOMPMotionClause<clang::OMPFromClause>(clang::OMPFromClause*) |
2382 | | |
2383 | 0 | void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) { |
2384 | 0 | VisitOMPMotionClause(Node); |
2385 | 0 | } |
2386 | | |
2387 | 0 | void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) { |
2388 | 0 | VisitOMPMotionClause(Node); |
2389 | 0 | } |
2390 | | |
2391 | 0 | void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) { |
2392 | 0 | OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName( |
2393 | 0 | OMPC_dist_schedule, Node->getDistScheduleKind()); |
2394 | 0 | if (auto *E = Node->getChunkSize()) { |
2395 | 0 | OS << ", "; |
2396 | 0 | E->printPretty(OS, nullptr, Policy); |
2397 | 0 | } |
2398 | 0 | OS << ")"; |
2399 | 0 | } |
2400 | | |
2401 | 0 | void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) { |
2402 | 0 | OS << "defaultmap("; |
2403 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
2404 | 0 | Node->getDefaultmapModifier()); |
2405 | 0 | if (Node->getDefaultmapKind() != OMPC_DEFAULTMAP_unknown) { |
2406 | 0 | OS << ": "; |
2407 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
2408 | 0 | Node->getDefaultmapKind()); |
2409 | 0 | } |
2410 | 0 | OS << ")"; |
2411 | 0 | } |
2412 | | |
2413 | 0 | void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) { |
2414 | 0 | if (!Node->varlist_empty()) { |
2415 | 0 | OS << "use_device_ptr"; |
2416 | 0 | VisitOMPClauseList(Node, '('); |
2417 | 0 | OS << ")"; |
2418 | 0 | } |
2419 | 0 | } |
2420 | | |
2421 | | void OMPClausePrinter::VisitOMPUseDeviceAddrClause( |
2422 | 0 | OMPUseDeviceAddrClause *Node) { |
2423 | 0 | if (!Node->varlist_empty()) { |
2424 | 0 | OS << "use_device_addr"; |
2425 | 0 | VisitOMPClauseList(Node, '('); |
2426 | 0 | OS << ")"; |
2427 | 0 | } |
2428 | 0 | } |
2429 | | |
2430 | 0 | void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { |
2431 | 0 | if (!Node->varlist_empty()) { |
2432 | 0 | OS << "is_device_ptr"; |
2433 | 0 | VisitOMPClauseList(Node, '('); |
2434 | 0 | OS << ")"; |
2435 | 0 | } |
2436 | 0 | } |
2437 | | |
2438 | 0 | void OMPClausePrinter::VisitOMPHasDeviceAddrClause(OMPHasDeviceAddrClause *Node) { |
2439 | 0 | if (!Node->varlist_empty()) { |
2440 | 0 | OS << "has_device_addr"; |
2441 | 0 | VisitOMPClauseList(Node, '('); |
2442 | 0 | OS << ")"; |
2443 | 0 | } |
2444 | 0 | } |
2445 | | |
2446 | 0 | void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) { |
2447 | 0 | if (!Node->varlist_empty()) { |
2448 | 0 | OS << "nontemporal"; |
2449 | 0 | VisitOMPClauseList(Node, '('); |
2450 | 0 | OS << ")"; |
2451 | 0 | } |
2452 | 0 | } |
2453 | | |
2454 | 0 | void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) { |
2455 | 0 | OS << "order("; |
2456 | 0 | if (Node->getModifier() != OMPC_ORDER_MODIFIER_unknown) { |
2457 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getModifier()); |
2458 | 0 | OS << ": "; |
2459 | 0 | } |
2460 | 0 | OS << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind()) << ")"; |
2461 | 0 | } |
2462 | | |
2463 | 0 | void OMPClausePrinter::VisitOMPInclusiveClause(OMPInclusiveClause *Node) { |
2464 | 0 | if (!Node->varlist_empty()) { |
2465 | 0 | OS << "inclusive"; |
2466 | 0 | VisitOMPClauseList(Node, '('); |
2467 | 0 | OS << ")"; |
2468 | 0 | } |
2469 | 0 | } |
2470 | | |
2471 | 0 | void OMPClausePrinter::VisitOMPExclusiveClause(OMPExclusiveClause *Node) { |
2472 | 0 | if (!Node->varlist_empty()) { |
2473 | 0 | OS << "exclusive"; |
2474 | 0 | VisitOMPClauseList(Node, '('); |
2475 | 0 | OS << ")"; |
2476 | 0 | } |
2477 | 0 | } |
2478 | | |
2479 | | void OMPClausePrinter::VisitOMPUsesAllocatorsClause( |
2480 | 0 | OMPUsesAllocatorsClause *Node) { |
2481 | 0 | if (Node->getNumberOfAllocators() == 0) |
2482 | 0 | return; |
2483 | 0 | OS << "uses_allocators("; |
2484 | 0 | for (unsigned I = 0, E = Node->getNumberOfAllocators(); I < E; ++I) { |
2485 | 0 | OMPUsesAllocatorsClause::Data Data = Node->getAllocatorData(I); |
2486 | 0 | Data.Allocator->printPretty(OS, nullptr, Policy); |
2487 | 0 | if (Data.AllocatorTraits) { |
2488 | 0 | OS << "("; |
2489 | 0 | Data.AllocatorTraits->printPretty(OS, nullptr, Policy); |
2490 | 0 | OS << ")"; |
2491 | 0 | } |
2492 | 0 | if (I < E - 1) |
2493 | 0 | OS << ","; |
2494 | 0 | } |
2495 | 0 | OS << ")"; |
2496 | 0 | } |
2497 | | |
2498 | 0 | void OMPClausePrinter::VisitOMPAffinityClause(OMPAffinityClause *Node) { |
2499 | 0 | if (Node->varlist_empty()) |
2500 | 0 | return; |
2501 | 0 | OS << "affinity"; |
2502 | 0 | char StartSym = '('; |
2503 | 0 | if (Expr *Modifier = Node->getModifier()) { |
2504 | 0 | OS << "("; |
2505 | 0 | Modifier->printPretty(OS, nullptr, Policy); |
2506 | 0 | OS << " :"; |
2507 | 0 | StartSym = ' '; |
2508 | 0 | } |
2509 | 0 | VisitOMPClauseList(Node, StartSym); |
2510 | 0 | OS << ")"; |
2511 | 0 | } |
2512 | | |
2513 | 0 | void OMPClausePrinter::VisitOMPFilterClause(OMPFilterClause *Node) { |
2514 | 0 | OS << "filter("; |
2515 | 0 | Node->getThreadID()->printPretty(OS, nullptr, Policy, 0); |
2516 | 0 | OS << ")"; |
2517 | 0 | } |
2518 | | |
2519 | 0 | void OMPClausePrinter::VisitOMPBindClause(OMPBindClause *Node) { |
2520 | 0 | OS << "bind(" |
2521 | 0 | << getOpenMPSimpleClauseTypeName(OMPC_bind, unsigned(Node->getBindKind())) |
2522 | 0 | << ")"; |
2523 | 0 | } |
2524 | | |
2525 | | void OMPClausePrinter::VisitOMPXDynCGroupMemClause( |
2526 | 0 | OMPXDynCGroupMemClause *Node) { |
2527 | 0 | OS << "ompx_dyn_cgroup_mem("; |
2528 | 0 | Node->getSize()->printPretty(OS, nullptr, Policy, 0); |
2529 | 0 | OS << ")"; |
2530 | 0 | } |
2531 | | |
2532 | 0 | void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) { |
2533 | 0 | OS << "doacross("; |
2534 | 0 | OpenMPDoacrossClauseModifier DepType = Node->getDependenceType(); |
2535 | |
|
2536 | 0 | switch (DepType) { |
2537 | 0 | case OMPC_DOACROSS_source: |
2538 | 0 | OS << "source:"; |
2539 | 0 | break; |
2540 | 0 | case OMPC_DOACROSS_sink: |
2541 | 0 | OS << "sink:"; |
2542 | 0 | break; |
2543 | 0 | case OMPC_DOACROSS_source_omp_cur_iteration: |
2544 | 0 | OS << "source: omp_cur_iteration"; |
2545 | 0 | break; |
2546 | 0 | case OMPC_DOACROSS_sink_omp_cur_iteration: |
2547 | 0 | OS << "sink: omp_cur_iteration - 1"; |
2548 | 0 | break; |
2549 | 0 | default: |
2550 | 0 | llvm_unreachable("unknown docaross modifier"); |
2551 | 0 | } |
2552 | 0 | VisitOMPClauseList(Node, ' '); |
2553 | 0 | OS << ")"; |
2554 | 0 | } |
2555 | | |
2556 | 0 | void OMPClausePrinter::VisitOMPXAttributeClause(OMPXAttributeClause *Node) { |
2557 | 0 | OS << "ompx_attribute("; |
2558 | 0 | bool IsFirst = true; |
2559 | 0 | for (auto &Attr : Node->getAttrs()) { |
2560 | 0 | if (!IsFirst) |
2561 | 0 | OS << ", "; |
2562 | 0 | Attr->printPretty(OS, Policy); |
2563 | 0 | IsFirst = false; |
2564 | 0 | } |
2565 | 0 | OS << ")"; |
2566 | 0 | } |
2567 | | |
2568 | 0 | void OMPClausePrinter::VisitOMPXBareClause(OMPXBareClause *Node) { |
2569 | 0 | OS << "ompx_bare"; |
2570 | 0 | } |
2571 | | |
2572 | | void OMPTraitInfo::getAsVariantMatchInfo(ASTContext &ASTCtx, |
2573 | 0 | VariantMatchInfo &VMI) const { |
2574 | 0 | for (const OMPTraitSet &Set : Sets) { |
2575 | 0 | for (const OMPTraitSelector &Selector : Set.Selectors) { |
2576 | | |
2577 | | // User conditions are special as we evaluate the condition here. |
2578 | 0 | if (Selector.Kind == TraitSelector::user_condition) { |
2579 | 0 | assert(Selector.ScoreOrCondition && |
2580 | 0 | "Ill-formed user condition, expected condition expression!"); |
2581 | 0 | assert(Selector.Properties.size() == 1 && |
2582 | 0 | Selector.Properties.front().Kind == |
2583 | 0 | TraitProperty::user_condition_unknown && |
2584 | 0 | "Ill-formed user condition, expected unknown trait property!"); |
2585 | | |
2586 | 0 | if (std::optional<APSInt> CondVal = |
2587 | 0 | Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx)) |
2588 | 0 | VMI.addTrait(CondVal->isZero() ? TraitProperty::user_condition_false |
2589 | 0 | : TraitProperty::user_condition_true, |
2590 | 0 | "<condition>"); |
2591 | 0 | else |
2592 | 0 | VMI.addTrait(TraitProperty::user_condition_false, "<condition>"); |
2593 | 0 | continue; |
2594 | 0 | } |
2595 | | |
2596 | 0 | std::optional<llvm::APSInt> Score; |
2597 | 0 | llvm::APInt *ScorePtr = nullptr; |
2598 | 0 | if (Selector.ScoreOrCondition) { |
2599 | 0 | if ((Score = Selector.ScoreOrCondition->getIntegerConstantExpr(ASTCtx))) |
2600 | 0 | ScorePtr = &*Score; |
2601 | 0 | else |
2602 | 0 | VMI.addTrait(TraitProperty::user_condition_false, |
2603 | 0 | "<non-constant-score>"); |
2604 | 0 | } |
2605 | |
|
2606 | 0 | for (const OMPTraitProperty &Property : Selector.Properties) |
2607 | 0 | VMI.addTrait(Set.Kind, Property.Kind, Property.RawString, ScorePtr); |
2608 | |
|
2609 | 0 | if (Set.Kind != TraitSet::construct) |
2610 | 0 | continue; |
2611 | | |
2612 | | // TODO: This might not hold once we implement SIMD properly. |
2613 | 0 | assert(Selector.Properties.size() == 1 && |
2614 | 0 | Selector.Properties.front().Kind == |
2615 | 0 | getOpenMPContextTraitPropertyForSelector( |
2616 | 0 | Selector.Kind) && |
2617 | 0 | "Ill-formed construct selector!"); |
2618 | 0 | } |
2619 | 0 | } |
2620 | 0 | } |
2621 | | |
2622 | | void OMPTraitInfo::print(llvm::raw_ostream &OS, |
2623 | 0 | const PrintingPolicy &Policy) const { |
2624 | 0 | bool FirstSet = true; |
2625 | 0 | for (const OMPTraitSet &Set : Sets) { |
2626 | 0 | if (!FirstSet) |
2627 | 0 | OS << ", "; |
2628 | 0 | FirstSet = false; |
2629 | 0 | OS << getOpenMPContextTraitSetName(Set.Kind) << "={"; |
2630 | |
|
2631 | 0 | bool FirstSelector = true; |
2632 | 0 | for (const OMPTraitSelector &Selector : Set.Selectors) { |
2633 | 0 | if (!FirstSelector) |
2634 | 0 | OS << ", "; |
2635 | 0 | FirstSelector = false; |
2636 | 0 | OS << getOpenMPContextTraitSelectorName(Selector.Kind); |
2637 | |
|
2638 | 0 | bool AllowsTraitScore = false; |
2639 | 0 | bool RequiresProperty = false; |
2640 | 0 | isValidTraitSelectorForTraitSet( |
2641 | 0 | Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty); |
2642 | |
|
2643 | 0 | if (!RequiresProperty) |
2644 | 0 | continue; |
2645 | | |
2646 | 0 | OS << "("; |
2647 | 0 | if (Selector.Kind == TraitSelector::user_condition) { |
2648 | 0 | if (Selector.ScoreOrCondition) |
2649 | 0 | Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy); |
2650 | 0 | else |
2651 | 0 | OS << "..."; |
2652 | 0 | } else { |
2653 | |
|
2654 | 0 | if (Selector.ScoreOrCondition) { |
2655 | 0 | OS << "score("; |
2656 | 0 | Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy); |
2657 | 0 | OS << "): "; |
2658 | 0 | } |
2659 | |
|
2660 | 0 | bool FirstProperty = true; |
2661 | 0 | for (const OMPTraitProperty &Property : Selector.Properties) { |
2662 | 0 | if (!FirstProperty) |
2663 | 0 | OS << ", "; |
2664 | 0 | FirstProperty = false; |
2665 | 0 | OS << getOpenMPContextTraitPropertyName(Property.Kind, |
2666 | 0 | Property.RawString); |
2667 | 0 | } |
2668 | 0 | } |
2669 | 0 | OS << ")"; |
2670 | 0 | } |
2671 | 0 | OS << "}"; |
2672 | 0 | } |
2673 | 0 | } |
2674 | | |
2675 | 0 | std::string OMPTraitInfo::getMangledName() const { |
2676 | 0 | std::string MangledName; |
2677 | 0 | llvm::raw_string_ostream OS(MangledName); |
2678 | 0 | for (const OMPTraitSet &Set : Sets) { |
2679 | 0 | OS << '$' << 'S' << unsigned(Set.Kind); |
2680 | 0 | for (const OMPTraitSelector &Selector : Set.Selectors) { |
2681 | |
|
2682 | 0 | bool AllowsTraitScore = false; |
2683 | 0 | bool RequiresProperty = false; |
2684 | 0 | isValidTraitSelectorForTraitSet( |
2685 | 0 | Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty); |
2686 | 0 | OS << '$' << 's' << unsigned(Selector.Kind); |
2687 | |
|
2688 | 0 | if (!RequiresProperty || |
2689 | 0 | Selector.Kind == TraitSelector::user_condition) |
2690 | 0 | continue; |
2691 | | |
2692 | 0 | for (const OMPTraitProperty &Property : Selector.Properties) |
2693 | 0 | OS << '$' << 'P' |
2694 | 0 | << getOpenMPContextTraitPropertyName(Property.Kind, |
2695 | 0 | Property.RawString); |
2696 | 0 | } |
2697 | 0 | } |
2698 | 0 | return MangledName; |
2699 | 0 | } |
2700 | | |
2701 | 0 | OMPTraitInfo::OMPTraitInfo(StringRef MangledName) { |
2702 | 0 | unsigned long U; |
2703 | 0 | do { |
2704 | 0 | if (!MangledName.consume_front("$S")) |
2705 | 0 | break; |
2706 | 0 | if (MangledName.consumeInteger(10, U)) |
2707 | 0 | break; |
2708 | 0 | Sets.push_back(OMPTraitSet()); |
2709 | 0 | OMPTraitSet &Set = Sets.back(); |
2710 | 0 | Set.Kind = TraitSet(U); |
2711 | 0 | do { |
2712 | 0 | if (!MangledName.consume_front("$s")) |
2713 | 0 | break; |
2714 | 0 | if (MangledName.consumeInteger(10, U)) |
2715 | 0 | break; |
2716 | 0 | Set.Selectors.push_back(OMPTraitSelector()); |
2717 | 0 | OMPTraitSelector &Selector = Set.Selectors.back(); |
2718 | 0 | Selector.Kind = TraitSelector(U); |
2719 | 0 | do { |
2720 | 0 | if (!MangledName.consume_front("$P")) |
2721 | 0 | break; |
2722 | 0 | Selector.Properties.push_back(OMPTraitProperty()); |
2723 | 0 | OMPTraitProperty &Property = Selector.Properties.back(); |
2724 | 0 | std::pair<StringRef, StringRef> PropRestPair = MangledName.split('$'); |
2725 | 0 | Property.RawString = PropRestPair.first; |
2726 | 0 | Property.Kind = getOpenMPContextTraitPropertyKind( |
2727 | 0 | Set.Kind, Selector.Kind, PropRestPair.first); |
2728 | 0 | MangledName = MangledName.drop_front(PropRestPair.first.size()); |
2729 | 0 | } while (true); |
2730 | 0 | } while (true); |
2731 | 0 | } while (true); |
2732 | 0 | } |
2733 | | |
2734 | | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
2735 | 0 | const OMPTraitInfo &TI) { |
2736 | 0 | LangOptions LO; |
2737 | 0 | PrintingPolicy Policy(LO); |
2738 | 0 | TI.print(OS, Policy); |
2739 | 0 | return OS; |
2740 | 0 | } |
2741 | | llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS, |
2742 | 0 | const OMPTraitInfo *TI) { |
2743 | 0 | return TI ? OS << *TI : OS; |
2744 | 0 | } |
2745 | | |
2746 | | TargetOMPContext::TargetOMPContext( |
2747 | | ASTContext &ASTCtx, std::function<void(StringRef)> &&DiagUnknownTrait, |
2748 | | const FunctionDecl *CurrentFunctionDecl, |
2749 | | ArrayRef<llvm::omp::TraitProperty> ConstructTraits) |
2750 | | : OMPContext(ASTCtx.getLangOpts().OpenMPIsTargetDevice, |
2751 | | ASTCtx.getTargetInfo().getTriple()), |
2752 | 0 | FeatureValidityCheck([&](StringRef FeatureName) { |
2753 | 0 | return ASTCtx.getTargetInfo().isValidFeatureName(FeatureName); |
2754 | 0 | }), |
2755 | 0 | DiagUnknownTrait(std::move(DiagUnknownTrait)) { |
2756 | 0 | ASTCtx.getFunctionFeatureMap(FeatureMap, CurrentFunctionDecl); |
2757 | |
|
2758 | 0 | for (llvm::omp::TraitProperty Property : ConstructTraits) |
2759 | 0 | addTrait(Property); |
2760 | 0 | } |
2761 | | |
2762 | 0 | bool TargetOMPContext::matchesISATrait(StringRef RawString) const { |
2763 | 0 | auto It = FeatureMap.find(RawString); |
2764 | 0 | if (It != FeatureMap.end()) |
2765 | 0 | return It->second; |
2766 | 0 | if (!FeatureValidityCheck(RawString)) |
2767 | 0 | DiagUnknownTrait(RawString); |
2768 | 0 | return false; |
2769 | 0 | } |