xref: /netbsd-src/external/gpl3/gcc/dist/libgomp/scope.c (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1*b1e83836Smrg /* Copyright (C) 2021-2022 Free Software Foundation, Inc.
2*b1e83836Smrg    Contributed by Jakub Jelinek <jakub@redhat.com>.
3*b1e83836Smrg 
4*b1e83836Smrg    This file is part of the GNU Offloading and Multi Processing Library
5*b1e83836Smrg    (libgomp).
6*b1e83836Smrg 
7*b1e83836Smrg    Libgomp is free software; you can redistribute it and/or modify it
8*b1e83836Smrg    under the terms of the GNU General Public License as published by
9*b1e83836Smrg    the Free Software Foundation; either version 3, or (at your option)
10*b1e83836Smrg    any later version.
11*b1e83836Smrg 
12*b1e83836Smrg    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13*b1e83836Smrg    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14*b1e83836Smrg    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15*b1e83836Smrg    more details.
16*b1e83836Smrg 
17*b1e83836Smrg    Under Section 7 of GPL version 3, you are granted additional
18*b1e83836Smrg    permissions described in the GCC Runtime Library Exception, version
19*b1e83836Smrg    3.1, as published by the Free Software Foundation.
20*b1e83836Smrg 
21*b1e83836Smrg    You should have received a copy of the GNU General Public License and
22*b1e83836Smrg    a copy of the GCC Runtime Library Exception along with this program;
23*b1e83836Smrg    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*b1e83836Smrg    <http://www.gnu.org/licenses/>.  */
25*b1e83836Smrg 
26*b1e83836Smrg /* This file handles the SCOPE construct with task reductions.  */
27*b1e83836Smrg 
28*b1e83836Smrg #include "libgomp.h"
29*b1e83836Smrg #include <string.h>
30*b1e83836Smrg 
31*b1e83836Smrg 
ialias_redirect(GOMP_taskgroup_reduction_register)32*b1e83836Smrg ialias_redirect (GOMP_taskgroup_reduction_register)
33*b1e83836Smrg 
34*b1e83836Smrg /* This routine is called when first encountering a scope construct
35*b1e83836Smrg    with task reductions.  While scope is not a work-sharing construct,
36*b1e83836Smrg    if it has task reductions on it, we treat it as one, but as if it is
37*b1e83836Smrg    nowait, so the work-sharing behavior is done solely to choose which
38*b1e83836Smrg    thread does the initial initialization of task reductions and which
39*b1e83836Smrg    threads follow.  scope with task reductions must not be nowait,
40*b1e83836Smrg    but the barrier and GOMP_workshare_task_reduction_unregister are emitted
41*b1e83836Smrg    by the lowered code later.  */
42*b1e83836Smrg 
43*b1e83836Smrg void
44*b1e83836Smrg GOMP_scope_start (uintptr_t *reductions)
45*b1e83836Smrg {
46*b1e83836Smrg   struct gomp_thread *thr = gomp_thread ();
47*b1e83836Smrg 
48*b1e83836Smrg   gomp_workshare_taskgroup_start ();
49*b1e83836Smrg   if (gomp_work_share_start (0))
50*b1e83836Smrg     {
51*b1e83836Smrg       GOMP_taskgroup_reduction_register (reductions);
52*b1e83836Smrg       thr->task->taskgroup->workshare = true;
53*b1e83836Smrg       thr->ts.work_share->task_reductions = reductions;
54*b1e83836Smrg       gomp_work_share_init_done ();
55*b1e83836Smrg     }
56*b1e83836Smrg   else
57*b1e83836Smrg     {
58*b1e83836Smrg       uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
59*b1e83836Smrg       gomp_workshare_task_reduction_register (reductions,
60*b1e83836Smrg 					      first_reductions);
61*b1e83836Smrg     }
62*b1e83836Smrg }
63