PR69195, Reload confused by invalid reg_equiv
[official-gcc.git] / libcilkrts / runtime / os.h
blob8066f0313c2d03f5e6040e5f44f1b3d256765f9f
1 /* os.h -*-C++-*-
3 *************************************************************************
5 * @copyright
6 * Copyright (C) 2009-2013, Intel Corporation
7 * All rights reserved.
8 *
9 * @copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * @copyright
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 **************************************************************************/
39 /**
40 * @file os.h
42 * @brief Low-level operating-system dependent facilities, not dependent on
43 * any Cilk facilities.
46 #ifndef INCLUDED_OS_DOT_H
47 #define INCLUDED_OS_DOT_H
49 #include "rts-common.h"
50 #include "cilk/common.h"
51 #include "cilk-tbb-interop.h"
53 #ifdef __cplusplus
54 # include <cstddef>
55 #else
56 # include <stddef.h>
57 #endif
59 __CILKRTS_BEGIN_EXTERN_C
62 // /* Thread-local storage */
63 // #ifdef _WIN32
64 // typedef unsigned cilkos_tls_key_t;
65 // #else
66 // typedef pthread_key_t cilkos_tls_key_t;
67 // #endif
68 // cilkos_tls_key_t cilkos_allocate_tls_key();
69 // void cilkos_set_tls_pointer(cilkos_tls_key_t key, void* ptr);
70 // void* cilkos_get_tls_pointer(cilkos_tls_key_t key);
72 /* The RTS assumes that some thread-local state exists that stores the
73 worker and reducer map currently associated with a thread. These routines
74 manipulate this state. */
76 /** @brief Thread-local state for cilk fibers. */
77 typedef struct cilk_fiber_sysdep cilk_fiber_sysdep;
79 /** @brief Initialize all TLS variables for Cilk. */
80 COMMON_SYSDEP void __cilkrts_init_tls_variables(void);
82 /** @brief Set worker struct in TLS. */
83 COMMON_SYSDEP
84 void __cilkrts_set_tls_worker(__cilkrts_worker *w) cilk_nothrow;
86 /** @brief Get stack_op for TBB-interop structures from TLS. */
87 COMMON_SYSDEP
88 __cilk_tbb_stack_op_thunk *__cilkrts_get_tls_tbb_interop(void);
90 /** @brief Set stack_op for TBB-interop structures in TLS. */
91 COMMON_SYSDEP
92 void __cilkrts_set_tls_tbb_interop(__cilk_tbb_stack_op_thunk *t);
94 /**
95 * @brief Get the pointer to the pedigree leaf node from TLS.
97 * Function to get a pointer to the thread's pedigree leaf node. This
98 * pointer can be NULL.
100 COMMON_SYSDEP
101 __cilkrts_pedigree * __cilkrts_get_tls_pedigree_leaf(int create_new);
104 * @brief Sets the pointer to the pedigree leaf node in TLS.
106 * If the previous pointer value was not NULL, it is the caller's
107 * responsibility to ensure that previous pointer value is saved and
108 * freed.
110 * @param pedigree_leaf The leaf node to store into TLS.
112 COMMON_SYSDEP
113 void __cilkrts_set_tls_pedigree_leaf(__cilkrts_pedigree* pedigree_leaf);
116 #if SUPPORT_GET_CURRENT_FIBER > 0
118 * @brief Get the cilk_fiber from TLS.
120 COMMON_SYSDEP
121 cilk_fiber_sysdep* cilkos_get_tls_cilk_fiber(void);
124 * @brief Set the cilk_fiber in TLS.
126 * @param fiber The fiber to store into TLS.
128 COMMON_SYSDEP
129 void cilkos_set_tls_cilk_fiber(cilk_fiber_sysdep* fiber);
130 #endif
133 * @brief Function for returning the current thread id.
134 * @warning This function is useful for debugging purposes only.
136 COMMON_SYSDEP
137 void* cilkos_get_current_thread_id(void);
139 /** @brief Return number of CPUs supported by this hardware, using whatever definition
140 of CPU is considered appropriate. */
141 COMMON_SYSDEP int __cilkrts_hardware_cpu_count(void);
143 /** @brief Get current value of timer */
144 COMMON_SYSDEP unsigned long long __cilkrts_getticks(void);
146 /* Machine instructions */
148 /// Stall execution for a few cycles.
149 COMMON_SYSDEP void __cilkrts_short_pause(void);
150 /// Wrapper for xchg instruction
151 COMMON_SYSDEP int __cilkrts_xchg(volatile int *ptr, int x);
153 // Defines __cilkrts_fence - A macro for x86, a function call for other
154 // architectures
155 #include "os-fence.h"
157 COMMON_SYSDEP void __cilkrts_sleep(void); ///< Sleep briefly
158 COMMON_SYSDEP void __cilkrts_yield(void); ///< Yield quantum
161 * @brief Gets environment variable 'varname' and copy its value into 'value'.
163 * If the entire value, including the null terminator fits into 'vallen'
164 * bytes, then returns the length of the value excluding the null. Otherwise,
165 * leaves the contents of 'value' undefined and returns the number of
166 * characters needed to store the environment variable's value, *including*
167 * the null terminator.
169 * @param value Buffer to store value.
170 * @param vallen Length of value buffer
171 * @param varname Name of the environment variable.
172 * @return Length of value buffer (excluding the null).
174 COMMON_SYSDEP __STDNS size_t cilkos_getenv(char* value, __STDNS size_t vallen,
175 const char* varname);
178 * @brief Unrecoverable error: Print an error message and abort execution.
180 COMMON_SYSDEP void cilkos_error(const char *fmt, ...);
183 * @brief Print a warning message and return.
185 COMMON_SYSDEP void cilkos_warning(const char *fmt, ...);
188 * @brief Convert the user's specified stack size into a "reasonable"
189 * value for the current OS.
191 * @param specified_stack_size User-specified stack size.
192 * @return New stack size value, modified for the OS.
194 COMMON_SYSDEP size_t cilkos_validate_stack_size(size_t specified_stack_size);
197 * @brief Atomic addition: computes *p += x.
199 * @param p Pointer to value to update
200 * @param x Value of x.
202 COMMON_SYSDEP long cilkos_atomic_add(volatile long* p, long x);
204 #ifdef _WIN32
207 * @brief Windows-only low-level functions for processor groups.
209 typedef struct _GROUP_AFFINITY GROUP_AFFINITY;
212 * @brief Probe the executing OS to see if it supports processor
213 * groups. These functions are expected to be available in Windows 7
214 * or later.
216 void win_init_processor_groups(void);
218 unsigned long win_get_active_processor_count(unsigned short GroupNumber);
219 unsigned short win_get_active_processor_group_count(void);
220 int win_set_thread_group_affinity(/*HANDLE*/ void* hThread,
221 const GROUP_AFFINITY *GroupAffinity,
222 GROUP_AFFINITY* PreviousGroupAffinity);
225 * @brief Cleans up any state allocated in TLS.
227 * Only defined for Windows because Linux calls destructors for each
228 * thread-local variable.
230 void __cilkrts_per_thread_tls_cleanup(void);
232 #endif // _WIN32
234 __CILKRTS_END_EXTERN_C
236 #endif // ! defined(INCLUDED_OS_DOT_H)