blob: 6836567319cd18216abcce8b54c5d530c63ac9d0 [file] [log] [blame]
Jonathan Peytonff800772015-05-26 16:30:41 +00001/*
Jonathan Peytonde4749b2016-12-14 23:01:24 +00002 * kmp_error.cpp -- KPTS functions for error checking at runtime
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
Jim Cownie5e8470a2013-09-27 10:38:44 +00005//===----------------------------------------------------------------------===//
6//
Chandler Carruth57b08b02019-01-19 10:56:40 +00007// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8// See https://llvm.org/LICENSE.txt for license information.
9// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Jim Cownie5e8470a2013-09-27 10:38:44 +000010//
11//===----------------------------------------------------------------------===//
12
Jim Cownie5e8470a2013-09-27 10:38:44 +000013#include "kmp.h"
Jonathan Peyton30419822017-05-12 18:01:32 +000014#include "kmp_error.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000015#include "kmp_i18n.h"
16#include "kmp_str.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000017
18/* ------------------------------------------------------------------------ */
Jim Cownie5e8470a2013-09-27 10:38:44 +000019
Jonathan Peyton30419822017-05-12 18:01:32 +000020#define MIN_STACK 100
Jim Cownie5e8470a2013-09-27 10:38:44 +000021
Jonathan Peyton30419822017-05-12 18:01:32 +000022static char const *cons_text_c[] = {
23 "(none)", "\"parallel\"", "work-sharing", /* this is not called "for"
24 because of lowering of
25 "sections" pragmas */
26 "\"ordered\" work-sharing", /* this is not called "for ordered" because of
27 lowering of "sections" pragmas */
Jim Cownie5e8470a2013-09-27 10:38:44 +000028 "\"sections\"",
Jonathan Peyton30419822017-05-12 18:01:32 +000029 "work-sharing", /* this is not called "single" because of lowering of
30 "sections" pragmas */
31 "\"taskq\"", "\"taskq\"", "\"taskq ordered\"", "\"critical\"",
32 "\"ordered\"", /* in PARALLEL */
33 "\"ordered\"", /* in PDO */
34 "\"ordered\"", /* in TASKQ */
35 "\"master\"", "\"reduce\"", "\"barrier\""};
Jim Cownie5e8470a2013-09-27 10:38:44 +000036
Jonathan Peyton30419822017-05-12 18:01:32 +000037#define get_src(ident) ((ident) == NULL ? NULL : (ident)->psource)
Jim Cownie5e8470a2013-09-27 10:38:44 +000038
Jonathan Peyton30419822017-05-12 18:01:32 +000039#define PUSH_MSG(ct, ident) \
40 "\tpushing on stack: %s (%s)\n", cons_text_c[(ct)], get_src((ident))
41#define POP_MSG(p) \
42 "\tpopping off stack: %s (%s)\n", cons_text_c[(p)->stack_data[tos].type], \
43 get_src((p)->stack_data[tos].ident)
Jim Cownie5e8470a2013-09-27 10:38:44 +000044
Jonathan Peyton30419822017-05-12 18:01:32 +000045static int const cons_text_c_num = sizeof(cons_text_c) / sizeof(char const *);
Jim Cownie5e8470a2013-09-27 10:38:44 +000046
Jim Cownie5e8470a2013-09-27 10:38:44 +000047/* --------------- START OF STATIC LOCAL ROUTINES ------------------------- */
Jim Cownie5e8470a2013-09-27 10:38:44 +000048
Jonathan Peyton30419822017-05-12 18:01:32 +000049static void __kmp_check_null_func(void) { /* nothing to do */
Jim Cownie5e8470a2013-09-27 10:38:44 +000050}
51
Jonathan Peyton30419822017-05-12 18:01:32 +000052static void __kmp_expand_cons_stack(int gtid, struct cons_header *p) {
53 int i;
54 struct cons_data *d;
Jim Cownie5e8470a2013-09-27 10:38:44 +000055
Jonathan Peyton30419822017-05-12 18:01:32 +000056 /* TODO for monitor perhaps? */
57 if (gtid < 0)
58 __kmp_check_null_func();
Jim Cownie5e8470a2013-09-27 10:38:44 +000059
Jonathan Peyton30419822017-05-12 18:01:32 +000060 KE_TRACE(10, ("expand cons_stack (%d %d)\n", gtid, __kmp_get_gtid()));
Jim Cownie5e8470a2013-09-27 10:38:44 +000061
Jonathan Peyton30419822017-05-12 18:01:32 +000062 d = p->stack_data;
Jim Cownie5e8470a2013-09-27 10:38:44 +000063
Jonathan Peyton30419822017-05-12 18:01:32 +000064 p->stack_size = (p->stack_size * 2) + 100;
Jim Cownie5e8470a2013-09-27 10:38:44 +000065
Jonathan Peyton30419822017-05-12 18:01:32 +000066 /* TODO free the old data */
67 p->stack_data = (struct cons_data *)__kmp_allocate(sizeof(struct cons_data) *
68 (p->stack_size + 1));
Jim Cownie5e8470a2013-09-27 10:38:44 +000069
Jonathan Peyton30419822017-05-12 18:01:32 +000070 for (i = p->stack_top; i >= 0; --i)
71 p->stack_data[i] = d[i];
Jim Cownie5e8470a2013-09-27 10:38:44 +000072
Jonathan Peyton30419822017-05-12 18:01:32 +000073 /* NOTE: we do not free the old stack_data */
Jim Cownie5e8470a2013-09-27 10:38:44 +000074}
75
76// NOTE: Function returns allocated memory, caller must free it!
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +000077static char *__kmp_pragma(int ct, ident_t const *ident) {
Jonathan Peyton30419822017-05-12 18:01:32 +000078 char const *cons = NULL; // Construct name.
79 char *file = NULL; // File name.
80 char *func = NULL; // Function (routine) name.
81 char *line = NULL; // Line number.
82 kmp_str_buf_t buffer;
83 kmp_msg_t prgm;
84 __kmp_str_buf_init(&buffer);
85 if (0 < ct && ct < cons_text_c_num) {
86 cons = cons_text_c[ct];
87 } else {
88 KMP_DEBUG_ASSERT(0);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +000089 }
Jonathan Peyton30419822017-05-12 18:01:32 +000090 if (ident != NULL && ident->psource != NULL) {
91 char *tail = NULL;
92 __kmp_str_buf_print(&buffer, "%s",
93 ident->psource); // Copy source to buffer.
94 // Split string in buffer to file, func, and line.
95 tail = buffer.str;
96 __kmp_str_split(tail, ';', NULL, &tail);
97 __kmp_str_split(tail, ';', &file, &tail);
98 __kmp_str_split(tail, ';', &func, &tail);
99 __kmp_str_split(tail, ';', &line, &tail);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000100 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000101 prgm = __kmp_msg_format(kmp_i18n_fmt_Pragma, cons, file, func, line);
102 __kmp_str_buf_free(&buffer);
103 return prgm.str;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000104} // __kmp_pragma
105
Jim Cownie5e8470a2013-09-27 10:38:44 +0000106/* ----------------- END OF STATIC LOCAL ROUTINES ------------------------- */
Jim Cownie5e8470a2013-09-27 10:38:44 +0000107
Jonathan Peyton30419822017-05-12 18:01:32 +0000108void __kmp_error_construct(kmp_i18n_id_t id, // Message identifier.
109 enum cons_type ct, // Construct type.
110 ident_t const *ident // Construct ident.
111 ) {
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +0000112 char *construct = __kmp_pragma(ct, ident);
Jonathan Peyton6a393f72017-09-05 15:43:58 +0000113 __kmp_fatal(__kmp_msg_format(id, construct), __kmp_msg_null);
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +0000114 KMP_INTERNAL_FREE(construct);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000115}
116
Jonathan Peyton30419822017-05-12 18:01:32 +0000117void __kmp_error_construct2(kmp_i18n_id_t id, // Message identifier.
118 enum cons_type ct, // First construct type.
119 ident_t const *ident, // First construct ident.
120 struct cons_data const *cons // Second construct.
121 ) {
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +0000122 char *construct1 = __kmp_pragma(ct, ident);
123 char *construct2 = __kmp_pragma(cons->type, cons->ident);
Jonathan Peyton6a393f72017-09-05 15:43:58 +0000124 __kmp_fatal(__kmp_msg_format(id, construct1, construct2), __kmp_msg_null);
Jonas Hahnfeldaeb40ad2017-11-09 15:52:25 +0000125 KMP_INTERNAL_FREE(construct1);
126 KMP_INTERNAL_FREE(construct2);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000127}
128
Jonathan Peyton30419822017-05-12 18:01:32 +0000129struct cons_header *__kmp_allocate_cons_stack(int gtid) {
130 struct cons_header *p;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000131
Jonathan Peyton30419822017-05-12 18:01:32 +0000132 /* TODO for monitor perhaps? */
133 if (gtid < 0) {
134 __kmp_check_null_func();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000135 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000136 KE_TRACE(10, ("allocate cons_stack (%d)\n", gtid));
137 p = (struct cons_header *)__kmp_allocate(sizeof(struct cons_header));
138 p->p_top = p->w_top = p->s_top = 0;
139 p->stack_data = (struct cons_data *)__kmp_allocate(sizeof(struct cons_data) *
140 (MIN_STACK + 1));
141 p->stack_size = MIN_STACK;
142 p->stack_top = 0;
143 p->stack_data[0].type = ct_none;
144 p->stack_data[0].prev = 0;
145 p->stack_data[0].ident = NULL;
146 return p;
147}
Jim Cownie5e8470a2013-09-27 10:38:44 +0000148
Jonathan Peyton30419822017-05-12 18:01:32 +0000149void __kmp_free_cons_stack(void *ptr) {
150 struct cons_header *p = (struct cons_header *)ptr;
151 if (p != NULL) {
152 if (p->stack_data != NULL) {
153 __kmp_free(p->stack_data);
154 p->stack_data = NULL;
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000155 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000156 __kmp_free(p);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000157 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000158}
159
Jonathan Peyton2321d572015-06-08 19:25:25 +0000160#if KMP_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000161static void dump_cons_stack(int gtid, struct cons_header *p) {
162 int i;
163 int tos = p->stack_top;
164 kmp_str_buf_t buffer;
165 __kmp_str_buf_init(&buffer);
166 __kmp_str_buf_print(
167 &buffer,
168 "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
169 __kmp_str_buf_print(&buffer,
170 "Begin construct stack with %d items for thread %d\n",
171 tos, gtid);
172 __kmp_str_buf_print(&buffer, " stack_top=%d { P=%d, W=%d, S=%d }\n", tos,
173 p->p_top, p->w_top, p->s_top);
174 for (i = tos; i > 0; i--) {
175 struct cons_data *c = &(p->stack_data[i]);
176 __kmp_str_buf_print(
177 &buffer, " stack_data[%2d] = { %s (%s) %d %p }\n", i,
178 cons_text_c[c->type], get_src(c->ident), c->prev, c->name);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000179 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000180 __kmp_str_buf_print(&buffer, "End construct stack for thread %d\n", gtid);
181 __kmp_str_buf_print(
182 &buffer,
183 "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
184 __kmp_debug_printf("%s", buffer.str);
185 __kmp_str_buf_free(&buffer);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000186}
Jonathan Peyton2321d572015-06-08 19:25:25 +0000187#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000188
Jonathan Peyton30419822017-05-12 18:01:32 +0000189void __kmp_push_parallel(int gtid, ident_t const *ident) {
190 int tos;
191 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000192
Jonathan Peyton30419822017-05-12 18:01:32 +0000193 KMP_DEBUG_ASSERT(__kmp_threads[gtid]->th.th_cons);
194 KE_TRACE(10, ("__kmp_push_parallel (%d %d)\n", gtid, __kmp_get_gtid()));
195 KE_TRACE(100, (PUSH_MSG(ct_parallel, ident)));
196 if (p->stack_top >= p->stack_size) {
197 __kmp_expand_cons_stack(gtid, p);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000198 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000199 tos = ++p->stack_top;
200 p->stack_data[tos].type = ct_parallel;
201 p->stack_data[tos].prev = p->p_top;
202 p->stack_data[tos].ident = ident;
203 p->stack_data[tos].name = NULL;
204 p->p_top = tos;
205 KE_DUMP(1000, dump_cons_stack(gtid, p));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000206}
207
Jonathan Peyton30419822017-05-12 18:01:32 +0000208void __kmp_check_workshare(int gtid, enum cons_type ct, ident_t const *ident) {
209 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000210
Jonathan Peyton30419822017-05-12 18:01:32 +0000211 KMP_DEBUG_ASSERT(__kmp_threads[gtid]->th.th_cons);
212 KE_TRACE(10, ("__kmp_check_workshare (%d %d)\n", gtid, __kmp_get_gtid()));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000213
Jonathan Peyton30419822017-05-12 18:01:32 +0000214 if (p->stack_top >= p->stack_size) {
215 __kmp_expand_cons_stack(gtid, p);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000216 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000217 if (p->w_top > p->p_top &&
218 !(IS_CONS_TYPE_TASKQ(p->stack_data[p->w_top].type) &&
219 IS_CONS_TYPE_TASKQ(ct))) {
220 // We are already in a WORKSHARE construct for this PARALLEL region.
221 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
222 &p->stack_data[p->w_top]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000223 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000224 if (p->s_top > p->p_top) {
225 // We are already in a SYNC construct for this PARALLEL region.
226 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
227 &p->stack_data[p->s_top]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000228 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000229}
230
Jonathan Peyton30419822017-05-12 18:01:32 +0000231void __kmp_push_workshare(int gtid, enum cons_type ct, ident_t const *ident) {
232 int tos;
233 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
234 KE_TRACE(10, ("__kmp_push_workshare (%d %d)\n", gtid, __kmp_get_gtid()));
235 __kmp_check_workshare(gtid, ct, ident);
236 KE_TRACE(100, (PUSH_MSG(ct, ident)));
237 tos = ++p->stack_top;
238 p->stack_data[tos].type = ct;
239 p->stack_data[tos].prev = p->w_top;
240 p->stack_data[tos].ident = ident;
241 p->stack_data[tos].name = NULL;
242 p->w_top = tos;
243 KE_DUMP(1000, dump_cons_stack(gtid, p));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000244}
245
246void
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000247#if KMP_USE_DYNAMIC_LOCK
248__kmp_check_sync( int gtid, enum cons_type ct, ident_t const * ident, kmp_user_lock_p lck, kmp_uint32 seq )
249#else
Jim Cownie5e8470a2013-09-27 10:38:44 +0000250__kmp_check_sync( int gtid, enum cons_type ct, ident_t const * ident, kmp_user_lock_p lck )
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000251#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000252{
Jonathan Peyton30419822017-05-12 18:01:32 +0000253 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000254
Jonathan Peyton30419822017-05-12 18:01:32 +0000255 KE_TRACE(10, ("__kmp_check_sync (gtid=%d)\n", __kmp_get_gtid()));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000256
Jonathan Peyton30419822017-05-12 18:01:32 +0000257 if (p->stack_top >= p->stack_size)
258 __kmp_expand_cons_stack(gtid, p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000259
Jonathan Peyton30419822017-05-12 18:01:32 +0000260 if (ct == ct_ordered_in_parallel || ct == ct_ordered_in_pdo ||
261 ct == ct_ordered_in_taskq) {
262 if (p->w_top <= p->p_top) {
263/* we are not in a worksharing construct */
264#ifdef BUILD_PARALLEL_ORDERED
265 /* do not report error messages for PARALLEL ORDERED */
266 KMP_ASSERT(ct == ct_ordered_in_parallel);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000267#else
Jonathan Peyton30419822017-05-12 18:01:32 +0000268 __kmp_error_construct(kmp_i18n_msg_CnsBoundToWorksharing, ct, ident);
269#endif /* BUILD_PARALLEL_ORDERED */
270 } else {
271 /* inside a WORKSHARING construct for this PARALLEL region */
272 if (!IS_CONS_TYPE_ORDERED(p->stack_data[p->w_top].type)) {
273 if (p->stack_data[p->w_top].type == ct_taskq) {
274 __kmp_error_construct2(kmp_i18n_msg_CnsNotInTaskConstruct, ct, ident,
275 &p->stack_data[p->w_top]);
276 } else {
277 __kmp_error_construct2(kmp_i18n_msg_CnsNoOrderedClause, ct, ident,
278 &p->stack_data[p->w_top]);
279 }
280 }
281 }
282 if (p->s_top > p->p_top && p->s_top > p->w_top) {
283 /* inside a sync construct which is inside a worksharing construct */
284 int index = p->s_top;
285 enum cons_type stack_type;
286
287 stack_type = p->stack_data[index].type;
288
289 if (stack_type == ct_critical ||
290 ((stack_type == ct_ordered_in_parallel ||
291 stack_type == ct_ordered_in_pdo ||
292 stack_type ==
293 ct_ordered_in_taskq) && /* C doesn't allow named ordered;
294 ordered in ordered gets error */
295 p->stack_data[index].ident != NULL &&
296 (p->stack_data[index].ident->flags & KMP_IDENT_KMPC))) {
297 /* we are in ORDERED which is inside an ORDERED or CRITICAL construct */
298 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
299 &p->stack_data[index]);
300 }
301 }
302 } else if (ct == ct_critical) {
303#if KMP_USE_DYNAMIC_LOCK
304 if (lck != NULL &&
305 __kmp_get_user_lock_owner(lck, seq) ==
306 gtid) { /* this thread already has lock for this critical section */
307#else
308 if (lck != NULL &&
309 __kmp_get_user_lock_owner(lck) ==
310 gtid) { /* this thread already has lock for this critical section */
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000311#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000312 int index = p->s_top;
313 struct cons_data cons = {NULL, ct_critical, 0, NULL};
314 /* walk up construct stack and try to find critical with matching name */
315 while (index != 0 && p->stack_data[index].name != lck) {
316 index = p->stack_data[index].prev;
317 }
318 if (index != 0) {
319 /* found match on the stack (may not always because of interleaved
320 * critical for Fortran) */
321 cons = p->stack_data[index];
322 }
323 /* we are in CRITICAL which is inside a CRITICAL construct of same name */
324 __kmp_error_construct2(kmp_i18n_msg_CnsNestingSameName, ct, ident, &cons);
325 }
326 } else if (ct == ct_master || ct == ct_reduce) {
327 if (p->w_top > p->p_top) {
328 /* inside a WORKSHARING construct for this PARALLEL region */
329 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
330 &p->stack_data[p->w_top]);
331 }
332 if (ct == ct_reduce && p->s_top > p->p_top) {
333 /* inside a another SYNC construct for this PARALLEL region */
334 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
335 &p->stack_data[p->s_top]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000336 }
337 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000338}
339
340void
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000341#if KMP_USE_DYNAMIC_LOCK
342__kmp_push_sync( int gtid, enum cons_type ct, ident_t const * ident, kmp_user_lock_p lck, kmp_uint32 seq )
343#else
Jim Cownie5e8470a2013-09-27 10:38:44 +0000344__kmp_push_sync( int gtid, enum cons_type ct, ident_t const * ident, kmp_user_lock_p lck )
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000345#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000346{
Jonathan Peyton30419822017-05-12 18:01:32 +0000347 int tos;
348 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000349
Jonathan Peyton30419822017-05-12 18:01:32 +0000350 KMP_ASSERT(gtid == __kmp_get_gtid());
351 KE_TRACE(10, ("__kmp_push_sync (gtid=%d)\n", gtid));
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000352#if KMP_USE_DYNAMIC_LOCK
Jonathan Peyton30419822017-05-12 18:01:32 +0000353 __kmp_check_sync(gtid, ct, ident, lck, seq);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000354#else
Jonathan Peyton30419822017-05-12 18:01:32 +0000355 __kmp_check_sync(gtid, ct, ident, lck);
Andrey Churbanov5c56fb52015-02-20 18:05:17 +0000356#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000357 KE_TRACE(100, (PUSH_MSG(ct, ident)));
358 tos = ++p->stack_top;
359 p->stack_data[tos].type = ct;
360 p->stack_data[tos].prev = p->s_top;
361 p->stack_data[tos].ident = ident;
362 p->stack_data[tos].name = lck;
363 p->s_top = tos;
364 KE_DUMP(1000, dump_cons_stack(gtid, p));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000365}
366
367/* ------------------------------------------------------------------------ */
368
Jonathan Peyton30419822017-05-12 18:01:32 +0000369void __kmp_pop_parallel(int gtid, ident_t const *ident) {
370 int tos;
371 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
372 tos = p->stack_top;
373 KE_TRACE(10, ("__kmp_pop_parallel (%d %d)\n", gtid, __kmp_get_gtid()));
374 if (tos == 0 || p->p_top == 0) {
375 __kmp_error_construct(kmp_i18n_msg_CnsDetectedEnd, ct_parallel, ident);
376 }
377 if (tos != p->p_top || p->stack_data[tos].type != ct_parallel) {
378 __kmp_error_construct2(kmp_i18n_msg_CnsExpectedEnd, ct_parallel, ident,
379 &p->stack_data[tos]);
380 }
381 KE_TRACE(100, (POP_MSG(p)));
382 p->p_top = p->stack_data[tos].prev;
383 p->stack_data[tos].type = ct_none;
384 p->stack_data[tos].ident = NULL;
385 p->stack_top = tos - 1;
386 KE_DUMP(1000, dump_cons_stack(gtid, p));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000387}
388
Jonathan Peyton30419822017-05-12 18:01:32 +0000389enum cons_type __kmp_pop_workshare(int gtid, enum cons_type ct,
390 ident_t const *ident) {
391 int tos;
392 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000393
Jonathan Peyton30419822017-05-12 18:01:32 +0000394 tos = p->stack_top;
395 KE_TRACE(10, ("__kmp_pop_workshare (%d %d)\n", gtid, __kmp_get_gtid()));
396 if (tos == 0 || p->w_top == 0) {
397 __kmp_error_construct(kmp_i18n_msg_CnsDetectedEnd, ct, ident);
398 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000399
Jonathan Peyton30419822017-05-12 18:01:32 +0000400 if (tos != p->w_top ||
401 (p->stack_data[tos].type != ct &&
402 // below are two exceptions to the rule that construct types must match
403 !(p->stack_data[tos].type == ct_pdo_ordered && ct == ct_pdo) &&
404 !(p->stack_data[tos].type == ct_task_ordered && ct == ct_task))) {
405 __kmp_check_null_func();
406 __kmp_error_construct2(kmp_i18n_msg_CnsExpectedEnd, ct, ident,
407 &p->stack_data[tos]);
408 }
409 KE_TRACE(100, (POP_MSG(p)));
410 p->w_top = p->stack_data[tos].prev;
411 p->stack_data[tos].type = ct_none;
412 p->stack_data[tos].ident = NULL;
413 p->stack_top = tos - 1;
414 KE_DUMP(1000, dump_cons_stack(gtid, p));
415 return p->stack_data[p->w_top].type;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000416}
417
Jonathan Peyton30419822017-05-12 18:01:32 +0000418void __kmp_pop_sync(int gtid, enum cons_type ct, ident_t const *ident) {
419 int tos;
420 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
421 tos = p->stack_top;
422 KE_TRACE(10, ("__kmp_pop_sync (%d %d)\n", gtid, __kmp_get_gtid()));
423 if (tos == 0 || p->s_top == 0) {
424 __kmp_error_construct(kmp_i18n_msg_CnsDetectedEnd, ct, ident);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000425 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000426 if (tos != p->s_top || p->stack_data[tos].type != ct) {
427 __kmp_check_null_func();
428 __kmp_error_construct2(kmp_i18n_msg_CnsExpectedEnd, ct, ident,
429 &p->stack_data[tos]);
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000430 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000431 if (gtid < 0) {
432 __kmp_check_null_func();
Jonathan Peytonbd3a7632017-09-27 20:36:27 +0000433 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000434 KE_TRACE(100, (POP_MSG(p)));
435 p->s_top = p->stack_data[tos].prev;
436 p->stack_data[tos].type = ct_none;
437 p->stack_data[tos].ident = NULL;
438 p->stack_top = tos - 1;
439 KE_DUMP(1000, dump_cons_stack(gtid, p));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000440}
441
442/* ------------------------------------------------------------------------ */
443
Jonathan Peyton30419822017-05-12 18:01:32 +0000444void __kmp_check_barrier(int gtid, enum cons_type ct, ident_t const *ident) {
445 struct cons_header *p = __kmp_threads[gtid]->th.th_cons;
446 KE_TRACE(10, ("__kmp_check_barrier (loc: %p, gtid: %d %d)\n", ident, gtid,
447 __kmp_get_gtid()));
448 if (ident != 0) {
449 __kmp_check_null_func();
450 }
451 if (p->w_top > p->p_top) {
452 /* we are already in a WORKSHARING construct for this PARALLEL region */
453 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
454 &p->stack_data[p->w_top]);
455 }
456 if (p->s_top > p->p_top) {
457 /* we are already in a SYNC construct for this PARALLEL region */
458 __kmp_error_construct2(kmp_i18n_msg_CnsInvalidNesting, ct, ident,
459 &p->stack_data[p->s_top]);
460 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000461}