common.opt (fvect-cost-model): Remove RejectNegative flag...
[official-gcc.git] / libcilkrts / runtime / full_frame.c
blob5d1f2a1b5d0cfe575bddf8263abd065d7c336908
1 /* full_frame.c -*-C++-*-
3 *************************************************************************
5 * Copyright (C) 2010-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.
49 **************************************************************************/
51 #include "full_frame.h"
52 #include "stats.h"
53 #include "os.h"
54 #include "bug.h"
55 #include "jmpbuf.h"
56 #include "frame_malloc.h"
58 COMMON_PORTABLE
59 full_frame *__cilkrts_make_full_frame(__cilkrts_worker *w,
60 __cilkrts_stack_frame *sf)
62 full_frame *ff;
64 START_INTERVAL(w, INTERVAL_ALLOC_FULL_FRAME) {
65 ff = (full_frame *)__cilkrts_frame_malloc(w, sizeof(*ff));
66 __cilkrts_mutex_init(&ff->lock);
68 ff->full_frame_magic_0 = FULL_FRAME_MAGIC_0;
69 ff->join_counter = 0;
70 ff->parent = 0;
71 ff->rightmost_child = 0;
72 ff->left_sibling = ff->right_sibling = 0;
73 ff->call_stack = sf;
74 ff->is_call_child = 0;
75 ff->simulated_stolen = 0;
76 ff->children_reducer_map = ff->right_reducer_map = 0;
77 ff->pending_exception =
78 ff->child_pending_exception =
79 ff->right_pending_exception = NULL;
81 ff->sync_sp = 0;
82 #ifdef _WIN32
83 ff->exception_sp = 0;
84 ff->trylevel = (unsigned long)-1;
85 ff->registration = 0;
86 #endif
87 ff->frame_size = 0;
88 ff->fiber_self = 0;
89 ff->fiber_child = 0;
91 ff->sync_master = 0;
93 /*__cilkrts_init_full_frame_sysdep(w, ff);*/
94 ff->full_frame_magic_1 = FULL_FRAME_MAGIC_1;
95 } STOP_INTERVAL(w, INTERVAL_ALLOC_FULL_FRAME);
96 return ff;
99 COMMON_PORTABLE void __cilkrts_put_stack(full_frame *ff,
100 __cilkrts_stack_frame *sf)
102 /* When suspending frame ff prior to stealing it, __cilkrts_put_stack is
103 * used to store the stack pointer for eventual sync. When suspending
104 * frame ff prior to a sync, __cilkrts_put_stack is called to re-establish
105 * the sync stack pointer, offsetting it by any change in the stack depth
106 * that occured between the spawn and the sync.
107 * Although it is not usually meaningful to add two pointers, the value of
108 * ff->sync_sp at the time of this call is really an integer, not a
109 * pointer.
111 ptrdiff_t sync_sp_i = (ptrdiff_t) ff->sync_sp;
112 char* sp = (char*) __cilkrts_get_sp(sf);
114 ff->sync_sp = sp + sync_sp_i;
116 DBGPRINTF("%d- __cilkrts_put_stack - adjust (+) sync "
117 "stack of full frame %p (+sp: %p) to %p\n",
118 __cilkrts_get_tls_worker()->self, ff, sp, ff->sync_sp);
121 COMMON_PORTABLE void __cilkrts_take_stack(full_frame *ff, void *sp)
123 /* When resuming the parent after a steal, __cilkrts_take_stack is used to
124 * subtract the new stack pointer from the current stack pointer, storing
125 * the offset in ff->sync_sp. When resuming after a sync,
126 * __cilkrts_take_stack is used to subtract the new stack pointer from
127 * itself, leaving ff->sync_sp at zero (null). Although the pointers being
128 * subtracted are not part of the same contiguous chunk of memory, the
129 * flat memory model allows us to subtract them and get a useable offset.
131 ptrdiff_t sync_sp_i = ff->sync_sp - (char*) sp;
133 ff->sync_sp = (char *) sync_sp_i;
135 DBGPRINTF("%d- __cilkrts_take_stack - adjust (-) sync "
136 "stack of full frame %p to %p (-sp: %p)\n",
137 __cilkrts_get_tls_worker()->self, ff, ff->sync_sp, sp);
140 COMMON_PORTABLE void __cilkrts_adjust_stack(full_frame *ff, size_t size)
142 /* When resuming the parent after a steal, __cilkrts_take_stack is used to
143 * subtract the new stack pointer from the current stack pointer, storing
144 * the offset in ff->sync_sp. When resuming after a sync,
145 * __cilkrts_take_stack is used to subtract the new stack pointer from
146 * itself, leaving ff->sync_sp at zero (null). Although the pointers being
147 * subtracted are not part of the same contiguous chunk of memory, the
148 * flat memory model allows us to subtract them and get a useable offset.
150 * __cilkrts_adjust_stack() is used to deallocate a Variable Length Array
151 * by adding it's size to ff->sync_sp.
153 ff->sync_sp = ff->sync_sp + size;
155 DBGPRINTF("%d- __cilkrts_adjust_stack - adjust (+) sync "
156 "stack of full frame %p to %p (+ size: 0x%x)\n",
157 __cilkrts_get_tls_worker()->self, ff, ff->sync_sp, size);
160 COMMON_PORTABLE
161 void __cilkrts_destroy_full_frame(__cilkrts_worker *w, full_frame *ff)
163 validate_full_frame(ff);
164 CILK_ASSERT(ff->children_reducer_map == 0);
165 CILK_ASSERT(ff->right_reducer_map == 0);
166 CILK_ASSERT(NULL == ff->pending_exception);
167 CILK_ASSERT(NULL == ff->child_pending_exception);
168 CILK_ASSERT(NULL == ff->right_pending_exception);
169 __cilkrts_mutex_destroy(w, &ff->lock);
170 __cilkrts_frame_free(w, ff, sizeof(*ff));
173 COMMON_PORTABLE void validate_full_frame(full_frame *ff)
175 /* check the magic numbers, for debugging purposes */
176 if (ff->full_frame_magic_0 != FULL_FRAME_MAGIC_0 ||
177 ff->full_frame_magic_1 != FULL_FRAME_MAGIC_1)
178 abort_because_rts_is_corrupted();
181 void __cilkrts_frame_lock(__cilkrts_worker *w, full_frame *ff)
183 validate_full_frame(ff);
184 __cilkrts_mutex_lock(w, &ff->lock);
187 void __cilkrts_frame_unlock(__cilkrts_worker *w, full_frame *ff)
189 __cilkrts_mutex_unlock(w, &ff->lock);
192 /* End full_frame.c */