Reset prologue_location before calling code_end
[official-gcc.git] / libgomp / icv.c
blobe32e5b2fdb0f3fadc3fcc532c4fa0390a618ea10
1 /* Copyright (C) 2005-2021 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp).
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This file defines the OpenMP API entry points that operate on internal
27 control variables. */
29 #include "libgomp.h"
30 #include "gomp-constants.h"
31 #include <limits.h>
33 void
34 omp_set_num_threads (int n)
36 struct gomp_task_icv *icv = gomp_icv (true);
37 icv->nthreads_var = (n > 0 ? n : 1);
40 void
41 omp_set_dynamic (int val)
43 struct gomp_task_icv *icv = gomp_icv (true);
44 icv->dyn_var = val;
47 int
48 omp_get_dynamic (void)
50 struct gomp_task_icv *icv = gomp_icv (false);
51 return icv->dyn_var;
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
56 void
57 omp_set_nested (int val)
59 struct gomp_task_icv *icv = gomp_icv (true);
60 if (val)
61 icv->max_active_levels_var = gomp_supported_active_levels;
62 else if (icv->max_active_levels_var > 1)
63 icv->max_active_levels_var = 1;
66 int
67 omp_get_nested (void)
69 struct gomp_task_icv *icv = gomp_icv (false);
70 return (icv->max_active_levels_var > 1
71 && icv->max_active_levels_var > omp_get_active_level ());
73 #pragma GCC diagnostic pop
75 void
76 omp_set_schedule (omp_sched_t kind, int chunk_size)
78 struct gomp_task_icv *icv = gomp_icv (true);
79 switch (kind & ~omp_sched_monotonic)
81 case omp_sched_static:
82 if (chunk_size < 1)
83 chunk_size = 0;
84 icv->run_sched_chunk_size = chunk_size;
85 break;
86 case omp_sched_dynamic:
87 case omp_sched_guided:
88 if (chunk_size < 1)
89 chunk_size = 1;
90 icv->run_sched_chunk_size = chunk_size;
91 break;
92 case omp_sched_auto:
93 break;
94 default:
95 return;
97 icv->run_sched_var = kind;
100 void
101 omp_get_schedule (omp_sched_t *kind, int *chunk_size)
103 struct gomp_task_icv *icv = gomp_icv (false);
104 *kind = icv->run_sched_var;
105 *chunk_size = icv->run_sched_chunk_size;
109 omp_get_max_threads (void)
111 struct gomp_task_icv *icv = gomp_icv (false);
112 return icv->nthreads_var;
116 omp_get_thread_limit (void)
118 struct gomp_task_icv *icv = gomp_icv (false);
119 return icv->thread_limit_var > INT_MAX ? INT_MAX : icv->thread_limit_var;
122 void
123 omp_set_max_active_levels (int max_levels)
125 if (max_levels >= 0)
127 struct gomp_task_icv *icv = gomp_icv (true);
129 if (max_levels <= gomp_supported_active_levels)
130 icv->max_active_levels_var = max_levels;
131 else
132 icv->max_active_levels_var = gomp_supported_active_levels;
137 omp_get_max_active_levels (void)
139 struct gomp_task_icv *icv = gomp_icv (false);
140 return icv->max_active_levels_var;
144 omp_get_supported_active_levels (void)
146 return gomp_supported_active_levels;
150 omp_get_cancellation (void)
152 return gomp_cancel_var;
156 omp_get_max_task_priority (void)
158 return gomp_max_task_priority_var;
161 omp_proc_bind_t
162 omp_get_proc_bind (void)
164 struct gomp_task_icv *icv = gomp_icv (false);
165 return icv->bind_var;
169 omp_get_num_places (void)
171 return gomp_places_list_len;
175 omp_get_place_num (void)
177 if (gomp_places_list == NULL)
178 return -1;
180 struct gomp_thread *thr = gomp_thread ();
181 if (thr->place == 0)
182 gomp_init_affinity ();
184 return (int) thr->place - 1;
188 omp_get_partition_num_places (void)
190 if (gomp_places_list == NULL)
191 return 0;
193 struct gomp_thread *thr = gomp_thread ();
194 if (thr->place == 0)
195 gomp_init_affinity ();
197 return thr->ts.place_partition_len;
200 void
201 omp_get_partition_place_nums (int *place_nums)
203 if (gomp_places_list == NULL)
204 return;
206 struct gomp_thread *thr = gomp_thread ();
207 if (thr->place == 0)
208 gomp_init_affinity ();
210 unsigned int i;
211 for (i = 0; i < thr->ts.place_partition_len; i++)
212 *place_nums++ = thr->ts.place_partition_off + i;
215 void
216 omp_set_default_allocator (omp_allocator_handle_t allocator)
218 struct gomp_thread *thr = gomp_thread ();
219 if (allocator == omp_null_allocator)
220 allocator = omp_default_mem_alloc;
221 thr->ts.def_allocator = (uintptr_t) allocator;
224 omp_allocator_handle_t
225 omp_get_default_allocator (void)
227 struct gomp_thread *thr = gomp_thread ();
228 if (thr->ts.def_allocator == omp_null_allocator)
229 return (omp_allocator_handle_t) gomp_def_allocator;
230 else
231 return (omp_allocator_handle_t) thr->ts.def_allocator;
234 ialias (omp_set_dynamic)
235 ialias (omp_get_dynamic)
236 #pragma GCC diagnostic push
237 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
238 ialias (omp_set_nested)
239 ialias (omp_get_nested)
240 #pragma GCC diagnostic pop
241 ialias (omp_set_num_threads)
242 ialias (omp_set_schedule)
243 ialias (omp_get_schedule)
244 ialias (omp_get_max_threads)
245 ialias (omp_get_thread_limit)
246 ialias (omp_set_max_active_levels)
247 ialias (omp_get_max_active_levels)
248 ialias (omp_get_supported_active_levels)
249 ialias (omp_get_cancellation)
250 ialias (omp_get_proc_bind)
251 ialias (omp_get_max_task_priority)
252 ialias (omp_get_num_places)
253 ialias (omp_get_place_num)
254 ialias (omp_get_partition_num_places)
255 ialias (omp_get_partition_place_nums)
256 ialias (omp_set_default_allocator)
257 ialias (omp_get_default_allocator)