Coverage Report

Created: 2021-08-24 07:12

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