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