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