aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorBalaji V. Iyer <balaji.v.iyer@intel.com>2013-10-29 18:36:31 +0000
committerBalaji V. Iyer <bviyer@gcc.gnu.org>2013-10-29 11:36:31 -0700
commit939b37da6ded55070bd78fc28d3fd2222b4278fa (patch)
tree14c7dd8b636c3ec3f3957e767f7e6ef4f3421824 /gcc/c
parent67348ccc9ca5c667400851fa252a0e542847cb66 (diff)
downloadgcc-939b37da6ded55070bd78fc28d3fd2222b4278fa.zip
gcc-939b37da6ded55070bd78fc28d3fd2222b4278fa.tar.gz
gcc-939b37da6ded55070bd78fc28d3fd2222b4278fa.tar.bz2
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. From-SVN: r204172
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog18
-rw-r--r--gcc/c/c-decl.c7
-rw-r--r--gcc/c/c-objc-common.h9
-rw-r--r--gcc/c/c-parser.c32
-rw-r--r--gcc/c/c-typeck.c14
5 files changed, 80 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 707c5d2..ed60988 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,21 @@
+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.
+
2013-10-27 Tobias Burnus <burnus@net-b.de>
PR other/33426
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 0554e72..64718c5 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see
#include "pointer-set.h"
#include "plugin.h"
#include "c-family/c-ada-spec.h"
+#include "cilk.h"
/* In grokdeclarator, distinguish syntactic contexts of declarators. */
enum decl_context
@@ -8447,6 +8448,12 @@ finish_function (void)
/* Tie off the statement tree for this function. */
DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
+ /* If the function has _Cilk_spawn in front of a function call inside it
+ i.e. it is a spawning function, then add the appropriate Cilk plus
+ functions inside. */
+ if (fn_contains_cilk_spawn_p (cfun))
+ cfun->cilk_frame_decl = insert_cilk_frame (fndecl);
+
finish_fname_decls ();
/* Complain if there's just no return statement. */
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index e144824..6ae7b3e 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -105,4 +105,13 @@ along with GCC; see the file COPYING3. If not see
#undef LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P
#define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P c_vla_unspec_p
+#undef LANG_HOOKS_CILKPLUS_GIMPLIFY_SPAWN
+#define LANG_HOOKS_CILKPLUS_GIMPLIFY_SPAWN gimplify_cilk_spawn
+
+#undef LANG_HOOKS_CILKPLUS_FRAME_CLEANUP
+#define LANG_HOOKS_CILKPLUS_FRAME_CLEANUP c_cilk_install_body_w_frame_cleanup
+
+#undef LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP
+#define LANG_HOOKS_CILKPLUS_DETECT_SPAWN_AND_UNWRAP \
+ cilk_detect_spawn_and_unwrap
#endif /* GCC_C_OBJC_COMMON */
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 9ccae3b..a8f4774 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -4587,6 +4587,14 @@ c_parser_statement_after_labels (c_parser *parser)
case RID_FOR:
c_parser_for_statement (parser, false);
break;
+ case RID_CILK_SYNC:
+ c_parser_consume_token (parser);
+ c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
+ if (!flag_enable_cilkplus)
+ error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
+ else
+ add_stmt (build_cilk_sync ());
+ break;
case RID_GOTO:
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_NAME))
@@ -7174,6 +7182,30 @@ c_parser_postfix_expression (c_parser *parser)
case RID_GENERIC:
expr = c_parser_generic_selection (parser);
break;
+ case RID_CILK_SPAWN:
+ c_parser_consume_token (parser);
+ if (!flag_enable_cilkplus)
+ {
+ error_at (loc, "-fcilkplus must be enabled to use "
+ "%<_Cilk_spawn%>");
+ expr = c_parser_postfix_expression (parser);
+ expr.value = error_mark_node;
+ }
+ if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
+ {
+ error_at (loc, "consecutive %<_Cilk_spawn%> keywords "
+ "are not permitted");
+ /* Now flush out all the _Cilk_spawns. */
+ while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
+ c_parser_consume_token (parser);
+ expr = c_parser_postfix_expression (parser);
+ }
+ else
+ {
+ expr = c_parser_postfix_expression (parser);
+ expr.value = build_cilk_spawn (loc, expr.value);
+ }
+ break;
default:
c_parser_error (parser, "expected expression");
expr.value = error_mark_node;
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 1d83137..1034cee 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -4387,6 +4387,14 @@ build_compound_expr (location_t loc, tree expr1, tree expr2)
tree eptype = NULL_TREE;
tree ret;
+ if (flag_enable_cilkplus
+ && (TREE_CODE (expr1) == CILK_SPAWN_STMT
+ || TREE_CODE (expr2) == CILK_SPAWN_STMT))
+ {
+ error_at (loc,
+ "spawned function call cannot be part of a comma expression");
+ return error_mark_node;
+ }
expr1_int_operands = EXPR_INT_CONST_OPERANDS (expr1);
if (expr1_int_operands)
expr1 = remove_c_maybe_const_expr (expr1);
@@ -8694,6 +8702,12 @@ c_finish_return (location_t loc, tree retval, tree origtype)
return error_mark_node;
}
}
+ if (flag_enable_cilkplus && retval && TREE_CODE (retval) == CILK_SPAWN_STMT)
+ {
+ error_at (loc, "use of %<_Cilk_spawn%> in a return statement is not "
+ "allowed");
+ return error_mark_node;
+ }
if (retval)
{
tree semantic_type = NULL_TREE;