From 9a771876d342f9cf0b64c2ceada267ff50e18206 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 2 Sep 2014 14:52:29 +0200 Subject: cilk-builtins.def (__cilkrts_cilk_for_32): New. gcc/ * cilk-builtins.def (__cilkrts_cilk_for_32): New. (__cilkrts_cilk_for_64): Likewise. * cilk-common.c (declare_cilk_for_builtin): New function. (cilk_init_builtins): Declare __cilkrts_cilk_for_32 and __cilkrts_cilk_for_64 bultins. * cilk.h (enum cilk_tree_index): Added CILK_TI_F_LOOP_32 and CILK_TI_F_LOOP_64. (cilk_for_32_fndecl): New define. (cilk_for_64_fndecl): Likewise. * gimple-pretty-print.c (dump_gimple_omp_for): Correct hadling of GF_OMP_FOR_KIND_CILKFOR cases; Added NE_EXPR case. * gimple.h (enum gf_mask): Added GF_OMP_FOR_KIND_CILKFOR; adjusted GF_OMP_FOR_KIND_MASK, GF_OMP_FOR_SIMD, GF_OMP_FOR_COMBINED, GF_OMP_FOR_COMBINED_INTO. * gimplify.c (gimplify_scan_omp_clauses): Added OMP_CLAUSE__CILK_FOR_COUNT_ case. (gimplify_adjust_omp_clauses): Ditto. (gimplify_omp_for): Added CILK_FOR case. (gimplify_expr): Ditto. * omp-low.c: Include cilk.h. (extract_omp_for_data): Set appropriate kind for GF_OMP_FOR_KIND_CILKFOR; added check for GF_OMP_FOR_KIND_CILKFOR. (scan_sharing_clauses): Added OMP_CLAUSE__CILK_FOR_COUNT_ cases. (create_omp_child_function_name): Added second argument to handle cilk_for case. (cilk_for_check_loop_diff_type): New function. (expand_cilk_for_call): Likewise. (expand_cilk_for): Likewise. (create_omp_child_function): Set cilk_for_count; handle the cases when it is true; call create_omp_child_function_name with second argument. (expand_omp_taskreg): Set is_cilk_for and handle cases when it's true. (expand_omp_for): Handle case of GF_OMP_FOR_KIND_CILKFOR. * tree-core.h (omp_clause_code): Added OMP_CLAUSE__CILK_FOR_COUNT_. * tree-nested.c (convert_nonlocal_omp_clauses): Added OMP_CLAUSE__CILK_FOR_COUNT_ case. (convert_local_omp_clauses): Ditto. * tree-pretty-print.c (dump_omp_clause): Added OMP_CLAUSE__CILK_FOR_COUNT_ and OMP_CLAUSE_SCHEDULE_CILKFOR cases. (dump_generic_node): Added CILK_FOR case. * tree.c (omp_clause_num_ops): New element OMP_CLAUSE__CILK_FOR_COUNT_ (1). (omp_clause_code_name): New element _Cilk_for_count_. (walk_tree_1): Added OMP_CLAUSE__CILK_FOR_COUNT_ case. * tree.def: Add tree code for CILK_FOR. gcc/c/ * c-parser.c (c_parser_cilk_for): New function. (c_parser_cilk_grainsize): Likewise. (c_get_temp_regvar): Likewise. (c_parser_statement_after_labels): Added RID_CILK_FOR case. (c_parser_pragma): Added PRAGMA_CILK_GRAINSIZE case. (c_parser_omp_for_loop): Added CILK_FOR and CILK_SIMD checks. * c-typeck.c (c_finish_omp_clauses): Added OMP_CLAUSE__CILK_FOR_COUNT_ case. gcc/cp/ * cp-cilkplus.c (cpp_validate_cilk_plus_loop_aux): Loc definition simplified. * parser.c (cp_parser_cilk_for): New function. (cp_parser_cilk_grainsize): Likewise. (cp_parser_statement): Added RID_CILK_FOR case. (cp_parser_omp_for_cond): Added CILK_FOR check. (cp_parser_omp_for_loop_init): Change function argument to accept tree_code instead just a bool flag; change the check to use that tree_code; check for initialization declaration in case of Cilk_for. (cp_parser_omp_for_loop): Added checks for CILK_FOR and RID_CILK_FOR; changed call to cp_parser_omp_for_loop_init according new arguments' list. (cp_parser_pragma): Added PRAGMA_CILK_GRAINSIZE case. * pt.c (tsubst_expr): Added CILK_FOR case. * semantics.c: Include convert.h. (finish_omp_clauses): Properly handle OMP_CLAUSE_SCHEDULE_CILKFOR case; added OMP_CLAUSE__CILK_FOR_COUNT_. (handle_omp_for_class_iterator): New argument lastp and its usage; added NE_EXPR case. (finish_omp_for): Changed call to handle_omp_for_class_iterator according new arguments' list; in case of Cilk_for save very first decl and create empty stmt_list block; use block to build correct statement tree. gcc/c-family/ * c-cilkplus.c (cilk_for_number_of_iterations): New function. * c-common.c (c_common_reswords): Added _Cilk_for. * c-common.h (enum rid): Added RID_CILK_FOR. (cilk_for_number_of_iterations): Add declaration. * c-omp.c (c_finish_omp_for): Added checks for CILK_SIMD and CILK_FOR. * c-pragma.c (init_pragma): Register "grainsize" pragma. * c-pragma.h (enum pragma_kind): Add PRAGMA_CILK_GRAINSIZE. gcc/testsuite/ * c-c++-common/cilk-plus/CK/cilk-fors.c: New test. * c-c++-common/cilk-plus/CK/cilk-for-2.c: New test. * c-c++-common/cilk-plus/CK/cilk-for-3.c: New test. * c-c++-common/cilk-plus/CK/cilk_for_errors.c: New test. * c-c++-common/cilk-plus/CK/cilk_for_grain.c: New test. * c-c++-common/cilk-plus/CK/cilk_for_grain_errors.c: New test. * c-c++-common/cilk-plus/CK/cilk_for_ptr_iter.c: New test. * c-c++-common/cilk-plus/CK/nested_cilk_for.c: New test. * g++.dg/cilk-plus/CK/cf3.cc: New test. * g++.dg/cilk-plus/CK/cilk-for-tplt.cc: New test. * g++.dg/cilk-plus/CK/for1.cc: New test. * g++.dg/cilk-plus/CK/stl_iter.cc: New test. * g++.dg/cilk-plus/CK/stl_rev_iter.cc: New test. * g++.dg/cilk-plus/CK/stl_test.cc: New test. Co-Authored-By: Balaji V. Iyer Co-Authored-By: Igor Zamyatin From-SVN: r214818 --- gcc/c/ChangeLog | 13 ++++ gcc/c/c-parser.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- gcc/c/c-typeck.c | 1 + 3 files changed, 193 insertions(+), 4 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index c4661ff..2d02c7b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,16 @@ +2014-09-02 Jakub Jelinek + Balaji V. Iyer + Igor Zamyatin + + * c-parser.c (c_parser_cilk_for): New function. + (c_parser_cilk_grainsize): Likewise. + (c_get_temp_regvar): Likewise. + (c_parser_statement_after_labels): Added RID_CILK_FOR case. + (c_parser_pragma): Added PRAGMA_CILK_GRAINSIZE case. + (c_parser_omp_for_loop): Added CILK_FOR and CILK_SIMD checks. + * c-typeck.c (c_finish_omp_clauses): Added OMP_CLAUSE__CILK_FOR_COUNT_ + case. + 2014-08-27 Chen Gang * c-aux-info.c (gen_type): Resize 'buff' from 10 to 23 bytes, diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 34f1e47..03c6830 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1264,9 +1264,11 @@ static bool c_parser_objc_diagnose_bad_element_prefix /* Cilk Plus supporting routines. */ static void c_parser_cilk_simd (c_parser *); +static void c_parser_cilk_for (c_parser *, tree); static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); static tree c_parser_array_notation (location_t, c_parser *, tree, tree); static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); +static void c_parser_cilk_grainsize (c_parser *); /* Parse a translation unit (C90 6.7, C99 6.9). @@ -4895,6 +4897,16 @@ c_parser_statement_after_labels (c_parser *parser) case RID_FOR: c_parser_for_statement (parser, false); break; + case RID_CILK_FOR: + if (!flag_cilkplus) + { + error_at (c_parser_peek_token (parser)->location, + "-fcilkplus must be enabled to use %<_Cilk_for%>"); + c_parser_skip_to_end_of_block_or_statement (parser); + } + else + c_parser_cilk_for (parser, integer_zero_node); + break; case RID_CILK_SYNC: c_parser_consume_token (parser); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); @@ -9582,6 +9594,23 @@ c_parser_pragma (c_parser *parser, enum pragma_context context) c_parser_consume_pragma (parser); c_parser_cilk_simd (parser); return false; + case PRAGMA_CILK_GRAINSIZE: + if (!flag_cilkplus) + { + warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not" + " enabled"); + c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); + return false; + } + if (context == pragma_external) + { + error_at (c_parser_peek_token (parser)->location, + "%<#pragma grainsize%> must be inside a function"); + c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); + return false; + } + c_parser_cilk_grainsize (parser); + return false; default: if (id < PRAGMA_FIRST_EXTERNAL) @@ -11715,11 +11744,18 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, condv = make_tree_vec (collapse); incrv = make_tree_vec (collapse); - if (!c_parser_next_token_is_keyword (parser, RID_FOR)) + if (code != CILK_FOR + && !c_parser_next_token_is_keyword (parser, RID_FOR)) { c_parser_error (parser, "for statement expected"); return NULL; } + if (code == CILK_FOR + && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR)) + { + c_parser_error (parser, "_Cilk_for statement expected"); + return NULL; + } for_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); @@ -11797,7 +11833,7 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, case LE_EXPR: break; case NE_EXPR: - if (code == CILK_SIMD) + if (code == CILK_SIMD || code == CILK_FOR) break; /* FALLTHRU. */ default: @@ -13890,8 +13926,48 @@ c_parser_cilk_all_clauses (c_parser *parser) return c_finish_cilk_clauses (clauses); } -/* Main entry point for parsing Cilk Plus <#pragma simd> for - loops. */ +/* This function helps parse the grainsize pragma for a _Cilk_for statement. + Here is the correct syntax of this pragma: + #pragma cilk grainsize = + */ + +static void +c_parser_cilk_grainsize (c_parser *parser) +{ + extern tree convert_to_integer (tree, tree); + + /* consume the 'grainsize' keyword. */ + c_parser_consume_pragma (parser); + + if (c_parser_require (parser, CPP_EQ, "expected %<=%>") != 0) + { + struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL); + if (g_expr.value == error_mark_node) + { + c_parser_skip_to_pragma_eol (parser); + return; + } + tree grain = convert_to_integer (long_integer_type_node, + c_fully_fold (g_expr.value, false, + NULL)); + c_parser_skip_to_pragma_eol (parser); + c_token *token = c_parser_peek_token (parser); + if (token && token->type == CPP_KEYWORD + && token->keyword == RID_CILK_FOR) + { + if (grain == NULL_TREE || grain == error_mark_node) + grain = integer_zero_node; + c_parser_cilk_for (parser, grain); + } + else + warning (0, "%<#pragma cilk grainsize%> is not followed by " + "%<_Cilk_for%>"); + } + else + c_parser_skip_to_pragma_eol (parser); +} + +/* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */ static void c_parser_cilk_simd (c_parser *parser) @@ -13903,6 +13979,105 @@ c_parser_cilk_simd (c_parser *parser) block = c_end_compound_stmt (loc, block, true); add_stmt (block); } + +/* Create an artificial decl with TYPE and emit initialization of it with + INIT. */ + +static tree +c_get_temp_regvar (tree type, tree init) +{ + location_t loc = EXPR_LOCATION (init); + tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type); + DECL_ARTIFICIAL (decl) = 1; + DECL_IGNORED_P (decl) = 1; + pushdecl (decl); + tree t = build2 (INIT_EXPR, type, decl, init); + add_stmt (t); + return decl; +} + +/* Main entry point for parsing Cilk Plus _Cilk_for loops. + GRAIN is the grain value passed in through pragma or 0. */ + +static void +c_parser_cilk_for (c_parser *parser, tree grain) +{ + tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE); + OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR; + OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain; + clauses = c_finish_omp_clauses (clauses); + + tree block = c_begin_compound_stmt (true); + tree sb = push_stmt_list (); + location_t loc = c_parser_peek_token (parser)->location; + tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL); + sb = pop_stmt_list (sb); + + if (omp_for) + { + tree omp_par = make_node (OMP_PARALLEL); + TREE_TYPE (omp_par) = void_type_node; + OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; + tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); + TREE_SIDE_EFFECTS (bind) = 1; + BIND_EXPR_BODY (bind) = sb; + OMP_PARALLEL_BODY (omp_par) = bind; + if (OMP_FOR_PRE_BODY (omp_for)) + { + add_stmt (OMP_FOR_PRE_BODY (omp_for)); + OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; + } + tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); + tree decl = TREE_OPERAND (init, 0); + tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); + tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); + tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE; + if (TREE_CODE (t) != INTEGER_CST) + { + TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t); + c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); + OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); + OMP_CLAUSE_CHAIN (c) = clauses; + clauses = c; + } + if (TREE_CODE (incr) == MODIFY_EXPR) + { + t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); + if (TREE_CODE (t) != INTEGER_CST) + { + TREE_OPERAND (TREE_OPERAND (incr, 1), 1) + = c_get_temp_regvar (TREE_TYPE (t), t); + c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); + OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); + OMP_CLAUSE_CHAIN (c) = clauses; + clauses = c; + } + } + t = TREE_OPERAND (init, 1); + if (TREE_CODE (t) != INTEGER_CST) + { + TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t); + c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); + OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); + OMP_CLAUSE_CHAIN (c) = clauses; + clauses = c; + } + c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); + OMP_CLAUSE_DECL (c) = decl; + OMP_CLAUSE_CHAIN (c) = clauses; + clauses = c; + c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); + OMP_CLAUSE_OPERAND (c, 0) + = cilk_for_number_of_iterations (omp_for); + OMP_CLAUSE_CHAIN (c) = clauses; + OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c); + add_stmt (omp_par); + } + + block = c_end_compound_stmt (loc, block, true); + add_stmt (block); +} + /* Parse a transaction attribute (GCC Extension). diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a7de8f3..da71ab2 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -12229,6 +12229,7 @@ c_finish_omp_clauses (tree clauses) case OMP_CLAUSE_SECTIONS: case OMP_CLAUSE_TASKGROUP: case OMP_CLAUSE_PROC_BIND: + case OMP_CLAUSE__CILK_FOR_COUNT_: pc = &OMP_CLAUSE_CHAIN (c); continue; -- cgit v1.1