annotate gcc/cilk-common.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* This file is part of the Intel(R) Cilk(TM) Plus support
kono
parents:
diff changeset
2 This file contains the CilkPlus Intrinsics
kono
parents:
diff changeset
3 Copyright (C) 2013-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
4 Contributed by Balaji V. Iyer <balaji.v.iyer@intel.com>,
kono
parents:
diff changeset
5 Intel Corporation
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 This file is part of GCC.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
10 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
11 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
12 any later version.
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 GCC is distributed in the hope that it will be useful, but
kono
parents:
diff changeset
15 WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
17 General Public License for more details.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
20 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
21 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "config.h"
kono
parents:
diff changeset
24 #include "system.h"
kono
parents:
diff changeset
25 #include "coretypes.h"
kono
parents:
diff changeset
26 #include "tm.h"
kono
parents:
diff changeset
27 #include "function.h"
kono
parents:
diff changeset
28 #include "rtl.h"
kono
parents:
diff changeset
29 #include "tree.h"
kono
parents:
diff changeset
30 #include "stringpool.h"
kono
parents:
diff changeset
31 #include "expmed.h"
kono
parents:
diff changeset
32 #include "optabs-query.h"
kono
parents:
diff changeset
33 #include "insn-config.h"
kono
parents:
diff changeset
34 #include "memmodel.h"
kono
parents:
diff changeset
35 #include "emit-rtl.h"
kono
parents:
diff changeset
36 #include "recog.h"
kono
parents:
diff changeset
37 #include "fold-const.h"
kono
parents:
diff changeset
38 #include "stor-layout.h"
kono
parents:
diff changeset
39 #include "langhooks.h"
kono
parents:
diff changeset
40 #include "explow.h"
kono
parents:
diff changeset
41 #include "profile-count.h"
kono
parents:
diff changeset
42 #include "expr.h"
kono
parents:
diff changeset
43 #include "tree-iterator.h"
kono
parents:
diff changeset
44 #include "gimplify.h"
kono
parents:
diff changeset
45 #include "cilk.h"
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 /* This structure holds all the important fields of the internal structures,
kono
parents:
diff changeset
48 internal built-in functions, and Cilk-specific data types. Explanation of
kono
parents:
diff changeset
49 all the these fielsd are given in cilk.h. */
kono
parents:
diff changeset
50 tree cilk_trees[(int) CILK_TI_MAX];
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* Returns the value in structure FRAME pointed by the FIELD_NUMBER
kono
parents:
diff changeset
53 (e.g. X.y).
kono
parents:
diff changeset
54 FIELD_NUMBER is an index to the structure FRAME_PTR. For details
kono
parents:
diff changeset
55 about these fields, refer to cilk_trees structure in cilk.h and
kono
parents:
diff changeset
56 cilk_init_builtins function in this file. Returns a TREE that is the type
kono
parents:
diff changeset
57 of the field represented by FIELD_NUMBER. If VOLATIL parameter is set
kono
parents:
diff changeset
58 to true then the returning field is set as volatile. */
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 tree
kono
parents:
diff changeset
61 cilk_dot (tree frame, int field_number, bool volatil)
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 tree field = cilk_trees[field_number];
kono
parents:
diff changeset
64 field = fold_build3 (COMPONENT_REF, TREE_TYPE (field), frame, field,
kono
parents:
diff changeset
65 NULL_TREE);
kono
parents:
diff changeset
66 TREE_THIS_VOLATILE (field) = volatil;
kono
parents:
diff changeset
67 return field;
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 /* Returns the address of a field in FRAME_PTR, pointed by FIELD_NUMBER.
kono
parents:
diff changeset
71 (e.g. (&X)->y). Please see cilk_dot function for explanation of the
kono
parents:
diff changeset
72 FIELD_NUMBER. Returns a tree that is the type of the field represented
kono
parents:
diff changeset
73 by FIELD_NUMBER. If VOLATIL parameter is set to true then the returning
kono
parents:
diff changeset
74 field is set as volatile. */
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 tree
kono
parents:
diff changeset
77 cilk_arrow (tree frame_ptr, int field_number, bool volatil)
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 return cilk_dot (build_simple_mem_ref (frame_ptr),
kono
parents:
diff changeset
80 field_number, volatil);
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* This function will add FIELD of type TYPE to a defined built-in
kono
parents:
diff changeset
85 structure. *NAME is the name of the field to be added. */
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 static tree
kono
parents:
diff changeset
88 add_field (const char *name, tree type, tree fields)
kono
parents:
diff changeset
89 {
kono
parents:
diff changeset
90 tree t = get_identifier (name);
kono
parents:
diff changeset
91 tree field = build_decl (BUILTINS_LOCATION, FIELD_DECL, t, type);
kono
parents:
diff changeset
92 TREE_CHAIN (field) = fields;
kono
parents:
diff changeset
93 return field;
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 /* This function will define a built-in function of NAME, of type FNTYPE and
kono
parents:
diff changeset
97 register it under the built-in function code CODE. If PUBLISH is set then
kono
parents:
diff changeset
98 the declaration is pushed into the declaration list. CODE is the index
kono
parents:
diff changeset
99 to the cilk_trees array. *NAME is the name of the function to be added. */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 static tree
kono
parents:
diff changeset
102 install_builtin (const char *name, tree fntype, enum built_in_function code,
kono
parents:
diff changeset
103 bool publish)
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 tree fndecl = build_fn_decl (name, fntype);
kono
parents:
diff changeset
106 DECL_BUILT_IN_CLASS (fndecl) = BUILT_IN_NORMAL;
kono
parents:
diff changeset
107 DECL_FUNCTION_CODE (fndecl) = code;
kono
parents:
diff changeset
108 if (publish)
kono
parents:
diff changeset
109 {
kono
parents:
diff changeset
110 tree t = lang_hooks.decls.pushdecl (fndecl);
kono
parents:
diff changeset
111 if (t)
kono
parents:
diff changeset
112 fndecl = t;
kono
parents:
diff changeset
113 }
kono
parents:
diff changeset
114 set_builtin_decl (code, fndecl, true);
kono
parents:
diff changeset
115 return fndecl;
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* Returns a FUNCTION_DECL of type TYPE whose name is *NAME. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 static tree
kono
parents:
diff changeset
121 declare_cilk_for_builtin (const char *name, tree type,
kono
parents:
diff changeset
122 enum built_in_function code)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 tree cb, ft, fn;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 cb = build_function_type_list (void_type_node,
kono
parents:
diff changeset
127 ptr_type_node, type, type,
kono
parents:
diff changeset
128 NULL_TREE);
kono
parents:
diff changeset
129 cb = build_pointer_type (cb);
kono
parents:
diff changeset
130 ft = build_function_type_list (void_type_node,
kono
parents:
diff changeset
131 cb, ptr_type_node, type,
kono
parents:
diff changeset
132 integer_type_node, NULL_TREE);
kono
parents:
diff changeset
133 fn = install_builtin (name, ft, code, false);
kono
parents:
diff changeset
134 TREE_NOTHROW (fn) = 0;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 return fn;
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 /* Creates and initializes all the built-in Cilk keywords functions and three
kono
parents:
diff changeset
140 structures: __cilkrts_stack_frame, __cilkrts_pedigree and __cilkrts_worker.
kono
parents:
diff changeset
141 Detailed information about __cilkrts_stack_frame and
kono
parents:
diff changeset
142 __cilkrts_worker structures are given in libcilkrts/include/internal/abi.h.
kono
parents:
diff changeset
143 __cilkrts_pedigree is described in libcilkrts/include/cilk/common.h. */
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 void
kono
parents:
diff changeset
146 cilk_init_builtins (void)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 /* Now build the following __cilkrts_pedigree struct:
kono
parents:
diff changeset
149 struct __cilkrts_pedigree {
kono
parents:
diff changeset
150 uint64_t rank;
kono
parents:
diff changeset
151 struct __cilkrts_pedigree *parent;
kono
parents:
diff changeset
152 } */
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 tree pedigree_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
155 tree pedigree_ptr = build_pointer_type (pedigree_type);
kono
parents:
diff changeset
156 tree field = add_field ("rank", uint64_type_node, NULL_TREE);
kono
parents:
diff changeset
157 cilk_trees[CILK_TI_PEDIGREE_RANK] = field;
kono
parents:
diff changeset
158 field = add_field ("parent", pedigree_ptr, field);
kono
parents:
diff changeset
159 cilk_trees[CILK_TI_PEDIGREE_PARENT] = field;
kono
parents:
diff changeset
160 finish_builtin_struct (pedigree_type, "__cilkrts_pedigree_GCC", field,
kono
parents:
diff changeset
161 NULL_TREE);
kono
parents:
diff changeset
162 lang_hooks.types.register_builtin_type (pedigree_type,
kono
parents:
diff changeset
163 "__cilkrts_pedigree_t");
kono
parents:
diff changeset
164 cilk_pedigree_type_decl = pedigree_type;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 /* Build the Cilk Stack Frame:
kono
parents:
diff changeset
167 struct __cilkrts_stack_frame {
kono
parents:
diff changeset
168 uint32_t flags;
kono
parents:
diff changeset
169 uint32_t size;
kono
parents:
diff changeset
170 struct __cilkrts_stack_frame *call_parent;
kono
parents:
diff changeset
171 __cilkrts_worker *worker;
kono
parents:
diff changeset
172 void *except_data;
kono
parents:
diff changeset
173 void *ctx[4];
kono
parents:
diff changeset
174 uint32_t mxcsr;
kono
parents:
diff changeset
175 uint16_t fpcsr;
kono
parents:
diff changeset
176 uint16_t reserved;
kono
parents:
diff changeset
177 __cilkrts_pedigree pedigree;
kono
parents:
diff changeset
178 }; */
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 tree frame = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
181 tree frame_ptr = build_pointer_type (frame);
kono
parents:
diff changeset
182 tree worker_type = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
183 tree worker_ptr = build_pointer_type (worker_type);
kono
parents:
diff changeset
184 tree s_type_node = build_int_cst (size_type_node, 4);
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 tree flags = add_field ("flags", uint32_type_node, NULL_TREE);
kono
parents:
diff changeset
187 tree size = add_field ("size", uint32_type_node, flags);
kono
parents:
diff changeset
188 tree parent = add_field ("call_parent", frame_ptr, size);
kono
parents:
diff changeset
189 tree worker = add_field ("worker", worker_ptr, parent);
kono
parents:
diff changeset
190 tree except = add_field ("except_data", frame_ptr, worker);
kono
parents:
diff changeset
191 tree context = add_field ("ctx",
kono
parents:
diff changeset
192 build_array_type (ptr_type_node,
kono
parents:
diff changeset
193 build_index_type (s_type_node)),
kono
parents:
diff changeset
194 except);
kono
parents:
diff changeset
195 tree mxcsr = add_field ("mxcsr", uint32_type_node, context);
kono
parents:
diff changeset
196 tree fpcsr = add_field ("fpcsr", uint16_type_node, mxcsr);
kono
parents:
diff changeset
197 tree reserved = add_field ("reserved", uint16_type_node, fpcsr);
kono
parents:
diff changeset
198 tree pedigree = add_field ("pedigree", pedigree_type, reserved);
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 /* Now add them to a common structure whose fields are #defined to something
kono
parents:
diff changeset
201 that is used at a later stage. */
kono
parents:
diff changeset
202 cilk_trees[CILK_TI_FRAME_FLAGS] = flags;
kono
parents:
diff changeset
203 cilk_trees[CILK_TI_FRAME_PARENT] = parent;
kono
parents:
diff changeset
204 cilk_trees[CILK_TI_FRAME_WORKER] = worker;
kono
parents:
diff changeset
205 cilk_trees[CILK_TI_FRAME_EXCEPTION] = except;
kono
parents:
diff changeset
206 cilk_trees[CILK_TI_FRAME_CONTEXT] = context;
kono
parents:
diff changeset
207 /* We don't care about reserved, so no need to store it in cilk_trees. */
kono
parents:
diff changeset
208 cilk_trees[CILK_TI_FRAME_PEDIGREE] = pedigree;
kono
parents:
diff changeset
209 TREE_ADDRESSABLE (frame) = 1;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 finish_builtin_struct (frame, "__cilkrts_st_frame_GCC", pedigree, NULL_TREE);
kono
parents:
diff changeset
212 cilk_frame_type_decl = frame;
kono
parents:
diff changeset
213 lang_hooks.types.register_builtin_type (frame, "__cilkrts_frame_t");
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 cilk_frame_ptr_type_decl = build_qualified_type (frame_ptr,
kono
parents:
diff changeset
216 TYPE_QUAL_VOLATILE);
kono
parents:
diff changeset
217 /* Now let's do the following worker struct:
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 struct __cilkrts_worker {
kono
parents:
diff changeset
220 __cilkrts_stack_frame *volatile *volatile tail;
kono
parents:
diff changeset
221 __cilkrts_stack_frame *volatile *volatile head;
kono
parents:
diff changeset
222 __cilkrts_stack_frame *volatile *volatile exc;
kono
parents:
diff changeset
223 __cilkrts_stack_frame *volatile *volatile protected_tail;
kono
parents:
diff changeset
224 __cilkrts_stack_frame *volatile *ltq_limit;
kono
parents:
diff changeset
225 int32_t self;
kono
parents:
diff changeset
226 global_state_t *g;
kono
parents:
diff changeset
227 local_state *l;
kono
parents:
diff changeset
228 cilkred_map *reducer_map;
kono
parents:
diff changeset
229 __cilkrts_stack_frame *current_stack_frame;
kono
parents:
diff changeset
230 void *reserved;
kono
parents:
diff changeset
231 __cilkrts_worker_sysdep_state *sysdep;
kono
parents:
diff changeset
232 __cilkrts_pedigree pedigree;
kono
parents:
diff changeset
233 } */
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 tree fptr_volatil_type = build_qualified_type (frame_ptr, TYPE_QUAL_VOLATILE);
kono
parents:
diff changeset
236 tree fptr_volatile_ptr = build_pointer_type (fptr_volatil_type);
kono
parents:
diff changeset
237 tree fptr_vol_ptr_vol = build_qualified_type (fptr_volatile_ptr,
kono
parents:
diff changeset
238 TYPE_QUAL_VOLATILE);
kono
parents:
diff changeset
239 tree g = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
240 finish_builtin_struct (g, "__cilkrts_global_state", NULL_TREE, NULL_TREE);
kono
parents:
diff changeset
241 tree l = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
242 finish_builtin_struct (l, "__cilkrts_local_state", NULL_TREE, NULL_TREE);
kono
parents:
diff changeset
243 tree sysdep_t = lang_hooks.types.make_type (RECORD_TYPE);
kono
parents:
diff changeset
244 finish_builtin_struct (sysdep_t, "__cilkrts_worker_sysdep_state", NULL_TREE,
kono
parents:
diff changeset
245 NULL_TREE);
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 field = add_field ("tail", fptr_vol_ptr_vol, NULL_TREE);
kono
parents:
diff changeset
248 cilk_trees[CILK_TI_WORKER_TAIL] = field;
kono
parents:
diff changeset
249 field = add_field ("head", fptr_vol_ptr_vol, field);
kono
parents:
diff changeset
250 field = add_field ("exc", fptr_vol_ptr_vol, field);
kono
parents:
diff changeset
251 field = add_field ("protected_tail", fptr_vol_ptr_vol, field);
kono
parents:
diff changeset
252 field = add_field ("ltq_limit", fptr_volatile_ptr, field);
kono
parents:
diff changeset
253 field = add_field ("self", integer_type_node, field);
kono
parents:
diff changeset
254 field = add_field ("g", build_pointer_type (g), field);
kono
parents:
diff changeset
255 field = add_field ("l", build_pointer_type (g), field);
kono
parents:
diff changeset
256 field = add_field ("reducer_map", ptr_type_node, field);
kono
parents:
diff changeset
257 field = add_field ("current_stack_frame", frame_ptr, field);
kono
parents:
diff changeset
258 cilk_trees[CILK_TI_WORKER_CUR] = field;
kono
parents:
diff changeset
259 field = add_field ("saved_protected_tail", fptr_volatile_ptr, field);
kono
parents:
diff changeset
260 field = add_field ("sysdep", build_pointer_type (sysdep_t), field);
kono
parents:
diff changeset
261 field = add_field ("pedigree", pedigree_type, field);
kono
parents:
diff changeset
262 cilk_trees[CILK_TI_WORKER_PEDIGREE] = field;
kono
parents:
diff changeset
263 finish_builtin_struct (worker_type, "__cilkrts_worker_GCC", field,
kono
parents:
diff changeset
264 NULL_TREE);
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 tree fptr_arglist = tree_cons (NULL_TREE, frame_ptr, void_list_node);
kono
parents:
diff changeset
267 tree fptr_fun = build_function_type (void_type_node, fptr_arglist);
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 /* void __cilkrts_enter_frame_1 (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
270 cilk_enter_fndecl = install_builtin ("__cilkrts_enter_frame_1", fptr_fun,
kono
parents:
diff changeset
271 BUILT_IN_CILK_ENTER_FRAME, false);
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 /* void __cilkrts_enter_frame_fast_1 (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
274 cilk_enter_fast_fndecl =
kono
parents:
diff changeset
275 install_builtin ("__cilkrts_enter_frame_fast_1", fptr_fun,
kono
parents:
diff changeset
276 BUILT_IN_CILK_ENTER_FRAME_FAST, false);
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 /* void __cilkrts_pop_frame (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
279 cilk_pop_fndecl = install_builtin ("__cilkrts_pop_frame", fptr_fun,
kono
parents:
diff changeset
280 BUILT_IN_CILK_POP_FRAME, false);
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 /* void __cilkrts_leave_frame (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
283 cilk_leave_fndecl = install_builtin ("__cilkrts_leave_frame", fptr_fun,
kono
parents:
diff changeset
284 BUILT_IN_CILK_LEAVE_FRAME, false);
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 /* void __cilkrts_sync (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
287 cilk_sync_fndecl = install_builtin ("__cilkrts_sync", fptr_fun,
kono
parents:
diff changeset
288 BUILT_IN_CILK_SYNC, false);
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 /* void __cilkrts_detach (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
291 cilk_detach_fndecl = install_builtin ("__cilkrts_detach", fptr_fun,
kono
parents:
diff changeset
292 BUILT_IN_CILK_DETACH, false);
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 /* __cilkrts_rethrow (struct stack_frame *); */
kono
parents:
diff changeset
295 cilk_rethrow_fndecl = install_builtin ("__cilkrts_rethrow", fptr_fun,
kono
parents:
diff changeset
296 BUILT_IN_CILK_RETHROW, false);
kono
parents:
diff changeset
297 TREE_NOTHROW (cilk_rethrow_fndecl) = 0;
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 /* __cilkrts_save_fp_ctrl_state (__cilkrts_stack_frame *); */
kono
parents:
diff changeset
300 cilk_save_fp_fndecl = install_builtin ("__cilkrts_save_fp_ctrl_state",
kono
parents:
diff changeset
301 fptr_fun, BUILT_IN_CILK_SAVE_FP,
kono
parents:
diff changeset
302 false);
kono
parents:
diff changeset
303 /* __cilkrts_cilk_for_32 (...); */
kono
parents:
diff changeset
304 cilk_for_32_fndecl = declare_cilk_for_builtin ("__cilkrts_cilk_for_32",
kono
parents:
diff changeset
305 unsigned_intSI_type_node,
kono
parents:
diff changeset
306 BUILT_IN_CILK_FOR_32);
kono
parents:
diff changeset
307 /* __cilkrts_cilk_for_64 (...); */
kono
parents:
diff changeset
308 cilk_for_64_fndecl = declare_cilk_for_builtin ("__cilkrts_cilk_for_64",
kono
parents:
diff changeset
309 unsigned_intDI_type_node,
kono
parents:
diff changeset
310 BUILT_IN_CILK_FOR_64);
kono
parents:
diff changeset
311 }
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 /* Get the appropriate frame arguments for CALL that is of type CALL_EXPR. */
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 static tree
kono
parents:
diff changeset
316 get_frame_arg (tree call)
kono
parents:
diff changeset
317 {
kono
parents:
diff changeset
318 tree arg, argtype;
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 gcc_assert (call_expr_nargs (call) >= 1);
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 arg = CALL_EXPR_ARG (call, 0);
kono
parents:
diff changeset
323 argtype = TREE_TYPE (arg);
kono
parents:
diff changeset
324 gcc_assert (TREE_CODE (argtype) == POINTER_TYPE);
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 argtype = TREE_TYPE (argtype);
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 /* If it is passed in as an address, then just use the value directly
kono
parents:
diff changeset
329 since the function is inlined. */
kono
parents:
diff changeset
330 if (TREE_CODE (arg) == ADDR_EXPR)
kono
parents:
diff changeset
331 return TREE_OPERAND (arg, 0);
kono
parents:
diff changeset
332 return arg;
kono
parents:
diff changeset
333 }
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 /* Expands the __cilkrts_pop_frame function call stored in EXP. */
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 void
kono
parents:
diff changeset
338 expand_builtin_cilk_pop_frame (tree exp)
kono
parents:
diff changeset
339 {
kono
parents:
diff changeset
340 tree frame = get_frame_arg (exp);
kono
parents:
diff changeset
341 tree parent = cilk_dot (frame, CILK_TI_FRAME_PARENT, 0);
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 tree clear_parent = build2 (MODIFY_EXPR, void_type_node, parent,
kono
parents:
diff changeset
344 build_int_cst (TREE_TYPE (parent), 0));
kono
parents:
diff changeset
345 expand_expr (clear_parent, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 /* During LTO, the is_cilk_function flag gets cleared.
kono
parents:
diff changeset
348 If __cilkrts_pop_frame is called, then this definitely must be a
kono
parents:
diff changeset
349 cilk function. */
kono
parents:
diff changeset
350 if (cfun)
kono
parents:
diff changeset
351 cfun->is_cilk_function = 1;
kono
parents:
diff changeset
352 }
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 /* Expands the cilk_detach function call stored in EXP. */
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 void
kono
parents:
diff changeset
357 expand_builtin_cilk_detach (tree exp)
kono
parents:
diff changeset
358 {
kono
parents:
diff changeset
359 rtx_insn *insn;
kono
parents:
diff changeset
360 tree fptr = get_frame_arg (exp);
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 if (fptr == NULL_TREE)
kono
parents:
diff changeset
363 return;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 tree parent = cilk_dot (fptr, CILK_TI_FRAME_PARENT, 0);
kono
parents:
diff changeset
366 tree worker = cilk_dot (fptr, CILK_TI_FRAME_WORKER, 0);
kono
parents:
diff changeset
367 tree tail = cilk_arrow (worker, CILK_TI_WORKER_TAIL, 1);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 tree faddr = build1 (ADDR_EXPR, cilk_frame_ptr_type_decl, fptr);
kono
parents:
diff changeset
370 tree enter_frame = build_call_expr (cilk_enter_fast_fndecl, 1, faddr);
kono
parents:
diff changeset
371 expand_expr (enter_frame, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 tree pedigree = cilk_dot (fptr, CILK_TI_FRAME_PEDIGREE, 0);
kono
parents:
diff changeset
374 tree pedigree_rank = cilk_dot (pedigree, CILK_TI_PEDIGREE_RANK, 0);
kono
parents:
diff changeset
375 tree parent_pedigree = cilk_dot (pedigree, CILK_TI_PEDIGREE_PARENT, 0);
kono
parents:
diff changeset
376 tree pedigree_parent = cilk_arrow (parent, CILK_TI_FRAME_PEDIGREE, 0);
kono
parents:
diff changeset
377 tree pedigree_parent_rank = cilk_dot (pedigree_parent,
kono
parents:
diff changeset
378 CILK_TI_PEDIGREE_RANK, 0);
kono
parents:
diff changeset
379 tree pedigree_parent_parent = cilk_dot (pedigree_parent,
kono
parents:
diff changeset
380 CILK_TI_PEDIGREE_PARENT, 0);
kono
parents:
diff changeset
381 tree worker_pedigree = cilk_arrow (worker, CILK_TI_WORKER_PEDIGREE, 1);
kono
parents:
diff changeset
382 tree w_pedigree_rank = cilk_dot (worker_pedigree, CILK_TI_PEDIGREE_RANK, 0);
kono
parents:
diff changeset
383 tree w_pedigree_parent = cilk_dot (worker_pedigree,
kono
parents:
diff changeset
384 CILK_TI_PEDIGREE_PARENT, 0);
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 rtx wreg = expand_expr (worker, NULL_RTX, Pmode, EXPAND_NORMAL);
kono
parents:
diff changeset
387 if (GET_CODE (wreg) != REG)
kono
parents:
diff changeset
388 wreg = copy_to_reg (wreg);
kono
parents:
diff changeset
389 rtx preg = expand_expr (parent, NULL_RTX, Pmode, EXPAND_NORMAL);
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 /* sf.pedigree.rank = worker->pedigree.rank. */
kono
parents:
diff changeset
392 tree exp1 = build2 (MODIFY_EXPR, void_type_node, pedigree_rank,
kono
parents:
diff changeset
393 w_pedigree_rank);
kono
parents:
diff changeset
394 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 /* sf.pedigree.parent = worker->pedigree.parent. */
kono
parents:
diff changeset
397 exp1 = build2 (MODIFY_EXPR, void_type_node, parent_pedigree,
kono
parents:
diff changeset
398 w_pedigree_parent);
kono
parents:
diff changeset
399 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 /* sf.call_parent->pedigree.rank = worker->pedigree.rank. */
kono
parents:
diff changeset
402 exp1 = build2 (MODIFY_EXPR, void_type_node, pedigree_parent_rank,
kono
parents:
diff changeset
403 w_pedigree_rank);
kono
parents:
diff changeset
404 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
405
kono
parents:
diff changeset
406 /* sf.call_parent->pedigree.parent = worker->pedigree.parent. */
kono
parents:
diff changeset
407 exp1 = build2 (MODIFY_EXPR, void_type_node, pedigree_parent_parent,
kono
parents:
diff changeset
408 w_pedigree_parent);
kono
parents:
diff changeset
409 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 /* sf->worker.pedigree.rank = 0. */
kono
parents:
diff changeset
412 exp1 = build2 (MODIFY_EXPR, void_type_node, w_pedigree_rank,
kono
parents:
diff changeset
413 build_zero_cst (uint64_type_node));
kono
parents:
diff changeset
414 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 /* sf->pedigree.parent = &sf->pedigree. */
kono
parents:
diff changeset
417 exp1 = build2 (MODIFY_EXPR, void_type_node, w_pedigree_parent,
kono
parents:
diff changeset
418 build1 (ADDR_EXPR,
kono
parents:
diff changeset
419 build_pointer_type (cilk_pedigree_type_decl),
kono
parents:
diff changeset
420 pedigree));
kono
parents:
diff changeset
421 expand_expr (exp1, const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 /* TMP <- WORKER.TAIL
kono
parents:
diff changeset
424 *TMP <- PARENT
kono
parents:
diff changeset
425 TMP <- TMP + 1
kono
parents:
diff changeset
426 WORKER.TAIL <- TMP */
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 HOST_WIDE_INT worker_tail_offset =
kono
parents:
diff changeset
429 tree_to_shwi (DECL_FIELD_OFFSET (cilk_trees[CILK_TI_WORKER_TAIL])) +
kono
parents:
diff changeset
430 tree_to_shwi (DECL_FIELD_BIT_OFFSET (cilk_trees[CILK_TI_WORKER_TAIL])) /
kono
parents:
diff changeset
431 BITS_PER_UNIT;
kono
parents:
diff changeset
432 rtx tmem0 = gen_rtx_MEM (Pmode,
kono
parents:
diff changeset
433 plus_constant (Pmode, wreg, worker_tail_offset));
kono
parents:
diff changeset
434 set_mem_attributes (tmem0, tail, 0);
kono
parents:
diff changeset
435 MEM_NOTRAP_P (tmem0) = 1;
kono
parents:
diff changeset
436 gcc_assert (MEM_VOLATILE_P (tmem0));
kono
parents:
diff changeset
437 rtx treg = copy_to_mode_reg (Pmode, tmem0);
kono
parents:
diff changeset
438 rtx tmem1 = gen_rtx_MEM (Pmode, treg);
kono
parents:
diff changeset
439 set_mem_attributes (tmem1, TREE_TYPE (TREE_TYPE (tail)), 0);
kono
parents:
diff changeset
440 MEM_NOTRAP_P (tmem1) = 1;
kono
parents:
diff changeset
441 emit_move_insn (tmem1, preg);
kono
parents:
diff changeset
442 emit_move_insn (treg, plus_constant (Pmode, treg, GET_MODE_SIZE (Pmode)));
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 /* There is a release barrier (st8.rel, membar #StoreStore,
kono
parents:
diff changeset
445 sfence, lwsync, etc.) between the two stores. On x86
kono
parents:
diff changeset
446 normal volatile stores have proper semantics; the sfence
kono
parents:
diff changeset
447 would only be needed for nontemporal stores (which we
kono
parents:
diff changeset
448 could generate using the storent optab, for no benefit
kono
parents:
diff changeset
449 in this case).
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 The predicate may return false even for a REG if this is
kono
parents:
diff changeset
452 the limited release operation that only stores 0. */
kono
parents:
diff changeset
453 enum insn_code icode = direct_optab_handler (sync_lock_release_optab, Pmode);
kono
parents:
diff changeset
454 if (icode != CODE_FOR_nothing
kono
parents:
diff changeset
455 && insn_data[icode].operand[1].predicate (treg, Pmode)
kono
parents:
diff changeset
456 && (insn = GEN_FCN (icode) (tmem0, treg)) != NULL_RTX)
kono
parents:
diff changeset
457 emit_insn (insn);
kono
parents:
diff changeset
458 else
kono
parents:
diff changeset
459 emit_move_insn (tmem0, treg);
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 /* The memory barrier inserted above should not prevent
kono
parents:
diff changeset
462 the load of flags from being moved before the stores,
kono
parents:
diff changeset
463 but in practice it does because it is implemented with
kono
parents:
diff changeset
464 unspec_volatile. In-order RISC machines should
kono
parents:
diff changeset
465 explicitly load flags earlier. */
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 tree flags = cilk_dot (fptr, CILK_TI_FRAME_FLAGS, 0);
kono
parents:
diff changeset
468 expand_expr (build2 (MODIFY_EXPR, void_type_node, flags,
kono
parents:
diff changeset
469 build2 (BIT_IOR_EXPR, TREE_TYPE (flags), flags,
kono
parents:
diff changeset
470 build_int_cst (TREE_TYPE (flags),
kono
parents:
diff changeset
471 CILK_FRAME_DETACHED))),
kono
parents:
diff changeset
472 const0_rtx, VOIDmode, EXPAND_NORMAL);
kono
parents:
diff changeset
473 }
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 /* Returns a setjmp CALL_EXPR with FRAME->context as its parameter. */
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 tree
kono
parents:
diff changeset
478 cilk_call_setjmp (tree frame)
kono
parents:
diff changeset
479 {
kono
parents:
diff changeset
480 tree c = cilk_dot (frame, CILK_TI_FRAME_CONTEXT, false);
kono
parents:
diff changeset
481 c = build1 (ADDR_EXPR, build_pointer_type (ptr_type_node), c);
kono
parents:
diff changeset
482 return build_call_expr (builtin_decl_implicit (BUILT_IN_SETJMP), 1, c);
kono
parents:
diff changeset
483 }
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 /* This function will expand the _Cilk_sync keyword. */
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 static tree
kono
parents:
diff changeset
488 expand_cilk_sync (void)
kono
parents:
diff changeset
489 {
kono
parents:
diff changeset
490 tree frame = cfun->cilk_frame_decl;
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 /* Cilk_sync is converted to the following code:
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 sf.pedigree = sf.worker->pedigree;
kono
parents:
diff changeset
495 if (frame.flags & CILK_FRAME_UNSYNCHED)
kono
parents:
diff changeset
496 {
kono
parents:
diff changeset
497 __cilkrts_save_fp_state (&sf);
kono
parents:
diff changeset
498 if (!builtin_setjmp (sf.ctx)
kono
parents:
diff changeset
499 __cilkrts_sync (&sf);
kono
parents:
diff changeset
500 else
kono
parents:
diff changeset
501 if (sf.flags & CILK_FRAME_EXCEPTING)
kono
parents:
diff changeset
502 __cilkrts_rethrow (&sf);
kono
parents:
diff changeset
503 }
kono
parents:
diff changeset
504 sf.worker->pedigree.rank = sf.worker->pedigree.rank + 1; */
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 tree flags = cilk_dot (frame, CILK_TI_FRAME_FLAGS, false);
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 tree unsynched = fold_build2 (BIT_AND_EXPR, TREE_TYPE (flags), flags,
kono
parents:
diff changeset
509 build_int_cst (TREE_TYPE (flags),
kono
parents:
diff changeset
510 CILK_FRAME_UNSYNCHED));
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 unsynched = fold_build2 (NE_EXPR, TREE_TYPE (unsynched), unsynched,
kono
parents:
diff changeset
513 build_int_cst (TREE_TYPE (unsynched), 0));
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 tree frame_addr = build1 (ADDR_EXPR, cilk_frame_ptr_type_decl, frame);
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 /* Check if exception (0x10) bit is set in the sf->flags. */
kono
parents:
diff changeset
518 tree except_flag = fold_build2 (BIT_AND_EXPR, TREE_TYPE (flags), flags,
kono
parents:
diff changeset
519 build_int_cst (TREE_TYPE (flags),
kono
parents:
diff changeset
520 CILK_FRAME_EXCEPTING));
kono
parents:
diff changeset
521 except_flag = fold_build2 (NE_EXPR, TREE_TYPE (except_flag), except_flag,
kono
parents:
diff changeset
522 build_int_cst (TREE_TYPE (except_flag), 0));
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 /* If the exception flag is set then call the __cilkrts_rethrow (&sf). */
kono
parents:
diff changeset
525 tree except_cond = fold_build3 (COND_EXPR, void_type_node, except_flag,
kono
parents:
diff changeset
526 build_call_expr (cilk_rethrow_fndecl, 1,
kono
parents:
diff changeset
527 frame_addr),
kono
parents:
diff changeset
528 build_empty_stmt (EXPR_LOCATION (unsynched)));
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 tree sync_expr = build_call_expr (cilk_sync_fndecl, 1, frame_addr);
kono
parents:
diff changeset
531 tree setjmp_expr = cilk_call_setjmp (frame);
kono
parents:
diff changeset
532 setjmp_expr = fold_build2 (EQ_EXPR, TREE_TYPE (setjmp_expr), setjmp_expr,
kono
parents:
diff changeset
533 build_int_cst (TREE_TYPE (setjmp_expr), 0));
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 setjmp_expr = fold_build3 (COND_EXPR, void_type_node, setjmp_expr,
kono
parents:
diff changeset
536 sync_expr, except_cond);
kono
parents:
diff changeset
537 tree sync_list = alloc_stmt_list ();
kono
parents:
diff changeset
538 append_to_statement_list (build_call_expr (cilk_save_fp_fndecl, 1,
kono
parents:
diff changeset
539 frame_addr), &sync_list);
kono
parents:
diff changeset
540 append_to_statement_list (setjmp_expr, &sync_list);
kono
parents:
diff changeset
541 tree sync = fold_build3 (COND_EXPR, void_type_node, unsynched, sync_list,
kono
parents:
diff changeset
542 build_empty_stmt (EXPR_LOCATION (unsynched)));
kono
parents:
diff changeset
543 tree parent_pedigree = cilk_dot (frame, CILK_TI_FRAME_PEDIGREE, false);
kono
parents:
diff changeset
544 tree worker = cilk_dot (frame, CILK_TI_FRAME_WORKER, false);
kono
parents:
diff changeset
545 tree worker_pedigree = cilk_arrow (worker, CILK_TI_WORKER_PEDIGREE, false);
kono
parents:
diff changeset
546 tree assign_pedigree = fold_build2 (MODIFY_EXPR, void_type_node,
kono
parents:
diff changeset
547 parent_pedigree, worker_pedigree);
kono
parents:
diff changeset
548 tree w_ped_rank = cilk_dot (unshare_expr (worker_pedigree),
kono
parents:
diff changeset
549 CILK_TI_PEDIGREE_RANK, false);
kono
parents:
diff changeset
550 tree incr_ped_rank = fold_build2 (PLUS_EXPR, TREE_TYPE (w_ped_rank),
kono
parents:
diff changeset
551 w_ped_rank,
kono
parents:
diff changeset
552 build_one_cst (TREE_TYPE (w_ped_rank)));
kono
parents:
diff changeset
553 incr_ped_rank = fold_build2 (MODIFY_EXPR, void_type_node, w_ped_rank,
kono
parents:
diff changeset
554 incr_ped_rank);
kono
parents:
diff changeset
555 tree ret_sync_exp = alloc_stmt_list ();
kono
parents:
diff changeset
556 append_to_statement_list (assign_pedigree, &ret_sync_exp);
kono
parents:
diff changeset
557 append_to_statement_list (sync, &ret_sync_exp);
kono
parents:
diff changeset
558 append_to_statement_list (incr_ped_rank, &ret_sync_exp);
kono
parents:
diff changeset
559 return ret_sync_exp;
kono
parents:
diff changeset
560 }
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 /* Gimplifies the cilk_sync expression passed in *EXPR_P. Returns GS_ALL_DONE
kono
parents:
diff changeset
563 when finished. */
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 void
kono
parents:
diff changeset
566 gimplify_cilk_sync (tree *expr_p, gimple_seq *pre_p)
kono
parents:
diff changeset
567 {
kono
parents:
diff changeset
568 tree sync_expr = expand_cilk_sync ();
kono
parents:
diff changeset
569 *expr_p = NULL_TREE;
kono
parents:
diff changeset
570 gimplify_and_add (sync_expr, pre_p);
kono
parents:
diff changeset
571 }