[gcc/testsuite]
[official-gcc.git] / libcilkrts / runtime / metacall_impl.c
blobe5b3f0f9d8b8379daa978ae66f3bfc5b5581b475
1 /* metacall_impl.c -*-C-*-
3 *************************************************************************
5 * Copyright (C) 2009-2016, Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * *********************************************************************
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
38 * a repository at cilkplus.org. Changes made to this file that are not
39 * submitted through the contribution process detailed at
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
41 * time that a new version is released. Changes only submitted to the
42 * GNU compiler collection or posted to the git repository at
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
44 * not tracked.
46 * We welcome your contributions to this open source project. Thank you
47 * for your assistance in helping us improve Cilk Plus.
48 **************************************************************************/
50 #include "metacall_impl.h"
52 NOINLINE
53 CILK_API_VOID
54 __cilkrts_metacall(unsigned int tool, unsigned int code, void *data)
56 #ifdef ENABLE_NOTIFY_ZC_INTRINSIC
57 // The metacall type, code and data are packed together into a single
58 // struct which will be interpreted by the tool. This function is the
59 // one and only use of a "cilkscreen_metacall" annotation
60 metacall_data_t d = { tool, code, data };
62 // Note that Inspector uses probe mode, and is implementing the metacall
63 // interface to force the runtime to run with a single worker. So
64 // __cilkrts_metacall must use __notify_intrinsic instead of
65 // __notify_zc_intrinsic
66 __notify_intrinsic("cilkscreen_metacall", &d);
67 #endif // ENABLE_NOTIFY_ZC_INTRINSIC
70 int __cilkrts_running_under_sequential_ptool(void)
72 static int running_under_sequential_ptool = -1;
73 volatile char c = ~0;
75 // If we haven't been called before, see if we're running under Cilkscreen
76 // or Cilkview
77 if (-1 == running_under_sequential_ptool)
79 // metacall #2 writes 0 in C if we are running under
80 // a p-tools that requires serial execution, and is a
81 // no-op otherwise
83 // Note that removing the volatile is required to prevent the compiler
84 // from assuming that the value has not changed
85 __cilkrts_metacall(METACALL_TOOL_SYSTEM,
86 HYPER_ZERO_IF_SEQUENTIAL_PTOOL, (void *)&c);
88 running_under_sequential_ptool = (0 == c);
91 return running_under_sequential_ptool;
95 * __cilkrts_cilkscreen_establish_c_stack
97 * Notify Cilkscreen of the extent of the stack
100 void __cilkrts_cilkscreen_establish_c_stack(char *begin, char *end)
102 char *limits[2] = {begin, end};
104 __cilkrts_metacall(METACALL_TOOL_SYSTEM, HYPER_ESTABLISH_C_STACK, limits);
107 #ifdef WORKSPAN // Workspan stuff - remove when we're sure what we can drop
109 void __cilkview_workspan_start(void) {
110 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
113 void __cilkview_workspan_stop(void) {
114 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
117 void __cilkview_workspan_dump(const char *str) {
118 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
122 void __cilkview_workspan_reset(void) {
123 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
127 void __cilkview_use_default_grain(void) {
128 __cilkrts_metacall(HYPER_USE_DEFAULT_GRAIN, 0);
131 void __cilkview_get_workspan_data(unsigned long long *values, int size)
133 void *data[2];
135 /* reset counters to zero in case we are not running under
136 a p-tool */
138 values[0] = 0;
140 data[0] = (void*) values;
141 data[1] = (void*) &size;
142 __cilkrts_metacall(HYPER_WORKSPAN_QUERY, &data);
145 void __cilkview_workspan_connected (int *flag) {
146 *flag = 0;
147 __cilkrts_metacall(HYPER_WORKSPAN_CONNECTED, (void *)flag);
150 void __cilkview_workspan_suspend() {
151 __cilkrts_metacall(HYPER_WORKSPAN_SUSPEND, 0);
154 void __cilkview_workspan_resume() {
155 __cilkrts_metacall(HYPER_WORKSPAN_RESUME, 0);
158 /* depreciated interfaces */
159 void __cilkometer_workspan_start(void) {
160 __cilkrts_metacall(HYPER_WORKSPAN_START, 0);
163 void __cilkometer_workspan_stop(void) {
164 __cilkrts_metacall(HYPER_WORKSPAN_STOP, 0);
167 void __cilkometer_workspan_dump(const char *str) {
168 __cilkrts_metacall(HYPER_WORKSPAN_DUMP, (void*)str);
172 void __cilkometer_workspan_reset(void) {
173 __cilkrts_metacall(HYPER_WORKSPAN_RESET, 0);
176 #endif // WORKSPAN
178 /* End metacall_impl.c */