summaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorbviyer <bviyer@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-29 18:36:31 +0000
committerbviyer <bviyer@138bc75d-0d04-0410-961f-82ee72b054a4>2013-10-29 18:36:31 +0000
commitd037099fed7476ffedb6784a1f544132f258d792 (patch)
tree14c7dd8b636c3ec3f3957e767f7e6ef4f3421824 /gcc/gimplify.c
parent02774f2d493655713721ceef4ebfd7d0c8fb1d8d (diff)
downloadgcc-d037099fed7476ffedb6784a1f544132f258d792.tar.gz
Added _Cilk_spawn and _Cilk_sync (2 cilk keywords) for C.
gcc/ChangeLog: 2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com> * builtins.c (is_builtin_name): Added a check for __cilkrts_detach and __cilkrts_pop_frame. If matched, then return true for built-in function name. (expand_builtin): Added BUILT_IN_CILK_DETACH and BUILT_IN_CILK_POP_FRAME case. * langhooks-def.h (lhd_install_body_with_frame_cleanup): New prototype. (lhs_cilk_detect_spawn): Likewise. (LANG_HOOKS_DECLS): Added LANG_HOOKS_CILKPLUS. (LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP): New #define. (LANG_HOOKS_CILKPLUS_FRAME_CLEANUP): Likewise. (LANG_HOOKS_CILKPLUS_GIMPLIFY_SPAWN): Likewise. (LANG_HOOKS_CILKPLUS): Likewise. * tree.h (CILK_SPAWN_FN): Likewise. * builtin.def (DEF_CILK_BUILTIN_STUB): Likewise. * Makefile.in (C_COMMON_OBJS): Added c-family/cilk.o. (OBJS): Added cilk-common.o. (CILK_H): Added a new define. (gimplify.o): Added CILK_H into dependency list. (builtins.o): Likewise. (ipa-inline.o): Likewise. (ipa-inline-analysis.o): Likewise. (BUILTINS_DEF): Added cilk-builtins.def. * langhooks.c (lhd_install_body_with_frame_cleanup): New function. (lhd_cilk_detect_spawn): Likewise. * langhooks.h (lang_hooks_for_cilkplus): New struct. (struct lang_hooks): Added new field called "cilkplus." * cilk-common.c: New file. * cilk.h: Likewise. * cilk-builtins.def: Likewise. * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Added "__cilk" macro and set it to 200. * function.h (struct function::cilk_frame_decl): New field. (struct function::is_cilk_function): Likewise. (struct function::calls_cilk_spawn): Likewise. * gimplify.c (gimplify_call_expr): Added a check if the function call being gimplified is a spawn detach point. If so, then add pop_frame and detach function calls. (gimplify_expr): Added a CILK_SPAWN_STMT and CILK_SYNC_STMT case for gimplifying _Cilk_spawn and _Cilk_sync statements. (gimplify_return_expr): Added a check for _Cilk_spawn usage in function. If so, added a _Cilk_sync and gimplified it. (gimplify_modify_expr): Added a check for _Cilk_spawn in MODIFY and INIT_EXPRs. If so, then call gimplify_cilk_spawn. * ipa-inline-analysis (initialize_inline_failed): Prevent inlining of spawner function. (can_inline_edge_p): Prevent inling of spawnee function. * ira.c (ira_setup_eliminable_regset): Force usage of frame pointer for functions that use Cilk keywords. * tree-inline.h (struct copy_body_data::remap_var_for_cilk): New field. * tree-pretty-print.c (dump_generic_node): Added CILK_SPAWN_STMT and CILK_SYNC_STMT cases. * tree.def (DEFTREECODE): Added CILK_SPAWN_STMT and CILK_SYNC_STMT trees. * generic.texi (CILK_SPAWN_STMT): Added documentation for _Cilk_spawn. (CILK_SYNC_STMT): Added documentation for _Cilk_sync. * passes.texi (Cilk Keywords): New section that describes the compiler code changes for handling Cilk Keywords. gcc/c/ChangeLog: 2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-decl.c (finish_function): Added a call for insert_cilk_frame when a spawning function is found. * c-objc-common.h (LANG_HOOKS_CILKPLUS_GIMPLIFY_SPAWN): New #define. (LANG_HOOKS_CILKPLUS_FRAME_CLEANUP): Likewise. (LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP): Likewise. * c-parser.c (c_parser_statement_after_labels): Added RID_CILK_SYNC case. (c_parser_postfix_expression): Added RID_CILK_SPAWN case. * c-typeck.c (build_compound_expr): Reject _Cilk_spawn in a comma expr. (c_finish_return): Added a check to reject _Cilk_spawn in return expression. (build_cilk_spawn): New function. (build_cilk_sync): Likewise. * Makefile.in (c-decl.o): Added cilk.h in dependency list. gcc/c-family/ChangeLog 2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-common.c (c_common_reswords[]): Added _Cilk_spawn and _Cilk_sync fields. (c_define_builtins): Called cilk_init_builtins if Cilk Plus is enabled. * c-common.h (enum rid): Added RID_CILK_SPAWN and RID_CILK_SYNC. (insert_cilk_frame): New prototype. (cilk_init_builtins): Likewise. (gimplify_cilk_spawn): Likewise. (c_cilk_install_body_w_frame_cleanup): Likewise. (cilk_detect_spawn_and_unwrap): Likewise. (cilk_set_spawn_marker): Likewise. (build_cilk_sync): Likewise. (build_cilk_spawn): Likewise. * cilk.c: New file. gcc/lto/ChangeLog 2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com> * Make-lang.in (lto/lto-lang.o): Added cilk.h in dependency list. * lto-lang.c (lto_init): Added a call to cilk_init_builtins if Cilk Plus is enabled. gcc/testsuite/ChangeLog 2013-10-29 Balaji V. Iyer <balaji.v.iyer@intel.com> * c-c++-common/cilk-plus/CK/compound_cilk_spawn.c: New test. * c-c++-common/cilk-plus/CK/concec_cilk_spawn.c: Likewise. * c-c++-common/cilk-plus/CK/fib.c: Likewise. * c-c++-common/cilk-plus/CK/no_args_error.c: Likewise. * c-c++-common/cilk-plus/CK/spawnee_inline.c: Likewise. * c-c++-common/cilk-plus/CK/spawner_inline.c: Likewise. * c-c++-common/cilk-plus/CK/spawning_arg.c: Likewise. * c-c++-common/cilk-plus/CK/steal_check.c: Likewise. * c-c++-common/cilk-plus/CK/test__cilk.c: Likewise. * c-c++-common/cilk-plus/CK/varargs_test.c: Likewise. * c-c++-common/cilk-plus/CK/sync_wo_spawn.c: Likewise. * c-c++-common/cilk-plus/CK/invalid_spawn.c: Likewise. * c-c++-common/cilk-plus/CK/spawn_in_return.c: Likewise. * c-c++-common/cilk-plus/CK/fib_init_expr_xy.c: Likewise. * c-c++-common/cilk-plus/CK/fib_no_sync.c: Likewise. * c-c++-common/cilk-plus/CK/fib_no_return.c: Likewise. * gcc.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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204172 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 04f08b3461e..5edc6e8c33d 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see
#include "vec.h"
#include "omp-low.h"
#include "gimple-low.h"
+#include "cilk.h"
#include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name */
#include "tree-pass.h" /* FIXME: only for PROP_gimple_any */
@@ -1309,6 +1310,15 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p)
if (ret_expr == error_mark_node)
return GS_ERROR;
+ /* Implicit _Cilk_sync must be inserted right before any return statement
+ if there is a _Cilk_spawn in the function. If the user has provided a
+ _Cilk_sync, the optimizer should remove this duplicate one. */
+ if (fn_contains_cilk_spawn_p (cfun))
+ {
+ tree impl_sync = build0 (CILK_SYNC_STMT, void_type_node);
+ gimplify_and_add (impl_sync, pre_p);
+ }
+
if (!ret_expr
|| TREE_CODE (ret_expr) == RESULT_DECL
|| ret_expr == error_mark_node)
@@ -2498,6 +2508,12 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
if (! EXPR_HAS_LOCATION (*expr_p))
SET_EXPR_LOCATION (*expr_p, input_location);
+ if (fn_contains_cilk_spawn_p (cfun)
+ && lang_hooks.cilkplus.cilk_detect_spawn_and_unwrap (expr_p)
+ && !seen_error ())
+ return (enum gimplify_status)
+ lang_hooks.cilkplus.gimplify_cilk_spawn (expr_p, pre_p, NULL);
+
/* This may be a call to a builtin function.
Builtin function calls may be transformed into different
@@ -4714,6 +4730,12 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
gcc_assert (TREE_CODE (*expr_p) == MODIFY_EXPR
|| TREE_CODE (*expr_p) == INIT_EXPR);
+
+ if (fn_contains_cilk_spawn_p (cfun)
+ && lang_hooks.cilkplus.cilk_detect_spawn_and_unwrap (expr_p)
+ && !seen_error ())
+ return (enum gimplify_status)
+ lang_hooks.cilkplus.gimplify_cilk_spawn (expr_p, pre_p, post_p);
/* Trying to simplify a clobber using normal logic doesn't work,
so handle it here. */
@@ -7660,6 +7682,19 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
}
break;
+ case CILK_SPAWN_STMT:
+ gcc_assert
+ (fn_contains_cilk_spawn_p (cfun)
+ && lang_hooks.cilkplus.cilk_detect_spawn_and_unwrap (expr_p));
+ if (!seen_error ())
+ {
+ ret = (enum gimplify_status)
+ lang_hooks.cilkplus.gimplify_cilk_spawn (expr_p, pre_p,
+ post_p);
+ break;
+ }
+ /* If errors are seen, then just process it as a CALL_EXPR. */
+
case CALL_EXPR:
ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none);
@@ -8295,6 +8330,22 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
break;
}
+ case CILK_SYNC_STMT:
+ {
+ if (!fn_contains_cilk_spawn_p (cfun))
+ {
+ error_at (EXPR_LOCATION (*expr_p),
+ "expected %<_Cilk_spawn%> before %<_Cilk_sync%>");
+ ret = GS_ERROR;
+ }
+ else
+ {
+ gimplify_cilk_sync (expr_p, pre_p);
+ ret = GS_ALL_DONE;
+ }
+ break;
+ }
+
default:
switch (TREE_CODE_CLASS (TREE_CODE (*expr_p)))
{