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