cilk-common.c 19 KB

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