| 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); |
| 43 | case OMPC_default: |
| 44 | case OMPC_proc_bind: |
| 45 | case OMPC_if: |
| 46 | case OMPC_final: |
| 47 | case OMPC_num_threads: |
| 48 | case OMPC_safelen: |
| 49 | case OMPC_simdlen: |
| 50 | case OMPC_collapse: |
| 51 | case OMPC_private: |
| 52 | case OMPC_firstprivate: |
| 53 | case OMPC_lastprivate: |
| 54 | case OMPC_shared: |
| 55 | case OMPC_reduction: |
| 56 | case OMPC_linear: |
| 57 | case OMPC_aligned: |
| 58 | case OMPC_copyin: |
| 59 | case OMPC_copyprivate: |
| 60 | case OMPC_ordered: |
| 61 | case OMPC_nowait: |
| 62 | case OMPC_untied: |
| 63 | case OMPC_mergeable: |
| 64 | case OMPC_threadprivate: |
| 65 | case OMPC_flush: |
| 66 | case OMPC_read: |
| 67 | case OMPC_write: |
| 68 | case OMPC_update: |
| 69 | case OMPC_capture: |
| 70 | case OMPC_seq_cst: |
| 71 | case OMPC_depend: |
| 72 | case OMPC_device: |
| 73 | case OMPC_threads: |
| 74 | case OMPC_simd: |
| 75 | case OMPC_map: |
| 76 | case OMPC_num_teams: |
| 77 | case OMPC_thread_limit: |
| 78 | case OMPC_priority: |
| 79 | case OMPC_grainsize: |
| 80 | case OMPC_nogroup: |
| 81 | case OMPC_num_tasks: |
| 82 | case OMPC_hint: |
| 83 | case OMPC_defaultmap: |
| 84 | case OMPC_unknown: |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 91 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 92 | assert(VL.size() == varlist_size() && |
| 93 | "Number of private copies is not the same as the preallocated buffer"); |
| 94 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 95 | } |
| 96 | |
| 97 | OMPPrivateClause * |
| 98 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 99 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 100 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 101 | // Allocate space for private variables and initializer expressions. |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 102 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 103 | OMPPrivateClause *Clause = |
| 104 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 105 | Clause->setVarRefs(VL); |
| 106 | Clause->setPrivateCopies(PrivateVL); |
| 107 | return Clause; |
| 108 | } |
| 109 | |
| 110 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
| 111 | unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 112 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 113 | return new (Mem) OMPPrivateClause(N); |
| 114 | } |
| 115 | |
| 116 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 117 | assert(VL.size() == varlist_size() && |
| 118 | "Number of private copies is not the same as the preallocated buffer"); |
| 119 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 120 | } |
| 121 | |
| 122 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 123 | assert(VL.size() == varlist_size() && |
| 124 | "Number of inits is not the same as the preallocated buffer"); |
| 125 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 126 | } |
| 127 | |
| 128 | OMPFirstprivateClause * |
| 129 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 130 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 131 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
| 132 | ArrayRef<Expr *> InitVL) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 133 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 134 | OMPFirstprivateClause *Clause = |
| 135 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 136 | Clause->setVarRefs(VL); |
| 137 | Clause->setPrivateCopies(PrivateVL); |
| 138 | Clause->setInits(InitVL); |
| 139 | return Clause; |
| 140 | } |
| 141 | |
| 142 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 143 | unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 144 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 145 | return new (Mem) OMPFirstprivateClause(N); |
| 146 | } |
| 147 | |
| 148 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
| 149 | assert(PrivateCopies.size() == varlist_size() && |
| 150 | "Number of private copies is not the same as the preallocated buffer"); |
| 151 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
| 152 | } |
| 153 | |
| 154 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 155 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 156 | "not the same as the " |
| 157 | "preallocated buffer"); |
| 158 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
| 159 | } |
| 160 | |
| 161 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 162 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 163 | "expressions is not the same as " |
| 164 | "the preallocated buffer"); |
| 165 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 166 | } |
| 167 | |
| 168 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 169 | assert(AssignmentOps.size() == varlist_size() && |
| 170 | "Number of assignment expressions is not the same as the preallocated " |
| 171 | "buffer"); |
| 172 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 173 | getDestinationExprs().end()); |
| 174 | } |
| 175 | |
| 176 | OMPLastprivateClause *OMPLastprivateClause::Create( |
| 177 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 178 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 179 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 180 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 181 | OMPLastprivateClause *Clause = |
| 182 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 183 | Clause->setVarRefs(VL); |
| 184 | Clause->setSourceExprs(SrcExprs); |
| 185 | Clause->setDestinationExprs(DstExprs); |
| 186 | Clause->setAssignmentOps(AssignmentOps); |
| 187 | return Clause; |
| 188 | } |
| 189 | |
| 190 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 191 | unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 192 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 193 | return new (Mem) OMPLastprivateClause(N); |
| 194 | } |
| 195 | |
| 196 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 197 | SourceLocation StartLoc, |
| 198 | SourceLocation LParenLoc, |
| 199 | SourceLocation EndLoc, |
| 200 | ArrayRef<Expr *> VL) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 201 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 202 | OMPSharedClause *Clause = |
| 203 | new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 204 | Clause->setVarRefs(VL); |
| 205 | return Clause; |
| 206 | } |
| 207 | |
| 208 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 209 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 210 | return new (Mem) OMPSharedClause(N); |
| 211 | } |
| 212 | |
| 213 | void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { |
| 214 | assert(PL.size() == varlist_size() && |
| 215 | "Number of privates is not the same as the preallocated buffer"); |
| 216 | std::copy(PL.begin(), PL.end(), varlist_end()); |
| 217 | } |
| 218 | |
| 219 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
| 220 | assert(IL.size() == varlist_size() && |
| 221 | "Number of inits is not the same as the preallocated buffer"); |
| 222 | std::copy(IL.begin(), IL.end(), getPrivates().end()); |
| 223 | } |
| 224 | |
| 225 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
| 226 | assert(UL.size() == varlist_size() && |
| 227 | "Number of updates is not the same as the preallocated buffer"); |
| 228 | std::copy(UL.begin(), UL.end(), getInits().end()); |
| 229 | } |
| 230 | |
| 231 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
| 232 | assert(FL.size() == varlist_size() && |
| 233 | "Number of final updates is not the same as the preallocated buffer"); |
| 234 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
| 235 | } |
| 236 | |
| 237 | OMPLinearClause *OMPLinearClause::Create( |
| 238 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 239 | OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, |
| 240 | SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, |
| 241 | ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) { |
| 242 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 243 | // (Step and CalcStep). |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 244 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 245 | OMPLinearClause *Clause = new (Mem) OMPLinearClause( |
| 246 | StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); |
| 247 | Clause->setVarRefs(VL); |
| 248 | Clause->setPrivates(PL); |
| 249 | Clause->setInits(IL); |
| 250 | // Fill update and final expressions with zeroes, they are provided later, |
| 251 | // after the directive construction. |
| 252 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
| 253 | nullptr); |
| 254 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
| 255 | nullptr); |
| 256 | Clause->setStep(Step); |
| 257 | Clause->setCalcStep(CalcStep); |
| 258 | return Clause; |
| 259 | } |
| 260 | |
| 261 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 262 | unsigned NumVars) { |
| 263 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 264 | // (Step and CalcStep). |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 265 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 266 | return new (Mem) OMPLinearClause(NumVars); |
| 267 | } |
| 268 | |
| 269 | OMPAlignedClause * |
| 270 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 271 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 272 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 273 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 274 | OMPAlignedClause *Clause = new (Mem) |
| 275 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 276 | Clause->setVarRefs(VL); |
| 277 | Clause->setAlignment(A); |
| 278 | return Clause; |
| 279 | } |
| 280 | |
| 281 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 282 | unsigned NumVars) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 283 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 284 | return new (Mem) OMPAlignedClause(NumVars); |
| 285 | } |
| 286 | |
| 287 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 288 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 289 | "not the same as the " |
| 290 | "preallocated buffer"); |
| 291 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 292 | } |
| 293 | |
| 294 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 295 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 296 | "expressions is not the same as " |
| 297 | "the preallocated buffer"); |
| 298 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 299 | } |
| 300 | |
| 301 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 302 | assert(AssignmentOps.size() == varlist_size() && |
| 303 | "Number of assignment expressions is not the same as the preallocated " |
| 304 | "buffer"); |
| 305 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 306 | getDestinationExprs().end()); |
| 307 | } |
| 308 | |
| 309 | OMPCopyinClause *OMPCopyinClause::Create( |
| 310 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 311 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 312 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 313 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 314 | OMPCopyinClause *Clause = |
| 315 | new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 316 | Clause->setVarRefs(VL); |
| 317 | Clause->setSourceExprs(SrcExprs); |
| 318 | Clause->setDestinationExprs(DstExprs); |
| 319 | Clause->setAssignmentOps(AssignmentOps); |
| 320 | return Clause; |
| 321 | } |
| 322 | |
| 323 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 324 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 325 | return new (Mem) OMPCopyinClause(N); |
| 326 | } |
| 327 | |
| 328 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 329 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 330 | "not the same as the " |
| 331 | "preallocated buffer"); |
| 332 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 333 | } |
| 334 | |
| 335 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 336 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 337 | "expressions is not the same as " |
| 338 | "the preallocated buffer"); |
| 339 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 340 | } |
| 341 | |
| 342 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 343 | assert(AssignmentOps.size() == varlist_size() && |
| 344 | "Number of assignment expressions is not the same as the preallocated " |
| 345 | "buffer"); |
| 346 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 347 | getDestinationExprs().end()); |
| 348 | } |
| 349 | |
| 350 | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
| 351 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 352 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 353 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 354 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 355 | OMPCopyprivateClause *Clause = |
| 356 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 357 | Clause->setVarRefs(VL); |
| 358 | Clause->setSourceExprs(SrcExprs); |
| 359 | Clause->setDestinationExprs(DstExprs); |
| 360 | Clause->setAssignmentOps(AssignmentOps); |
| 361 | return Clause; |
| 362 | } |
| 363 | |
| 364 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 365 | unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 366 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 367 | return new (Mem) OMPCopyprivateClause(N); |
| 368 | } |
| 369 | |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 370 | void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
| 371 | assert(Privates.size() == varlist_size() && |
| 372 | "Number of private copies is not the same as the preallocated buffer"); |
| 373 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
| 374 | } |
| 375 | |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 376 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 377 | assert( |
| 378 | LHSExprs.size() == varlist_size() && |
| 379 | "Number of LHS expressions is not the same as the preallocated buffer"); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 380 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 384 | assert( |
| 385 | RHSExprs.size() == varlist_size() && |
| 386 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 387 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 388 | } |
| 389 | |
| 390 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 391 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
| 392 | "expressions is not the same " |
| 393 | "as the preallocated buffer"); |
| 394 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 395 | } |
| 396 | |
| 397 | OMPReductionClause *OMPReductionClause::Create( |
| 398 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 399 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 400 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 401 | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
| 402 | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 403 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 404 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 405 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 406 | Clause->setVarRefs(VL); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 407 | Clause->setPrivates(Privates); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 408 | Clause->setLHSExprs(LHSExprs); |
| 409 | Clause->setRHSExprs(RHSExprs); |
| 410 | Clause->setReductionOps(ReductionOps); |
| 411 | return Clause; |
| 412 | } |
| 413 | |
| 414 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 415 | unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 416 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 417 | return new (Mem) OMPReductionClause(N); |
| 418 | } |
| 419 | |
| 420 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 421 | SourceLocation StartLoc, |
| 422 | SourceLocation LParenLoc, |
| 423 | SourceLocation EndLoc, |
| 424 | ArrayRef<Expr *> VL) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 425 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 426 | OMPFlushClause *Clause = |
| 427 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 428 | Clause->setVarRefs(VL); |
| 429 | return Clause; |
| 430 | } |
| 431 | |
| 432 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 433 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 434 | return new (Mem) OMPFlushClause(N); |
| 435 | } |
| 436 | |
| 437 | OMPDependClause * |
| 438 | OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 439 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 440 | OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 441 | SourceLocation ColonLoc, ArrayRef<Expr *> VL) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 442 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 443 | OMPDependClause *Clause = |
| 444 | new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 445 | Clause->setVarRefs(VL); |
| 446 | Clause->setDependencyKind(DepKind); |
| 447 | Clause->setDependencyLoc(DepLoc); |
| 448 | Clause->setColonLoc(ColonLoc); |
| 449 | return Clause; |
| 450 | } |
| 451 | |
| 452 | OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 453 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 454 | return new (Mem) OMPDependClause(N); |
| 455 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 456 | |
| 457 | OMPMapClause *OMPMapClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 458 | SourceLocation LParenLoc, |
| 459 | SourceLocation EndLoc, ArrayRef<Expr *> VL, |
| 460 | OpenMPMapClauseKind TypeModifier, |
| 461 | OpenMPMapClauseKind Type, |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 462 | bool TypeIsImplicit, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 463 | SourceLocation TypeLoc) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 464 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 465 | OMPMapClause *Clause = |
| 466 | new (Mem) OMPMapClause(TypeModifier, Type, TypeIsImplicit, TypeLoc, |
| 467 | StartLoc, LParenLoc, EndLoc, VL.size()); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 468 | Clause->setVarRefs(VL); |
| 469 | Clause->setMapTypeModifier(TypeModifier); |
| 470 | Clause->setMapType(Type); |
| 471 | Clause->setMapLoc(TypeLoc); |
| 472 | return Clause; |
| 473 | } |
| 474 | |
| 475 | OMPMapClause *OMPMapClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 476 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 477 | return new (Mem) OMPMapClause(N); |
| 478 | } |