diff options
author | Balaji V. Iyer <balaji.v.iyer@intel.com> | 2013-12-11 18:23:27 +0000 |
---|---|---|
committer | Balaji V. Iyer <bviyer@gcc.gnu.org> | 2013-12-11 10:23:27 -0800 |
commit | 12893402ec1718a978e540eb1f6bd9c32a4555ab (patch) | |
tree | 9072ab2966c9b71528a27a7a515b6a3bd19545b2 /gcc/cp/cp-cilkplus.c | |
parent | 996947e67d449d87376e12b389485c5f1cc76f48 (diff) | |
download | gcc-12893402ec1718a978e540eb1f6bd9c32a4555ab.zip gcc-12893402ec1718a978e540eb1f6bd9c32a4555ab.tar.gz gcc-12893402ec1718a978e540eb1f6bd9c32a4555ab.tar.bz2 |
Added Compiler Support for _Cilk_spawn and _Cilk_sync for C++.
gcc/c-family/ChangeLog
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* cilk.c (cilk_outline): Made this function non-static.
(gimplify_cilk_spawn): Removed pre_p and post_p arguments.
(create_cilk_wrapper): Added a new parameter: a function pointer.
(c_install_body_w_frame_cleanup): Remove
(extract_free_variables): Added VEC_INIT_EXPR and CONSTRUCTOR case.
* c-common.h (cilk_outline): New prototype.
(gimplify_cilk_spawn): Removed two parameters.
(cilk_install_body_with_frame_cleanup): New prototype.
* c-gimplify.c (c_gimplify_expr): Added MODIFY_EXPR, CALL_EXPR and
CILK_SPAWN_STMT case.
gcc/c/ChangeLog
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* c-objc-common.h (LANG_HOOKS_CILKPLUS_FRAME_CLEANUP): Remove.
(LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP): Likewise.
(LANG_HOOKS_CILKPLUS_CILKPLUS_GIMPLIFY_SPAWN): Likewise.
* c-typeck.c (cilk_install_body_with_frame_cleanup): New function.
gcc/ChangeLog
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* langhooks.h (lang_hooks_for_decls): Remove lang_hooks_for_cilkplus.
(lang_hooks_for_cilkplus): Remove.
* langhooks.c (lhd_cilk_detect_spawn): Likewise.
(lhd_install_body_with_frame_cleanup): Likewise.
* langhooks-def.h (LANG_HOOKS_CILKPLUS_FRAME_CLEANUP): Likewise.
(LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP): Likewise.
(LANG_HOOKS_CILKPLUS_CILKPLUS_GIMPLIFY_SPAWN): Likewise.
(LANG_HOOKS_CILKPLUS): Likewise.
(LANG_HOOKS_DECLS): Remove LANG_HOOKS_CILKPLUS.
* gimplify.c (gimplify_expr): Removed CILK_SPAWN_STMT case.
(gimplify_modify_expr): Removed handling of _Cilk_spawn in expr.
(gimplify_call_expr): Likewise.
gcc/cp/ChangeLog
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* cp-tree.h (cilk_valid_spawn): New prototype.
(gimplify_cilk_spawn): Likewise.
(create_try_catch_expr): Likewise.
* decl.c (finish_function): Insert Cilk function-calls when a
_Cilk_spawn is used in a function.
* parser.c (cp_parser_postfix_expression): Added RID_CILK_SPAWN and
RID_CILK_SYNC cases.
* cp-cilkplus.c (set_cilk_except_flag): New function.
(set_cilk_except_data): Likewise.
(cilk_install_body_with_frame_cleanup): Likewise.
* except.c (create_try_catch_expr): Likewise.
* parser.h (IN_CILK_SPAWN): New #define.
* pt.c (tsubst_expr): Added CILK_SPAWN_STMT and CILK_SYNC_STMT cases.
* semantics.c (potential_constant_expression_1): Likewise.
* typeck.c (cp_build_compound_expr): Reject a spawned function in a
compound expression.
(check_return_expr): Reject a spawned function in a return expression.
* cp-gimplify.c (cp_gimplify_expr): Added a CILK_SPAWN_STMT and
CALL_EXPR case. Added handling of spawned function in MODIFY_EXPR
and INIT_EXPR.
gcc/testsuite/ChangeLog
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* g++.dg/cilk-plus/CK/catch_exc.cc: New test case.
* g++.dg/cilk-plus/CK/const_spawn.cc: Likewise.
* g++.dg/cilk-plus/CK/fib-opr-overload.cc: Likewise.
* g++.dg/cilk-plus/CK/fib-tplt.cc: Likewise.
* g++.dg/cilk-plus/CK/lambda_spawns.cc: Likewise.
* g++.dg/cilk-plus/CK/lambda_spawns_tplt.cc: Likewise.
* g++.dg/cilk-plus/cilk-plus.exp: Added support to run Cilk Keywords
test stored in c-c++-common. Also, added the Cilk runtime's library
to the ld_library_path.
From-SVN: r205902
Diffstat (limited to 'gcc/cp/cp-cilkplus.c')
-rw-r--r-- | gcc/cp/cp-cilkplus.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/gcc/cp/cp-cilkplus.c b/gcc/cp/cp-cilkplus.c index 5c1090a..d3f3323 100644 --- a/gcc/cp/cp-cilkplus.c +++ b/gcc/cp/cp-cilkplus.c @@ -25,7 +25,10 @@ #include "coretypes.h" #include "cp-tree.h" #include "diagnostic-core.h" - +#include "tree-iterator.h" +#include "tree-inline.h" /* for copy_tree_body_r. */ +#include "ggc.h" +#include "cilk.h" /* Callback for cp_walk_tree to validate the body of a pragma simd loop or _cilk_for loop. @@ -75,3 +78,68 @@ cpp_validate_cilk_plus_loop (tree body) (void *) &valid, NULL); return valid; } + +/* Sets the EXCEPTION bit (0x10) in the FRAME.flags field. */ + +static tree +set_cilk_except_flag (tree frame) +{ + tree flags = cilk_dot (frame, CILK_TI_FRAME_FLAGS, 0); + + flags = build2 (MODIFY_EXPR, void_type_node, flags, + build2 (BIT_IOR_EXPR, TREE_TYPE (flags), flags, + build_int_cst (TREE_TYPE (flags), + CILK_FRAME_EXCEPTING))); + return flags; +} + +/* Sets the frame.EXCEPT_DATA field to the head of the exception pointer. */ + +static tree +set_cilk_except_data (tree frame) +{ + tree except_data = cilk_dot (frame, CILK_TI_FRAME_EXCEPTION, 0); + tree uresume_fn = builtin_decl_implicit (BUILT_IN_EH_POINTER); + tree ret_expr; + uresume_fn = build_call_expr (uresume_fn, 1, + build_int_cst (integer_type_node, 0)); + ret_expr = build2 (MODIFY_EXPR, void_type_node, except_data, uresume_fn); + return ret_expr; +} + +/* Installs BODY into function FNDECL with appropriate exception handling + code. WD holds information of wrapper function used to pass into the + outlining function, cilk_outline. */ + +void +cilk_install_body_with_frame_cleanup (tree fndecl, tree orig_body, void *wd) +{ + tree frame = make_cilk_frame (fndecl); + tree dtor = create_cilk_function_exit (frame, false, false); + add_local_decl (cfun, frame); + + cfun->language = ggc_alloc_cleared_language_function (); + + location_t loc = EXPR_LOCATION (orig_body); + tree list = alloc_stmt_list (); + DECL_SAVED_TREE (fndecl) = list; + tree fptr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (frame)), frame); + tree body = cilk_install_body_pedigree_operations (fptr); + gcc_assert (TREE_CODE (body) == STATEMENT_LIST); + tree detach_expr = build_call_expr (cilk_detach_fndecl, 1, fptr); + append_to_statement_list (detach_expr, &body); + cilk_outline (fndecl, &orig_body, (struct wrapper_data *) wd); + append_to_statement_list (orig_body, &body); + if (flag_exceptions) + { + tree except_flag = set_cilk_except_flag (frame); + tree except_data = set_cilk_except_data (frame); + tree catch_list = alloc_stmt_list (); + append_to_statement_list (except_flag, &catch_list); + append_to_statement_list (except_data, &catch_list); + body = create_try_catch_expr (body, catch_list); + } + append_to_statement_list (build_stmt (loc, TRY_FINALLY_EXPR, body, dtor), + &list); +} + |