Coverage Report

Created: 2022-05-17 06:19

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