Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/lib/AST/OpenMPClause.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- OpenMPClause.cpp - Classes for OpenMP clauses --------------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file implements the subclesses of Stmt class declared in OpenMPClause.h
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/OpenMPClause.h"
15
16
#include "clang/AST/ASTContext.h"
17
18
using namespace clang;
19
20
18.9k
OMPClause::child_range OMPClause::children() {
21
18.9k
  switch (getClauseKind()) {
22
0
  default:
23
0
    break;
24
18.9k
#define OPENMP_CLAUSE(Name, Class)                                             \
25
18.9k
  case OMPC_##Name:                                                            \
26
18.3k
    return static_cast<Class *>(this)->children();
27
128
#include "clang/Basic/OpenMPKinds.def"
28
18.9k
  }
29
0
  
llvm_unreachable0
("unknown OMPClause");
30
0
}
31
32
11.2k
OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) {
33
11.2k
  auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C));
34
11.2k
  return Res ? 
const_cast<OMPClauseWithPreInit *>(Res)3.65k
:
nullptr7.62k
;
35
11.2k
}
36
37
15.2k
const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
38
15.2k
  switch (C->getClauseKind()) {
39
705
  case OMPC_schedule:
40
705
    return static_cast<const OMPScheduleClause *>(C);
41
290
  case OMPC_dist_schedule:
42
290
    return static_cast<const OMPDistScheduleClause *>(C);
43
914
  case OMPC_firstprivate:
44
914
    return static_cast<const OMPFirstprivateClause *>(C);
45
87
  case OMPC_lastprivate:
46
87
    return static_cast<const OMPLastprivateClause *>(C);
47
184
  case OMPC_reduction:
48
184
    return static_cast<const OMPReductionClause *>(C);
49
16
  case OMPC_task_reduction:
50
16
    return static_cast<const OMPTaskReductionClause *>(C);
51
12
  case OMPC_in_reduction:
52
12
    return static_cast<const OMPInReductionClause *>(C);
53
94
  case OMPC_linear:
54
94
    return static_cast<const OMPLinearClause *>(C);
55
1.76k
  case OMPC_if:
56
1.76k
    return static_cast<const OMPIfClause *>(C);
57
610
  case OMPC_num_threads:
58
610
    return static_cast<const OMPNumThreadsClause *>(C);
59
582
  case OMPC_num_teams:
60
582
    return static_cast<const OMPNumTeamsClause *>(C);
61
517
  case OMPC_thread_limit:
62
517
    return static_cast<const OMPThreadLimitClause *>(C);
63
9.44k
  case OMPC_default:
64
9.44k
  case OMPC_proc_bind:
65
9.44k
  case OMPC_final:
66
9.44k
  case OMPC_safelen:
67
9.44k
  case OMPC_simdlen:
68
9.44k
  case OMPC_collapse:
69
9.44k
  case OMPC_private:
70
9.44k
  case OMPC_shared:
71
9.44k
  case OMPC_aligned:
72
9.44k
  case OMPC_copyin:
73
9.44k
  case OMPC_copyprivate:
74
9.44k
  case OMPC_ordered:
75
9.44k
  case OMPC_nowait:
76
9.44k
  case OMPC_untied:
77
9.44k
  case OMPC_mergeable:
78
9.44k
  case OMPC_threadprivate:
79
9.44k
  case OMPC_flush:
80
9.44k
  case OMPC_read:
81
9.44k
  case OMPC_write:
82
9.44k
  case OMPC_update:
83
9.44k
  case OMPC_capture:
84
9.44k
  case OMPC_seq_cst:
85
9.44k
  case OMPC_depend:
86
9.44k
  case OMPC_device:
87
9.44k
  case OMPC_threads:
88
9.44k
  case OMPC_simd:
89
9.44k
  case OMPC_map:
90
9.44k
  case OMPC_priority:
91
9.44k
  case OMPC_grainsize:
92
9.44k
  case OMPC_nogroup:
93
9.44k
  case OMPC_num_tasks:
94
9.44k
  case OMPC_hint:
95
9.44k
  case OMPC_defaultmap:
96
9.44k
  case OMPC_unknown:
97
9.44k
  case OMPC_uniform:
98
9.44k
  case OMPC_to:
99
9.44k
  case OMPC_from:
100
9.44k
  case OMPC_use_device_ptr:
101
9.44k
  case OMPC_is_device_ptr:
102
9.44k
    break;
103
9.44k
  }
104
9.44k
105
9.44k
  return nullptr;
106
9.44k
}
107
108
11.2k
OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) {
109
11.2k
  auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C));
110
11.2k
  return Res ? 
const_cast<OMPClauseWithPostUpdate *>(Res)0
:
nullptr11.2k
;
111
11.2k
}
112
113
11.2k
const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) {
114
11.2k
  switch (C->getClauseKind()) {
115
0
  case OMPC_lastprivate:
116
0
    return static_cast<const OMPLastprivateClause *>(C);
117
0
  case OMPC_reduction:
118
0
    return static_cast<const OMPReductionClause *>(C);
119
0
  case OMPC_task_reduction:
120
0
    return static_cast<const OMPTaskReductionClause *>(C);
121
0
  case OMPC_in_reduction:
122
0
    return static_cast<const OMPInReductionClause *>(C);
123
0
  case OMPC_linear:
124
0
    return static_cast<const OMPLinearClause *>(C);
125
11.2k
  case OMPC_schedule:
126
11.2k
  case OMPC_dist_schedule:
127
11.2k
  case OMPC_firstprivate:
128
11.2k
  case OMPC_default:
129
11.2k
  case OMPC_proc_bind:
130
11.2k
  case OMPC_if:
131
11.2k
  case OMPC_final:
132
11.2k
  case OMPC_num_threads:
133
11.2k
  case OMPC_safelen:
134
11.2k
  case OMPC_simdlen:
135
11.2k
  case OMPC_collapse:
136
11.2k
  case OMPC_private:
137
11.2k
  case OMPC_shared:
138
11.2k
  case OMPC_aligned:
139
11.2k
  case OMPC_copyin:
140
11.2k
  case OMPC_copyprivate:
141
11.2k
  case OMPC_ordered:
142
11.2k
  case OMPC_nowait:
143
11.2k
  case OMPC_untied:
144
11.2k
  case OMPC_mergeable:
145
11.2k
  case OMPC_threadprivate:
146
11.2k
  case OMPC_flush:
147
11.2k
  case OMPC_read:
148
11.2k
  case OMPC_write:
149
11.2k
  case OMPC_update:
150
11.2k
  case OMPC_capture:
151
11.2k
  case OMPC_seq_cst:
152
11.2k
  case OMPC_depend:
153
11.2k
  case OMPC_device:
154
11.2k
  case OMPC_threads:
155
11.2k
  case OMPC_simd:
156
11.2k
  case OMPC_map:
157
11.2k
  case OMPC_num_teams:
158
11.2k
  case OMPC_thread_limit:
159
11.2k
  case OMPC_priority:
160
11.2k
  case OMPC_grainsize:
161
11.2k
  case OMPC_nogroup:
162
11.2k
  case OMPC_num_tasks:
163
11.2k
  case OMPC_hint:
164
11.2k
  case OMPC_defaultmap:
165
11.2k
  case OMPC_unknown:
166
11.2k
  case OMPC_uniform:
167
11.2k
  case OMPC_to:
168
11.2k
  case OMPC_from:
169
11.2k
  case OMPC_use_device_ptr:
170
11.2k
  case OMPC_is_device_ptr:
171
11.2k
    break;
172
11.2k
  }
173
11.2k
174
11.2k
  return nullptr;
175
11.2k
}
176
177
3.94k
void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
178
3.94k
  assert(VL.size() == varlist_size() &&
179
3.94k
         "Number of private copies is not the same as the preallocated buffer");
180
3.94k
  std::copy(VL.begin(), VL.end(), varlist_end());
181
3.94k
}
182
183
OMPPrivateClause *
184
OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
185
                         SourceLocation LParenLoc, SourceLocation EndLoc,
186
3.55k
                         ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
187
3.55k
  // Allocate space for private variables and initializer expressions.
188
3.55k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size()));
189
3.55k
  OMPPrivateClause *Clause =
190
3.55k
      new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
191
3.55k
  Clause->setVarRefs(VL);
192
3.55k
  Clause->setPrivateCopies(PrivateVL);
193
3.55k
  return Clause;
194
3.55k
}
195
196
OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
197
393
                                                unsigned N) {
198
393
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N));
199
393
  return new (Mem) OMPPrivateClause(N);
200
393
}
201
202
9.12k
void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
203
9.12k
  assert(VL.size() == varlist_size() &&
204
9.12k
         "Number of private copies is not the same as the preallocated buffer");
205
9.12k
  std::copy(VL.begin(), VL.end(), varlist_end());
206
9.12k
}
207
208
9.12k
void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
209
9.12k
  assert(VL.size() == varlist_size() &&
210
9.12k
         "Number of inits is not the same as the preallocated buffer");
211
9.12k
  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
212
9.12k
}
213
214
OMPFirstprivateClause *
215
OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
216
                              SourceLocation LParenLoc, SourceLocation EndLoc,
217
                              ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
218
8.62k
                              ArrayRef<Expr *> InitVL, Stmt *PreInit) {
219
8.62k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size()));
220
8.62k
  OMPFirstprivateClause *Clause =
221
8.62k
      new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
222
8.62k
  Clause->setVarRefs(VL);
223
8.62k
  Clause->setPrivateCopies(PrivateVL);
224
8.62k
  Clause->setInits(InitVL);
225
8.62k
  Clause->setPreInitStmt(PreInit);
226
8.62k
  return Clause;
227
8.62k
}
228
229
OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
230
502
                                                          unsigned N) {
231
502
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N));
232
502
  return new (Mem) OMPFirstprivateClause(N);
233
502
}
234
235
1.22k
void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
236
1.22k
  assert(PrivateCopies.size() == varlist_size() &&
237
1.22k
         "Number of private copies is not the same as the preallocated buffer");
238
1.22k
  std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
239
1.22k
}
240
241
1.24k
void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
242
1.24k
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
243
1.24k
                                              "not the same as the "
244
1.24k
                                              "preallocated buffer");
245
1.24k
  std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
246
1.24k
}
247
248
1.24k
void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
249
1.24k
  assert(DstExprs.size() == varlist_size() && "Number of destination "
250
1.24k
                                              "expressions is not the same as "
251
1.24k
                                              "the preallocated buffer");
252
1.24k
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
253
1.24k
}
254
255
1.24k
void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
256
1.24k
  assert(AssignmentOps.size() == varlist_size() &&
257
1.24k
         "Number of assignment expressions is not the same as the preallocated "
258
1.24k
         "buffer");
259
1.24k
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
260
1.24k
            getDestinationExprs().end());
261
1.24k
}
262
263
OMPLastprivateClause *OMPLastprivateClause::Create(
264
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
265
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
266
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit,
267
1.16k
    Expr *PostUpdate) {
268
1.16k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
269
1.16k
  OMPLastprivateClause *Clause =
270
1.16k
      new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
271
1.16k
  Clause->setVarRefs(VL);
272
1.16k
  Clause->setSourceExprs(SrcExprs);
273
1.16k
  Clause->setDestinationExprs(DstExprs);
274
1.16k
  Clause->setAssignmentOps(AssignmentOps);
275
1.16k
  Clause->setPreInitStmt(PreInit);
276
1.16k
  Clause->setPostUpdateExpr(PostUpdate);
277
1.16k
  return Clause;
278
1.16k
}
279
280
OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
281
75
                                                        unsigned N) {
282
75
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
283
75
  return new (Mem) OMPLastprivateClause(N);
284
75
}
285
286
OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
287
                                         SourceLocation StartLoc,
288
                                         SourceLocation LParenLoc,
289
                                         SourceLocation EndLoc,
290
1.01k
                                         ArrayRef<Expr *> VL) {
291
1.01k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
292
1.01k
  OMPSharedClause *Clause =
293
1.01k
      new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size());
294
1.01k
  Clause->setVarRefs(VL);
295
1.01k
  return Clause;
296
1.01k
}
297
298
77
OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) {
299
77
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
300
77
  return new (Mem) OMPSharedClause(N);
301
77
}
302
303
1.06k
void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
304
1.06k
  assert(PL.size() == varlist_size() &&
305
1.06k
         "Number of privates is not the same as the preallocated buffer");
306
1.06k
  std::copy(PL.begin(), PL.end(), varlist_end());
307
1.06k
}
308
309
1.06k
void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
310
1.06k
  assert(IL.size() == varlist_size() &&
311
1.06k
         "Number of inits is not the same as the preallocated buffer");
312
1.06k
  std::copy(IL.begin(), IL.end(), getPrivates().end());
313
1.06k
}
314
315
650
void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
316
650
  assert(UL.size() == varlist_size() &&
317
650
         "Number of updates is not the same as the preallocated buffer");
318
650
  std::copy(UL.begin(), UL.end(), getInits().end());
319
650
}
320
321
650
void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
322
650
  assert(FL.size() == varlist_size() &&
323
650
         "Number of final updates is not the same as the preallocated buffer");
324
650
  std::copy(FL.begin(), FL.end(), getUpdates().end());
325
650
}
326
327
OMPLinearClause *OMPLinearClause::Create(
328
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
329
    OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
330
    SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
331
    ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
332
991
    Stmt *PreInit, Expr *PostUpdate) {
333
991
  // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
334
991
  // (Step and CalcStep).
335
991
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2));
336
991
  OMPLinearClause *Clause = new (Mem) OMPLinearClause(
337
991
      StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
338
991
  Clause->setVarRefs(VL);
339
991
  Clause->setPrivates(PL);
340
991
  Clause->setInits(IL);
341
991
  // Fill update and final expressions with zeroes, they are provided later,
342
991
  // after the directive construction.
343
991
  std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
344
991
            nullptr);
345
991
  std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
346
991
            nullptr);
347
991
  Clause->setStep(Step);
348
991
  Clause->setCalcStep(CalcStep);
349
991
  Clause->setPreInitStmt(PreInit);
350
991
  Clause->setPostUpdateExpr(PostUpdate);
351
991
  return Clause;
352
991
}
353
354
OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
355
69
                                              unsigned NumVars) {
356
69
  // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
357
69
  // (Step and CalcStep).
358
69
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2));
359
69
  return new (Mem) OMPLinearClause(NumVars);
360
69
}
361
362
OMPAlignedClause *
363
OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
364
                         SourceLocation LParenLoc, SourceLocation ColonLoc,
365
517
                         SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
366
517
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
367
517
  OMPAlignedClause *Clause = new (Mem)
368
517
      OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
369
517
  Clause->setVarRefs(VL);
370
517
  Clause->setAlignment(A);
371
517
  return Clause;
372
517
}
373
374
OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
375
44
                                                unsigned NumVars) {
376
44
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1));
377
44
  return new (Mem) OMPAlignedClause(NumVars);
378
44
}
379
380
162
void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
381
162
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
382
162
                                              "not the same as the "
383
162
                                              "preallocated buffer");
384
162
  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
385
162
}
386
387
162
void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
388
162
  assert(DstExprs.size() == varlist_size() && "Number of destination "
389
162
                                              "expressions is not the same as "
390
162
                                              "the preallocated buffer");
391
162
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
392
162
}
393
394
162
void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
395
162
  assert(AssignmentOps.size() == varlist_size() &&
396
162
         "Number of assignment expressions is not the same as the preallocated "
397
162
         "buffer");
398
162
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
399
162
            getDestinationExprs().end());
400
162
}
401
402
OMPCopyinClause *OMPCopyinClause::Create(
403
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
404
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
405
143
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
406
143
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
407
143
  OMPCopyinClause *Clause =
408
143
      new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size());
409
143
  Clause->setVarRefs(VL);
410
143
  Clause->setSourceExprs(SrcExprs);
411
143
  Clause->setDestinationExprs(DstExprs);
412
143
  Clause->setAssignmentOps(AssignmentOps);
413
143
  return Clause;
414
143
}
415
416
19
OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) {
417
19
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
418
19
  return new (Mem) OMPCopyinClause(N);
419
19
}
420
421
80
void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
422
80
  assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
423
80
                                              "not the same as the "
424
80
                                              "preallocated buffer");
425
80
  std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
426
80
}
427
428
80
void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
429
80
  assert(DstExprs.size() == varlist_size() && "Number of destination "
430
80
                                              "expressions is not the same as "
431
80
                                              "the preallocated buffer");
432
80
  std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
433
80
}
434
435
80
void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
436
80
  assert(AssignmentOps.size() == varlist_size() &&
437
80
         "Number of assignment expressions is not the same as the preallocated "
438
80
         "buffer");
439
80
  std::copy(AssignmentOps.begin(), AssignmentOps.end(),
440
80
            getDestinationExprs().end());
441
80
}
442
443
OMPCopyprivateClause *OMPCopyprivateClause::Create(
444
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
445
    SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
446
71
    ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
447
71
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size()));
448
71
  OMPCopyprivateClause *Clause =
449
71
      new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
450
71
  Clause->setVarRefs(VL);
451
71
  Clause->setSourceExprs(SrcExprs);
452
71
  Clause->setDestinationExprs(DstExprs);
453
71
  Clause->setAssignmentOps(AssignmentOps);
454
71
  return Clause;
455
71
}
456
457
OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
458
9
                                                        unsigned N) {
459
9
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N));
460
9
  return new (Mem) OMPCopyprivateClause(N);
461
9
}
462
463
5.13k
void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
464
5.13k
  assert(Privates.size() == varlist_size() &&
465
5.13k
         "Number of private copies is not the same as the preallocated buffer");
466
5.13k
  std::copy(Privates.begin(), Privates.end(), varlist_end());
467
5.13k
}
468
469
5.13k
void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
470
5.13k
  assert(
471
5.13k
      LHSExprs.size() == varlist_size() &&
472
5.13k
      "Number of LHS expressions is not the same as the preallocated buffer");
473
5.13k
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
474
5.13k
}
475
476
5.13k
void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
477
5.13k
  assert(
478
5.13k
      RHSExprs.size() == varlist_size() &&
479
5.13k
      "Number of RHS expressions is not the same as the preallocated buffer");
480
5.13k
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
481
5.13k
}
482
483
5.13k
void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
484
5.13k
  assert(ReductionOps.size() == varlist_size() && "Number of reduction "
485
5.13k
                                                  "expressions is not the same "
486
5.13k
                                                  "as the preallocated buffer");
487
5.13k
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
488
5.13k
}
489
490
OMPReductionClause *OMPReductionClause::Create(
491
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
492
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
493
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
494
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
495
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
496
4.92k
    Expr *PostUpdate) {
497
4.92k
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
498
4.92k
  OMPReductionClause *Clause = new (Mem) OMPReductionClause(
499
4.92k
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
500
4.92k
  Clause->setVarRefs(VL);
501
4.92k
  Clause->setPrivates(Privates);
502
4.92k
  Clause->setLHSExprs(LHSExprs);
503
4.92k
  Clause->setRHSExprs(RHSExprs);
504
4.92k
  Clause->setReductionOps(ReductionOps);
505
4.92k
  Clause->setPreInitStmt(PreInit);
506
4.92k
  Clause->setPostUpdateExpr(PostUpdate);
507
4.92k
  return Clause;
508
4.92k
}
509
510
OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
511
215
                                                    unsigned N) {
512
215
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
513
215
  return new (Mem) OMPReductionClause(N);
514
215
}
515
516
732
void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
517
732
  assert(Privates.size() == varlist_size() &&
518
732
         "Number of private copies is not the same as the preallocated buffer");
519
732
  std::copy(Privates.begin(), Privates.end(), varlist_end());
520
732
}
521
522
732
void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
523
732
  assert(
524
732
      LHSExprs.size() == varlist_size() &&
525
732
      "Number of LHS expressions is not the same as the preallocated buffer");
526
732
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
527
732
}
528
529
732
void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
530
732
  assert(
531
732
      RHSExprs.size() == varlist_size() &&
532
732
      "Number of RHS expressions is not the same as the preallocated buffer");
533
732
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
534
732
}
535
536
732
void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
537
732
  assert(ReductionOps.size() == varlist_size() && "Number of task reduction "
538
732
                                                  "expressions is not the same "
539
732
                                                  "as the preallocated buffer");
540
732
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
541
732
}
542
543
OMPTaskReductionClause *OMPTaskReductionClause::Create(
544
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
545
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
546
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
547
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
548
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit,
549
707
    Expr *PostUpdate) {
550
707
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size()));
551
707
  OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause(
552
707
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
553
707
  Clause->setVarRefs(VL);
554
707
  Clause->setPrivates(Privates);
555
707
  Clause->setLHSExprs(LHSExprs);
556
707
  Clause->setRHSExprs(RHSExprs);
557
707
  Clause->setReductionOps(ReductionOps);
558
707
  Clause->setPreInitStmt(PreInit);
559
707
  Clause->setPostUpdateExpr(PostUpdate);
560
707
  return Clause;
561
707
}
562
563
OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C,
564
25
                                                            unsigned N) {
565
25
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N));
566
25
  return new (Mem) OMPTaskReductionClause(N);
567
25
}
568
569
431
void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) {
570
431
  assert(Privates.size() == varlist_size() &&
571
431
         "Number of private copies is not the same as the preallocated buffer");
572
431
  std::copy(Privates.begin(), Privates.end(), varlist_end());
573
431
}
574
575
431
void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
576
431
  assert(
577
431
      LHSExprs.size() == varlist_size() &&
578
431
      "Number of LHS expressions is not the same as the preallocated buffer");
579
431
  std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end());
580
431
}
581
582
431
void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
583
431
  assert(
584
431
      RHSExprs.size() == varlist_size() &&
585
431
      "Number of RHS expressions is not the same as the preallocated buffer");
586
431
  std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
587
431
}
588
589
431
void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
590
431
  assert(ReductionOps.size() == varlist_size() && "Number of in reduction "
591
431
                                                  "expressions is not the same "
592
431
                                                  "as the preallocated buffer");
593
431
  std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
594
431
}
595
596
void OMPInReductionClause::setTaskgroupDescriptors(
597
431
    ArrayRef<Expr *> TaskgroupDescriptors) {
598
431
  assert(TaskgroupDescriptors.size() == varlist_size() &&
599
431
         "Number of in reduction descriptors is not the same as the "
600
431
         "preallocated buffer");
601
431
  std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(),
602
431
            getReductionOps().end());
603
431
}
604
605
OMPInReductionClause *OMPInReductionClause::Create(
606
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
607
    SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
608
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
609
    ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs,
610
    ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps,
611
417
    ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) {
612
417
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size()));
613
417
  OMPInReductionClause *Clause = new (Mem) OMPInReductionClause(
614
417
      StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
615
417
  Clause->setVarRefs(VL);
616
417
  Clause->setPrivates(Privates);
617
417
  Clause->setLHSExprs(LHSExprs);
618
417
  Clause->setRHSExprs(RHSExprs);
619
417
  Clause->setReductionOps(ReductionOps);
620
417
  Clause->setTaskgroupDescriptors(TaskgroupDescriptors);
621
417
  Clause->setPreInitStmt(PreInit);
622
417
  Clause->setPostUpdateExpr(PostUpdate);
623
417
  return Clause;
624
417
}
625
626
OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C,
627
14
                                                        unsigned N) {
628
14
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N));
629
14
  return new (Mem) OMPInReductionClause(N);
630
14
}
631
632
OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
633
                                       SourceLocation StartLoc,
634
                                       SourceLocation LParenLoc,
635
                                       SourceLocation EndLoc,
636
26
                                       ArrayRef<Expr *> VL) {
637
26
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
638
26
  OMPFlushClause *Clause =
639
26
      new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
640
26
  Clause->setVarRefs(VL);
641
26
  return Clause;
642
26
}
643
644
4
OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
645
4
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
646
4
  return new (Mem) OMPFlushClause(N);
647
4
}
648
649
OMPDependClause *OMPDependClause::Create(
650
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
651
    SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
652
610
    SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
653
610
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1));
654
610
  OMPDependClause *Clause =
655
610
      new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
656
610
  Clause->setVarRefs(VL);
657
610
  Clause->setDependencyKind(DepKind);
658
610
  Clause->setDependencyLoc(DepLoc);
659
610
  Clause->setColonLoc(ColonLoc);
660
610
  Clause->setCounterValue(nullptr);
661
610
  return Clause;
662
610
}
663
664
65
OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
665
65
  void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1));
666
65
  return new (Mem) OMPDependClause(N);
667
65
}
668
669
804
void OMPDependClause::setCounterValue(Expr *V) {
670
804
  assert(getDependencyKind() == OMPC_DEPEND_sink ||
671
804
         getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
672
804
  *getVarRefs().end() = V;
673
804
}
674
675
10
const Expr *OMPDependClause::getCounterValue() const {
676
10
  auto *V = *getVarRefs().end();
677
10
  assert(getDependencyKind() == OMPC_DEPEND_sink ||
678
10
         getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
679
10
  return V;
680
10
}
681
682
65
Expr *OMPDependClause::getCounterValue() {
683
65
  auto *V = *getVarRefs().end();
684
65
  assert(getDependencyKind() == OMPC_DEPEND_sink ||
685
65
         getDependencyKind() == OMPC_DEPEND_source || V == nullptr);
686
65
  return V;
687
65
}
688
689
unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
690
7.49k
    MappableExprComponentListsRef ComponentLists) {
691
7.49k
  unsigned TotalNum = 0u;
692
7.49k
  for (auto &C : ComponentLists)
693
7.43k
    TotalNum += C.size();
694
7.49k
  return TotalNum;
695
7.49k
}
696
697
unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
698
7.49k
    ArrayRef<ValueDecl *> Declarations) {
699
7.49k
  unsigned TotalNum = 0u;
700
7.49k
  llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
701
7.43k
  for (auto *D : Declarations) {
702
7.43k
    const ValueDecl *VD = D ? 
cast<ValueDecl>(D->getCanonicalDecl())6.94k
:
nullptr492
;
703
7.43k
    if (Cache.count(VD))
704
60
      continue;
705
7.37k
    ++TotalNum;
706
7.37k
    Cache.insert(VD);
707
7.37k
  }
708
7.49k
  return TotalNum;
709
7.49k
}
710
711
OMPMapClause *
712
OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc,
713
                     SourceLocation LParenLoc, SourceLocation EndLoc,
714
                     ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
715
                     MappableExprComponentListsRef ComponentLists,
716
                     OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type,
717
5.74k
                     bool TypeIsImplicit, SourceLocation TypeLoc) {
718
5.74k
719
5.74k
  unsigned NumVars = Vars.size();
720
5.74k
  unsigned NumUniqueDeclarations =
721
5.74k
      getUniqueDeclarationsTotalNumber(Declarations);
722
5.74k
  unsigned NumComponentLists = ComponentLists.size();
723
5.74k
  unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
724
5.74k
725
5.74k
  // We need to allocate:
726
5.74k
  // NumVars x Expr* - we have an original list expression for each clause list
727
5.74k
  // entry.
728
5.74k
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
729
5.74k
  // with each component list.
730
5.74k
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
731
5.74k
  // number of lists for each unique declaration and the size of each component
732
5.74k
  // list.
733
5.74k
  // NumComponents x MappableComponent - the total of all the components in all
734
5.74k
  // the lists.
735
5.74k
  void *Mem = C.Allocate(
736
5.74k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
737
5.74k
                       OMPClauseMappableExprCommon::MappableComponent>(
738
5.74k
          NumVars, NumUniqueDeclarations,
739
5.74k
          NumUniqueDeclarations + NumComponentLists, NumComponents));
740
5.74k
  OMPMapClause *Clause = new (Mem) OMPMapClause(
741
5.74k
      TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc,
742
5.74k
      NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents);
743
5.74k
744
5.74k
  Clause->setVarRefs(Vars);
745
5.74k
  Clause->setClauseInfo(Declarations, ComponentLists);
746
5.74k
  Clause->setMapTypeModifier(TypeModifier);
747
5.74k
  Clause->setMapType(Type);
748
5.74k
  Clause->setMapLoc(TypeLoc);
749
5.74k
  return Clause;
750
5.74k
}
751
752
OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
753
                                        unsigned NumUniqueDeclarations,
754
                                        unsigned NumComponentLists,
755
626
                                        unsigned NumComponents) {
756
626
  void *Mem = C.Allocate(
757
626
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
758
626
                       OMPClauseMappableExprCommon::MappableComponent>(
759
626
          NumVars, NumUniqueDeclarations,
760
626
          NumUniqueDeclarations + NumComponentLists, NumComponents));
761
626
  return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations,
762
626
                                NumComponentLists, NumComponents);
763
626
}
764
765
OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc,
766
                                 SourceLocation LParenLoc,
767
                                 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
768
                                 ArrayRef<ValueDecl *> Declarations,
769
349
                                 MappableExprComponentListsRef ComponentLists) {
770
349
  unsigned NumVars = Vars.size();
771
349
  unsigned NumUniqueDeclarations =
772
349
      getUniqueDeclarationsTotalNumber(Declarations);
773
349
  unsigned NumComponentLists = ComponentLists.size();
774
349
  unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
775
349
776
349
  // We need to allocate:
777
349
  // NumVars x Expr* - we have an original list expression for each clause list
778
349
  // entry.
779
349
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
780
349
  // with each component list.
781
349
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
782
349
  // number of lists for each unique declaration and the size of each component
783
349
  // list.
784
349
  // NumComponents x MappableComponent - the total of all the components in all
785
349
  // the lists.
786
349
  void *Mem = C.Allocate(
787
349
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
788
349
                       OMPClauseMappableExprCommon::MappableComponent>(
789
349
          NumVars, NumUniqueDeclarations,
790
349
          NumUniqueDeclarations + NumComponentLists, NumComponents));
791
349
792
349
  OMPToClause *Clause = new (Mem)
793
349
      OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
794
349
                  NumComponentLists, NumComponents);
795
349
796
349
  Clause->setVarRefs(Vars);
797
349
  Clause->setClauseInfo(Declarations, ComponentLists);
798
349
  return Clause;
799
349
}
800
801
OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
802
                                      unsigned NumUniqueDeclarations,
803
                                      unsigned NumComponentLists,
804
10
                                      unsigned NumComponents) {
805
10
  void *Mem = C.Allocate(
806
10
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
807
10
                       OMPClauseMappableExprCommon::MappableComponent>(
808
10
          NumVars, NumUniqueDeclarations,
809
10
          NumUniqueDeclarations + NumComponentLists, NumComponents));
810
10
  return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations,
811
10
                               NumComponentLists, NumComponents);
812
10
}
813
814
OMPFromClause *
815
OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc,
816
                      SourceLocation LParenLoc, SourceLocation EndLoc,
817
                      ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
818
173
                      MappableExprComponentListsRef ComponentLists) {
819
173
  unsigned NumVars = Vars.size();
820
173
  unsigned NumUniqueDeclarations =
821
173
      getUniqueDeclarationsTotalNumber(Declarations);
822
173
  unsigned NumComponentLists = ComponentLists.size();
823
173
  unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
824
173
825
173
  // We need to allocate:
826
173
  // NumVars x Expr* - we have an original list expression for each clause list
827
173
  // entry.
828
173
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
829
173
  // with each component list.
830
173
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
831
173
  // number of lists for each unique declaration and the size of each component
832
173
  // list.
833
173
  // NumComponents x MappableComponent - the total of all the components in all
834
173
  // the lists.
835
173
  void *Mem = C.Allocate(
836
173
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
837
173
                       OMPClauseMappableExprCommon::MappableComponent>(
838
173
          NumVars, NumUniqueDeclarations,
839
173
          NumUniqueDeclarations + NumComponentLists, NumComponents));
840
173
841
173
  OMPFromClause *Clause = new (Mem)
842
173
      OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
843
173
                    NumComponentLists, NumComponents);
844
173
845
173
  Clause->setVarRefs(Vars);
846
173
  Clause->setClauseInfo(Declarations, ComponentLists);
847
173
  return Clause;
848
173
}
849
850
OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars,
851
                                          unsigned NumUniqueDeclarations,
852
                                          unsigned NumComponentLists,
853
12
                                          unsigned NumComponents) {
854
12
  void *Mem = C.Allocate(
855
12
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
856
12
                       OMPClauseMappableExprCommon::MappableComponent>(
857
12
          NumVars, NumUniqueDeclarations,
858
12
          NumUniqueDeclarations + NumComponentLists, NumComponents));
859
12
  return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations,
860
12
                                 NumComponentLists, NumComponents);
861
12
}
862
863
214
void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) {
864
214
  assert(VL.size() == varlist_size() &&
865
214
         "Number of private copies is not the same as the preallocated buffer");
866
214
  std::copy(VL.begin(), VL.end(), varlist_end());
867
214
}
868
869
214
void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) {
870
214
  assert(VL.size() == varlist_size() &&
871
214
         "Number of inits is not the same as the preallocated buffer");
872
214
  std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
873
214
}
874
875
OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(
876
    const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
877
    SourceLocation EndLoc, ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
878
    ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
879
172
    MappableExprComponentListsRef ComponentLists) {
880
172
  unsigned NumVars = Vars.size();
881
172
  unsigned NumUniqueDeclarations =
882
172
      getUniqueDeclarationsTotalNumber(Declarations);
883
172
  unsigned NumComponentLists = ComponentLists.size();
884
172
  unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
885
172
886
172
  // We need to allocate:
887
172
  // 3 x NumVars x Expr* - we have an original list expression for each clause
888
172
  // list entry and an equal number of private copies and inits.
889
172
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
890
172
  // with each component list.
891
172
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
892
172
  // number of lists for each unique declaration and the size of each component
893
172
  // list.
894
172
  // NumComponents x MappableComponent - the total of all the components in all
895
172
  // the lists.
896
172
  void *Mem = C.Allocate(
897
172
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
898
172
                       OMPClauseMappableExprCommon::MappableComponent>(
899
172
          3 * NumVars, NumUniqueDeclarations,
900
172
          NumUniqueDeclarations + NumComponentLists, NumComponents));
901
172
902
172
  OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(
903
172
      StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
904
172
      NumComponentLists, NumComponents);
905
172
906
172
  Clause->setVarRefs(Vars);
907
172
  Clause->setPrivateCopies(PrivateVars);
908
172
  Clause->setInits(Inits);
909
172
  Clause->setClauseInfo(Declarations, ComponentLists);
910
172
  return Clause;
911
172
}
912
913
OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(
914
    const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
915
42
    unsigned NumComponentLists, unsigned NumComponents) {
916
42
  void *Mem = C.Allocate(
917
42
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
918
42
                       OMPClauseMappableExprCommon::MappableComponent>(
919
42
          3 * NumVars, NumUniqueDeclarations,
920
42
          NumUniqueDeclarations + NumComponentLists, NumComponents));
921
42
  return new (Mem) OMPUseDevicePtrClause(NumVars, NumUniqueDeclarations,
922
42
                                         NumComponentLists, NumComponents);
923
42
}
924
925
OMPIsDevicePtrClause *
926
OMPIsDevicePtrClause::Create(const ASTContext &C, SourceLocation StartLoc,
927
                             SourceLocation LParenLoc, SourceLocation EndLoc,
928
                             ArrayRef<Expr *> Vars,
929
                             ArrayRef<ValueDecl *> Declarations,
930
1.05k
                             MappableExprComponentListsRef ComponentLists) {
931
1.05k
  unsigned NumVars = Vars.size();
932
1.05k
  unsigned NumUniqueDeclarations =
933
1.05k
      getUniqueDeclarationsTotalNumber(Declarations);
934
1.05k
  unsigned NumComponentLists = ComponentLists.size();
935
1.05k
  unsigned NumComponents = getComponentsTotalNumber(ComponentLists);
936
1.05k
937
1.05k
  // We need to allocate:
938
1.05k
  // NumVars x Expr* - we have an original list expression for each clause list
939
1.05k
  // entry.
940
1.05k
  // NumUniqueDeclarations x ValueDecl* - unique base declarations associated
941
1.05k
  // with each component list.
942
1.05k
  // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the
943
1.05k
  // number of lists for each unique declaration and the size of each component
944
1.05k
  // list.
945
1.05k
  // NumComponents x MappableComponent - the total of all the components in all
946
1.05k
  // the lists.
947
1.05k
  void *Mem = C.Allocate(
948
1.05k
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
949
1.05k
                       OMPClauseMappableExprCommon::MappableComponent>(
950
1.05k
          NumVars, NumUniqueDeclarations,
951
1.05k
          NumUniqueDeclarations + NumComponentLists, NumComponents));
952
1.05k
953
1.05k
  OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(
954
1.05k
      StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations,
955
1.05k
      NumComponentLists, NumComponents);
956
1.05k
957
1.05k
  Clause->setVarRefs(Vars);
958
1.05k
  Clause->setClauseInfo(Declarations, ComponentLists);
959
1.05k
  return Clause;
960
1.05k
}
961
962
OMPIsDevicePtrClause *OMPIsDevicePtrClause::CreateEmpty(
963
    const ASTContext &C, unsigned NumVars, unsigned NumUniqueDeclarations,
964
190
    unsigned NumComponentLists, unsigned NumComponents) {
965
190
  void *Mem = C.Allocate(
966
190
      totalSizeToAlloc<Expr *, ValueDecl *, unsigned,
967
190
                       OMPClauseMappableExprCommon::MappableComponent>(
968
190
          NumVars, NumUniqueDeclarations,
969
190
          NumUniqueDeclarations + NumComponentLists, NumComponents));
970
190
  return new (Mem) OMPIsDevicePtrClause(NumVars, NumUniqueDeclarations,
971
190
                                        NumComponentLists, NumComponents);
972
190
}