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