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