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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the subclesses of Stmt class declared in OpenMPClause.h |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/AST/OpenMPClause.h" |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | d1b2d22 | 2017-11-29 23:27:36 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclOpenMP.h" |
Eugene Zelenko | d1b2d22 | 2017-11-29 23:27:36 +0000 | [diff] [blame] | 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 | c2c21ef | 2019-07-11 14:54:17 +0000 | [diff] [blame] | 38 | OMPClause::child_range OMPClause::used_children() { |
| 39 | switch (getClauseKind()) { |
| 40 | #define OPENMP_CLAUSE(Name, Class) \ |
| 41 | case OMPC_##Name: \ |
| 42 | return static_cast<Class *>(this)->used_children(); |
| 43 | #include "clang/Basic/OpenMPKinds.def" |
| 44 | case OMPC_threadprivate: |
| 45 | case OMPC_uniform: |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 46 | case OMPC_device_type: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 47 | case OMPC_match: |
Alexey Bataev | c2c21ef | 2019-07-11 14:54:17 +0000 | [diff] [blame] | 48 | case OMPC_unknown: |
| 49 | break; |
| 50 | } |
| 51 | llvm_unreachable("unknown OMPClause"); |
| 52 | } |
| 53 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 54 | OMPClauseWithPreInit *OMPClauseWithPreInit::get(OMPClause *C) { |
| 55 | auto *Res = OMPClauseWithPreInit::get(const_cast<const OMPClause *>(C)); |
| 56 | return Res ? const_cast<OMPClauseWithPreInit *>(Res) : nullptr; |
| 57 | } |
| 58 | |
| 59 | const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { |
| 60 | switch (C->getClauseKind()) { |
| 61 | case OMPC_schedule: |
| 62 | return static_cast<const OMPScheduleClause *>(C); |
| 63 | case OMPC_dist_schedule: |
| 64 | return static_cast<const OMPDistScheduleClause *>(C); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 65 | case OMPC_firstprivate: |
| 66 | return static_cast<const OMPFirstprivateClause *>(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 67 | case OMPC_lastprivate: |
| 68 | return static_cast<const OMPLastprivateClause *>(C); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 69 | case OMPC_reduction: |
| 70 | return static_cast<const OMPReductionClause *>(C); |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 71 | case OMPC_task_reduction: |
| 72 | return static_cast<const OMPTaskReductionClause *>(C); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 73 | case OMPC_in_reduction: |
| 74 | return static_cast<const OMPInReductionClause *>(C); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 75 | case OMPC_linear: |
| 76 | return static_cast<const OMPLinearClause *>(C); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 77 | case OMPC_if: |
| 78 | return static_cast<const OMPIfClause *>(C); |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 79 | case OMPC_num_threads: |
| 80 | return static_cast<const OMPNumThreadsClause *>(C); |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 81 | case OMPC_num_teams: |
| 82 | return static_cast<const OMPNumTeamsClause *>(C); |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 83 | case OMPC_thread_limit: |
| 84 | return static_cast<const OMPThreadLimitClause *>(C); |
Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 85 | case OMPC_device: |
| 86 | return static_cast<const OMPDeviceClause *>(C); |
Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame^] | 87 | case OMPC_grainsize: |
| 88 | return static_cast<const OMPGrainsizeClause *>(C); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 89 | case OMPC_default: |
| 90 | case OMPC_proc_bind: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 91 | case OMPC_final: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 92 | case OMPC_safelen: |
| 93 | case OMPC_simdlen: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 94 | case OMPC_allocator: |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 95 | case OMPC_allocate: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 96 | case OMPC_collapse: |
| 97 | case OMPC_private: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 98 | case OMPC_shared: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 99 | case OMPC_aligned: |
| 100 | case OMPC_copyin: |
| 101 | case OMPC_copyprivate: |
| 102 | case OMPC_ordered: |
| 103 | case OMPC_nowait: |
| 104 | case OMPC_untied: |
| 105 | case OMPC_mergeable: |
| 106 | case OMPC_threadprivate: |
| 107 | case OMPC_flush: |
| 108 | case OMPC_read: |
| 109 | case OMPC_write: |
| 110 | case OMPC_update: |
| 111 | case OMPC_capture: |
| 112 | case OMPC_seq_cst: |
| 113 | case OMPC_depend: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 114 | case OMPC_threads: |
| 115 | case OMPC_simd: |
| 116 | case OMPC_map: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 117 | case OMPC_priority: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 118 | case OMPC_nogroup: |
| 119 | case OMPC_num_tasks: |
| 120 | case OMPC_hint: |
| 121 | case OMPC_defaultmap: |
| 122 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 123 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 124 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 125 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 126 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 127 | case OMPC_is_device_ptr: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 128 | case OMPC_unified_address: |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 129 | case OMPC_unified_shared_memory: |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 130 | case OMPC_reverse_offload: |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 131 | case OMPC_dynamic_allocators: |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 132 | case OMPC_atomic_default_mem_order: |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 133 | case OMPC_device_type: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 134 | case OMPC_match: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 135 | break; |
| 136 | } |
| 137 | |
| 138 | return nullptr; |
| 139 | } |
| 140 | |
| 141 | OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(OMPClause *C) { |
| 142 | auto *Res = OMPClauseWithPostUpdate::get(const_cast<const OMPClause *>(C)); |
| 143 | return Res ? const_cast<OMPClauseWithPostUpdate *>(Res) : nullptr; |
| 144 | } |
| 145 | |
| 146 | const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) { |
| 147 | switch (C->getClauseKind()) { |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 148 | case OMPC_lastprivate: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 149 | return static_cast<const OMPLastprivateClause *>(C); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 150 | case OMPC_reduction: |
| 151 | return static_cast<const OMPReductionClause *>(C); |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 152 | case OMPC_task_reduction: |
| 153 | return static_cast<const OMPTaskReductionClause *>(C); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 154 | case OMPC_in_reduction: |
| 155 | return static_cast<const OMPInReductionClause *>(C); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 156 | case OMPC_linear: |
| 157 | return static_cast<const OMPLinearClause *>(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 158 | case OMPC_schedule: |
| 159 | case OMPC_dist_schedule: |
| 160 | case OMPC_firstprivate: |
| 161 | case OMPC_default: |
| 162 | case OMPC_proc_bind: |
| 163 | case OMPC_if: |
| 164 | case OMPC_final: |
| 165 | case OMPC_num_threads: |
| 166 | case OMPC_safelen: |
| 167 | case OMPC_simdlen: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 168 | case OMPC_allocator: |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 169 | case OMPC_allocate: |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 170 | case OMPC_collapse: |
| 171 | case OMPC_private: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 172 | case OMPC_shared: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 173 | case OMPC_aligned: |
| 174 | case OMPC_copyin: |
| 175 | case OMPC_copyprivate: |
| 176 | case OMPC_ordered: |
| 177 | case OMPC_nowait: |
| 178 | case OMPC_untied: |
| 179 | case OMPC_mergeable: |
| 180 | case OMPC_threadprivate: |
| 181 | case OMPC_flush: |
| 182 | case OMPC_read: |
| 183 | case OMPC_write: |
| 184 | case OMPC_update: |
| 185 | case OMPC_capture: |
| 186 | case OMPC_seq_cst: |
| 187 | case OMPC_depend: |
| 188 | case OMPC_device: |
| 189 | case OMPC_threads: |
| 190 | case OMPC_simd: |
| 191 | case OMPC_map: |
| 192 | case OMPC_num_teams: |
| 193 | case OMPC_thread_limit: |
| 194 | case OMPC_priority: |
| 195 | case OMPC_grainsize: |
| 196 | case OMPC_nogroup: |
| 197 | case OMPC_num_tasks: |
| 198 | case OMPC_hint: |
| 199 | case OMPC_defaultmap: |
| 200 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 201 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 202 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 203 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 204 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 205 | case OMPC_is_device_ptr: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 206 | case OMPC_unified_address: |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 207 | case OMPC_unified_shared_memory: |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 208 | case OMPC_reverse_offload: |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 209 | case OMPC_dynamic_allocators: |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 210 | case OMPC_atomic_default_mem_order: |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 211 | case OMPC_device_type: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 212 | case OMPC_match: |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | |
| 216 | return nullptr; |
| 217 | } |
| 218 | |
Alexey Bataev | 655cb4a | 2019-07-16 14:51:46 +0000 | [diff] [blame] | 219 | /// Gets the address of the original, non-captured, expression used in the |
| 220 | /// clause as the preinitializer. |
| 221 | static Stmt **getAddrOfExprAsWritten(Stmt *S) { |
| 222 | if (!S) |
| 223 | return nullptr; |
| 224 | if (auto *DS = dyn_cast<DeclStmt>(S)) { |
| 225 | assert(DS->isSingleDecl() && "Only single expression must be captured."); |
| 226 | if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl())) |
| 227 | return OED->getInitAddress(); |
| 228 | } |
| 229 | return nullptr; |
| 230 | } |
| 231 | |
| 232 | OMPClause::child_range OMPIfClause::used_children() { |
| 233 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
| 234 | return child_range(C, C + 1); |
| 235 | return child_range(&Condition, &Condition + 1); |
| 236 | } |
| 237 | |
Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame^] | 238 | OMPClause::child_range OMPGrainsizeClause::used_children() { |
| 239 | if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt())) |
| 240 | return child_range(C, C + 1); |
| 241 | return child_range(&Grainsize, &Grainsize + 1); |
| 242 | } |
| 243 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 244 | OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num, |
| 245 | unsigned NumLoops, |
| 246 | SourceLocation StartLoc, |
| 247 | SourceLocation LParenLoc, |
| 248 | SourceLocation EndLoc) { |
| 249 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); |
| 250 | auto *Clause = |
| 251 | new (Mem) OMPOrderedClause(Num, NumLoops, StartLoc, LParenLoc, EndLoc); |
| 252 | for (unsigned I = 0; I < NumLoops; ++I) { |
| 253 | Clause->setLoopNumIterations(I, nullptr); |
| 254 | Clause->setLoopCounter(I, nullptr); |
| 255 | } |
| 256 | return Clause; |
| 257 | } |
| 258 | |
| 259 | OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C, |
| 260 | unsigned NumLoops) { |
| 261 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * NumLoops)); |
| 262 | auto *Clause = new (Mem) OMPOrderedClause(NumLoops); |
| 263 | for (unsigned I = 0; I < NumLoops; ++I) { |
| 264 | Clause->setLoopNumIterations(I, nullptr); |
| 265 | Clause->setLoopCounter(I, nullptr); |
| 266 | } |
| 267 | return Clause; |
| 268 | } |
| 269 | |
| 270 | void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop, |
| 271 | Expr *NumIterations) { |
| 272 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
| 273 | getTrailingObjects<Expr *>()[NumLoop] = NumIterations; |
| 274 | } |
| 275 | |
| 276 | ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const { |
| 277 | return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumberOfLoops); |
| 278 | } |
| 279 | |
| 280 | void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) { |
| 281 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
| 282 | getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter; |
| 283 | } |
| 284 | |
Mike Rice | 0ed4666 | 2018-09-20 17:19:41 +0000 | [diff] [blame] | 285 | Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) { |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 286 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
| 287 | return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; |
| 288 | } |
| 289 | |
Mike Rice | 0ed4666 | 2018-09-20 17:19:41 +0000 | [diff] [blame] | 290 | const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const { |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 291 | assert(NumLoop < NumberOfLoops && "out of loops number."); |
| 292 | return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop]; |
| 293 | } |
| 294 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 295 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 296 | assert(VL.size() == varlist_size() && |
| 297 | "Number of private copies is not the same as the preallocated buffer"); |
| 298 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 299 | } |
| 300 | |
| 301 | OMPPrivateClause * |
| 302 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 303 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 304 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 305 | // Allocate space for private variables and initializer expressions. |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 306 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 307 | OMPPrivateClause *Clause = |
| 308 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 309 | Clause->setVarRefs(VL); |
| 310 | Clause->setPrivateCopies(PrivateVL); |
| 311 | return Clause; |
| 312 | } |
| 313 | |
| 314 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
| 315 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 316 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(2 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 317 | return new (Mem) OMPPrivateClause(N); |
| 318 | } |
| 319 | |
| 320 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 321 | assert(VL.size() == varlist_size() && |
| 322 | "Number of private copies is not the same as the preallocated buffer"); |
| 323 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 324 | } |
| 325 | |
| 326 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 327 | assert(VL.size() == varlist_size() && |
| 328 | "Number of inits is not the same as the preallocated buffer"); |
| 329 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 330 | } |
| 331 | |
| 332 | OMPFirstprivateClause * |
| 333 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 334 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 335 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 336 | ArrayRef<Expr *> InitVL, Stmt *PreInit) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 337 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 338 | OMPFirstprivateClause *Clause = |
| 339 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 340 | Clause->setVarRefs(VL); |
| 341 | Clause->setPrivateCopies(PrivateVL); |
| 342 | Clause->setInits(InitVL); |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 343 | Clause->setPreInitStmt(PreInit); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 344 | return Clause; |
| 345 | } |
| 346 | |
| 347 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 348 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 349 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(3 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 350 | return new (Mem) OMPFirstprivateClause(N); |
| 351 | } |
| 352 | |
| 353 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
| 354 | assert(PrivateCopies.size() == varlist_size() && |
| 355 | "Number of private copies is not the same as the preallocated buffer"); |
| 356 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
| 357 | } |
| 358 | |
| 359 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 360 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 361 | "not the same as the " |
| 362 | "preallocated buffer"); |
| 363 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
| 364 | } |
| 365 | |
| 366 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 367 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 368 | "expressions is not the same as " |
| 369 | "the preallocated buffer"); |
| 370 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 371 | } |
| 372 | |
| 373 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 374 | assert(AssignmentOps.size() == varlist_size() && |
| 375 | "Number of assignment expressions is not the same as the preallocated " |
| 376 | "buffer"); |
| 377 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 378 | getDestinationExprs().end()); |
| 379 | } |
| 380 | |
| 381 | OMPLastprivateClause *OMPLastprivateClause::Create( |
| 382 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 383 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 384 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps, Stmt *PreInit, |
| 385 | Expr *PostUpdate) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 386 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 387 | OMPLastprivateClause *Clause = |
| 388 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 389 | Clause->setVarRefs(VL); |
| 390 | Clause->setSourceExprs(SrcExprs); |
| 391 | Clause->setDestinationExprs(DstExprs); |
| 392 | Clause->setAssignmentOps(AssignmentOps); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 393 | Clause->setPreInitStmt(PreInit); |
| 394 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 395 | return Clause; |
| 396 | } |
| 397 | |
| 398 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 399 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 400 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 401 | return new (Mem) OMPLastprivateClause(N); |
| 402 | } |
| 403 | |
| 404 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 405 | SourceLocation StartLoc, |
| 406 | SourceLocation LParenLoc, |
| 407 | SourceLocation EndLoc, |
| 408 | ArrayRef<Expr *> VL) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 409 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 410 | OMPSharedClause *Clause = |
| 411 | new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 412 | Clause->setVarRefs(VL); |
| 413 | return Clause; |
| 414 | } |
| 415 | |
| 416 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 417 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 418 | return new (Mem) OMPSharedClause(N); |
| 419 | } |
| 420 | |
| 421 | void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { |
| 422 | assert(PL.size() == varlist_size() && |
| 423 | "Number of privates is not the same as the preallocated buffer"); |
| 424 | std::copy(PL.begin(), PL.end(), varlist_end()); |
| 425 | } |
| 426 | |
| 427 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
| 428 | assert(IL.size() == varlist_size() && |
| 429 | "Number of inits is not the same as the preallocated buffer"); |
| 430 | std::copy(IL.begin(), IL.end(), getPrivates().end()); |
| 431 | } |
| 432 | |
| 433 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
| 434 | assert(UL.size() == varlist_size() && |
| 435 | "Number of updates is not the same as the preallocated buffer"); |
| 436 | std::copy(UL.begin(), UL.end(), getInits().end()); |
| 437 | } |
| 438 | |
| 439 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
| 440 | assert(FL.size() == varlist_size() && |
| 441 | "Number of final updates is not the same as the preallocated buffer"); |
| 442 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
| 443 | } |
| 444 | |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 445 | void OMPLinearClause::setUsedExprs(ArrayRef<Expr *> UE) { |
| 446 | assert( |
| 447 | UE.size() == varlist_size() + 1 && |
| 448 | "Number of used expressions is not the same as the preallocated buffer"); |
| 449 | std::copy(UE.begin(), UE.end(), getFinals().end() + 2); |
| 450 | } |
| 451 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 452 | OMPLinearClause *OMPLinearClause::Create( |
| 453 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 454 | OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, |
| 455 | SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 456 | ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, |
| 457 | Stmt *PreInit, Expr *PostUpdate) { |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 458 | // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions |
| 459 | // (Step and CalcStep), list of used expression + step. |
| 460 | void *Mem = |
| 461 | C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size() + 2 + VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 462 | OMPLinearClause *Clause = new (Mem) OMPLinearClause( |
| 463 | StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); |
| 464 | Clause->setVarRefs(VL); |
| 465 | Clause->setPrivates(PL); |
| 466 | Clause->setInits(IL); |
| 467 | // Fill update and final expressions with zeroes, they are provided later, |
| 468 | // after the directive construction. |
| 469 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
| 470 | nullptr); |
| 471 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
| 472 | nullptr); |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 473 | std::fill(Clause->getUsedExprs().begin(), Clause->getUsedExprs().end(), |
| 474 | nullptr); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 475 | Clause->setStep(Step); |
| 476 | Clause->setCalcStep(CalcStep); |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 477 | Clause->setPreInitStmt(PreInit); |
| 478 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 479 | return Clause; |
| 480 | } |
| 481 | |
| 482 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 483 | unsigned NumVars) { |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 484 | // Allocate space for 5 lists (Vars, Inits, Updates, Finals), 2 expressions |
| 485 | // (Step and CalcStep), list of used expression + step. |
| 486 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * NumVars + 2 + NumVars +1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 487 | return new (Mem) OMPLinearClause(NumVars); |
| 488 | } |
| 489 | |
Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 490 | OMPClause::child_range OMPLinearClause::used_children() { |
| 491 | // Range includes only non-nullptr elements. |
| 492 | return child_range( |
| 493 | reinterpret_cast<Stmt **>(getUsedExprs().begin()), |
| 494 | reinterpret_cast<Stmt **>(llvm::find(getUsedExprs(), nullptr))); |
| 495 | } |
| 496 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 497 | OMPAlignedClause * |
| 498 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 499 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 500 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 501 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 502 | OMPAlignedClause *Clause = new (Mem) |
| 503 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 504 | Clause->setVarRefs(VL); |
| 505 | Clause->setAlignment(A); |
| 506 | return Clause; |
| 507 | } |
| 508 | |
| 509 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 510 | unsigned NumVars) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 511 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumVars + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 512 | return new (Mem) OMPAlignedClause(NumVars); |
| 513 | } |
| 514 | |
| 515 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 516 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 517 | "not the same as the " |
| 518 | "preallocated buffer"); |
| 519 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 520 | } |
| 521 | |
| 522 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 523 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 524 | "expressions is not the same as " |
| 525 | "the preallocated buffer"); |
| 526 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 527 | } |
| 528 | |
| 529 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 530 | assert(AssignmentOps.size() == varlist_size() && |
| 531 | "Number of assignment expressions is not the same as the preallocated " |
| 532 | "buffer"); |
| 533 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 534 | getDestinationExprs().end()); |
| 535 | } |
| 536 | |
| 537 | OMPCopyinClause *OMPCopyinClause::Create( |
| 538 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 539 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 540 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 541 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 542 | OMPCopyinClause *Clause = |
| 543 | new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 544 | Clause->setVarRefs(VL); |
| 545 | Clause->setSourceExprs(SrcExprs); |
| 546 | Clause->setDestinationExprs(DstExprs); |
| 547 | Clause->setAssignmentOps(AssignmentOps); |
| 548 | return Clause; |
| 549 | } |
| 550 | |
| 551 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 552 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 553 | return new (Mem) OMPCopyinClause(N); |
| 554 | } |
| 555 | |
| 556 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 557 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 558 | "not the same as the " |
| 559 | "preallocated buffer"); |
| 560 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 561 | } |
| 562 | |
| 563 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 564 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 565 | "expressions is not the same as " |
| 566 | "the preallocated buffer"); |
| 567 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 568 | } |
| 569 | |
| 570 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 571 | assert(AssignmentOps.size() == varlist_size() && |
| 572 | "Number of assignment expressions is not the same as the preallocated " |
| 573 | "buffer"); |
| 574 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 575 | getDestinationExprs().end()); |
| 576 | } |
| 577 | |
| 578 | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
| 579 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 580 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 581 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 582 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 583 | OMPCopyprivateClause *Clause = |
| 584 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 585 | Clause->setVarRefs(VL); |
| 586 | Clause->setSourceExprs(SrcExprs); |
| 587 | Clause->setDestinationExprs(DstExprs); |
| 588 | Clause->setAssignmentOps(AssignmentOps); |
| 589 | return Clause; |
| 590 | } |
| 591 | |
| 592 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 593 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 594 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(4 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 595 | return new (Mem) OMPCopyprivateClause(N); |
| 596 | } |
| 597 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 598 | void OMPReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
| 599 | assert(Privates.size() == varlist_size() && |
| 600 | "Number of private copies is not the same as the preallocated buffer"); |
| 601 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
| 602 | } |
| 603 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 604 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 605 | assert( |
| 606 | LHSExprs.size() == varlist_size() && |
| 607 | "Number of LHS expressions is not the same as the preallocated buffer"); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 608 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 612 | assert( |
| 613 | RHSExprs.size() == varlist_size() && |
| 614 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 615 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 616 | } |
| 617 | |
| 618 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 619 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
| 620 | "expressions is not the same " |
| 621 | "as the preallocated buffer"); |
| 622 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 623 | } |
| 624 | |
| 625 | OMPReductionClause *OMPReductionClause::Create( |
| 626 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 627 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 628 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 629 | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 630 | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, |
| 631 | Expr *PostUpdate) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 632 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 633 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 634 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 635 | Clause->setVarRefs(VL); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 636 | Clause->setPrivates(Privates); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 637 | Clause->setLHSExprs(LHSExprs); |
| 638 | Clause->setRHSExprs(RHSExprs); |
| 639 | Clause->setReductionOps(ReductionOps); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 640 | Clause->setPreInitStmt(PreInit); |
| 641 | Clause->setPostUpdateExpr(PostUpdate); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 642 | return Clause; |
| 643 | } |
| 644 | |
| 645 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 646 | unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 647 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 648 | return new (Mem) OMPReductionClause(N); |
| 649 | } |
| 650 | |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 651 | void OMPTaskReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
| 652 | assert(Privates.size() == varlist_size() && |
| 653 | "Number of private copies is not the same as the preallocated buffer"); |
| 654 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
| 655 | } |
| 656 | |
| 657 | void OMPTaskReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 658 | assert( |
| 659 | LHSExprs.size() == varlist_size() && |
| 660 | "Number of LHS expressions is not the same as the preallocated buffer"); |
| 661 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
| 662 | } |
| 663 | |
| 664 | void OMPTaskReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 665 | assert( |
| 666 | RHSExprs.size() == varlist_size() && |
| 667 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 668 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 669 | } |
| 670 | |
| 671 | void OMPTaskReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 672 | assert(ReductionOps.size() == varlist_size() && "Number of task reduction " |
| 673 | "expressions is not the same " |
| 674 | "as the preallocated buffer"); |
| 675 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 676 | } |
| 677 | |
| 678 | OMPTaskReductionClause *OMPTaskReductionClause::Create( |
| 679 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 680 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 681 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| 682 | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
| 683 | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, Stmt *PreInit, |
| 684 | Expr *PostUpdate) { |
| 685 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * VL.size())); |
| 686 | OMPTaskReductionClause *Clause = new (Mem) OMPTaskReductionClause( |
| 687 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 688 | Clause->setVarRefs(VL); |
| 689 | Clause->setPrivates(Privates); |
| 690 | Clause->setLHSExprs(LHSExprs); |
| 691 | Clause->setRHSExprs(RHSExprs); |
| 692 | Clause->setReductionOps(ReductionOps); |
| 693 | Clause->setPreInitStmt(PreInit); |
| 694 | Clause->setPostUpdateExpr(PostUpdate); |
| 695 | return Clause; |
| 696 | } |
| 697 | |
| 698 | OMPTaskReductionClause *OMPTaskReductionClause::CreateEmpty(const ASTContext &C, |
| 699 | unsigned N) { |
| 700 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(5 * N)); |
| 701 | return new (Mem) OMPTaskReductionClause(N); |
| 702 | } |
| 703 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 704 | void OMPInReductionClause::setPrivates(ArrayRef<Expr *> Privates) { |
| 705 | assert(Privates.size() == varlist_size() && |
| 706 | "Number of private copies is not the same as the preallocated buffer"); |
| 707 | std::copy(Privates.begin(), Privates.end(), varlist_end()); |
| 708 | } |
| 709 | |
| 710 | void OMPInReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 711 | assert( |
| 712 | LHSExprs.size() == varlist_size() && |
| 713 | "Number of LHS expressions is not the same as the preallocated buffer"); |
| 714 | std::copy(LHSExprs.begin(), LHSExprs.end(), getPrivates().end()); |
| 715 | } |
| 716 | |
| 717 | void OMPInReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 718 | assert( |
| 719 | RHSExprs.size() == varlist_size() && |
| 720 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 721 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 722 | } |
| 723 | |
| 724 | void OMPInReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 725 | assert(ReductionOps.size() == varlist_size() && "Number of in reduction " |
| 726 | "expressions is not the same " |
| 727 | "as the preallocated buffer"); |
| 728 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 729 | } |
| 730 | |
Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 731 | void OMPInReductionClause::setTaskgroupDescriptors( |
| 732 | ArrayRef<Expr *> TaskgroupDescriptors) { |
| 733 | assert(TaskgroupDescriptors.size() == varlist_size() && |
| 734 | "Number of in reduction descriptors is not the same as the " |
| 735 | "preallocated buffer"); |
| 736 | std::copy(TaskgroupDescriptors.begin(), TaskgroupDescriptors.end(), |
| 737 | getReductionOps().end()); |
| 738 | } |
| 739 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 740 | OMPInReductionClause *OMPInReductionClause::Create( |
| 741 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 742 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 743 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| 744 | ArrayRef<Expr *> Privates, ArrayRef<Expr *> LHSExprs, |
Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 745 | ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps, |
| 746 | ArrayRef<Expr *> TaskgroupDescriptors, Stmt *PreInit, Expr *PostUpdate) { |
| 747 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * VL.size())); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 748 | OMPInReductionClause *Clause = new (Mem) OMPInReductionClause( |
| 749 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 750 | Clause->setVarRefs(VL); |
| 751 | Clause->setPrivates(Privates); |
| 752 | Clause->setLHSExprs(LHSExprs); |
| 753 | Clause->setRHSExprs(RHSExprs); |
| 754 | Clause->setReductionOps(ReductionOps); |
Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 755 | Clause->setTaskgroupDescriptors(TaskgroupDescriptors); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 756 | Clause->setPreInitStmt(PreInit); |
| 757 | Clause->setPostUpdateExpr(PostUpdate); |
| 758 | return Clause; |
| 759 | } |
| 760 | |
| 761 | OMPInReductionClause *OMPInReductionClause::CreateEmpty(const ASTContext &C, |
| 762 | unsigned N) { |
Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 763 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(6 * N)); |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 764 | return new (Mem) OMPInReductionClause(N); |
| 765 | } |
| 766 | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 767 | OMPAllocateClause * |
| 768 | OMPAllocateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 769 | SourceLocation LParenLoc, Expr *Allocator, |
| 770 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 771 | ArrayRef<Expr *> VL) { |
| 772 | // Allocate space for private variables and initializer expressions. |
| 773 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size())); |
| 774 | auto *Clause = new (Mem) OMPAllocateClause(StartLoc, LParenLoc, Allocator, |
| 775 | ColonLoc, EndLoc, VL.size()); |
| 776 | Clause->setVarRefs(VL); |
| 777 | return Clause; |
| 778 | } |
| 779 | |
| 780 | OMPAllocateClause *OMPAllocateClause::CreateEmpty(const ASTContext &C, |
| 781 | unsigned N) { |
| 782 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
| 783 | return new (Mem) OMPAllocateClause(N); |
| 784 | } |
| 785 | |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 786 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 787 | SourceLocation StartLoc, |
| 788 | SourceLocation LParenLoc, |
| 789 | SourceLocation EndLoc, |
| 790 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 791 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + 1)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 792 | OMPFlushClause *Clause = |
| 793 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 794 | Clause->setVarRefs(VL); |
| 795 | return Clause; |
| 796 | } |
| 797 | |
| 798 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
James Y Knight | 374fd20 | 2016-01-01 00:38:24 +0000 | [diff] [blame] | 799 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N)); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 800 | return new (Mem) OMPFlushClause(N); |
| 801 | } |
| 802 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 803 | OMPDependClause * |
| 804 | OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 805 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 806 | OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 807 | SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
| 808 | unsigned NumLoops) { |
| 809 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size() + NumLoops)); |
| 810 | OMPDependClause *Clause = new (Mem) |
| 811 | OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size(), NumLoops); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 812 | Clause->setVarRefs(VL); |
| 813 | Clause->setDependencyKind(DepKind); |
| 814 | Clause->setDependencyLoc(DepLoc); |
| 815 | Clause->setColonLoc(ColonLoc); |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 816 | for (unsigned I = 0 ; I < NumLoops; ++I) |
| 817 | Clause->setLoopData(I, nullptr); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 818 | return Clause; |
| 819 | } |
| 820 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 821 | OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N, |
| 822 | unsigned NumLoops) { |
| 823 | void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N + NumLoops)); |
| 824 | return new (Mem) OMPDependClause(N, NumLoops); |
James Y Knight | b8bfd96 | 2015-10-02 13:41:04 +0000 | [diff] [blame] | 825 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 826 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 827 | void OMPDependClause::setLoopData(unsigned NumLoop, Expr *Cnt) { |
| 828 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
| 829 | getDependencyKind() == OMPC_DEPEND_source) && |
| 830 | NumLoop < NumLoops && |
| 831 | "Expected sink or source depend + loop index must be less number of " |
| 832 | "loops."); |
| 833 | auto It = std::next(getVarRefs().end(), NumLoop); |
| 834 | *It = Cnt; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 837 | Expr *OMPDependClause::getLoopData(unsigned NumLoop) { |
| 838 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
| 839 | getDependencyKind() == OMPC_DEPEND_source) && |
| 840 | NumLoop < NumLoops && |
| 841 | "Expected sink or source depend + loop index must be less number of " |
| 842 | "loops."); |
| 843 | auto It = std::next(getVarRefs().end(), NumLoop); |
| 844 | return *It; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 847 | const Expr *OMPDependClause::getLoopData(unsigned NumLoop) const { |
| 848 | assert((getDependencyKind() == OMPC_DEPEND_sink || |
| 849 | getDependencyKind() == OMPC_DEPEND_source) && |
| 850 | NumLoop < NumLoops && |
| 851 | "Expected sink or source depend + loop index must be less number of " |
| 852 | "loops."); |
| 853 | auto It = std::next(getVarRefs().end(), NumLoop); |
| 854 | return *It; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 857 | unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber( |
| 858 | MappableExprComponentListsRef ComponentLists) { |
| 859 | unsigned TotalNum = 0u; |
| 860 | for (auto &C : ComponentLists) |
| 861 | TotalNum += C.size(); |
| 862 | return TotalNum; |
| 863 | } |
| 864 | |
| 865 | unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber( |
Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 866 | ArrayRef<const ValueDecl *> Declarations) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 867 | unsigned TotalNum = 0u; |
| 868 | llvm::SmallPtrSet<const ValueDecl *, 8> Cache; |
Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 869 | for (const ValueDecl *D : Declarations) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 870 | const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr; |
| 871 | if (Cache.count(VD)) |
| 872 | continue; |
| 873 | ++TotalNum; |
| 874 | Cache.insert(VD); |
| 875 | } |
| 876 | return TotalNum; |
| 877 | } |
| 878 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 879 | OMPMapClause *OMPMapClause::Create( |
| 880 | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
| 881 | ArrayRef<ValueDecl *> Declarations, |
| 882 | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
| 883 | ArrayRef<OpenMPMapModifierKind> MapModifiers, |
| 884 | ArrayRef<SourceLocation> MapModifiersLoc, |
| 885 | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId, |
| 886 | OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc) { |
| 887 | OMPMappableExprListSizeTy Sizes; |
| 888 | Sizes.NumVars = Vars.size(); |
| 889 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
| 890 | Sizes.NumComponentLists = ComponentLists.size(); |
| 891 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 892 | |
| 893 | // We need to allocate: |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 894 | // 2 x NumVars x Expr* - we have an original list expression and an associated |
| 895 | // user-defined mapper for each clause list entry. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 896 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 897 | // with each component list. |
| 898 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 899 | // number of lists for each unique declaration and the size of each component |
| 900 | // list. |
| 901 | // NumComponents x MappableComponent - the total of all the components in all |
| 902 | // the lists. |
| 903 | void *Mem = C.Allocate( |
| 904 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 905 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 906 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 907 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 908 | Sizes.NumComponents)); |
| 909 | OMPMapClause *Clause = new (Mem) |
| 910 | OMPMapClause(MapModifiers, MapModifiersLoc, UDMQualifierLoc, MapperId, |
| 911 | Type, TypeIsImplicit, TypeLoc, Locs, Sizes); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 912 | |
| 913 | Clause->setVarRefs(Vars); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 914 | Clause->setUDMapperRefs(UDMapperRefs); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 915 | Clause->setClauseInfo(Declarations, ComponentLists); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 916 | Clause->setMapType(Type); |
| 917 | Clause->setMapLoc(TypeLoc); |
| 918 | return Clause; |
| 919 | } |
| 920 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 921 | OMPMapClause * |
| 922 | OMPMapClause::CreateEmpty(const ASTContext &C, |
| 923 | const OMPMappableExprListSizeTy &Sizes) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 924 | void *Mem = C.Allocate( |
| 925 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 926 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 927 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 928 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 929 | Sizes.NumComponents)); |
| 930 | return new (Mem) OMPMapClause(Sizes); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 931 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 932 | |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 933 | OMPToClause *OMPToClause::Create( |
| 934 | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
| 935 | ArrayRef<ValueDecl *> Declarations, |
| 936 | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
| 937 | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 938 | OMPMappableExprListSizeTy Sizes; |
| 939 | Sizes.NumVars = Vars.size(); |
| 940 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
| 941 | Sizes.NumComponentLists = ComponentLists.size(); |
| 942 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 943 | |
| 944 | // We need to allocate: |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 945 | // 2 x NumVars x Expr* - we have an original list expression and an associated |
| 946 | // user-defined mapper for each clause list entry. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 947 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 948 | // with each component list. |
| 949 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 950 | // number of lists for each unique declaration and the size of each component |
| 951 | // list. |
| 952 | // NumComponents x MappableComponent - the total of all the components in all |
| 953 | // the lists. |
| 954 | void *Mem = C.Allocate( |
| 955 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 956 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 957 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 958 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 959 | Sizes.NumComponents)); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 960 | |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 961 | auto *Clause = new (Mem) OMPToClause(UDMQualifierLoc, MapperId, Locs, Sizes); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 962 | |
| 963 | Clause->setVarRefs(Vars); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 964 | Clause->setUDMapperRefs(UDMapperRefs); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 965 | Clause->setClauseInfo(Declarations, ComponentLists); |
| 966 | return Clause; |
| 967 | } |
| 968 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 969 | OMPToClause *OMPToClause::CreateEmpty(const ASTContext &C, |
| 970 | const OMPMappableExprListSizeTy &Sizes) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 971 | void *Mem = C.Allocate( |
| 972 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 973 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 974 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 975 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 976 | Sizes.NumComponents)); |
| 977 | return new (Mem) OMPToClause(Sizes); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 978 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 979 | |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 980 | OMPFromClause *OMPFromClause::Create( |
| 981 | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
| 982 | ArrayRef<ValueDecl *> Declarations, |
| 983 | MappableExprComponentListsRef ComponentLists, ArrayRef<Expr *> UDMapperRefs, |
| 984 | NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 985 | OMPMappableExprListSizeTy Sizes; |
| 986 | Sizes.NumVars = Vars.size(); |
| 987 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
| 988 | Sizes.NumComponentLists = ComponentLists.size(); |
| 989 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 990 | |
| 991 | // We need to allocate: |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 992 | // 2 x NumVars x Expr* - we have an original list expression and an associated |
| 993 | // user-defined mapper for each clause list entry. |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 994 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 995 | // with each component list. |
| 996 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 997 | // number of lists for each unique declaration and the size of each component |
| 998 | // list. |
| 999 | // NumComponents x MappableComponent - the total of all the components in all |
| 1000 | // the lists. |
| 1001 | void *Mem = C.Allocate( |
| 1002 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1003 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1004 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1005 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1006 | Sizes.NumComponents)); |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1007 | |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1008 | auto *Clause = |
| 1009 | new (Mem) OMPFromClause(UDMQualifierLoc, MapperId, Locs, Sizes); |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1010 | |
| 1011 | Clause->setVarRefs(Vars); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1012 | Clause->setUDMapperRefs(UDMapperRefs); |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1013 | Clause->setClauseInfo(Declarations, ComponentLists); |
| 1014 | return Clause; |
| 1015 | } |
| 1016 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1017 | OMPFromClause * |
| 1018 | OMPFromClause::CreateEmpty(const ASTContext &C, |
| 1019 | const OMPMappableExprListSizeTy &Sizes) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1020 | void *Mem = C.Allocate( |
| 1021 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1022 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1023 | 2 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1024 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1025 | Sizes.NumComponents)); |
| 1026 | return new (Mem) OMPFromClause(Sizes); |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1027 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1028 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1029 | void OMPUseDevicePtrClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1030 | assert(VL.size() == varlist_size() && |
| 1031 | "Number of private copies is not the same as the preallocated buffer"); |
| 1032 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1033 | } |
| 1034 | |
| 1035 | void OMPUseDevicePtrClause::setInits(ArrayRef<Expr *> VL) { |
| 1036 | assert(VL.size() == varlist_size() && |
| 1037 | "Number of inits is not the same as the preallocated buffer"); |
| 1038 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 1039 | } |
| 1040 | |
| 1041 | OMPUseDevicePtrClause *OMPUseDevicePtrClause::Create( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1042 | const ASTContext &C, const OMPVarListLocTy &Locs, ArrayRef<Expr *> Vars, |
| 1043 | ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits, |
| 1044 | ArrayRef<ValueDecl *> Declarations, |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1045 | MappableExprComponentListsRef ComponentLists) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1046 | OMPMappableExprListSizeTy Sizes; |
| 1047 | Sizes.NumVars = Vars.size(); |
| 1048 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
| 1049 | Sizes.NumComponentLists = ComponentLists.size(); |
| 1050 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1051 | |
| 1052 | // We need to allocate: |
| 1053 | // 3 x NumVars x Expr* - we have an original list expression for each clause |
| 1054 | // list entry and an equal number of private copies and inits. |
| 1055 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 1056 | // with each component list. |
| 1057 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 1058 | // number of lists for each unique declaration and the size of each component |
| 1059 | // list. |
| 1060 | // NumComponents x MappableComponent - the total of all the components in all |
| 1061 | // the lists. |
| 1062 | void *Mem = C.Allocate( |
| 1063 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1064 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1065 | 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 1066 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1067 | Sizes.NumComponents)); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1068 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1069 | OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause(Locs, Sizes); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1070 | |
| 1071 | Clause->setVarRefs(Vars); |
| 1072 | Clause->setPrivateCopies(PrivateVars); |
| 1073 | Clause->setInits(Inits); |
| 1074 | Clause->setClauseInfo(Declarations, ComponentLists); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1075 | return Clause; |
| 1076 | } |
| 1077 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1078 | OMPUseDevicePtrClause * |
| 1079 | OMPUseDevicePtrClause::CreateEmpty(const ASTContext &C, |
| 1080 | const OMPMappableExprListSizeTy &Sizes) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 1081 | void *Mem = C.Allocate( |
| 1082 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1083 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1084 | 3 * Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 1085 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1086 | Sizes.NumComponents)); |
| 1087 | return new (Mem) OMPUseDevicePtrClause(Sizes); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1088 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1089 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1090 | OMPIsDevicePtrClause * |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1091 | OMPIsDevicePtrClause::Create(const ASTContext &C, const OMPVarListLocTy &Locs, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1092 | ArrayRef<Expr *> Vars, |
| 1093 | ArrayRef<ValueDecl *> Declarations, |
| 1094 | MappableExprComponentListsRef ComponentLists) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1095 | OMPMappableExprListSizeTy Sizes; |
| 1096 | Sizes.NumVars = Vars.size(); |
| 1097 | Sizes.NumUniqueDeclarations = getUniqueDeclarationsTotalNumber(Declarations); |
| 1098 | Sizes.NumComponentLists = ComponentLists.size(); |
| 1099 | Sizes.NumComponents = getComponentsTotalNumber(ComponentLists); |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1100 | |
| 1101 | // We need to allocate: |
| 1102 | // NumVars x Expr* - we have an original list expression for each clause list |
| 1103 | // entry. |
| 1104 | // NumUniqueDeclarations x ValueDecl* - unique base declarations associated |
| 1105 | // with each component list. |
| 1106 | // (NumUniqueDeclarations + NumComponentLists) x unsigned - we specify the |
| 1107 | // number of lists for each unique declaration and the size of each component |
| 1108 | // list. |
| 1109 | // NumComponents x MappableComponent - the total of all the components in all |
| 1110 | // the lists. |
| 1111 | void *Mem = C.Allocate( |
| 1112 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1113 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1114 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 1115 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1116 | Sizes.NumComponents)); |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1117 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1118 | OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause(Locs, Sizes); |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1119 | |
| 1120 | Clause->setVarRefs(Vars); |
| 1121 | Clause->setClauseInfo(Declarations, ComponentLists); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1122 | return Clause; |
| 1123 | } |
| 1124 | |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1125 | OMPIsDevicePtrClause * |
| 1126 | OMPIsDevicePtrClause::CreateEmpty(const ASTContext &C, |
| 1127 | const OMPMappableExprListSizeTy &Sizes) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1128 | void *Mem = C.Allocate( |
| 1129 | totalSizeToAlloc<Expr *, ValueDecl *, unsigned, |
| 1130 | OMPClauseMappableExprCommon::MappableComponent>( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1131 | Sizes.NumVars, Sizes.NumUniqueDeclarations, |
| 1132 | Sizes.NumUniqueDeclarations + Sizes.NumComponentLists, |
| 1133 | Sizes.NumComponents)); |
| 1134 | return new (Mem) OMPIsDevicePtrClause(Sizes); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1135 | } |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1136 | |
| 1137 | //===----------------------------------------------------------------------===// |
| 1138 | // OpenMP clauses printing methods |
| 1139 | //===----------------------------------------------------------------------===// |
| 1140 | |
| 1141 | void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { |
| 1142 | OS << "if("; |
| 1143 | if (Node->getNameModifier() != OMPD_unknown) |
| 1144 | OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": "; |
| 1145 | Node->getCondition()->printPretty(OS, nullptr, Policy, 0); |
| 1146 | OS << ")"; |
| 1147 | } |
| 1148 | |
| 1149 | void OMPClausePrinter::VisitOMPFinalClause(OMPFinalClause *Node) { |
| 1150 | OS << "final("; |
| 1151 | Node->getCondition()->printPretty(OS, nullptr, Policy, 0); |
| 1152 | OS << ")"; |
| 1153 | } |
| 1154 | |
| 1155 | void OMPClausePrinter::VisitOMPNumThreadsClause(OMPNumThreadsClause *Node) { |
| 1156 | OS << "num_threads("; |
| 1157 | Node->getNumThreads()->printPretty(OS, nullptr, Policy, 0); |
| 1158 | OS << ")"; |
| 1159 | } |
| 1160 | |
| 1161 | void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { |
| 1162 | OS << "safelen("; |
| 1163 | Node->getSafelen()->printPretty(OS, nullptr, Policy, 0); |
| 1164 | OS << ")"; |
| 1165 | } |
| 1166 | |
| 1167 | void OMPClausePrinter::VisitOMPSimdlenClause(OMPSimdlenClause *Node) { |
| 1168 | OS << "simdlen("; |
| 1169 | Node->getSimdlen()->printPretty(OS, nullptr, Policy, 0); |
| 1170 | OS << ")"; |
| 1171 | } |
| 1172 | |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1173 | void OMPClausePrinter::VisitOMPAllocatorClause(OMPAllocatorClause *Node) { |
| 1174 | OS << "allocator("; |
| 1175 | Node->getAllocator()->printPretty(OS, nullptr, Policy, 0); |
| 1176 | OS << ")"; |
| 1177 | } |
| 1178 | |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1179 | void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) { |
| 1180 | OS << "collapse("; |
| 1181 | Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0); |
| 1182 | OS << ")"; |
| 1183 | } |
| 1184 | |
| 1185 | void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { |
| 1186 | OS << "default(" |
| 1187 | << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind()) |
| 1188 | << ")"; |
| 1189 | } |
| 1190 | |
| 1191 | void OMPClausePrinter::VisitOMPProcBindClause(OMPProcBindClause *Node) { |
| 1192 | OS << "proc_bind(" |
| 1193 | << getOpenMPSimpleClauseTypeName(OMPC_proc_bind, Node->getProcBindKind()) |
| 1194 | << ")"; |
| 1195 | } |
| 1196 | |
| 1197 | void OMPClausePrinter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) { |
| 1198 | OS << "unified_address"; |
| 1199 | } |
| 1200 | |
| 1201 | void OMPClausePrinter::VisitOMPUnifiedSharedMemoryClause( |
| 1202 | OMPUnifiedSharedMemoryClause *) { |
| 1203 | OS << "unified_shared_memory"; |
| 1204 | } |
| 1205 | |
| 1206 | void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) { |
| 1207 | OS << "reverse_offload"; |
| 1208 | } |
| 1209 | |
| 1210 | void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( |
| 1211 | OMPDynamicAllocatorsClause *) { |
| 1212 | OS << "dynamic_allocators"; |
| 1213 | } |
| 1214 | |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 1215 | void OMPClausePrinter::VisitOMPAtomicDefaultMemOrderClause( |
| 1216 | OMPAtomicDefaultMemOrderClause *Node) { |
| 1217 | OS << "atomic_default_mem_order(" |
| 1218 | << getOpenMPSimpleClauseTypeName(OMPC_atomic_default_mem_order, |
| 1219 | Node->getAtomicDefaultMemOrderKind()) |
| 1220 | << ")"; |
| 1221 | } |
| 1222 | |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1223 | void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { |
| 1224 | OS << "schedule("; |
| 1225 | if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { |
| 1226 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, |
| 1227 | Node->getFirstScheduleModifier()); |
| 1228 | if (Node->getSecondScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { |
| 1229 | OS << ", "; |
| 1230 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, |
| 1231 | Node->getSecondScheduleModifier()); |
| 1232 | } |
| 1233 | OS << ": "; |
| 1234 | } |
| 1235 | OS << getOpenMPSimpleClauseTypeName(OMPC_schedule, Node->getScheduleKind()); |
| 1236 | if (auto *E = Node->getChunkSize()) { |
| 1237 | OS << ", "; |
| 1238 | E->printPretty(OS, nullptr, Policy); |
| 1239 | } |
| 1240 | OS << ")"; |
| 1241 | } |
| 1242 | |
| 1243 | void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) { |
| 1244 | OS << "ordered"; |
| 1245 | if (auto *Num = Node->getNumForLoops()) { |
| 1246 | OS << "("; |
| 1247 | Num->printPretty(OS, nullptr, Policy, 0); |
| 1248 | OS << ")"; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { |
| 1253 | OS << "nowait"; |
| 1254 | } |
| 1255 | |
| 1256 | void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) { |
| 1257 | OS << "untied"; |
| 1258 | } |
| 1259 | |
| 1260 | void OMPClausePrinter::VisitOMPNogroupClause(OMPNogroupClause *) { |
| 1261 | OS << "nogroup"; |
| 1262 | } |
| 1263 | |
| 1264 | void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) { |
| 1265 | OS << "mergeable"; |
| 1266 | } |
| 1267 | |
| 1268 | void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; } |
| 1269 | |
| 1270 | void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; } |
| 1271 | |
| 1272 | void OMPClausePrinter::VisitOMPUpdateClause(OMPUpdateClause *) { |
| 1273 | OS << "update"; |
| 1274 | } |
| 1275 | |
| 1276 | void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { |
| 1277 | OS << "capture"; |
| 1278 | } |
| 1279 | |
| 1280 | void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { |
| 1281 | OS << "seq_cst"; |
| 1282 | } |
| 1283 | |
| 1284 | void OMPClausePrinter::VisitOMPThreadsClause(OMPThreadsClause *) { |
| 1285 | OS << "threads"; |
| 1286 | } |
| 1287 | |
| 1288 | void OMPClausePrinter::VisitOMPSIMDClause(OMPSIMDClause *) { OS << "simd"; } |
| 1289 | |
| 1290 | void OMPClausePrinter::VisitOMPDeviceClause(OMPDeviceClause *Node) { |
| 1291 | OS << "device("; |
| 1292 | Node->getDevice()->printPretty(OS, nullptr, Policy, 0); |
| 1293 | OS << ")"; |
| 1294 | } |
| 1295 | |
| 1296 | void OMPClausePrinter::VisitOMPNumTeamsClause(OMPNumTeamsClause *Node) { |
| 1297 | OS << "num_teams("; |
| 1298 | Node->getNumTeams()->printPretty(OS, nullptr, Policy, 0); |
| 1299 | OS << ")"; |
| 1300 | } |
| 1301 | |
| 1302 | void OMPClausePrinter::VisitOMPThreadLimitClause(OMPThreadLimitClause *Node) { |
| 1303 | OS << "thread_limit("; |
| 1304 | Node->getThreadLimit()->printPretty(OS, nullptr, Policy, 0); |
| 1305 | OS << ")"; |
| 1306 | } |
| 1307 | |
| 1308 | void OMPClausePrinter::VisitOMPPriorityClause(OMPPriorityClause *Node) { |
| 1309 | OS << "priority("; |
| 1310 | Node->getPriority()->printPretty(OS, nullptr, Policy, 0); |
| 1311 | OS << ")"; |
| 1312 | } |
| 1313 | |
| 1314 | void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) { |
| 1315 | OS << "grainsize("; |
| 1316 | Node->getGrainsize()->printPretty(OS, nullptr, Policy, 0); |
| 1317 | OS << ")"; |
| 1318 | } |
| 1319 | |
| 1320 | void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) { |
| 1321 | OS << "num_tasks("; |
| 1322 | Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0); |
| 1323 | OS << ")"; |
| 1324 | } |
| 1325 | |
| 1326 | void OMPClausePrinter::VisitOMPHintClause(OMPHintClause *Node) { |
| 1327 | OS << "hint("; |
| 1328 | Node->getHint()->printPretty(OS, nullptr, Policy, 0); |
| 1329 | OS << ")"; |
| 1330 | } |
| 1331 | |
| 1332 | template<typename T> |
| 1333 | void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { |
| 1334 | for (typename T::varlist_iterator I = Node->varlist_begin(), |
| 1335 | E = Node->varlist_end(); |
| 1336 | I != E; ++I) { |
| 1337 | assert(*I && "Expected non-null Stmt"); |
| 1338 | OS << (I == Node->varlist_begin() ? StartSym : ','); |
| 1339 | if (auto *DRE = dyn_cast<DeclRefExpr>(*I)) { |
| 1340 | if (isa<OMPCapturedExprDecl>(DRE->getDecl())) |
| 1341 | DRE->printPretty(OS, nullptr, Policy, 0); |
| 1342 | else |
| 1343 | DRE->getDecl()->printQualifiedName(OS); |
| 1344 | } else |
| 1345 | (*I)->printPretty(OS, nullptr, Policy, 0); |
| 1346 | } |
| 1347 | } |
| 1348 | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 1349 | void OMPClausePrinter::VisitOMPAllocateClause(OMPAllocateClause *Node) { |
| 1350 | if (Node->varlist_empty()) |
| 1351 | return; |
| 1352 | OS << "allocate"; |
| 1353 | if (Expr *Allocator = Node->getAllocator()) { |
| 1354 | OS << "("; |
| 1355 | Allocator->printPretty(OS, nullptr, Policy, 0); |
| 1356 | OS << ":"; |
| 1357 | VisitOMPClauseList(Node, ' '); |
| 1358 | } else { |
| 1359 | VisitOMPClauseList(Node, '('); |
| 1360 | } |
| 1361 | OS << ")"; |
| 1362 | } |
| 1363 | |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1364 | void OMPClausePrinter::VisitOMPPrivateClause(OMPPrivateClause *Node) { |
| 1365 | if (!Node->varlist_empty()) { |
| 1366 | OS << "private"; |
| 1367 | VisitOMPClauseList(Node, '('); |
| 1368 | OS << ")"; |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | void OMPClausePrinter::VisitOMPFirstprivateClause(OMPFirstprivateClause *Node) { |
| 1373 | if (!Node->varlist_empty()) { |
| 1374 | OS << "firstprivate"; |
| 1375 | VisitOMPClauseList(Node, '('); |
| 1376 | OS << ")"; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | void OMPClausePrinter::VisitOMPLastprivateClause(OMPLastprivateClause *Node) { |
| 1381 | if (!Node->varlist_empty()) { |
| 1382 | OS << "lastprivate"; |
| 1383 | VisitOMPClauseList(Node, '('); |
| 1384 | OS << ")"; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { |
| 1389 | if (!Node->varlist_empty()) { |
| 1390 | OS << "shared"; |
| 1391 | VisitOMPClauseList(Node, '('); |
| 1392 | OS << ")"; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | void OMPClausePrinter::VisitOMPReductionClause(OMPReductionClause *Node) { |
| 1397 | if (!Node->varlist_empty()) { |
| 1398 | OS << "reduction("; |
| 1399 | NestedNameSpecifier *QualifierLoc = |
| 1400 | Node->getQualifierLoc().getNestedNameSpecifier(); |
| 1401 | OverloadedOperatorKind OOK = |
| 1402 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
| 1403 | if (QualifierLoc == nullptr && OOK != OO_None) { |
| 1404 | // Print reduction identifier in C format |
| 1405 | OS << getOperatorSpelling(OOK); |
| 1406 | } else { |
| 1407 | // Use C++ format |
| 1408 | if (QualifierLoc != nullptr) |
| 1409 | QualifierLoc->print(OS, Policy); |
| 1410 | OS << Node->getNameInfo(); |
| 1411 | } |
| 1412 | OS << ":"; |
| 1413 | VisitOMPClauseList(Node, ' '); |
| 1414 | OS << ")"; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | void OMPClausePrinter::VisitOMPTaskReductionClause( |
| 1419 | OMPTaskReductionClause *Node) { |
| 1420 | if (!Node->varlist_empty()) { |
| 1421 | OS << "task_reduction("; |
| 1422 | NestedNameSpecifier *QualifierLoc = |
| 1423 | Node->getQualifierLoc().getNestedNameSpecifier(); |
| 1424 | OverloadedOperatorKind OOK = |
| 1425 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
| 1426 | if (QualifierLoc == nullptr && OOK != OO_None) { |
| 1427 | // Print reduction identifier in C format |
| 1428 | OS << getOperatorSpelling(OOK); |
| 1429 | } else { |
| 1430 | // Use C++ format |
| 1431 | if (QualifierLoc != nullptr) |
| 1432 | QualifierLoc->print(OS, Policy); |
| 1433 | OS << Node->getNameInfo(); |
| 1434 | } |
| 1435 | OS << ":"; |
| 1436 | VisitOMPClauseList(Node, ' '); |
| 1437 | OS << ")"; |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | void OMPClausePrinter::VisitOMPInReductionClause(OMPInReductionClause *Node) { |
| 1442 | if (!Node->varlist_empty()) { |
| 1443 | OS << "in_reduction("; |
| 1444 | NestedNameSpecifier *QualifierLoc = |
| 1445 | Node->getQualifierLoc().getNestedNameSpecifier(); |
| 1446 | OverloadedOperatorKind OOK = |
| 1447 | Node->getNameInfo().getName().getCXXOverloadedOperator(); |
| 1448 | if (QualifierLoc == nullptr && OOK != OO_None) { |
| 1449 | // Print reduction identifier in C format |
| 1450 | OS << getOperatorSpelling(OOK); |
| 1451 | } else { |
| 1452 | // Use C++ format |
| 1453 | if (QualifierLoc != nullptr) |
| 1454 | QualifierLoc->print(OS, Policy); |
| 1455 | OS << Node->getNameInfo(); |
| 1456 | } |
| 1457 | OS << ":"; |
| 1458 | VisitOMPClauseList(Node, ' '); |
| 1459 | OS << ")"; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | void OMPClausePrinter::VisitOMPLinearClause(OMPLinearClause *Node) { |
| 1464 | if (!Node->varlist_empty()) { |
| 1465 | OS << "linear"; |
| 1466 | if (Node->getModifierLoc().isValid()) { |
| 1467 | OS << '(' |
| 1468 | << getOpenMPSimpleClauseTypeName(OMPC_linear, Node->getModifier()); |
| 1469 | } |
| 1470 | VisitOMPClauseList(Node, '('); |
| 1471 | if (Node->getModifierLoc().isValid()) |
| 1472 | OS << ')'; |
| 1473 | if (Node->getStep() != nullptr) { |
| 1474 | OS << ": "; |
| 1475 | Node->getStep()->printPretty(OS, nullptr, Policy, 0); |
| 1476 | } |
| 1477 | OS << ")"; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | void OMPClausePrinter::VisitOMPAlignedClause(OMPAlignedClause *Node) { |
| 1482 | if (!Node->varlist_empty()) { |
| 1483 | OS << "aligned"; |
| 1484 | VisitOMPClauseList(Node, '('); |
| 1485 | if (Node->getAlignment() != nullptr) { |
| 1486 | OS << ": "; |
| 1487 | Node->getAlignment()->printPretty(OS, nullptr, Policy, 0); |
| 1488 | } |
| 1489 | OS << ")"; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | void OMPClausePrinter::VisitOMPCopyinClause(OMPCopyinClause *Node) { |
| 1494 | if (!Node->varlist_empty()) { |
| 1495 | OS << "copyin"; |
| 1496 | VisitOMPClauseList(Node, '('); |
| 1497 | OS << ")"; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | void OMPClausePrinter::VisitOMPCopyprivateClause(OMPCopyprivateClause *Node) { |
| 1502 | if (!Node->varlist_empty()) { |
| 1503 | OS << "copyprivate"; |
| 1504 | VisitOMPClauseList(Node, '('); |
| 1505 | OS << ")"; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | void OMPClausePrinter::VisitOMPFlushClause(OMPFlushClause *Node) { |
| 1510 | if (!Node->varlist_empty()) { |
| 1511 | VisitOMPClauseList(Node, '('); |
| 1512 | OS << ")"; |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | void OMPClausePrinter::VisitOMPDependClause(OMPDependClause *Node) { |
| 1517 | OS << "depend("; |
| 1518 | OS << getOpenMPSimpleClauseTypeName(Node->getClauseKind(), |
| 1519 | Node->getDependencyKind()); |
| 1520 | if (!Node->varlist_empty()) { |
| 1521 | OS << " :"; |
| 1522 | VisitOMPClauseList(Node, ' '); |
| 1523 | } |
| 1524 | OS << ")"; |
| 1525 | } |
| 1526 | |
| 1527 | void OMPClausePrinter::VisitOMPMapClause(OMPMapClause *Node) { |
| 1528 | if (!Node->varlist_empty()) { |
| 1529 | OS << "map("; |
| 1530 | if (Node->getMapType() != OMPC_MAP_unknown) { |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 1531 | for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) { |
| 1532 | if (Node->getMapTypeModifier(I) != OMPC_MAP_MODIFIER_unknown) { |
| 1533 | OS << getOpenMPSimpleClauseTypeName(OMPC_map, |
| 1534 | Node->getMapTypeModifier(I)); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 1535 | if (Node->getMapTypeModifier(I) == OMPC_MAP_MODIFIER_mapper) { |
| 1536 | OS << '('; |
| 1537 | NestedNameSpecifier *MapperNNS = |
| 1538 | Node->getMapperQualifierLoc().getNestedNameSpecifier(); |
| 1539 | if (MapperNNS) |
| 1540 | MapperNNS->print(OS, Policy); |
| 1541 | OS << Node->getMapperIdInfo() << ')'; |
| 1542 | } |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 1543 | OS << ','; |
| 1544 | } |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1545 | } |
| 1546 | OS << getOpenMPSimpleClauseTypeName(OMPC_map, Node->getMapType()); |
| 1547 | OS << ':'; |
| 1548 | } |
| 1549 | VisitOMPClauseList(Node, ' '); |
| 1550 | OS << ")"; |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | void OMPClausePrinter::VisitOMPToClause(OMPToClause *Node) { |
| 1555 | if (!Node->varlist_empty()) { |
| 1556 | OS << "to"; |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 1557 | DeclarationNameInfo MapperId = Node->getMapperIdInfo(); |
| 1558 | if (MapperId.getName() && !MapperId.getName().isEmpty()) { |
| 1559 | OS << '('; |
| 1560 | OS << "mapper("; |
| 1561 | NestedNameSpecifier *MapperNNS = |
| 1562 | Node->getMapperQualifierLoc().getNestedNameSpecifier(); |
| 1563 | if (MapperNNS) |
| 1564 | MapperNNS->print(OS, Policy); |
| 1565 | OS << MapperId << "):"; |
| 1566 | VisitOMPClauseList(Node, ' '); |
| 1567 | } else { |
| 1568 | VisitOMPClauseList(Node, '('); |
| 1569 | } |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1570 | OS << ")"; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void OMPClausePrinter::VisitOMPFromClause(OMPFromClause *Node) { |
| 1575 | if (!Node->varlist_empty()) { |
| 1576 | OS << "from"; |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 1577 | DeclarationNameInfo MapperId = Node->getMapperIdInfo(); |
| 1578 | if (MapperId.getName() && !MapperId.getName().isEmpty()) { |
| 1579 | OS << '('; |
| 1580 | OS << "mapper("; |
| 1581 | NestedNameSpecifier *MapperNNS = |
| 1582 | Node->getMapperQualifierLoc().getNestedNameSpecifier(); |
| 1583 | if (MapperNNS) |
| 1584 | MapperNNS->print(OS, Policy); |
| 1585 | OS << MapperId << "):"; |
| 1586 | VisitOMPClauseList(Node, ' '); |
| 1587 | } else { |
| 1588 | VisitOMPClauseList(Node, '('); |
| 1589 | } |
Patrick Lyster | 074c3ae2 | 2018-10-18 14:28:23 +0000 | [diff] [blame] | 1590 | OS << ")"; |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) { |
| 1595 | OS << "dist_schedule(" << getOpenMPSimpleClauseTypeName( |
| 1596 | OMPC_dist_schedule, Node->getDistScheduleKind()); |
| 1597 | if (auto *E = Node->getChunkSize()) { |
| 1598 | OS << ", "; |
| 1599 | E->printPretty(OS, nullptr, Policy); |
| 1600 | } |
| 1601 | OS << ")"; |
| 1602 | } |
| 1603 | |
| 1604 | void OMPClausePrinter::VisitOMPDefaultmapClause(OMPDefaultmapClause *Node) { |
| 1605 | OS << "defaultmap("; |
| 1606 | OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 1607 | Node->getDefaultmapModifier()); |
| 1608 | OS << ": "; |
| 1609 | OS << getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 1610 | Node->getDefaultmapKind()); |
| 1611 | OS << ")"; |
| 1612 | } |
| 1613 | |
| 1614 | void OMPClausePrinter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *Node) { |
| 1615 | if (!Node->varlist_empty()) { |
| 1616 | OS << "use_device_ptr"; |
| 1617 | VisitOMPClauseList(Node, '('); |
| 1618 | OS << ")"; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { |
| 1623 | if (!Node->varlist_empty()) { |
| 1624 | OS << "is_device_ptr"; |
| 1625 | VisitOMPClauseList(Node, '('); |
| 1626 | OS << ")"; |
| 1627 | } |
| 1628 | } |
| 1629 | |