Coverage Report

Created: 2020-02-18 08:44

/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/Decl.h"
16
#include "clang/AST/DeclOpenMP.h"
17
#include "clang/Basic/LLVM.h"
18
#include "clang/Basic/OpenMPKinds.h"
19
#include "llvm/ADT/SmallPtrSet.h"
20
#include "llvm/Support/Casting.h"
21
#include "llvm/Support/ErrorHandling.h"
22
#include <algorithm>
23
#include <cassert>
24
25
using namespace clang;
26
27
64.1k
OMPClause::child_range OMPClause::children() {
28
64.1k
  switch (getClauseKind()) {
29
0
  default:
30
0
    break;
31
0
#define OPENMP_CLAUSE(Name, Class)                                             \
32
64.1k
  case OMPC_##Name:                                                            \
33
64.1k
    return static_cast<Class *>(this)->children();
34
0
#include "clang/Basic/OpenMPKinds.def"
35
64.1k
  }
36
64.1k
  
llvm_unreachable0
("unknown OMPClause");
37
64.1k
}
38
39
78.3k
OMPClause::child_range OMPClause::used_children() {
40
78.3k
  switch (getClauseKind()) {
41
0
#define OPENMP_CLAUSE(Name, Class)                                             \
42
78.3k
  case OMPC_##Name:                                                            \
43
78.3k
    return static_cast<Class *>(this)->used_children();
44
0
#include "clang/Basic/OpenMPKinds.def"
45
0
  case OMPC_threadprivate:
46
0
  case OMPC_uniform:
47
0
  case OMPC_device_type:
48
0
  case OMPC_match:
49
0
  case OMPC_unknown:
50
0
    break;
51
0
  }
52
0
  llvm_unreachable("unknown OMPClause");
53
0
}
54
55
52.6k
OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
56
52.6k
  auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
57
52.6k
  return Res ? 
const_cast<OMPClauseWithPreInit *>(Res)18.2k
:
nullptr34.4k
;
58
52.6k
}
59
60
173k
const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
61
173k
  switch (C->getClauseKind()) {
62
7.35k
  case OMPC_schedule:
63
7.35k
    return static_cast<const OMPScheduleClause *>(C);
64
4.47k
  case OMPC_dist_schedule:
65
4.47k
    return static_cast<const OMPDistScheduleClause *>(C);
66
50.4k
  case OMPC_firstprivate:
67
50.4k
    return static_cast<const OMPFirstprivateClause *>(C);
68
6.79k
  case OMPC_lastprivate:
69
6.79k
    return static_cast<const OMPLastprivateClause *>(C);
70
15.1k
  case OMPC_reduction:
71
15.1k
    return static_cast<const OMPReductionClause *>(C);
72
2.39k
  case OMPC_task_reduction:
73
2.39k
    return static_cast<const OMPTaskReductionClause *>(C);
74
1.51k
  case OMPC_in_reduction:
75
1.51k
    return static_cast<const OMPInReductionClause *>(C);
76
3.47k
  case OMPC_linear:
77
3.47k
    return static_cast<const OMPLinearClause *>(C);
78
20.4k
  case OMPC_if:
79
20.4k
    return static_cast<const OMPIfClause *>(C);
80
3.16k
  case OMPC_num_threads:
81
3.16k
    return static_cast<const OMPNumThreadsClause *>(C);
82
3.27k
  case OMPC_num_teams:
83
3.27k
    return static_cast<const OMPNumTeamsClause *>(C);
84
3.01k
  case OMPC_thread_limit:
85
3.01k
    return static_cast<const OMPThreadLimitClause *>(C);
86
2.84k
  case OMPC_device:
87
2.84k
    return static_cast<const OMPDeviceClause *>(C);
88
954
  case OMPC_grainsize:
89
954
    return static_cast<const OMPGrainsizeClause *>(C);
90
1.08k
  case OMPC_num_tasks:
91
1.08k
    return static_cast<const OMPNumTasksClause *>(C);
92
1.10k
  case OMPC_final:
93
1.10k
    return static_cast<const OMPFinalClause *>(C);
94
1.42k
  case OMPC_priority:
95
1.42k
    return static_cast<const OMPPriorityClause *>(C);
96
44.5k
  case OMPC_default:
97
44.5k
  case OMPC_proc_bind:
98
44.5k
  case OMPC_safelen:
99
44.5k
  case OMPC_simdlen:
100
44.5k
  case OMPC_allocator:
101
44.5k
  case OMPC_allocate:
102
44.5k
  case OMPC_collapse:
103
44.5k
  case OMPC_private:
104
44.5k
  case OMPC_shared:
105
44.5k
  case OMPC_aligned:
106
44.5k
  case OMPC_copyin:
107
44.5k
  case OMPC_copyprivate:
108
44.5k
  case OMPC_ordered:
109
44.5k
  case OMPC_nowait:
110
44.5k
  case OMPC_untied:
111
44.5k
  case OMPC_mergeable:
112
44.5k
  case OMPC_threadprivate:
113
44.5k
  case OMPC_flush:
114
44.5k
  case OMPC_read:
115
44.5k
  case OMPC_write:
116
44.5k
  case OMPC_update:
117
44.5k
  case OMPC_capture:
118
44.5k
  case OMPC_seq_cst:
119
44.5k
  case OMPC_acq_rel:
120
44.5k
  case OMPC_acquire:
121
44.5k
  case OMPC_release:
122
44.5k
  case OMPC_relaxed:
123
44.5k
  case OMPC_depend:
124
44.5k
  case OMPC_threads:
125
44.5k
  case OMPC_simd:
126
44.5k
  case OMPC_map:
127
44.5k
  case OMPC_nogroup:
128
44.5k
  case OMPC_hint:
129
44.5k
  case OMPC_defaultmap:
130
44.5k
  case OMPC_unknown:
131
44.5k
  case OMPC_uniform:
132
44.5k
  case OMPC_to:
133
44.5k
  case OMPC_from:
134
44.5k
  case OMPC_use_device_ptr:
135
44.5k
  case OMPC_is_device_ptr:
136
44.5k
  case OMPC_unified_address:
137
44.5k
  case OMPC_unified_shared_memory:
138
44.5k
  case OMPC_reverse_offload:
139
44.5k
  case OMPC_dynamic_allocators:
140
44.5k
  case OMPC_atomic_default_mem_order:
141
44.5k
  case OMPC_device_type:
142
44.5k
  case OMPC_match:
143
44.5k
  case OMPC_nontemporal:
144
44.5k
  case OMPC_order:
145
44.5k
    break;
146
44.5k
  }
147
44.5k
148
44.5k
  return nullptr;
149
44.5k
}
150
151
52.6k
OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
152
52.6k
  auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
153
52.6k
  return Res ? 
const_cast<OMPClauseWithPostUpdate *>(Res)0
: nullptr;
154
52.6k
}
155
156
79.9k
const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
157
79.9k
  switch (C->getClauseKind()) {
158
6.20k
  case OMPC_lastprivate:
159
6.20k
    return static_cast<const OMPLastprivateClause *>(C);
160
14.3k
  case OMPC_reduction:
161
14.3k
    return static_cast<const OMPReductionClause *>(C);
162
2.34k
  case OMPC_task_reduction:
163
2.34k
    return static_cast<const OMPTaskReductionClause *>(C);
164
1.47k
  case OMPC_in_reduction:
165
1.47k
    return static_cast<const OMPInReductionClause *>(C);
166
2.93k
  case OMPC_linear:
167
2.93k
    return static_cast<const OMPLinearClause *>(C);
168
52.6k
  case OMPC_schedule:
169
52.6k
  case OMPC_dist_schedule:
170
52.6k
  case OMPC_firstprivate:
171
52.6k
  case OMPC_default:
172
52.6k
  case OMPC_proc_bind:
173
52.6k
  case OMPC_if:
174
52.6k
  case OMPC_final:
175
52.6k
  case OMPC_num_threads:
176
52.6k
  case OMPC_safelen:
177
52.6k
  case OMPC_simdlen:
178
52.6k
  case OMPC_allocator:
179
52.6k
  case OMPC_allocate:
180
52.6k
  case OMPC_collapse:
181
52.6k
  case OMPC_private:
182
52.6k
  case OMPC_shared:
183
52.6k
  case OMPC_aligned:
184
52.6k
  case OMPC_copyin:
185
52.6k
  case OMPC_copyprivate:
186
52.6k
  case OMPC_ordered:
187
52.6k
  case OMPC_nowait:
188
52.6k
  case OMPC_untied:
189
52.6k
  case OMPC_mergeable:
190
52.6k
  case OMPC_threadprivate:
191
52.6k
  case OMPC_flush:
192
52.6k
  case OMPC_read:
193
52.6k
  case OMPC_write:
194
52.6k
  case OMPC_update:
195
52.6k
  case OMPC_capture:
196
52.6k
  case OMPC_seq_cst:
197
52.6k
  case OMPC_acq_rel:
198
52.6k
  case OMPC_acquire:
199
52.6k
  case OMPC_release:
200
52.6k
  case OMPC_relaxed:
201
52.6k
  case OMPC_depend:
202
52.6k
  case OMPC_device:
203
52.6k
  case OMPC_threads:
204
52.6k
  case OMPC_simd:
205
52.6k
  case OMPC_map:
206
52.6k
  case OMPC_num_teams:
207
52.6k
  case OMPC_thread_limit:
208
52.6k
  case OMPC_priority:
209
52.6k
  case OMPC_grainsize:
210
52.6k
  case OMPC_nogroup:
211
52.6k
  case OMPC_num_tasks:
212
52.6k
  case OMPC_hint:
213
52.6k
  case OMPC_defaultmap:
214
52.6k
  case OMPC_unknown:
215
52.6k
  case OMPC_uniform:
216
52.6k
  case OMPC_to:
217
52.6k
  case OMPC_from:
218
52.6k
  case OMPC_use_device_ptr:
219
52.6k
  case OMPC_is_device_ptr:
220
52.6k
  case OMPC_unified_address:
221
52.6k
  case OMPC_unified_shared_memory:
222
52.6k
  case OMPC_reverse_offload:
223
52.6k
  case OMPC_dynamic_allocators:
224
52.6k
  case OMPC_atomic_default_mem_order:
225
52.6k
  case OMPC_device_type:
226
52.6k
  case OMPC_match:
227
52.6k
  case OMPC_nontemporal:
228
52.6k
  case OMPC_order:
229
52.6k
    break;
230
52.6k
  }
231
52.6k
232
52.6k
  return nullptr;
233
52.6k
}
234
235
/// Gets the address of the original, non-captured, expression used in the
236
/// clause as the preinitializer.
237
10.1k
static Stmt **getAddrOfExprAsWritten(Stmt *S) {
238
10.1k
  if (!S)
239
8.01k
    return nullptr;
240
2.11k
  if (auto *DS = dyn_cast<DeclStmt>(S)) {
241
2.11k
    assert(DS->isSingleDecl() && "Only single expression must be captured.");
242
2.11k
    if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
243
2.11k
      return OED->getInitAddress();
244
0
  }
245
0
  return nullptr;
246
0
}
247
248
8.13k
OMPClause::child_range OMPIfClause::used_children() {
249
8.13k
  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
250
1.77k
    return child_range(C, C + 1);
251
6.35k
  return child_range(&Condition, &Condition + 1);
252
6.35k
}
253
254
360
OMPClause::child_range OMPGrainsizeClause::used_children() {
255
360
  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
256
24
    return child_range(C, C + 1);
257
336
  return child_range(&Grainsize, &Grainsize + 1);
258
336
}
259
260
504
OMPClause::child_range OMPNumTasksClause::used_children() {
261
504
  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
262
48
    return child_range(C, C + 1);
263
456
  return child_range(&NumTasks, &NumTasks + 1);
264
456
}
265
266
384
OMPClause::child_range OMPFinalClause::used_children() {
267
384
  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
268
144
    return child_range(C, C + 1);
269
240
  return child_range(&Condition, &Condition + 1);
270
240
}
271
272
744
OMPClause::child_range OMPPriorityClause::used_children() {
273
744
  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
274
120
    return child_range(C, C + 1);
275
624
  return child_range(&Priority, &Priority + 1);
276
624
}
277
278
OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
279
                                           unsigned NumLoops,
280
                                           SourceLocation StartLoc,
281
                                           SourceLocation LParenLoc,
282
1.11k
                                           SourceLocation EndLoc) {
283
1.11k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
284
1.11k
  auto *Clause =
285
1.11k
      new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc);
286
2.06k
  for (unsigned I = 0; I < NumLoops; 
++I953
) {
287
953
    Clause->setLoopNumIterations(I, nullptr);
288
953
    Clause->setLoopCounter(I, nullptr);
289
953
  }
290
1.11k
  return Clause;
291
1.11k
}
292
293
OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
294
64
                                                unsigned NumLoops) {
295
64
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops));
296
64
  auto *Clause = new (Mem) OMPOrderedClause(NumLoops);
297
86
  for (unsigned I = 0; I < NumLoops; 
++I22
) {
298
22
    Clause->setLoopNumIterations(I, nullptr);
299
22
    Clause->setLoopCounter(I, nullptr);
300
22
  }
301
64
  return Clause;
302
64
}
303
304
void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
305
1.37k
                                            Expr *NumIterations) {
306
1.37k
  assert(NumLoop < NumberOfLoops && "out of loops number.");
307
1.37k
  getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
308
1.37k
}
309
310
625
ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
311
625
  return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops);
312
625
}
313
314
1.37k
void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
315
1.37k
  assert(NumLoop < NumberOfLoops && "out of loops number.");
316
1.37k
  getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
317
1.37k
}
318
319
22
Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
320
22
  assert(NumLoop < NumberOfLoops && "out of loops number.");
321
22
  return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
322
22
}
323
324
10
const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
325
10
  assert(NumLoop < NumberOfLoops && "out of loops number.");
326
10
  return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
327
10
}
328
329
11.7k
void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
330
11.7k
  assert(VL.size() == varlist_size() &&
331
11.7k
         "Number of private copies is not the same as the preallocated buffer");
332
11.7k
  std::copy(VL.begin(), VL.end(), varlist_end());
333
11.7k
}
334
335
OMPPrivateClause *
336
OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
337
                         SourceLocation LParenLoc, SourceLocation EndLoc,
338
10.4k
                         ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
339
10.4k
  // Allocate space for private variables and initializer expressions.
340
10.4k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
341
10.4k
  OMPPrivateClause *Clause =
342
10.4k
      new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
343
10.4k
  Clause->setVarRefs(VL);
344
10.4k
  Clause->setPrivateCopies(PrivateVL);
345
10.4k
  return Clause;
346
10.4k
}
347
348
OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
349
1.32k
                                                unsigned N) {
350
1.32k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
351
1.32k
  return new (Mem) OMPPrivateClause(N);
352
1.32k
}
353
354
42.8k
void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
355
42.8k
  assert(VL.size() == varlist_size() &&
356
42.8k
         "Number of private copies is not the same as the preallocated buffer");
357
42.8k
  std::copy(VL.begin(), VL.end(), varlist_end());
358
42.8k
}
359
360
42.8k
void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
361
42.8k
  assert(VL.size() == varlist_size() &&
362
42.8k
         "Number of inits is not the same as the preallocated buffer");
363
42.8k
  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
364
42.8k
}
365
366
OMPFirstprivateClause *
367
OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
368
                              SourceLocation LParenLoc, SourceLocation EndLoc,
369
                              ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
370
39.5k
                              ArrayRef<Expr *> InitVL, Stmt *PreInit) {
371
39.5k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
372
39.5k
  OMPFirstprivateClause *Clause =
373
39.5k
      new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
374
39.5k
  Clause->setVarRefs(VL);
375
39.5k
  Clause->setPrivateCopies(PrivateVL);
376
39.5k
  Clause->setInits(InitVL);
377
39.5k
  Clause->setPreInitStmt(PreInit);
378
39.5k
  return Clause;
379
39.5k
}
380
381
OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
382
3.25k
                                                          unsigned N) {
383
3.25k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
384
3.25k
  return new (Mem) OMPFirstprivateClause(N);
385
3.25k
}
386
387
6.20k
void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
388
6.20k
  assert(PrivateCopies.size() == varlist_size() &&
389
6.20k
         "Number of private copies is not the same as the preallocated buffer");
390
6.20k
  std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
391
6.20k
}
392
393
6.20k
void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
394
6.20k
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
395
6.20k
                                              "not the same as the "
396
6.20k
                                              "preallocated buffer");
397
6.20k
  std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
398
6.20k
}
399
400
6.20k
void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
401
6.20k
  assert(DstExprs.size() == varlist_size() && "Number of destination "
402
6.20k
                                              "expressions is not the same as "
403
6.20k
                                              "the preallocated buffer");
404
6.20k
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
405
6.20k
}
406
407
6.20k
void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
408
6.20k
  assert(AssignmentOps.size() == varlist_size() &&
409
6.20k
         "Number of assignment expressions is not the same as the preallocated "
410
6.20k
         "buffer");
411
6.20k
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
412
6.20k
            getDestinationExprs().end());
413
6.20k
}
414
415
OMPLastprivateClause *OMPLastprivateClause::Create(
416
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
417
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
418
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
419
    OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
420
5.81k
    SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate) {
421
5.81k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
422
5.81k
  OMPLastprivateClause *Clause = new (Mem) OMPLastprivateClause(
423
5.81k
      StartLoc, LParenLoc, EndLoc, LPKind, LPKindLoc, ColonLoc, VL.size());
424
5.81k
  Clause->setVarRefs(VL);
425
5.81k
  Clause->setSourceExprs(SrcExprs);
426
5.81k
  Clause->setDestinationExprs(DstExprs);
427
5.81k
  Clause->setAssignmentOps(AssignmentOps);
428
5.81k
  Clause->setPreInitStmt(PreInit);
429
5.81k
  Clause->setPostUpdateExpr(PostUpdate);
430
5.81k
  return Clause;
431
5.81k
}
432
433
OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
434
394
                                                        unsigned N) {
435
394
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
436
394
  return new (Mem) OMPLastprivateClause(N);
437
394
}
438
439
OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
440
                                         SourceLocation StartLoc,
441
                                         SourceLocation LParenLoc,
442
                                         SourceLocation EndLoc,
443
2.87k
                                         ArrayRef<Expr *> VL) {
444
2.87k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
445
2.87k
  OMPSharedClause *Clause =
446
2.87k
      new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
447
2.87k
  Clause->setVarRefs(VL);
448
2.87k
  return Clause;
449
2.87k
}
450
451
334
OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
452
334
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
453
334
  return new (Mem) OMPSharedClause(N);
454
334
}
455
456
2.93k
void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
457
2.93k
  assert(PL.size() == varlist_size() &&
458
2.93k
         "Number of privates is not the same as the preallocated buffer");
459
2.93k
  std::copy(PL.begin(), PL.end(), varlist_end());
460
2.93k
}
461
462
2.93k
void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
463
2.93k
  assert(IL.size() == varlist_size() &&
464
2.93k
         "Number of inits is not the same as the preallocated buffer");
465
2.93k
  std::copy(IL.begin(), IL.end(), getPrivates().end());
466
2.93k
}
467
468
2.30k
void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
469
2.30k
  assert(UL.size() == varlist_size() &&
470
2.30k
         "Number of updates is not the same as the preallocated buffer");
471
2.30k
  std::copy(UL.begin(), UL.end(), getInits().end());
472
2.30k
}
473
474
2.30k
void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
475
2.30k
  assert(FL.size() == varlist_size() &&
476
2.30k
         "Number of final updates is not the same as the preallocated buffer");
477
2.30k
  std::copy(FL.begin(), FL.end(), getUpdates().end());
478
2.30k
}
479
480
2.30k
void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) {
481
2.30k
  assert(
482
2.30k
      UE.size() == varlist_size() + 1 &&
483
2.30k
      "Number of used expressions is not the same as the preallocated buffer");
484
2.30k
  std::copy(UE.begin(), UE.end(), getFinals().end() + 2);
485
2.30k
}
486
487
OMPLinearClause *OMPLinearClause::Create(
488
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
489
    OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
490
    SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
491
    ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
492
2.58k
    Stmt *PreInit, Expr *PostUpdate) {
493
2.58k
  // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
494
2.58k
  // (Step and CalcStep), list of used expression + step.
495
2.58k
  void *Mem =
496
2.58k
      C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1));
497
2.58k
  OMPLinearClause *Clause = new (Mem) OMPLinearClause(
498
2.58k
      StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
499
2.58k
  Clause->setVarRefs(VL);
500
2.58k
  Clause->setPrivates(PL);
501
2.58k
  Clause->setInits(IL);
502
2.58k
  // Fill update and final expressions with zeroes, they are provided later,
503
2.58k
  // after the directive construction.
504
2.58k
  std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
505
2.58k
            nullptr);
506
2.58k
  std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
507
2.58k
            nullptr);
508
2.58k
  std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(),
509
2.58k
            nullptr);
510
2.58k
  Clause->setStep(Step);
511
2.58k
  Clause->setCalcStep(CalcStep);
512
2.58k
  Clause->setPreInitStmt(PreInit);
513
2.58k
  Clause->setPostUpdateExpr(PostUpdate);
514
2.58k
  return Clause;
515
2.58k
}
516
517
OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
518
358
                                              unsigned NumVars) {
519
358
  // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions
520
358
  // (Step and CalcStep), list of used expression + step.
521
358
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars  +1));
522
358
  return new (Mem) OMPLinearClause(NumVars);
523
358
}
524
525
1.91k
OMPClause::child_range OMPLinearClause::used_children() {
526
1.91k
  // Range includes only non-nullptr elements.
527
1.91k
  return child_range(
528
1.91k
      reinterpret_cast<Stmt **>(getUsedExprs().begin()),
529
1.91k
      reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr)));
530
1.91k
}
531
532
OMPAlignedClause *
533
OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
534
                         SourceLocation LParenLoc, SourceLocation ColonLoc,
535
1.69k
                         SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
536
1.69k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
537
1.69k
  OMPAlignedClause *Clause = new (Mem)
538
1.69k
      OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
539
1.69k
  Clause->setVarRefs(VL);
540
1.69k
  Clause->setAlignment(A);
541
1.69k
  return Clause;
542
1.69k
}
543
544
OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
545
244
                                                unsigned NumVars) {
546
244
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
547
244
  return new (Mem) OMPAlignedClause(NumVars);
548
244
}
549
550
471
void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
551
471
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
552
471
                                              "not the same as the "
553
471
                                              "preallocated buffer");
554
471
  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
555
471
}
556
557
471
void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
558
471
  assert(DstExprs.size() == varlist_size() && "Number of destination "
559
471
                                              "expressions is not the same as "
560
471
                                              "the preallocated buffer");
561
471
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
562
471
}
563
564
471
void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
565
471
  assert(AssignmentOps.size() == varlist_size() &&
566
471
         "Number of assignment expressions is not the same as the preallocated "
567
471
         "buffer");
568
471
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
569
471
            getDestinationExprs().end());
570
471
}
571
572
OMPCopyinClause *OMPCopyinClause::Create(
573
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
574
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
575
397
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
576
397
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
577
397
  OMPCopyinClause *Clause =
578
397
      new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
579
397
  Clause->setVarRefs(VL);
580
397
  Clause->setSourceExprs(SrcExprs);
581
397
  Clause->setDestinationExprs(DstExprs);
582
397
  Clause->setAssignmentOps(AssignmentOps);
583
397
  return Clause;
584
397
}
585
586
74
OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
587
74
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
588
74
  return new (Mem) OMPCopyinClause(N);
589
74
}
590
591
162
void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
592
162
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
593
162
                                              "not the same as the "
594
162
                                              "preallocated buffer");
595
162
  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
596
162
}
597
598
162
void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
599
162
  assert(DstExprs.size() == varlist_size() && "Number of destination "
600
162
                                              "expressions is not the same as "
601
162
                                              "the preallocated buffer");
602
162
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
603
162
}
604
605
162
void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
606
162
  assert(AssignmentOps.size() == varlist_size() &&
607
162
         "Number of assignment expressions is not the same as the preallocated "
608
162
         "buffer");
609
162
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
610
162
            getDestinationExprs().end());
611
162
}
612
613
OMPCopyprivateClause *OMPCopyprivateClause::Create(
614
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
615
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
616
144
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
617
144
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
618
144
  OMPCopyprivateClause *Clause =
619
144
      new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
620
144
  Clause->setVarRefs(VL);
621
144
  Clause->setSourceExprs(SrcExprs);
622
144
  Clause->setDestinationExprs(DstExprs);
623
144
  Clause->setAssignmentOps(AssignmentOps);
624
144
  return Clause;
625
144
}
626
627
OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
628
18
                                                        unsigned N) {
629
18
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
630
18
  return new (Mem) OMPCopyprivateClause(N);
631
18
}
632
633
14.3k
void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
634
14.3k
  assert(Privates.size() == varlist_size() &&
635
14.3k
         "Number of private copies is not the same as the preallocated buffer");
636
14.3k
  std::copy(Privates.begin(), Privates.end(), varlist_end());
637
14.3k
}
638
639
14.3k
void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
640
14.3k
  assert(
641
14.3k
      LHSExprs.size() == varlist_size() &&
642
14.3k
      "Number of LHS expressions is not the same as the preallocated buffer");
643
14.3k
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
644
14.3k
}
645
646
14.3k
void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
647
14.3k
  assert(
648
14.3k
      RHSExprs.size() == varlist_size() &&
649
14.3k
      "Number of RHS expressions is not the same as the preallocated buffer");
650
14.3k
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
651
14.3k
}
652
653
14.3k
void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
654
14.3k
  assert(ReductionOps.size() == varlist_size() && "Number of reduction "
655
14.3k
                                                  "expressions is not the same "
656
14.3k
                                                  "as the preallocated buffer");
657
14.3k
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
658
14.3k
}
659
660
OMPReductionClause *OMPReductionClause::Create(
661
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
662
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
663
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
664
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
665
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
666
13.5k
    Expr *PostUpdate) {
667
13.5k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
668
13.5k
  OMPReductionClause *Clause = new (Mem) OMPReductionClause(
669
13.5k
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
670
13.5k
  Clause->setVarRefs(VL);
671
13.5k
  Clause->setPrivates(Privates);
672
13.5k
  Clause->setLHSExprs(LHSExprs);
673
13.5k
  Clause->setRHSExprs(RHSExprs);
674
13.5k
  Clause->setReductionOps(ReductionOps);
675
13.5k
  Clause->setPreInitStmt(PreInit);
676
13.5k
  Clause->setPostUpdateExpr(PostUpdate);
677
13.5k
  return Clause;
678
13.5k
}
679
680
OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
681
795
                                                    unsigned N) {
682
795
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
683
795
  return new (Mem) OMPReductionClause(N);
684
795
}
685
686
2.34k
void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
687
2.34k
  assert(Privates.size() == varlist_size() &&
688
2.34k
         "Number of private copies is not the same as the preallocated buffer");
689
2.34k
  std::copy(Privates.begin(), Privates.end(), varlist_end());
690
2.34k
}
691
692
2.34k
void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
693
2.34k
  assert(
694
2.34k
      LHSExprs.size() == varlist_size() &&
695
2.34k
      "Number of LHS expressions is not the same as the preallocated buffer");
696
2.34k
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
697
2.34k
}
698
699
2.34k
void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
700
2.34k
  assert(
701
2.34k
      RHSExprs.size() == varlist_size() &&
702
2.34k
      "Number of RHS expressions is not the same as the preallocated buffer");
703
2.34k
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
704
2.34k
}
705
706
2.34k
void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
707
2.34k
  assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
708
2.34k
                                                  "expressions is not the same "
709
2.34k
                                                  "as the preallocated buffer");
710
2.34k
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
711
2.34k
}
712
713
OMPTaskReductionClause *OMPTaskReductionClause::Create(
714
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
715
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
716
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
717
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
718
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
719
2.26k
    Expr *PostUpdate) {
720
2.26k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
721
2.26k
  OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
722
2.26k
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
723
2.26k
  Clause->setVarRefs(VL);
724
2.26k
  Clause->setPrivates(Privates);
725
2.26k
  Clause->setLHSExprs(LHSExprs);
726
2.26k
  Clause->setRHSExprs(RHSExprs);
727
2.26k
  Clause->setReductionOps(ReductionOps);
728
2.26k
  Clause->setPreInitStmt(PreInit);
729
2.26k
  Clause->setPostUpdateExpr(PostUpdate);
730
2.26k
  return Clause;
731
2.26k
}
732
733
OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
734
86
                                                            unsigned N) {
735
86
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
736
86
  return new (Mem) OMPTaskReductionClause(N);
737
86
}
738
739
1.47k
void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
740
1.47k
  assert(Privates.size() == varlist_size() &&
741
1.47k
         "Number of private copies is not the same as the preallocated buffer");
742
1.47k
  std::copy(Privates.begin(), Privates.end(), varlist_end());
743
1.47k
}
744
745
1.47k
void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
746
1.47k
  assert(
747
1.47k
      LHSExprs.size() == varlist_size() &&
748
1.47k
      "Number of LHS expressions is not the same as the preallocated buffer");
749
1.47k
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
750
1.47k
}
751
752
1.47k
void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
753
1.47k
  assert(
754
1.47k
      RHSExprs.size() == varlist_size() &&
755
1.47k
      "Number of RHS expressions is not the same as the preallocated buffer");
756
1.47k
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
757
1.47k
}
758
759
1.47k
void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
760
1.47k
  assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
761
1.47k
                                                  "expressions is not the same "
762
1.47k
                                                  "as the preallocated buffer");
763
1.47k
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
764
1.47k
}
765
766
void OMPInReductionClause::setTaskgroupDescriptors(
767
1.47k
    ArrayRef<Expr *> TaskgroupDescriptors) {
768
1.47k
  assert(TaskgroupDescriptors.size() == varlist_size() &&
769
1.47k
         "Number of in reduction descriptors is not the same as the "
770
1.47k
         "preallocated buffer");
771
1.47k
  std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
772
1.47k
            getReductionOps().end());
773
1.47k
}
774
775
OMPInReductionClause *OMPInReductionClause::Create(
776
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
777
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
778
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
779
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
780
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
781
1.41k
    ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
782
1.41k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
783
1.41k
  OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
784
1.41k
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
785
1.41k
  Clause->setVarRefs(VL);
786
1.41k
  Clause->setPrivates(Privates);
787
1.41k
  Clause->setLHSExprs(LHSExprs);
788
1.41k
  Clause->setRHSExprs(RHSExprs);
789
1.41k
  Clause->setReductionOps(ReductionOps);
790
1.41k
  Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
791
1.41k
  Clause->setPreInitStmt(PreInit);
792
1.41k
  Clause->setPostUpdateExpr(PostUpdate);
793
1.41k
  return Clause;
794
1.41k
}
795
796
OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
797
52
                                                        unsigned N) {
798
52
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
799
52
  return new (Mem) OMPInReductionClause(N);
800
52
}
801
802
OMPAllocateClause *
803
OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc,
804
                          SourceLocation LParenLoc, Expr *Allocator,
805
                          SourceLocation ColonLoc, SourceLocation EndLoc,
806
1.42k
                          ArrayRef<Expr *> VL) {
807
1.42k
  // Allocate space for private variables and initializer expressions.
808
1.42k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
809
1.42k
  auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator,
810
1.42k
                                             ColonLoc, EndLoc, VL.size());
811
1.42k
  Clause->setVarRefs(VL);
812
1.42k
  return Clause;
813
1.42k
}
814
815
OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C,
816
216
                                                  unsigned N) {
817
216
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
818
216
  return new (Mem) OMPAllocateClause(N);
819
216
}
820
821
OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
822
                                       SourceLocation StartLoc,
823
                                       SourceLocation LParenLoc,
824
                                       SourceLocation EndLoc,
825
90
                                       ArrayRef<Expr *> VL) {
826
90
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
827
90
  OMPFlushClause *Clause =
828
90
      new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
829
90
  Clause->setVarRefs(VL);
830
90
  return Clause;
831
90
}
832
833
10
OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
834
10
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
835
10
  return new (Mem) OMPFlushClause(N);
836
10
}
837
838
OMPDependClause *
839
OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
840
                        SourceLocation LParenLoc, SourceLocation EndLoc,
841
                        OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
842
                        SourceLocation ColonLoc, ArrayRef<Expr *> VL,
843
2.21k
                        unsigned NumLoops) {
844
2.21k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops));
845
2.21k
  OMPDependClause *Clause = new (Mem)
846
2.21k
      OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops);
847
2.21k
  Clause->setVarRefs(VL);
848
2.21k
  Clause->setDependencyKind(DepKind);
849
2.21k
  Clause->setDependencyLoc(DepLoc);
850
2.21k
  Clause->setColonLoc(ColonLoc);
851
2.98k
  for (unsigned I = 0 ; I < NumLoops; 
++I775
)
852
775
    Clause->setLoopData(I, nullptr);
853
2.21k
  return Clause;
854
2.21k
}
855
856
OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N,
857
548
                                              unsigned NumLoops) {
858
548
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops));
859
548
  return new (Mem) OMPDependClause(N, NumLoops);
860
548
}
861
862
1.28k
void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) {
863
1.28k
  assert((getDependencyKind() == OMPC_DEPEND_sink ||
864
1.28k
          getDependencyKind() == OMPC_DEPEND_source) &&
865
1.28k
         NumLoop < NumLoops &&
866
1.28k
         "Expected sink or source depend + loop index must be less number of "
867
1.28k
         "loops.");
868
1.28k
  auto It = std::next(getVarRefs().end(), NumLoop);
869
1.28k
  *It = Cnt;
870
1.28k
}
871
872
28
Expr *OMPDependClause::getLoopData(unsigned NumLoop) {
873
28
  assert((getDependencyKind() == OMPC_DEPEND_sink ||
874
28
          getDependencyKind() == OMPC_DEPEND_source) &&
875
28
         NumLoop < NumLoops &&
876
28
         "Expected sink or source depend + loop index must be less number of "
877
28
         "loops.");
878
28
  auto It = std::next(getVarRefs().end(), NumLoop);
879
28
  return *It;
880
28
}
881
882
20
const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const {
883
20
  assert((getDependencyKind() == OMPC_DEPEND_sink ||
884
20
          getDependencyKind() == OMPC_DEPEND_source) &&
885
20
         NumLoop < NumLoops &&
886
20
         "Expected sink or source depend + loop index must be less number of "
887
20
         "loops.");
888
20
  auto It = std::next(getVarRefs().end(), NumLoop);
889
20
  return *It;
890
20
}
891
892
unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
893
48.8k
    MappableExprComponentListsRef ComponentLists) {
894
48.8k
  unsigned TotalNum = 0u;
895
48.8k
  for (auto &C : ComponentLists)
896
54.1k
    TotalNum += C.size();
897
48.8k
  return TotalNum;
898
48.8k
}
899
900
unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
901
48.8k
    ArrayRef<const ValueDecl *> Declarations) {
902
48.8k
  unsigned TotalNum = 0u;
903
48.8k
  llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
904
54.1k
  for (const ValueDecl *D : Declarations) {
905
54.1k
    const ValueDecl *VD = D ? 
cast<ValueDecl>(D->getCanonicalDecl())50.5k
:
nullptr3.59k
;
906
54.1k
    if (Cache.count(VD))
907
432
      continue;
908
53.6k
    ++TotalNum;
909
53.6k
    Cache.insert(VD);
910
53.6k
  }
911
48.8k
  return TotalNum;
912
48.8k
}
913
914
OMPMapClause *OMPMapClause::Create(
915
    const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
916
    ArrayRef<ValueDecl *> Declarations,
917
    MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
918
    ArrayRef<OpenMPMapModifierKind> MapModifiers,
919
    ArrayRef<SourceLocation> MapModifiersLoc,
920
    NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
921
20.2k
    OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) {
922
20.2k
  OMPMappableExprListSizeTy Sizes;
923
20.2k
  Sizes.NumVars = Vars.size();
924
20.2k
  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
925
20.2k
  Sizes.NumComponentLists = ComponentLists.size();
926
20.2k
  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
927
20.2k
928
20.2k
  // We need to allocate:
929
20.2k
  // 2 x NumVars x Expr* - we have an original list expression and an associated
930
20.2k
  // user-defined mapper for each clause list entry.
931
20.2k
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
932
20.2k
  // with each component list.
933
20.2k
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
934
20.2k
  // number of lists for each unique declaration and the size of each component
935
20.2k
  // list.
936
20.2k
  // NumComponents x MappableComponent - the total of all the components in all
937
20.2k
  // the lists.
938
20.2k
  void *Mem = C.Allocate(
939
20.2k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
940
20.2k
                       OMPClauseMappableExprCommon::MappableComponent>(
941
20.2k
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
942
20.2k
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
943
20.2k
          Sizes.NumComponents));
944
20.2k
  OMPMapClause *Clause = new (Mem)
945
20.2k
      OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId,
946
20.2k
                   Type, TypeIsImplicit, TypeLoc, Locs, Sizes);
947
20.2k
948
20.2k
  Clause->setVarRefs(Vars);
949
20.2k
  Clause->setUDMapperRefs(UDMapperRefs);
950
20.2k
  Clause->setClauseInfo(Declarations, ComponentLists);
951
20.2k
  Clause->setMapType(Type);
952
20.2k
  Clause->setMapLoc(TypeLoc);
953
20.2k
  return Clause;
954
20.2k
}
955
956
OMPMapClause *
957
OMPMapClause::CreateEmpty(const ASTContext &C,
958
2.27k
                          const OMPMappableExprListSizeTy &Sizes) {
959
2.27k
  void *Mem = C.Allocate(
960
2.27k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
961
2.27k
                       OMPClauseMappableExprCommon::MappableComponent>(
962
2.27k
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
963
2.27k
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
964
2.27k
          Sizes.NumComponents));
965
2.27k
  return new (Mem) OMPMapClause(Sizes);
966
2.27k
}
967
968
OMPToClause *OMPToClause::Create(
969
    const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
970
    ArrayRef<ValueDecl *> Declarations,
971
    MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
972
1.11k
    NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
973
1.11k
  OMPMappableExprListSizeTy Sizes;
974
1.11k
  Sizes.NumVars = Vars.size();
975
1.11k
  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
976
1.11k
  Sizes.NumComponentLists = ComponentLists.size();
977
1.11k
  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
978
1.11k
979
1.11k
  // We need to allocate:
980
1.11k
  // 2 x NumVars x Expr* - we have an original list expression and an associated
981
1.11k
  // user-defined mapper for each clause list entry.
982
1.11k
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
983
1.11k
  // with each component list.
984
1.11k
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
985
1.11k
  // number of lists for each unique declaration and the size of each component
986
1.11k
  // list.
987
1.11k
  // NumComponents x MappableComponent - the total of all the components in all
988
1.11k
  // the lists.
989
1.11k
  void *Mem = C.Allocate(
990
1.11k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
991
1.11k
                       OMPClauseMappableExprCommon::MappableComponent>(
992
1.11k
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
993
1.11k
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
994
1.11k
          Sizes.NumComponents));
995
1.11k
996
1.11k
  auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes);
997
1.11k
998
1.11k
  Clause->setVarRefs(Vars);
999
1.11k
  Clause->setUDMapperRefs(UDMapperRefs);
1000
1.11k
  Clause->setClauseInfo(Declarations, ComponentLists);
1001
1.11k
  return Clause;
1002
1.11k
}
1003
1004
OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C,
1005
46
                                      const OMPMappableExprListSizeTy &Sizes) {
1006
46
  void *Mem = C.Allocate(
1007
46
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1008
46
                       OMPClauseMappableExprCommon::MappableComponent>(
1009
46
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1010
46
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1011
46
          Sizes.NumComponents));
1012
46
  return new (Mem) OMPToClause(Sizes);
1013
46
}
1014
1015
OMPFromClause *OMPFromClause::Create(
1016
    const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1017
    ArrayRef<ValueDecl *> Declarations,
1018
    MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs,
1019
428
    NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) {
1020
428
  OMPMappableExprListSizeTy Sizes;
1021
428
  Sizes.NumVars = Vars.size();
1022
428
  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1023
428
  Sizes.NumComponentLists = ComponentLists.size();
1024
428
  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1025
428
1026
428
  // We need to allocate:
1027
428
  // 2 x NumVars x Expr* - we have an original list expression and an associated
1028
428
  // user-defined mapper for each clause list entry.
1029
428
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1030
428
  // with each component list.
1031
428
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1032
428
  // number of lists for each unique declaration and the size of each component
1033
428
  // list.
1034
428
  // NumComponents x MappableComponent - the total of all the components in all
1035
428
  // the lists.
1036
428
  void *Mem = C.Allocate(
1037
428
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1038
428
                       OMPClauseMappableExprCommon::MappableComponent>(
1039
428
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1040
428
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1041
428
          Sizes.NumComponents));
1042
428
1043
428
  auto *Clause =
1044
428
      new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes);
1045
428
1046
428
  Clause->setVarRefs(Vars);
1047
428
  Clause->setUDMapperRefs(UDMapperRefs);
1048
428
  Clause->setClauseInfo(Declarations, ComponentLists);
1049
428
  return Clause;
1050
428
}
1051
1052
OMPFromClause *
1053
OMPFromClause::CreateEmpty(const ASTContext &C,
1054
46
                           const OMPMappableExprListSizeTy &Sizes) {
1055
46
  void *Mem = C.Allocate(
1056
46
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1057
46
                       OMPClauseMappableExprCommon::MappableComponent>(
1058
46
          2 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1059
46
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1060
46
          Sizes.NumComponents));
1061
46
  return new (Mem) OMPFromClause(Sizes);
1062
46
}
1063
1064
428
void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1065
428
  assert(VL.size() == varlist_size() &&
1066
428
         "Number of private copies is not the same as the preallocated buffer");
1067
428
  std::copy(VL.begin(), VL.end(), varlist_end());
1068
428
}
1069
1070
428
void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
1071
428
  assert(VL.size() == varlist_size() &&
1072
428
         "Number of inits is not the same as the preallocated buffer");
1073
428
  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1074
428
}
1075
1076
OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
1077
    const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars,
1078
    ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
1079
    ArrayRef<ValueDecl *> Declarations,
1080
344
    MappableExprComponentListsRef ComponentLists) {
1081
344
  OMPMappableExprListSizeTy Sizes;
1082
344
  Sizes.NumVars = Vars.size();
1083
344
  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1084
344
  Sizes.NumComponentLists = ComponentLists.size();
1085
344
  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1086
344
1087
344
  // We need to allocate:
1088
344
  // 3 x NumVars x Expr* - we have an original list expression for each clause
1089
344
  // list entry and an equal number of private copies and inits.
1090
344
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1091
344
  // with each component list.
1092
344
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1093
344
  // number of lists for each unique declaration and the size of each component
1094
344
  // list.
1095
344
  // NumComponents x MappableComponent - the total of all the components in all
1096
344
  // the lists.
1097
344
  void *Mem = C.Allocate(
1098
344
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1099
344
                       OMPClauseMappableExprCommon::MappableComponent>(
1100
344
          3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1101
344
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1102
344
          Sizes.NumComponents));
1103
344
1104
344
  OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes);
1105
344
1106
344
  Clause->setVarRefs(Vars);
1107
344
  Clause->setPrivateCopies(PrivateVars);
1108
344
  Clause->setInits(Inits);
1109
344
  Clause->setClauseInfo(Declarations, ComponentLists);
1110
344
  return Clause;
1111
344
}
1112
1113
OMPUseDevicePtrClause *
1114
OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C,
1115
84
                                   const OMPMappableExprListSizeTy &Sizes) {
1116
84
  void *Mem = C.Allocate(
1117
84
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1118
84
                       OMPClauseMappableExprCommon::MappableComponent>(
1119
84
          3 * Sizes.NumVars, Sizes.NumUniqueDeclarations,
1120
84
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1121
84
          Sizes.NumComponents));
1122
84
  return new (Mem) OMPUseDevicePtrClause(Sizes);
1123
84
}
1124
1125
OMPIsDevicePtrClause *
1126
OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs,
1127
                             ArrayRef<Expr *> Vars,
1128
                             ArrayRef<ValueDecl *> Declarations,
1129
2.29k
                             MappableExprComponentListsRef ComponentLists) {
1130
2.29k
  OMPMappableExprListSizeTy Sizes;
1131
2.29k
  Sizes.NumVars = Vars.size();
1132
2.29k
  Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations);
1133
2.29k
  Sizes.NumComponentLists = ComponentLists.size();
1134
2.29k
  Sizes.NumComponents = getComponentsTotalNumber(ComponentLists);
1135
2.29k
1136
2.29k
  // We need to allocate:
1137
2.29k
  // NumVars x Expr* - we have an original list expression for each clause list
1138
2.29k
  // entry.
1139
2.29k
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
1140
2.29k
  // with each component list.
1141
2.29k
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
1142
2.29k
  // number of lists for each unique declaration and the size of each component
1143
2.29k
  // list.
1144
2.29k
  // NumComponents x MappableComponent - the total of all the components in all
1145
2.29k
  // the lists.
1146
2.29k
  void *Mem = C.Allocate(
1147
2.29k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1148
2.29k
                       OMPClauseMappableExprCommon::MappableComponent>(
1149
2.29k
          Sizes.NumVars, Sizes.NumUniqueDeclarations,
1150
2.29k
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1151
2.29k
          Sizes.NumComponents));
1152
2.29k
1153
2.29k
  OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes);
1154
2.29k
1155
2.29k
  Clause->setVarRefs(Vars);
1156
2.29k
  Clause->setClauseInfo(Declarations, ComponentLists);
1157
2.29k
  return Clause;
1158
2.29k
}
1159
1160
OMPIsDevicePtrClause *
1161
OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C,
1162
432
                                  const OMPMappableExprListSizeTy &Sizes) {
1163
432
  void *Mem = C.Allocate(
1164
432
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
1165
432
                       OMPClauseMappableExprCommon::MappableComponent>(
1166
432
          Sizes.NumVars, Sizes.NumUniqueDeclarations,
1167
432
          Sizes.NumUniqueDeclarations + Sizes.NumComponentLists,
1168
432
          Sizes.NumComponents));
1169
432
  return new (Mem) OMPIsDevicePtrClause(Sizes);
1170
432
}
1171
1172
OMPNontemporalClause *OMPNontemporalClause::Create(const ASTContext &C,
1173
                                                   SourceLocation StartLoc,
1174
                                                   SourceLocation LParenLoc,
1175
                                                   SourceLocation EndLoc,
1176
422
                                                   ArrayRef<Expr *> VL) {
1177
422
  // Allocate space for nontemporal variables + private references.
1178
422
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
1179
422
  auto *Clause =
1180
422
      new (Mem) OMPNontemporalClause(StartLoc, LParenLoc, EndLoc, VL.size());
1181
422
  Clause->setVarRefs(VL);
1182
422
  return Clause;
1183
422
}
1184
1185
OMPNontemporalClause *OMPNontemporalClause::CreateEmpty(const ASTContext &C,
1186
82
                                                        unsigned N) {
1187
82
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
1188
82
  return new (Mem) OMPNontemporalClause(N);
1189
82
}
1190
1191
504
void OMPNontemporalClause::setPrivateRefs(ArrayRef<Expr *> VL) {
1192
504
  assert(VL.size() == varlist_size() && "Number of private references is not "
1193
504
                                        "the same as the preallocated buffer");
1194
504
  std::copy(VL.begin(), VL.end(), varlist_end());
1195
504
}
1196
1197
//===----------------------------------------------------------------------===//
1198
//  OpenMP clauses printing methods
1199
//===----------------------------------------------------------------------===//
1200
1201
1.51k
void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
1202
1.51k
  OS << "if(";
1203
1.51k
  if (Node->getNameModifier() != llvm::omp::OMPD_unknown)
1204
761
    OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1205
1.51k
  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1206
1.51k
  OS << ")";
1207
1.51k
}
1208
1209
160
void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) {
1210
160
  OS << "final(";
1211
160
  Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
1212
160
  OS << ")";
1213
160
}
1214
1215
324
void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) {
1216
324
  OS << "num_threads(";
1217
324
  Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0);
1218
324
  OS << ")";
1219
324
}
1220
1221
384
void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) {
1222
384
  OS << "safelen(";
1223
384
  Node->getSafelen()->printPretty(OS, nullptr, Policy, 0);
1224
384
  OS << ")";
1225
384
}
1226
1227
384
void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) {
1228
384
  OS << "simdlen(";
1229
384
  Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0);
1230
384
  OS << ")";
1231
384
}
1232
1233
86
void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) {
1234
86
  OS << "allocator(";
1235
86
  Node->getAllocator()->printPretty(OS, nullptr, Policy, 0);
1236
86
  OS << ")";
1237
86
}
1238
1239
488
void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) {
1240
488
  OS << "collapse(";
1241
488
  Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0);
1242
488
  OS << ")";
1243
488
}
1244
1245
700
void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) {
1246
700
  OS << "default("
1247
700
     << getOpenMPSimpleClauseTypeName(OMPC_default,
1248
700
                                      unsigned(Node->getDefaultKind()))
1249
700
     << ")";
1250
700
}
1251
1252
196
void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) {
1253
196
  OS << "proc_bind("
1254
196
     << getOpenMPSimpleClauseTypeName(OMPC_proc_bind,
1255
196
                                      unsigned(Node->getProcBindKind()))
1256
196
     << ")";
1257
196
}
1258
1259
4
void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {
1260
4
  OS << "unified_address";
1261
4
}
1262
1263
void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause(
1264
4
    OMPUnifiedSharedMemoryClause *) {
1265
4
  OS << "unified_shared_memory";
1266
4
}
1267
1268
4
void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {
1269
4
  OS << "reverse_offload";
1270
4
}
1271
1272
void OMPClausePrinter::VisitOMPDynamicAllocatorsClause(
1273
4
    OMPDynamicAllocatorsClause *) {
1274
4
  OS << "dynamic_allocators";
1275
4
}
1276
1277
void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause(
1278
12
    OMPAtomicDefaultMemOrderClause *Node) {
1279
12
  OS << "atomic_default_mem_order("
1280
12
     << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order,
1281
12
                                      Node->getAtomicDefaultMemOrderKind())
1282
12
     << ")";
1283
12
}
1284
1285
292
void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
1286
292
  OS << "schedule(";
1287
292
  if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1288
0
    OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1289
0
                                        Node->getFirstScheduleModifier());
1290
0
    if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) {
1291
0
      OS << ", ";
1292
0
      OS << getOpenMPSimpleClauseTypeName(OMPC_schedule,
1293
0
                                          Node->getSecondScheduleModifier());
1294
0
    }
1295
0
    OS << ": ";
1296
0
  }
1297
292
  OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind());
1298
292
  if (auto *E = Node->getChunkSize()) {
1299
144
    OS << ", ";
1300
144
    E->printPretty(OS, nullptr, Policy);
1301
144
  }
1302
292
  OS << ")";
1303
292
}
1304
1305
137
void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) {
1306
137
  OS << "ordered";
1307
137
  if (auto *Num = Node->getNumForLoops()) {
1308
48
    OS << "(";
1309
48
    Num->printPretty(OS, nullptr, Policy, 0);
1310
48
    OS << ")";
1311
48
  }
1312
137
}
1313
1314
708
void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
1315
708
  OS << "nowait";
1316
708
}
1317
1318
124
void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) {
1319
124
  OS << "untied";
1320
124
}
1321
1322
108
void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) {
1323
108
  OS << "nogroup";
1324
108
}
1325
1326
160
void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
1327
160
  OS << "mergeable";
1328
160
}
1329
1330
85
void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; }
1331
1332
84
void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; }
1333
1334
84
void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) {
1335
84
  OS << "update";
1336
84
}
1337
1338
168
void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) {
1339
168
  OS << "capture";
1340
168
}
1341
1342
72
void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) {
1343
72
  OS << "seq_cst";
1344
72
}
1345
1346
40
void OMPClausePrinter::VisitOMPAcqRelClause(OMPAcqRelClause *) {
1347
40
  OS << "acq_rel";
1348
40
}
1349
1350
52
void OMPClausePrinter::VisitOMPAcquireClause(OMPAcquireClause *) {
1351
52
  OS << "acquire";
1352
52
}
1353
1354
76
void OMPClausePrinter::VisitOMPReleaseClause(OMPReleaseClause *) {
1355
76
  OS << "release";
1356
76
}
1357
1358
60
void OMPClausePrinter::VisitOMPRelaxedClause(OMPRelaxedClause *) {
1359
60
  OS << "relaxed";
1360
60
}
1361
1362
12
void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) {
1363
12
  OS << "threads";
1364
12
}
1365
1366
36
void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; }
1367
1368
32
void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) {
1369
32
  OS << "device(";
1370
32
  Node->getDevice()->printPretty(OS, nullptr, Policy, 0);
1371
32
  OS << ")";
1372
32
}
1373
1374
216
void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) {
1375
216
  OS << "num_teams(";
1376
216
  Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0);
1377
216
  OS << ")";
1378
216
}
1379
1380
216
void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) {
1381
216
  OS << "thread_limit(";
1382
216
  Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0);
1383
216
  OS << ")";
1384
216
}
1385
1386
320
void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) {
1387
320
  OS << "priority(";
1388
320
  Node->getPriority()->printPretty(OS, nullptr, Policy, 0);
1389
320
  OS << ")";
1390
320
}
1391
1392
144
void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
1393
144
  OS << "grainsize(";
1394
144
  Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0);
1395
144
  OS << ")";
1396
144
}
1397
1398
144
void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
1399
144
  OS << "num_tasks(";
1400
144
  Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
1401
144
  OS << ")";
1402
144
}
1403
1404
84
void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) {
1405
84
  OS << "hint(";
1406
84
  Node->getHint()->printPretty(OS, nullptr, Policy, 0);
1407
84
  OS << ")";
1408
84
}
1409
1410
template<typename T>
1411
12.5k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
12.5k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
12.5k
                                    E = Node->varlist_end();
1414
28.4k
       I != E; 
++I15.9k
) {
1415
15.9k
    assert(*I && "Expected non-null Stmt");
1416
15.9k
    OS << (I == Node->varlist_begin() ? 
StartSym12.5k
:
','3.38k
);
1417
15.9k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
12.9k
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
1.24k
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
11.7k
      else
1421
11.7k
        DRE->getDecl()->printQualifiedName(OS);
1422
12.9k
    } else
1423
2.94k
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
15.9k
  }
1425
12.5k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPAllocateClause>(clang::OMPAllocateClause*, char)
Line
Count
Source
1411
788
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
788
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
788
                                    E = Node->varlist_end();
1414
1.57k
       I != E; 
++I788
) {
1415
788
    assert(*I && "Expected non-null Stmt");
1416
788
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
788
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
744
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
20
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
724
      else
1421
724
        DRE->getDecl()->printQualifiedName(OS);
1422
744
    } else
1423
44
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
788
  }
1425
788
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPPrivateClause>(clang::OMPPrivateClause*, char)
Line
Count
Source
1411
2.66k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
2.66k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
2.66k
                                    E = Node->varlist_end();
1414
6.03k
       I != E; 
++I3.37k
) {
1415
3.37k
    assert(*I && "Expected non-null Stmt");
1416
3.37k
    OS << (I == Node->varlist_begin() ? 
StartSym2.66k
:
','716
);
1417
3.37k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
2.73k
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
1.02k
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
1.71k
      else
1421
1.71k
        DRE->getDecl()->printQualifiedName(OS);
1422
2.73k
    } else
1423
640
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
3.37k
  }
1425
2.66k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFirstprivateClause>(clang::OMPFirstprivateClause*, char)
Line
Count
Source
1411
1.09k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
1.09k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
1.09k
                                    E = Node->varlist_end();
1414
2.67k
       I != E; 
++I1.58k
) {
1415
1.58k
    assert(*I && "Expected non-null Stmt");
1416
1.58k
    OS << (I == Node->varlist_begin() ? 
StartSym1.09k
:
','496
);
1417
1.58k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
1.54k
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
84
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
1.45k
      else
1421
1.45k
        DRE->getDecl()->printQualifiedName(OS);
1422
1.54k
    } else
1423
44
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
1.58k
  }
1425
1.09k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPLastprivateClause>(clang::OMPLastprivateClause*, char)
Line
Count
Source
1411
500
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
500
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
500
                                    E = Node->varlist_end();
1414
1.36k
       I != E; 
++I860
) {
1415
860
    assert(*I && "Expected non-null Stmt");
1416
860
    OS << (I == Node->varlist_begin() ? 
StartSym500
:
','360
);
1417
860
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
840
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
32
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
808
      else
1421
808
        DRE->getDecl()->printQualifiedName(OS);
1422
840
    } else
1423
20
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
860
  }
1425
500
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPSharedClause>(clang::OMPSharedClause*, char)
Line
Count
Source
1411
762
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
762
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
762
                                    E = Node->varlist_end();
1414
1.55k
       I != E; 
++I790
) {
1415
790
    assert(*I && "Expected non-null Stmt");
1416
790
    OS << (I == Node->varlist_begin() ? 
StartSym762
:
','28
);
1417
790
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
686
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
686
      else
1421
686
        DRE->getDecl()->printQualifiedName(OS);
1422
686
    } else
1423
104
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
790
  }
1425
762
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPReductionClause>(clang::OMPReductionClause*, char)
Line
Count
Source
1411
1.47k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
1.47k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
1.47k
                                    E = Node->varlist_end();
1414
3.48k
       I != E; 
++I2.01k
) {
1415
2.01k
    assert(*I && "Expected non-null Stmt");
1416
2.01k
    OS << (I == Node->varlist_begin() ? 
StartSym1.47k
:
','532
);
1417
2.01k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
1.62k
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
24
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
1.60k
      else
1421
1.60k
        DRE->getDecl()->printQualifiedName(OS);
1422
1.62k
    } else
1423
384
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
2.01k
  }
1425
1.47k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPTaskReductionClause>(clang::OMPTaskReductionClause*, char)
Line
Count
Source
1411
216
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
216
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
216
                                    E = Node->varlist_end();
1414
432
       I != E; 
++I216
) {
1415
216
    assert(*I && "Expected non-null Stmt");
1416
216
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
216
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
184
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
16
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
168
      else
1421
168
        DRE->getDecl()->printQualifiedName(OS);
1422
184
    } else
1423
32
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
216
  }
1425
216
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPInReductionClause>(clang::OMPInReductionClause*, char)
Line
Count
Source
1411
124
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
124
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
124
                                    E = Node->varlist_end();
1414
248
       I != E; 
++I124
) {
1415
124
    assert(*I && "Expected non-null Stmt");
1416
124
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
124
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
120
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
4
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
116
      else
1421
116
        DRE->getDecl()->printQualifiedName(OS);
1422
120
    } else
1423
4
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
124
  }
1425
124
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPLinearClause>(clang::OMPLinearClause*, char)
Line
Count
Source
1411
417
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
417
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
417
                                    E = Node->varlist_end();
1414
882
       I != E; 
++I465
) {
1415
465
    assert(*I && "Expected non-null Stmt");
1416
465
    OS << (I == Node->varlist_begin() ? 
StartSym417
:
','48
);
1417
465
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
457
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
12
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
445
      else
1421
445
        DRE->getDecl()->printQualifiedName(OS);
1422
457
    } else
1423
8
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
465
  }
1425
417
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPAlignedClause>(clang::OMPAlignedClause*, char)
Line
Count
Source
1411
408
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
408
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
408
                                    E = Node->varlist_end();
1414
816
       I != E; 
++I408
) {
1415
408
    assert(*I && "Expected non-null Stmt");
1416
408
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
408
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
208
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
208
      else
1421
208
        DRE->getDecl()->printQualifiedName(OS);
1422
208
    } else
1423
200
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
408
  }
1425
408
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPCopyinClause>(clang::OMPCopyinClause*, char)
Line
Count
Source
1411
152
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
152
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
152
                                    E = Node->varlist_end();
1414
328
       I != E; 
++I176
) {
1415
176
    assert(*I && "Expected non-null Stmt");
1416
176
    OS << (I == Node->varlist_begin() ? 
StartSym152
:
','24
);
1417
176
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
164
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
164
      else
1421
164
        DRE->getDecl()->printQualifiedName(OS);
1422
164
    } else
1423
12
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
176
  }
1425
152
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPCopyprivateClause>(clang::OMPCopyprivateClause*, char)
Line
Count
Source
1411
32
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
32
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
32
                                    E = Node->varlist_end();
1414
72
       I != E; 
++I40
) {
1415
40
    assert(*I && "Expected non-null Stmt");
1416
40
    OS << (I == Node->varlist_begin() ? 
StartSym32
:
','8
);
1417
40
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
36
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
20
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
16
      else
1421
16
        DRE->getDecl()->printQualifiedName(OS);
1422
36
    } else
1423
4
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
40
  }
1425
32
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFlushClause>(clang::OMPFlushClause*, char)
Line
Count
Source
1411
16
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
16
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
16
                                    E = Node->varlist_end();
1414
32
       I != E; 
++I16
) {
1415
16
    assert(*I && "Expected non-null Stmt");
1416
16
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
16
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
16
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
16
      else
1421
16
        DRE->getDecl()->printQualifiedName(OS);
1422
16
    } else
1423
0
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
16
  }
1425
16
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPDependClause>(clang::OMPDependClause*, char)
Line
Count
Source
1411
433
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
433
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
433
                                    E = Node->varlist_end();
1414
1.63k
       I != E; 
++I1.20k
) {
1415
1.20k
    assert(*I && "Expected non-null Stmt");
1416
1.20k
    OS << (I == Node->varlist_begin() ? 
StartSym433
:
','772
);
1417
1.20k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
417
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
417
      else
1421
417
        DRE->getDecl()->printQualifiedName(OS);
1422
417
    } else
1423
788
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
1.20k
  }
1425
433
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPMapClause>(clang::OMPMapClause*, char)
Line
Count
Source
1411
2.15k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
2.15k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
2.15k
                                    E = Node->varlist_end();
1414
4.59k
       I != E; 
++I2.43k
) {
1415
2.43k
    assert(*I && "Expected non-null Stmt");
1416
2.43k
    OS << (I == Node->varlist_begin() ? 
StartSym2.15k
:
','288
);
1417
2.43k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
2.01k
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
2.01k
      else
1421
2.01k
        DRE->getDecl()->printQualifiedName(OS);
1422
2.01k
    } else
1423
420
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
2.43k
  }
1425
2.15k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPToClause>(clang::OMPToClause*, char)
Line
Count
Source
1411
46
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
46
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
46
                                    E = Node->varlist_end();
1414
92
       I != E; 
++I46
) {
1415
46
    assert(*I && "Expected non-null Stmt");
1416
46
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
46
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
38
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
38
      else
1421
38
        DRE->getDecl()->printQualifiedName(OS);
1422
38
    } else
1423
8
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
46
  }
1425
46
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPFromClause>(clang::OMPFromClause*, char)
Line
Count
Source
1411
44
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
44
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
44
                                    E = Node->varlist_end();
1414
88
       I != E; 
++I44
) {
1415
44
    assert(*I && "Expected non-null Stmt");
1416
44
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
44
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
32
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
32
      else
1421
32
        DRE->getDecl()->printQualifiedName(OS);
1422
32
    } else
1423
12
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
44
  }
1425
44
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPUseDevicePtrClause>(clang::OMPUseDevicePtrClause*, char)
Line
Count
Source
1411
20
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
20
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
20
                                    E = Node->varlist_end();
1414
40
       I != E; 
++I20
) {
1415
20
    assert(*I && "Expected non-null Stmt");
1416
20
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
20
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
20
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
4
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
16
      else
1421
16
        DRE->getDecl()->printQualifiedName(OS);
1422
20
    } else
1423
0
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
20
  }
1425
20
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPIsDevicePtrClause>(clang::OMPIsDevicePtrClause*, char)
Line
Count
Source
1411
1.16k
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
1.16k
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
1.16k
                                    E = Node->varlist_end();
1414
2.32k
       I != E; 
++I1.16k
) {
1415
1.16k
    assert(*I && "Expected non-null Stmt");
1416
1.16k
    OS << (I == Node->varlist_begin() ? StartSym : 
','0
);
1417
1.16k
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
936
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
936
      else
1421
936
        DRE->getDecl()->printQualifiedName(OS);
1422
936
    } else
1423
224
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
1.16k
  }
1425
1.16k
}
void clang::OMPClausePrinter::VisitOMPClauseList<clang::OMPNontemporalClause>(clang::OMPNontemporalClause*, char)
Line
Count
Source
1411
56
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
1412
56
  for (typename T::varlist_iterator I = Node->varlist_begin(),
1413
56
                                    E = Node->varlist_end();
1414
220
       I != E; 
++I164
) {
1415
164
    assert(*I && "Expected non-null Stmt");
1416
164
    OS << (I == Node->varlist_begin() ? 
StartSym56
:
','108
);
1417
164
    if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) {
1418
164
      if (isa<OMPCapturedExprDecl>(DRE->getDecl()))
1419
0
        DRE->printPretty(OS, nullptr, Policy, 0);
1420
164
      else
1421
164
        DRE->getDecl()->printQualifiedName(OS);
1422
164
    } else
1423
0
      (*I)->printPretty(OS, nullptr, Policy, 0);
1424
164
  }
1425
56
}
1426
1427
788
void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) {
1428
788
  if (Node->varlist_empty())
1429
0
    return;
1430
788
  OS << "allocate";
1431
788
  if (Expr *Allocator = Node->getAllocator()) {
1432
8
    OS << "(";
1433
8
    Allocator->printPretty(OS, nullptr, Policy, 0);
1434
8
    OS << ":";
1435
8
    VisitOMPClauseList(Node, ' ');
1436
780
  } else {
1437
780
    VisitOMPClauseList(Node, '(');
1438
780
  }
1439
788
  OS << ")";
1440
788
}
1441
1442
2.66k
void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) {
1443
2.66k
  if (!Node->varlist_empty()) {
1444
2.66k
    OS << "private";
1445
2.66k
    VisitOMPClauseList(Node, '(');
1446
2.66k
    OS << ")";
1447
2.66k
  }
1448
2.66k
}
1449
1450
1.09k
void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) {
1451
1.09k
  if (!Node->varlist_empty()) {
1452
1.09k
    OS << "firstprivate";
1453
1.09k
    VisitOMPClauseList(Node, '(');
1454
1.09k
    OS << ")";
1455
1.09k
  }
1456
1.09k
}
1457
1458
500
void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) {
1459
500
  if (!Node->varlist_empty()) {
1460
500
    OS << "lastprivate";
1461
500
    OpenMPLastprivateModifier LPKind = Node->getKind();
1462
500
    if (LPKind != OMPC_LASTPRIVATE_unknown) {
1463
24
      OS << "("
1464
24
         << getOpenMPSimpleClauseTypeName(OMPC_lastprivate, Node->getKind())
1465
24
         << ":";
1466
24
    }
1467
500
    VisitOMPClauseList(Node, LPKind == OMPC_LASTPRIVATE_unknown ? 
'('476
:
' '24
);
1468
500
    OS << ")";
1469
500
  }
1470
500
}
1471
1472
762
void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) {
1473
762
  if (!Node->varlist_empty()) {
1474
762
    OS << "shared";
1475
762
    VisitOMPClauseList(Node, '(');
1476
762
    OS << ")";
1477
762
  }
1478
762
}
1479
1480
1.47k
void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) {
1481
1.47k
  if (!Node->varlist_empty()) {
1482
1.47k
    OS << "reduction(";
1483
1.47k
    NestedNameSpecifier *QualifierLoc =
1484
1.47k
        Node->getQualifierLoc().getNestedNameSpecifier();
1485
1.47k
    OverloadedOperatorKind OOK =
1486
1.47k
        Node->getNameInfo().getName().getCXXOverloadedOperator();
1487
1.47k
    if (QualifierLoc == nullptr && OOK != OO_None) {
1488
1.11k
      // Print reduction identifier in C format
1489
1.11k
      OS << getOperatorSpelling(OOK);
1490
1.11k
    } else {
1491
360
      // Use C++ format
1492
360
      if (QualifierLoc != nullptr)
1493
0
        QualifierLoc->print(OS, Policy);
1494
360
      OS << Node->getNameInfo();
1495
360
    }
1496
1.47k
    OS << ":";
1497
1.47k
    VisitOMPClauseList(Node, ' ');
1498
1.47k
    OS << ")";
1499
1.47k
  }
1500
1.47k
}
1501
1502
void OMPClausePrinter::VisitOMPTaskReductionClause(
1503
216
    OMPTaskReductionClause *Node) {
1504
216
  if (!Node->varlist_empty()) {
1505
216
    OS << "task_reduction(";
1506
216
    NestedNameSpecifier *QualifierLoc =
1507
216
        Node->getQualifierLoc().getNestedNameSpecifier();
1508
216
    OverloadedOperatorKind OOK =
1509
216
        Node->getNameInfo().getName().getCXXOverloadedOperator();
1510
216
    if (QualifierLoc == nullptr && OOK != OO_None) {
1511
204
      // Print reduction identifier in C format
1512
204
      OS << getOperatorSpelling(OOK);
1513
204
    } else {
1514
12
      // Use C++ format
1515
12
      if (QualifierLoc != nullptr)
1516
0
        QualifierLoc->print(OS, Policy);
1517
12
      OS << Node->getNameInfo();
1518
12
    }
1519
216
    OS << ":";
1520
216
    VisitOMPClauseList(Node, ' ');
1521
216
    OS << ")";
1522
216
  }
1523
216
}
1524
1525
124
void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) {
1526
124
  if (!Node->varlist_empty()) {
1527
124
    OS << "in_reduction(";
1528
124
    NestedNameSpecifier *QualifierLoc =
1529
124
        Node->getQualifierLoc().getNestedNameSpecifier();
1530
124
    OverloadedOperatorKind OOK =
1531
124
        Node->getNameInfo().getName().getCXXOverloadedOperator();
1532
124
    if (QualifierLoc == nullptr && OOK != OO_None) {
1533
116
      // Print reduction identifier in C format
1534
116
      OS << getOperatorSpelling(OOK);
1535
116
    } else {
1536
8
      // Use C++ format
1537
8
      if (QualifierLoc != nullptr)
1538
0
        QualifierLoc->print(OS, Policy);
1539
8
      OS << Node->getNameInfo();
1540
8
    }
1541
124
    OS << ":";
1542
124
    VisitOMPClauseList(Node, ' ');
1543
124
    OS << ")";
1544
124
  }
1545
124
}
1546
1547
417
void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) {
1548
417
  if (!Node->varlist_empty()) {
1549
417
    OS << "linear";
1550
417
    if (Node->getModifierLoc().isValid()) {
1551
40
      OS << '('
1552
40
         << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier());
1553
40
    }
1554
417
    VisitOMPClauseList(Node, '(');
1555
417
    if (Node->getModifierLoc().isValid())
1556
40
      OS << ')';
1557
417
    if (Node->getStep() != nullptr) {
1558
165
      OS << ": ";
1559
165
      Node->getStep()->printPretty(OS, nullptr, Policy, 0);
1560
165
    }
1561
417
    OS << ")";
1562
417
  }
1563
417
}
1564
1565
408
void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) {
1566
408
  if (!Node->varlist_empty()) {
1567
408
    OS << "aligned";
1568
408
    VisitOMPClauseList(Node, '(');
1569
408
    if (Node->getAlignment() != nullptr) {
1570
296
      OS << ": ";
1571
296
      Node->getAlignment()->printPretty(OS, nullptr, Policy, 0);
1572
296
    }
1573
408
    OS << ")";
1574
408
  }
1575
408
}
1576
1577
152
void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) {
1578
152
  if (!Node->varlist_empty()) {
1579
152
    OS << "copyin";
1580
152
    VisitOMPClauseList(Node, '(');
1581
152
    OS << ")";
1582
152
  }
1583
152
}
1584
1585
32
void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) {
1586
32
  if (!Node->varlist_empty()) {
1587
32
    OS << "copyprivate";
1588
32
    VisitOMPClauseList(Node, '(');
1589
32
    OS << ")";
1590
32
  }
1591
32
}
1592
1593
16
void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) {
1594
16
  if (!Node->varlist_empty()) {
1595
16
    VisitOMPClauseList(Node, '(');
1596
16
    OS << ")";
1597
16
  }
1598
16
}
1599
1600
447
void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) {
1601
447
  OS << "depend(";
1602
447
  OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(),
1603
447
                                      Node->getDependencyKind());
1604
447
  if (!Node->varlist_empty()) {
1605
433
    OS << " :";
1606
433
    VisitOMPClauseList(Node, ' ');
1607
433
  }
1608
447
  OS << ")";
1609
447
}
1610
1611
2.15k
void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) {
1612
2.15k
  if (!Node->varlist_empty()) {
1613
2.15k
    OS << "map(";
1614
2.15k
    if (Node->getMapType() != OMPC_MAP_unknown) {
1615
8.60k
      for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; 
++I6.45k
) {
1616
6.45k
        if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) {
1617
424
          OS << getOpenMPSimpleClauseTypeName(OMPC_map,
1618
424
                                              Node->getMapTypeModifier(I));
1619
424
          if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) {
1620
40
            OS << '(';
1621
40
            NestedNameSpecifier *MapperNNS =
1622
40
                Node->getMapperQualifierLoc().getNestedNameSpecifier();
1623
40
            if (MapperNNS)
1624
12
              MapperNNS->print(OS, Policy);
1625
40
            OS << Node->getMapperIdInfo() << ')';
1626
40
          }
1627
424
          OS << ',';
1628
424
        }
1629
6.45k
      }
1630
2.15k
      OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType());
1631
2.15k
      OS << ':';
1632
2.15k
    }
1633
2.15k
    VisitOMPClauseList(Node, ' ');
1634
2.15k
    OS << ")";
1635
2.15k
  }
1636
2.15k
}
1637
1638
46
void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) {
1639
46
  if (!Node->varlist_empty()) {
1640
46
    OS << "to";
1641
46
    DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1642
46
    if (MapperId.getName() && 
!MapperId.getName().isEmpty()28
) {
1643
28
      OS << '(';
1644
28
      OS << "mapper(";
1645
28
      NestedNameSpecifier *MapperNNS =
1646
28
          Node->getMapperQualifierLoc().getNestedNameSpecifier();
1647
28
      if (MapperNNS)
1648
8
        MapperNNS->print(OS, Policy);
1649
28
      OS << MapperId << "):";
1650
28
      VisitOMPClauseList(Node, ' ');
1651
28
    } else {
1652
18
      VisitOMPClauseList(Node, '(');
1653
18
    }
1654
46
    OS << ")";
1655
46
  }
1656
46
}
1657
1658
44
void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) {
1659
44
  if (!Node->varlist_empty()) {
1660
44
    OS << "from";
1661
44
    DeclarationNameInfo MapperId = Node->getMapperIdInfo();
1662
44
    if (MapperId.getName() && 
!MapperId.getName().isEmpty()28
) {
1663
28
      OS << '(';
1664
28
      OS << "mapper(";
1665
28
      NestedNameSpecifier *MapperNNS =
1666
28
          Node->getMapperQualifierLoc().getNestedNameSpecifier();
1667
28
      if (MapperNNS)
1668
8
        MapperNNS->print(OS, Policy);
1669
28
      OS << MapperId << "):";
1670
28
      VisitOMPClauseList(Node, ' ');
1671
28
    } else {
1672
16
      VisitOMPClauseList(Node, '(');
1673
16
    }
1674
44
    OS << ")";
1675
44
  }
1676
44
}
1677
1678
272
void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) {
1679
272
  OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName(
1680
272
                           OMPC_dist_schedule, Node->getDistScheduleKind());
1681
272
  if (auto *E = Node->getChunkSize()) {
1682
272
    OS << ", ";
1683
272
    E->printPretty(OS, nullptr, Policy);
1684
272
  }
1685
272
  OS << ")";
1686
272
}
1687
1688
720
void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) {
1689
720
  OS << "defaultmap(";
1690
720
  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1691
720
                                      Node->getDefaultmapModifier());
1692
720
  OS << ": ";
1693
720
  OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap,
1694
720
    Node->getDefaultmapKind());
1695
720
  OS << ")";
1696
720
}
1697
1698
20
void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) {
1699
20
  if (!Node->varlist_empty()) {
1700
20
    OS << "use_device_ptr";
1701
20
    VisitOMPClauseList(Node, '(');
1702
20
    OS << ")";
1703
20
  }
1704
20
}
1705
1706
1.16k
void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) {
1707
1.16k
  if (!Node->varlist_empty()) {
1708
1.16k
    OS << "is_device_ptr";
1709
1.16k
    VisitOMPClauseList(Node, '(');
1710
1.16k
    OS << ")";
1711
1.16k
  }
1712
1.16k
}
1713
1714
56
void OMPClausePrinter::VisitOMPNontemporalClause(OMPNontemporalClause *Node) {
1715
56
  if (!Node->varlist_empty()) {
1716
56
    OS << "nontemporal";
1717
56
    VisitOMPClauseList(Node, '(');
1718
56
    OS << ")";
1719
56
  }
1720
56
}
1721
1722
100
void OMPClausePrinter::VisitOMPOrderClause(OMPOrderClause *Node) {
1723
100
  OS << "order(" << getOpenMPSimpleClauseTypeName(OMPC_order, Node->getKind())
1724
100
     << ")";
1725
100
}
1726
1727
void OMPTraitInfo::getAsVariantMatchInfo(
1728
1.09k
    ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const {
1729
1.18k
  for (const OMPTraitSet &Set : Sets) {
1730
1.18k
    for (const OMPTraitSelector &Selector : Set.Selectors) {
1731
1.18k
1732
1.18k
      // User conditions are special as we evaluate the condition here.
1733
1.18k
      if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1734
0
        assert(Selector.ScoreOrCondition &&
1735
0
               "Ill-formed user condition, expected condition expression!");
1736
0
        assert(Selector.Properties.size() == 1 &&
1737
0
               Selector.Properties.front().Kind ==
1738
0
                   llvm::omp::TraitProperty::user_condition_unknown &&
1739
0
               "Ill-formed user condition, expected unknown trait property!");
1740
0
1741
0
        llvm::APInt CondVal =
1742
0
            Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1743
0
        VMI.addTrait(CondVal.isNullValue()
1744
0
                         ? llvm::omp::TraitProperty::user_condition_false
1745
0
                         : llvm::omp::TraitProperty::user_condition_true);
1746
0
        continue;
1747
0
      }
1748
1.18k
1749
1.18k
      llvm::APInt Score;
1750
1.18k
      llvm::APInt *ScorePtr = nullptr;
1751
1.18k
      if (Selector.ScoreOrCondition) {
1752
45
        Score = Selector.ScoreOrCondition->EvaluateKnownConstInt(ASTCtx);
1753
45
        ScorePtr = &Score;
1754
45
      }
1755
1.18k
      for (const OMPTraitProperty &Property : Selector.Properties)
1756
1.90k
        VMI.addTrait(Set.Kind, Property.Kind, ScorePtr);
1757
1.18k
1758
1.18k
      if (Set.Kind != llvm::omp::TraitSet::construct)
1759
1.18k
        continue;
1760
0
1761
0
      // TODO: This might not hold once we implement SIMD properly.
1762
0
      assert(Selector.Properties.size() == 1 &&
1763
0
             Selector.Properties.front().Kind ==
1764
0
                 llvm::omp::getOpenMPContextTraitPropertyForSelector(
1765
0
                     Selector.Kind) &&
1766
0
             "Ill-formed construct selector!");
1767
0
1768
0
      VMI.ConstructTraits.push_back(Selector.Properties.front().Kind);
1769
0
    }
1770
1.18k
  }
1771
1.09k
}
1772
1773
void OMPTraitInfo::print(llvm::raw_ostream &OS,
1774
2.26k
                         const PrintingPolicy &Policy) const {
1775
2.26k
  bool FirstSet = true;
1776
2.48k
  for (const OMPTraitInfo::OMPTraitSet &Set : Sets) {
1777
2.48k
    if (!FirstSet)
1778
220
      OS << ", ";
1779
2.48k
    FirstSet = false;
1780
2.48k
    OS << llvm::omp::getOpenMPContextTraitSetName(Set.Kind) << "={";
1781
2.48k
1782
2.48k
    bool FirstSelector = true;
1783
2.48k
    for (const OMPTraitInfo::OMPTraitSelector &Selector : Set.Selectors) {
1784
2.48k
      if (!FirstSelector)
1785
0
        OS << ", ";
1786
2.48k
      FirstSelector = false;
1787
2.48k
      OS << llvm::omp::getOpenMPContextTraitSelectorName(Selector.Kind);
1788
2.48k
1789
2.48k
      bool AllowsTraitScore = false;
1790
2.48k
      bool RequiresProperty = false;
1791
2.48k
      llvm::omp::isValidTraitSelectorForTraitSet(
1792
2.48k
          Selector.Kind, Set.Kind, AllowsTraitScore, RequiresProperty);
1793
2.48k
1794
2.48k
      if (!RequiresProperty)
1795
0
        continue;
1796
2.48k
1797
2.48k
      OS << "(";
1798
2.48k
      if (Selector.Kind == llvm::omp::TraitSelector::user_condition) {
1799
8
        Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1800
2.47k
      } else {
1801
2.47k
1802
2.47k
        if (Selector.ScoreOrCondition) {
1803
102
          OS << "score(";
1804
102
          Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
1805
102
          OS << "): ";
1806
102
        }
1807
2.47k
1808
2.47k
        bool FirstProperty = true;
1809
2.47k
        for (const OMPTraitInfo::OMPTraitProperty &Property :
1810
3.95k
             Selector.Properties) {
1811
3.95k
          if (!FirstProperty)
1812
1.47k
            OS << ", ";
1813
3.95k
          FirstProperty = false;
1814
3.95k
          OS << llvm::omp::getOpenMPContextTraitPropertyName(Property.Kind);
1815
3.95k
        }
1816
2.47k
      }
1817
2.48k
      OS << ")";
1818
2.48k
    }
1819
2.48k
    OS << "}";
1820
2.48k
  }
1821
2.26k
}
1822
1823
llvm::raw_ostream &clang::operator<<(llvm::raw_ostream &OS,
1824
0
                                     const OMPTraitInfo &TI) {
1825
0
  LangOptions LO;
1826
0
  PrintingPolicy Policy(LO);
1827
0
  TI.print(OS, Policy);
1828
0
  return OS;
1829
0
}