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