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