James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 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 | OMPClause::child_range OMPClause::children() { |
| 21 | switch (getClauseKind()) { |
| 22 | default: |
| 23 | break; |
| 24 | #define OPENMP_CLAUSE(Name, Class) \ |
| 25 | case OMPC_##Name: \ |
| 26 | return static_cast<Class *>(this)->children(); |
| 27 | #include "clang/Basic/OpenMPKinds.def" |
| 28 | } |
| 29 | llvm_unreachable("unknown OMPClause"); |
| 30 | } |
| 31 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 32 | OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { |
| 33 | auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); |
| 34 | return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; |
| 35 | } |
| 36 | |
| 37 | const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { |
| 38 | switch (C->getClauseKind()) { |
| 39 | case OMPC_schedule: |
| 40 | return static_cast<const OMPScheduleClause *>(C); |
| 41 | case OMPC_dist_schedule: |
| 42 | return static_cast<const OMPDistScheduleClause *>(C); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 43 | case OMPC_firstprivate: |
| 44 | return static_cast<const OMPFirstprivateClause *>(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 45 | case OMPC_lastprivate: |
| 46 | return static_cast<const OMPLastprivateClause *>(C); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 47 | case OMPC_reduction: |
| 48 | return static_cast<const OMPReductionClause *>(C); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 49 | case OMPC_linear: |
| 50 | return static_cast<const OMPLinearClause *>(C); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 51 | case OMPC_default: |
| 52 | case OMPC_proc_bind: |
| 53 | case OMPC_if: |
| 54 | case OMPC_final: |
| 55 | case OMPC_num_threads: |
| 56 | case OMPC_safelen: |
| 57 | case OMPC_simdlen: |
| 58 | case OMPC_collapse: |
| 59 | case OMPC_private: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 60 | case OMPC_shared: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 61 | case OMPC_aligned: |
| 62 | case OMPC_copyin: |
| 63 | case OMPC_copyprivate: |
| 64 | case OMPC_ordered: |
| 65 | case OMPC_nowait: |
| 66 | case OMPC_untied: |
| 67 | case OMPC_mergeable: |
| 68 | case OMPC_threadprivate: |
| 69 | case OMPC_flush: |
| 70 | case OMPC_read: |
| 71 | case OMPC_write: |
| 72 | case OMPC_update: |
| 73 | case OMPC_capture: |
| 74 | case OMPC_seq_cst: |
| 75 | case OMPC_depend: |
| 76 | case OMPC_device: |
| 77 | case OMPC_threads: |
| 78 | case OMPC_simd: |
| 79 | case OMPC_map: |
| 80 | case OMPC_num_teams: |
| 81 | case OMPC_thread_limit: |
| 82 | case OMPC_priority: |
| 83 | case OMPC_grainsize: |
| 84 | case OMPC_nogroup: |
| 85 | case OMPC_num_tasks: |
| 86 | case OMPC_hint: |
| 87 | case OMPC_defaultmap: |
| 88 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 89 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 90 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 91 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame^] | 92 | case OMPC_use_device_ptr: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
| 99 | OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { |
| 100 | auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); |
| 101 | return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; |
| 102 | } |
| 103 | |
| 104 | const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { |
| 105 | switch (C->getClauseKind()) { |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 106 | case OMPC_lastprivate: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 107 | return static_cast<const OMPLastprivateClause *>(C); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 108 | case OMPC_reduction: |
| 109 | return static_cast<const OMPReductionClause *>(C); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 110 | case OMPC_linear: |
| 111 | return static_cast<const OMPLinearClause *>(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 112 | case OMPC_schedule: |
| 113 | case OMPC_dist_schedule: |
| 114 | case OMPC_firstprivate: |
| 115 | case OMPC_default: |
| 116 | case OMPC_proc_bind: |
| 117 | case OMPC_if: |
| 118 | case OMPC_final: |
| 119 | case OMPC_num_threads: |
| 120 | case OMPC_safelen: |
| 121 | case OMPC_simdlen: |
| 122 | case OMPC_collapse: |
| 123 | case OMPC_private: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 124 | case OMPC_shared: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 125 | case OMPC_aligned: |
| 126 | case OMPC_copyin: |
| 127 | case OMPC_copyprivate: |
| 128 | case OMPC_ordered: |
| 129 | case OMPC_nowait: |
| 130 | case OMPC_untied: |
| 131 | case OMPC_mergeable: |
| 132 | case OMPC_threadprivate: |
| 133 | case OMPC_flush: |
| 134 | case OMPC_read: |
| 135 | case OMPC_write: |
| 136 | case OMPC_update: |
| 137 | case OMPC_capture: |
| 138 | case OMPC_seq_cst: |
| 139 | case OMPC_depend: |
| 140 | case OMPC_device: |
| 141 | case OMPC_threads: |
| 142 | case OMPC_simd: |
| 143 | case OMPC_map: |
| 144 | case OMPC_num_teams: |
| 145 | case OMPC_thread_limit: |
| 146 | case OMPC_priority: |
| 147 | case OMPC_grainsize: |
| 148 | case OMPC_nogroup: |
| 149 | case OMPC_num_tasks: |
| 150 | case OMPC_hint: |
| 151 | case OMPC_defaultmap: |
| 152 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 153 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 154 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 155 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame^] | 156 | case OMPC_use_device_ptr: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | |
| 160 | return nullptr; |
| 161 | } |
| 162 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 163 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 164 | assert(VL.size() == varlist_size() && |
| 165 | "Number of private copies is not the same as the preallocated buffer"); |
| 166 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 167 | } |
| 168 | |
| 169 | OMPPrivateClause * |
| 170 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 171 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 172 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 173 | // Allocate space for private variables and initializer expressions. |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 174 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 175 | OMPPrivateClause *Clause = |
| 176 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 177 | Clause->setVarRefs(VL); |
| 178 | Clause->setPrivateCopies(PrivateVL); |
| 179 | return Clause; |
| 180 | } |
| 181 | |
| 182 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
| 183 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 184 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 185 | return new (Mem) OMPPrivateClause(N); |
| 186 | } |
| 187 | |
| 188 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 189 | assert(VL.size() == varlist_size() && |
| 190 | "Number of private copies is not the same as the preallocated buffer"); |
| 191 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 192 | } |
| 193 | |
| 194 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 195 | assert(VL.size() == varlist_size() && |
| 196 | "Number of inits is not the same as the preallocated buffer"); |
| 197 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 198 | } |
| 199 | |
| 200 | OMPFirstprivateClause * |
| 201 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 202 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 203 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 204 | ArrayRef<Expr *> InitVL, Stmt *PreInit) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 205 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 206 | OMPFirstprivateClause *Clause = |
| 207 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 208 | Clause->setVarRefs(VL); |
| 209 | Clause->setPrivateCopies(PrivateVL); |
| 210 | Clause->setInits(InitVL); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 211 | Clause->setPreInitStmt(PreInit); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 212 | return Clause; |
| 213 | } |
| 214 | |
| 215 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 216 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 217 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 218 | return new (Mem) OMPFirstprivateClause(N); |
| 219 | } |
| 220 | |
| 221 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
| 222 | assert(PrivateCopies.size() == varlist_size() && |
| 223 | "Number of private copies is not the same as the preallocated buffer"); |
| 224 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
| 225 | } |
| 226 | |
| 227 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 228 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 229 | "not the same as the " |
| 230 | "preallocated buffer"); |
| 231 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
| 232 | } |
| 233 | |
| 234 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 235 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 236 | "expressions is not the same as " |
| 237 | "the preallocated buffer"); |
| 238 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 239 | } |
| 240 | |
| 241 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 242 | assert(AssignmentOps.size() == varlist_size() && |
| 243 | "Number of assignment expressions is not the same as the preallocated " |
| 244 | "buffer"); |
| 245 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 246 | getDestinationExprs().end()); |
| 247 | } |
| 248 | |
| 249 | OMPLastprivateClause *OMPLastprivateClause::Create( |
| 250 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 251 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 252 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit, |
| 253 | Expr *PostUpdate) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 254 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 255 | OMPLastprivateClause *Clause = |
| 256 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 257 | Clause->setVarRefs(VL); |
| 258 | Clause->setSourceExprs(SrcExprs); |
| 259 | Clause->setDestinationExprs(DstExprs); |
| 260 | Clause->setAssignmentOps(AssignmentOps); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 261 | Clause->setPreInitStmt(PreInit); |
| 262 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 263 | return Clause; |
| 264 | } |
| 265 | |
| 266 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 267 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 268 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 269 | return new (Mem) OMPLastprivateClause(N); |
| 270 | } |
| 271 | |
| 272 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 273 | SourceLocation StartLoc, |
| 274 | SourceLocation LParenLoc, |
| 275 | SourceLocation EndLoc, |
| 276 | ArrayRef<Expr *> VL) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 277 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 278 | OMPSharedClause *Clause = |
| 279 | new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 280 | Clause->setVarRefs(VL); |
| 281 | return Clause; |
| 282 | } |
| 283 | |
| 284 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 285 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 286 | return new (Mem) OMPSharedClause(N); |
| 287 | } |
| 288 | |
| 289 | void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { |
| 290 | assert(PL.size() == varlist_size() && |
| 291 | "Number of privates is not the same as the preallocated buffer"); |
| 292 | std::copy(PL.begin(), PL.end(), varlist_end()); |
| 293 | } |
| 294 | |
| 295 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
| 296 | assert(IL.size() == varlist_size() && |
| 297 | "Number of inits is not the same as the preallocated buffer"); |
| 298 | std::copy(IL.begin(), IL.end(), getPrivates().end()); |
| 299 | } |
| 300 | |
| 301 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
| 302 | assert(UL.size() == varlist_size() && |
| 303 | "Number of updates is not the same as the preallocated buffer"); |
| 304 | std::copy(UL.begin(), UL.end(), getInits().end()); |
| 305 | } |
| 306 | |
| 307 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
| 308 | assert(FL.size() == varlist_size() && |
| 309 | "Number of final updates is not the same as the preallocated buffer"); |
| 310 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
| 311 | } |
| 312 | |
| 313 | OMPLinearClause *OMPLinearClause::Create( |
| 314 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 315 | OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, |
| 316 | SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 317 | ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, |
| 318 | Stmt *PreInit, Expr *PostUpdate) { |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 319 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 320 | // (Step and CalcStep). |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 321 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 322 | OMPLinearClause *Clause = new (Mem) OMPLinearClause( |
| 323 | StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); |
| 324 | Clause->setVarRefs(VL); |
| 325 | Clause->setPrivates(PL); |
| 326 | Clause->setInits(IL); |
| 327 | // Fill update and final expressions with zeroes, they are provided later, |
| 328 | // after the directive construction. |
| 329 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
| 330 | nullptr); |
| 331 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
| 332 | nullptr); |
| 333 | Clause->setStep(Step); |
| 334 | Clause->setCalcStep(CalcStep); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 335 | Clause->setPreInitStmt(PreInit); |
| 336 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 337 | return Clause; |
| 338 | } |
| 339 | |
| 340 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 341 | unsigned NumVars) { |
| 342 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 343 | // (Step and CalcStep). |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 344 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 345 | return new (Mem) OMPLinearClause(NumVars); |
| 346 | } |
| 347 | |
| 348 | OMPAlignedClause * |
| 349 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 350 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 351 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 352 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 353 | OMPAlignedClause *Clause = new (Mem) |
| 354 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 355 | Clause->setVarRefs(VL); |
| 356 | Clause->setAlignment(A); |
| 357 | return Clause; |
| 358 | } |
| 359 | |
| 360 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 361 | unsigned NumVars) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 362 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 363 | return new (Mem) OMPAlignedClause(NumVars); |
| 364 | } |
| 365 | |
| 366 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 367 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 368 | "not the same as the " |
| 369 | "preallocated buffer"); |
| 370 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 371 | } |
| 372 | |
| 373 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 374 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 375 | "expressions is not the same as " |
| 376 | "the preallocated buffer"); |
| 377 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 378 | } |
| 379 | |
| 380 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 381 | assert(AssignmentOps.size() == varlist_size() && |
| 382 | "Number of assignment expressions is not the same as the preallocated " |
| 383 | "buffer"); |
| 384 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 385 | getDestinationExprs().end()); |
| 386 | } |
| 387 | |
| 388 | OMPCopyinClause *OMPCopyinClause::Create( |
| 389 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 390 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 391 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 392 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 393 | OMPCopyinClause *Clause = |
| 394 | new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 395 | Clause->setVarRefs(VL); |
| 396 | Clause->setSourceExprs(SrcExprs); |
| 397 | Clause->setDestinationExprs(DstExprs); |
| 398 | Clause->setAssignmentOps(AssignmentOps); |
| 399 | return Clause; |
| 400 | } |
| 401 | |
| 402 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 403 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 404 | return new (Mem) OMPCopyinClause(N); |
| 405 | } |
| 406 | |
| 407 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 408 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 409 | "not the same as the " |
| 410 | "preallocated buffer"); |
| 411 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 412 | } |
| 413 | |
| 414 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 415 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 416 | "expressions is not the same as " |
| 417 | "the preallocated buffer"); |
| 418 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 419 | } |
| 420 | |
| 421 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 422 | assert(AssignmentOps.size() == varlist_size() && |
| 423 | "Number of assignment expressions is not the same as the preallocated " |
| 424 | "buffer"); |
| 425 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 426 | getDestinationExprs().end()); |
| 427 | } |
| 428 | |
| 429 | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
| 430 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 431 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 432 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 433 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 434 | OMPCopyprivateClause *Clause = |
| 435 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 436 | Clause->setVarRefs(VL); |
| 437 | Clause->setSourceExprs(SrcExprs); |
| 438 | Clause->setDestinationExprs(DstExprs); |
| 439 | Clause->setAssignmentOps(AssignmentOps); |
| 440 | return Clause; |
| 441 | } |
| 442 | |
| 443 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 444 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 445 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 446 | return new (Mem) OMPCopyprivateClause(N); |
| 447 | } |
| 448 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 449 | void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
| 450 | assert(Privates.size() == varlist_size() && |
| 451 | "Number of private copies is not the same as the preallocated buffer"); |
| 452 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
| 453 | } |
| 454 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 455 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 456 | assert( |
| 457 | LHSExprs.size() == varlist_size() && |
| 458 | "Number of LHS expressions is not the same as the preallocated buffer"); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 459 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 463 | assert( |
| 464 | RHSExprs.size() == varlist_size() && |
| 465 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 466 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 467 | } |
| 468 | |
| 469 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 470 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
| 471 | "expressions is not the same " |
| 472 | "as the preallocated buffer"); |
| 473 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 474 | } |
| 475 | |
| 476 | OMPReductionClause *OMPReductionClause::Create( |
| 477 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 478 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 479 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 480 | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 481 | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, |
| 482 | Expr *PostUpdate) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 483 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 484 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 485 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 486 | Clause->setVarRefs(VL); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 487 | Clause->setPrivates(Privates); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 488 | Clause->setLHSExprs(LHSExprs); |
| 489 | Clause->setRHSExprs(RHSExprs); |
| 490 | Clause->setReductionOps(ReductionOps); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 491 | Clause->setPreInitStmt(PreInit); |
| 492 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 493 | return Clause; |
| 494 | } |
| 495 | |
| 496 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 497 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 498 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 499 | return new (Mem) OMPReductionClause(N); |
| 500 | } |
| 501 | |
| 502 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 503 | SourceLocation StartLoc, |
| 504 | SourceLocation LParenLoc, |
| 505 | SourceLocation EndLoc, |
| 506 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 507 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 508 | OMPFlushClause *Clause = |
| 509 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 510 | Clause->setVarRefs(VL); |
| 511 | return Clause; |
| 512 | } |
| 513 | |
| 514 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 515 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 516 | return new (Mem) OMPFlushClause(N); |
| 517 | } |
| 518 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 519 | OMPDependClause *OMPDependClause::Create( |
| 520 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 521 | SourceLocation EndLoc, OpenMPDependClauseKind DepKind, |
| 522 | SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL) { |
| 523 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 524 | OMPDependClause *Clause = |
| 525 | new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 526 | Clause->setVarRefs(VL); |
| 527 | Clause->setDependencyKind(DepKind); |
| 528 | Clause->setDependencyLoc(DepLoc); |
| 529 | Clause->setColonLoc(ColonLoc); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 530 | Clause->setCounterValue(nullptr); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 531 | return Clause; |
| 532 | } |
| 533 | |
| 534 | OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) { |
Alexey Bataev | 2af82054 | 2016-05-25 12:51:24 +0000 | [diff] [blame] | 535 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 536 | return new (Mem) OMPDependClause(N); |
| 537 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 538 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 539 | void OMPDependClause::setCounterValue(Expr *V) { |
| 540 | assert(getDependencyKind() == OMPC_DEPEND_sink || |
| 541 | getDependencyKind() == OMPC_DEPEND_source || V == nullptr); |
| 542 | *getVarRefs().end() = V; |
| 543 | } |
| 544 | |
| 545 | const Expr *OMPDependClause::getCounterValue() const { |
| 546 | auto *V = *getVarRefs().end(); |
| 547 | assert(getDependencyKind() == OMPC_DEPEND_sink || |
| 548 | getDependencyKind() == OMPC_DEPEND_source || V == nullptr); |
| 549 | return V; |
| 550 | } |
| 551 | |
| 552 | Expr *OMPDependClause::getCounterValue() { |
| 553 | auto *V = *getVarRefs().end(); |
| 554 | assert(getDependencyKind() == OMPC_DEPEND_sink || |
| 555 | getDependencyKind() == OMPC_DEPEND_source || V == nullptr); |
| 556 | return V; |
| 557 | } |
| 558 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 559 | unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( |
| 560 | MappableExprComponentListsRef ComponentLists) { |
| 561 | unsigned TotalNum = 0u; |
| 562 | for (auto &C : ComponentLists) |
| 563 | TotalNum += C.size(); |
| 564 | return TotalNum; |
| 565 | } |
| 566 | |
| 567 | unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( |
| 568 | ArrayRef<ValueDecl *> Declarations) { |
| 569 | unsigned TotalNum = 0u; |
| 570 | llvm::SmallPtrSet<const ValueDecl *, 8> Cache; |
| 571 | for (auto *D : Declarations) { |
| 572 | const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; |
| 573 | if (Cache.count(VD)) |
| 574 | continue; |
| 575 | ++TotalNum; |
| 576 | Cache.insert(VD); |
| 577 | } |
| 578 | return TotalNum; |
| 579 | } |
| 580 | |
| 581 | OMPMapClause * |
| 582 | OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 583 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 584 | ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, |
| 585 | MappableExprComponentListsRef ComponentLists, |
| 586 | OpenMPMapClauseKind TypeModifier, OpenMPMapClauseKind Type, |
| 587 | bool TypeIsImplicit, SourceLocation TypeLoc) { |
| 588 | |
| 589 | unsigned NumVars = Vars.size(); |
| 590 | unsigned NumUniqueDeclarations = |
| 591 | getUniqueDeclarationsTotalNumber(Declarations); |
| 592 | unsigned NumComponentLists = ComponentLists.size(); |
| 593 | unsigned NumComponents = getComponentsTotalNumber(ComponentLists); |
| 594 | |
| 595 | // We need to allocate: |
| 596 | // NumVars x Expr* - we have an original list expression for each clause list |
| 597 | // entry. |
| 598 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 599 | // with each component list. |
| 600 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 601 | // number of lists for each unique declaration and the size of each component |
| 602 | // list. |
| 603 | // NumComponents x MappableComponent - the total of all the components in all |
| 604 | // the lists. |
| 605 | void *Mem = C.Allocate( |
| 606 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 607 | OMPClauseMappableExprCommon::MappableComponent>( |
| 608 | NumVars, NumUniqueDeclarations, |
| 609 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 610 | OMPMapClause *Clause = new (Mem) OMPMapClause( |
| 611 | TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc, |
| 612 | NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); |
| 613 | |
| 614 | Clause->setVarRefs(Vars); |
| 615 | Clause->setClauseInfo(Declarations, ComponentLists); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 616 | Clause->setMapTypeModifier(TypeModifier); |
| 617 | Clause->setMapType(Type); |
| 618 | Clause->setMapLoc(TypeLoc); |
| 619 | return Clause; |
| 620 | } |
| 621 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 622 | OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned NumVars, |
| 623 | unsigned NumUniqueDeclarations, |
| 624 | unsigned NumComponentLists, |
| 625 | unsigned NumComponents) { |
| 626 | void *Mem = C.Allocate( |
| 627 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 628 | OMPClauseMappableExprCommon::MappableComponent>( |
| 629 | NumVars, NumUniqueDeclarations, |
| 630 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 631 | return new (Mem) OMPMapClause(NumVars, NumUniqueDeclarations, |
| 632 | NumComponentLists, NumComponents); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 633 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 634 | |
| 635 | OMPToClause *OMPToClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 636 | SourceLocation LParenLoc, |
| 637 | SourceLocation EndLoc, ArrayRef<Expr *> Vars, |
| 638 | ArrayRef<ValueDecl *> Declarations, |
| 639 | MappableExprComponentListsRef ComponentLists) { |
| 640 | unsigned NumVars = Vars.size(); |
| 641 | unsigned NumUniqueDeclarations = |
| 642 | getUniqueDeclarationsTotalNumber(Declarations); |
| 643 | unsigned NumComponentLists = ComponentLists.size(); |
| 644 | unsigned NumComponents = getComponentsTotalNumber(ComponentLists); |
| 645 | |
| 646 | // We need to allocate: |
| 647 | // NumVars x Expr* - we have an original list expression for each clause list |
| 648 | // entry. |
| 649 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 650 | // with each component list. |
| 651 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 652 | // number of lists for each unique declaration and the size of each component |
| 653 | // list. |
| 654 | // NumComponents x MappableComponent - the total of all the components in all |
| 655 | // the lists. |
| 656 | void *Mem = C.Allocate( |
| 657 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 658 | OMPClauseMappableExprCommon::MappableComponent>( |
| 659 | NumVars, NumUniqueDeclarations, |
| 660 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 661 | |
| 662 | OMPToClause *Clause = new (Mem) |
| 663 | OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, |
| 664 | NumComponentLists, NumComponents); |
| 665 | |
| 666 | Clause->setVarRefs(Vars); |
| 667 | Clause->setClauseInfo(Declarations, ComponentLists); |
| 668 | return Clause; |
| 669 | } |
| 670 | |
| 671 | OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, unsigned NumVars, |
| 672 | unsigned NumUniqueDeclarations, |
| 673 | unsigned NumComponentLists, |
| 674 | unsigned NumComponents) { |
| 675 | void *Mem = C.Allocate( |
| 676 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 677 | OMPClauseMappableExprCommon::MappableComponent>( |
| 678 | NumVars, NumUniqueDeclarations, |
| 679 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 680 | return new (Mem) OMPToClause(NumVars, NumUniqueDeclarations, |
| 681 | NumComponentLists, NumComponents); |
| 682 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 683 | |
| 684 | OMPFromClause * |
| 685 | OMPFromClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 686 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 687 | ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations, |
| 688 | MappableExprComponentListsRef ComponentLists) { |
| 689 | unsigned NumVars = Vars.size(); |
| 690 | unsigned NumUniqueDeclarations = |
| 691 | getUniqueDeclarationsTotalNumber(Declarations); |
| 692 | unsigned NumComponentLists = ComponentLists.size(); |
| 693 | unsigned NumComponents = getComponentsTotalNumber(ComponentLists); |
| 694 | |
| 695 | // We need to allocate: |
| 696 | // NumVars x Expr* - we have an original list expression for each clause list |
| 697 | // entry. |
| 698 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 699 | // with each component list. |
| 700 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 701 | // number of lists for each unique declaration and the size of each component |
| 702 | // list. |
| 703 | // NumComponents x MappableComponent - the total of all the components in all |
| 704 | // the lists. |
| 705 | void *Mem = C.Allocate( |
| 706 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 707 | OMPClauseMappableExprCommon::MappableComponent>( |
| 708 | NumVars, NumUniqueDeclarations, |
| 709 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 710 | |
| 711 | OMPFromClause *Clause = new (Mem) |
| 712 | OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, |
| 713 | NumComponentLists, NumComponents); |
| 714 | |
| 715 | Clause->setVarRefs(Vars); |
| 716 | Clause->setClauseInfo(Declarations, ComponentLists); |
| 717 | return Clause; |
| 718 | } |
| 719 | |
| 720 | OMPFromClause *OMPFromClause::CreateEmpty(const ASTContext &C, unsigned NumVars, |
| 721 | unsigned NumUniqueDeclarations, |
| 722 | unsigned NumComponentLists, |
| 723 | unsigned NumComponents) { |
| 724 | void *Mem = C.Allocate( |
| 725 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 726 | OMPClauseMappableExprCommon::MappableComponent>( |
| 727 | NumVars, NumUniqueDeclarations, |
| 728 | NumUniqueDeclarations + NumComponentLists, NumComponents)); |
| 729 | return new (Mem) OMPFromClause(NumVars, NumUniqueDeclarations, |
| 730 | NumComponentLists, NumComponents); |
| 731 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame^] | 732 | |
| 733 | OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create(const ASTContext &C, |
| 734 | SourceLocation StartLoc, |
| 735 | SourceLocation LParenLoc, |
| 736 | SourceLocation EndLoc, |
| 737 | ArrayRef<Expr *> VL) { |
| 738 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| 739 | OMPUseDevicePtrClause *Clause = |
| 740 | new (Mem) OMPUseDevicePtrClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 741 | Clause->setVarRefs(VL); |
| 742 | return Clause; |
| 743 | } |
| 744 | |
| 745 | OMPUseDevicePtrClause *OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C, |
| 746 | unsigned N) { |
| 747 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| 748 | return new (Mem) OMPUseDevicePtrClause(N); |
| 749 | } |