Coverage Report

Created: 2021-01-26 06:56

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