2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libcilkrts / runtime / metacall_impl.c
blobce1c51a202b1d109740dfdfec16262ec08dac7f4
1 /* metacall_impl.c -*-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 #include "metacall_impl.h"
41 NOINLINE
42 CILK_API_VOID
43 __cilkrts_metacall(unsigned int tool, unsigned int code, void *data)
45 #ifdef ENABLE_NOTIFY_ZC_INTRINSIC
46 // The metacall type, code and data are packed together into a single
47 // struct which will be interpreted by the tool. This function is the
48 // one and only use of a "cilkscreen_metacall" annotation
49 metacall_data_t d = { tool, code, data };
51 // Note that Inspector uses probe mode, and is implementing the metacall
52 // interface to force the runtime to run with a single worker. So
53 // __cilkrts_metacall must use __notify_intrinsic instead of
54 // __notify_zc_intrinsic
55 __notify_intrinsic("cilkscreen_metacall", &d);
56 #endif // ENABLE_NOTIFY_ZC_INTRINSIC
59 int __cilkrts_running_under_sequential_ptool(void)
61 static int running_under_sequential_ptool = -1;
62 volatile char c = ~0;
64 // If we haven't been called before, see if we're running under Cilkscreen
65 // or Cilkview
66 if (-1 == running_under_sequential_ptool)
68 // metacall #2 writes 0 in C if we are running under
69 // a p-tools that requires serial execution, and is a
70 // no-op otherwise
72 // Note that removing the volatile is required to prevent the compiler
73 // from assuming that the value has not changed
74 __cilkrts_metacall(METACALL_TOOL_SYSTEM,
75 HYPER_ZERO_IF_SEQUENTIAL_PTOOL, (void *)&c);
77 running_under_sequential_ptool = (0 == c);
80 return running_under_sequential_ptool;
84 * __cilkrts_cilkscreen_establish_c_stack
86 * Notify Cilkscreen of the extent of the stack
89 void __cilkrts_cilkscreen_establish_c_stack(char *begin, char *end)
91 char *limits[2] = {begin, end};
93 __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_ESTABLISH_C_STACK, limits);
96 #ifdef WORKSPAN // Workspan stuff - remove when we're sure what we can drop
98 void __cilkview_workspan_start(void) {
99 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
102 void __cilkview_workspan_stop(void) {
103 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
106 void __cilkview_workspan_dump(const char *str) {
107 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
111 void __cilkview_workspan_reset(void) {
112 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
116 void __cilkview_use_default_grain(void) {
117 __cilkrts_metacall(HYPER_USE_DEFAULT_GRAIN, 0);
120 void __cilkview_get_workspan_data(unsigned long long *values, int size)
122 void *data[2];
124 /* reset counters to zero in case we are not running under
125 a p-tool */
127 values[0] = 0;
129 data[0] = (void*) values;
130 data[1] = (void*) &size;
131 __cilkrts_metacall(HYPER_WORKSPAN_QUERY, &data);
134 void __cilkview_workspan_connected (int *flag) {
135 *flag = 0;
136 __cilkrts_metacall(HYPER_WORKSPAN_CONNECTED, (void *)flag);
139 void __cilkview_workspan_suspend() {
140 __cilkrts_metacall(HYPER_WORKSPAN_SUSPEND, 0);
143 void __cilkview_workspan_resume() {
144 __cilkrts_metacall(HYPER_WORKSPAN_RESUME, 0);
147 /* depreciated interfaces */
148 void __cilkometer_workspan_start(void) {
149 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
152 void __cilkometer_workspan_stop(void) {
153 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
156 void __cilkometer_workspan_dump(const char *str) {
157 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
161 void __cilkometer_workspan_reset(void) {
162 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
165 #endif // WORKSPAN
167 /* End metacall_impl.c */