aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorBalaji V. Iyer <balaji.v.iyer@intel.com>2013-12-11 18:23:27 +0000
committerBalaji V. Iyer <bviyer@gcc.gnu.org>2013-12-11 10:23:27 -0800
commit12893402ec1718a978e540eb1f6bd9c32a4555ab (patch)
tree9072ab2966c9b71528a27a7a515b6a3bd19545b2 /gcc/cp
parent996947e67d449d87376e12b389485c5f1cc76f48 (diff)
downloadgcc-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')
-rw-r--r--gcc/cp/ChangeLog23
-rw-r--r--gcc/cp/cp-cilkplus.c70
-rw-r--r--gcc/cp/cp-gimplify.c25
-rw-r--r--gcc/cp/cp-objcp-common.h1
-rw-r--r--gcc/cp/cp-tree.h4
-rw-r--r--gcc/cp/decl.c4
-rw-r--r--gcc/cp/except.c18
-rw-r--r--gcc/cp/parser.c61
-rw-r--r--gcc/cp/parser.h1
-rw-r--r--gcc/cp/pt.c7
-rw-r--r--gcc/cp/semantics.c2
-rw-r--r--gcc/cp/typeck.c18
12 files changed, 232 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2acc8c7..fd5d4b7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,26 @@
+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.
+
2013-12-09 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/59435
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);
+}
+
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index b1270a1..5fa564c 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3. If not see
#include "splay-tree.h"
#include "target.h"
#include "c-family/c-ubsan.h"
+#include "cilk.h"
/* Forward declarations. */
@@ -584,12 +585,21 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
LHS of an assignment might also be involved in the RHS, as in bug
25979. */
case INIT_EXPR:
+ if (fn_contains_cilk_spawn_p (cfun)
+ && cilk_detect_spawn_and_unwrap (expr_p)
+ && !seen_error ())
+ return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
cp_gimplify_init_expr (expr_p);
if (TREE_CODE (*expr_p) != INIT_EXPR)
return GS_OK;
/* Otherwise fall through. */
case MODIFY_EXPR:
{
+ if (fn_contains_cilk_spawn_p (cfun)
+ && cilk_detect_spawn_and_unwrap (expr_p)
+ && !seen_error ())
+ return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
+
/* If the back end isn't clever enough to know that the lhs and rhs
types are the same, add an explicit conversion. */
tree op0 = TREE_OPERAND (*expr_p, 0);
@@ -698,6 +708,21 @@ cp_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)
+ && cilk_detect_spawn_and_unwrap (expr_p));
+
+ /* If errors are seen, then just process it as a CALL_EXPR. */
+ if (!seen_error ())
+ return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
+
+ case CALL_EXPR:
+ if (fn_contains_cilk_spawn_p (cfun)
+ && cilk_detect_spawn_and_unwrap (expr_p)
+ && !seen_error ())
+ return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
+
default:
ret = (enum gimplify_status) c_gimplify_expr (expr_p, pre_p, post_p);
break;
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h
index ee22423..0a8fdee 100644
--- a/gcc/cp/cp-objcp-common.h
+++ b/gcc/cp/cp-objcp-common.h
@@ -153,5 +153,4 @@ extern void cp_common_init_ts (void);
#undef LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS
#define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS cp_protect_cleanup_actions
-
#endif /* GCC_CP_OBJCP_COMMON */
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1fc4b59..0686825 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5356,6 +5356,7 @@ extern tree begin_eh_spec_block (void);
extern void finish_eh_spec_block (tree, tree);
extern tree build_eh_type_type (tree);
extern tree cp_protect_cleanup_actions (void);
+extern tree create_try_catch_expr (tree, tree);
/* in expr.c */
extern tree cplus_expand_constant (tree);
@@ -6185,6 +6186,9 @@ extern bool cpp_validate_cilk_plus_loop (tree);
extern tree expand_array_notation_exprs (tree);
bool cilkplus_an_triplet_types_ok_p (location_t, tree, tree, tree,
tree);
+/* In c-family/cilk.c */
+extern bool cilk_valid_spawn (tree);
+
/* -- end of C++ */
#endif /* ! GCC_CP_TREE_H */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a6744c7..5d06b37 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. If not see
#include "splay-tree.h"
#include "plugin.h"
#include "cgraph.h"
+#include "cilk.h"
/* Possible cases of bad specifiers type used by bad_specifiers. */
enum bad_spec_place {
@@ -13889,6 +13890,9 @@ finish_function (int flags)
/* If we're saving up tree structure, tie off the function now. */
DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
+ if (fn_contains_cilk_spawn_p (cfun) && !processing_template_decl)
+ cfun->cilk_frame_decl = insert_cilk_frame (fndecl);
+
finish_fname_decls ();
/* If this function can't throw any exceptions, remember that. */
diff --git a/gcc/cp/except.c b/gcc/cp/except.c
index d7d009b..be487cd 100644
--- a/gcc/cp/except.c
+++ b/gcc/cp/except.c
@@ -1342,4 +1342,22 @@ build_noexcept_spec (tree expr, int complain)
}
}
+/* Returns a TRY_CATCH_EXPR that will put TRY_LIST and CATCH_LIST in the
+ TRY and CATCH locations. CATCH_LIST must be a STATEMENT_LIST */
+
+tree
+create_try_catch_expr (tree try_expr, tree catch_list)
+{
+ location_t loc = EXPR_LOCATION (try_expr);
+
+ append_to_statement_list (do_begin_catch (), &catch_list);
+ append_to_statement_list (build_throw (NULL_TREE), &catch_list);
+ tree catch_tf_expr = build_stmt (loc, TRY_FINALLY_EXPR, catch_list,
+ do_end_catch (NULL_TREE));
+ catch_list = build2 (CATCH_EXPR, void_type_node, NULL_TREE,
+ catch_tf_expr);
+ tree try_catch_expr = build_stmt (loc, TRY_CATCH_EXPR, try_expr, catch_list);
+ return try_catch_expr;
+}
+
#include "gt-cp-except.h"
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 063d2ac..dd02734 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5627,6 +5627,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
cp_id_kind idk = CP_ID_KIND_NONE;
tree postfix_expression = NULL_TREE;
bool is_member_access = false;
+ int saved_in_statement = -1;
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
@@ -5771,6 +5772,66 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
}
break;
+ case RID_CILK_SPAWN:
+ {
+ cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
+ if (token->type == CPP_SEMICOLON)
+ {
+ error_at (token->location, "%<_Cilk_spawn%> must be followed by "
+ "an expression");
+ postfix_expression = error_mark_node;
+ break;
+ }
+ else if (!current_function_decl)
+ {
+ error_at (token->location, "%<_Cilk_spawn%> may only be used "
+ "inside a function");
+ postfix_expression = error_mark_node;
+ break;
+ }
+ else
+ {
+ /* Consecutive _Cilk_spawns are not allowed in a statement. */
+ saved_in_statement = parser->in_statement;
+ parser->in_statement |= IN_CILK_SPAWN;
+ }
+ cfun->calls_cilk_spawn = 1;
+ postfix_expression =
+ cp_parser_postfix_expression (parser, false, false,
+ false, false, &idk);
+ if (saved_in_statement & IN_CILK_SPAWN)
+ {
+ error_at (token->location, "consecutive %<_Cilk_spawn%> keywords "
+ "are not permitted");
+ postfix_expression = error_mark_node;
+ cfun->calls_cilk_spawn = 0;
+ }
+ else
+ {
+ postfix_expression = build_cilk_spawn (token->location,
+ postfix_expression);
+ if (postfix_expression != error_mark_node)
+ SET_EXPR_LOCATION (postfix_expression, input_location);
+ parser->in_statement = parser->in_statement & ~IN_CILK_SPAWN;
+ }
+ break;
+ }
+
+ case RID_CILK_SYNC:
+ if (flag_enable_cilkplus)
+ {
+ tree sync_expr = build_cilk_sync ();
+ SET_EXPR_LOCATION (sync_expr,
+ cp_lexer_peek_token (parser->lexer)->location);
+ finish_expr_stmt (sync_expr);
+ }
+ else
+ error_at (input_location, "_Cilk_sync cannot be used without enabling "
+ "Cilk Plus");
+ cp_lexer_consume_token (parser->lexer);
+ break;
+
case RID_BUILTIN_SHUFFLE:
{
vec<tree, va_gc> *vec;
diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h
index edd4e6e..e26e350 100644
--- a/gcc/cp/parser.h
+++ b/gcc/cp/parser.h
@@ -301,6 +301,7 @@ typedef struct GTY(()) cp_parser {
#define IN_OMP_FOR 8
#define IN_IF_STMT 16
#define IN_CILK_SIMD_FOR 32
+#define IN_CILK_SPAWN 64
unsigned char in_statement;
/* TRUE if we are presently parsing the body of a switch statement.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 01b2d44..2c64a71 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13762,6 +13762,13 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
error ("use %<...%> to expand argument pack");
RETURN (error_mark_node);
+ case CILK_SPAWN_STMT:
+ cfun->calls_cilk_spawn = 1;
+ RETURN (build_cilk_spawn (EXPR_LOCATION (t), RECUR (CILK_SPAWN_FN (t))));
+
+ case CILK_SYNC_STMT:
+ RETURN (build_cilk_sync ());
+
case COMPOUND_EXPR:
tmp = RECUR (TREE_OPERAND (t, 0));
if (tmp == NULL_TREE)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 7c1b18e..63f50fb 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -10429,6 +10429,8 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
return false;
return true;
+ case CILK_SYNC_STMT:
+ case CILK_SPAWN_STMT:
case ARRAY_NOTATION_REF:
return false;
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 74fc4d7..01afbac 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6166,6 +6166,17 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
if (lhs == error_mark_node || rhs == error_mark_node)
return error_mark_node;
+ if (flag_enable_cilkplus
+ && (TREE_CODE (lhs) == CILK_SPAWN_STMT
+ || TREE_CODE (rhs) == CILK_SPAWN_STMT))
+ {
+ location_t loc = (EXPR_HAS_LOCATION (lhs) ? EXPR_LOCATION (lhs)
+ : EXPR_LOCATION (rhs));
+ error_at (loc,
+ "spawned function call cannot be part of a comma expression");
+ return error_mark_node;
+ }
+
if (TREE_CODE (rhs) == TARGET_EXPR)
{
/* If the rhs is a TARGET_EXPR, then build the compound
@@ -8290,6 +8301,13 @@ check_return_expr (tree retval, bool *no_warning)
*no_warning = false;
+ if (flag_enable_cilkplus && retval && TREE_CODE (retval) == CILK_SPAWN_STMT)
+ {
+ error_at (EXPR_LOCATION (retval), "use of %<_Cilk_spawn%> in a return "
+ "statement is not allowed");
+ return NULL_TREE;
+ }
+
/* A `volatile' function is one that isn't supposed to return, ever.
(This is a G++ extension, used to get better code for functions
that call the `volatile' function.) */