On 04/28/2016 01:56 AM, Jakub Jelinek wrote: > On Wed, Apr 27, 2016 at 07:37:17PM -0700, Cesar Philippidis wrote: >> This patch replaces all of the bool argument to c_finish_omp_clauses and >> finish_omp_clauses in the c and c++ front ends, respectively. Right now >> there are three bool arguments, one for is_omp/allow_fields, >> declare_simd and is_cilk, the latter two have default values set. >> OpenACC will require some special handling in *finish_omp_clauses in the >> near future, too, so rather than add an is_oacc argument, I introduced >> an enum c_omp_region_type, similar to the one in gimplify.c. >> >> Is this patch ok for trunk? I'll make use of C_ORT_ACC shortly in a >> follow up patch. > > I've been long wanting to use just tree_code there, but as we don't have one > e.g. for DECLARE_SIMD, perhaps a separate enum is better. > >> --- a/gcc/c-family/c-common.h >> +++ b/gcc/c-family/c-common.h >> @@ -1261,6 +1261,17 @@ enum c_omp_clause_split >> C_OMP_CLAUSE_SPLIT_TASKLOOP = C_OMP_CLAUSE_SPLIT_FOR >> }; >> >> +enum c_omp_region_type >> +{ >> + C_ORT_NONE = 0, >> + C_ORT_OMP = 1 << 0, >> + C_ORT_SIMD = 1 << 1, >> + C_ORT_CILK = 1 << 2, >> + C_ORT_ACC = 1 << 3, >> + C_ORT_OMP_SIMD = C_ORT_OMP | C_ORT_SIMD, >> + C_ORT_OMP_CILK = C_ORT_OMP | C_ORT_CILK > > That said, the above names are just weird, it is non-obvious > what they mean at all. What is C_ORT_NONE for? We surely don't > have any clauses that aren't OpenMP, nor Cilk+, nor OpenACC > (ok, maybe the simd attribute, but donno if it ever calls the > *finish_omp_clauses functions).
*parser_clik_for was just passing is_omp/allow_fields = false. > So, IMHO the originating specification should be one thing, so > C_ORT_OMP, C_ORT_CILK, C_ORT_ACC. > And, beyond that the C FE cares about whether it is a clause > on #pragma omp declare simd or its Cilk+ counterpart (vector attribute), > so you want C_ORT_DECLARE_SIMD possibly ored with the language > (note, not C_ORT_SIMD, that is way too confusing - we have > #pragma omp simd (OpenMP), #pragma simd (Cilk+), and we certainly do not > want the declare simd behavior for those. > Perhaps #pragma omp declare target is another construct that is handled > differently and could be visible in the bitmask too. > > The C++ finish_omp_clauses also cares about whether fields (meaning > non-static members) are allowed, i.e. whether > struct S { int p; void foo () { > ... > #pragma omp ... private (p) > ... > }}; > should be allowed or not. That can be derived from the language and > the other construct bits though, I believe right now only OpenMP constructs > should handle it, and declare simd should not, and similarly declare target > should not. That sounds reasonable. This patch removes C_ORT_OMP_SIMD and C_ORT_OMP_CILK from the enum and introduces C_ORT_DECLARE_SIMD. Additionally, instead of taking an enum c_omp_region_type argument, *finish_omp_clauses just takes in a unsigned int bitmask. That way the enum doesn't get overly complicated. Note that I didn't include an allow_fields entry for c++ in the enum, since that information can be derived from C_ORT_OMP anyway. Is this ok for trunk? Cesar
2016-04-28 Cesar Philippidis <ce...@codesourcery.com> gcc/c-family/ * c-common.h (enum c_omp_region_type): Define. gcc/c/ * c-parser.c (c_parser_oacc_all_clauses): Update call to c_finish_omp_clauses. (c_parser_omp_all_clauses): Likewise. (c_parser_oacc_cache): Likewise. (c_parser_oacc_loop): Likewise. (omp_split_clauses): Likewise. (c_parser_omp_declare_target): Likewise. (c_parser_cilk_all_clauses): Likewise. (c_parser_cilk_for): Likewise. * c-typeck.c (c_finish_omp_clauses): Replace bool arguments is_omp, declare_simd, and is_cilk with bitmask ort. gcc/cp/ * cp-tree.h (finish_omp_clauses): Update prototype. * parser.c (cp_parser_oacc_all_clauses): Update call to finish_omp_clauses. (cp_parser_omp_all_clauses): Likewise. (cp_parser_omp_for_loop): Likewise. (cp_omp_split_clauses): Likewise. (cp_parser_oacc_cache): Likewise. (cp_parser_oacc_loop): Likewise. (cp_parser_omp_declare_target): (cp_parser_cilk_simd_all_clauses): Likewise. (cp_parser_cilk_for): Likewise. * pt.c (tsubst_attribute): Likewise. (tsubst_omp_clauses): Likewise. (tsubst_omp_for_iterator): Likewise. * semantics.c (finish_omp_clauses): Replace bool arguments allow_fields, declare_simd, and is_cilk with bitmask ort. (finish_omp_for): Update call to finish_omp_clauses. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 3a7805f..3473e66 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1261,6 +1261,14 @@ enum c_omp_clause_split C_OMP_CLAUSE_SPLIT_TASKLOOP = C_OMP_CLAUSE_SPLIT_FOR }; +enum c_omp_region_type +{ + C_ORT_OMP = 1 << 0, + C_ORT_CILK = 1 << 1, + C_ORT_ACC = 1 << 2, + C_ORT_DECLARE_SIMD = 1 << 3 +}; + extern tree c_finish_omp_master (location_t, tree); extern tree c_finish_omp_taskgroup (location_t, tree); extern tree c_finish_omp_critical (location_t, tree, tree, tree); diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 36c44ab..eb0ca16 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -13183,7 +13183,7 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, c_parser_skip_to_pragma_eol (parser); if (finish_p) - return c_finish_omp_clauses (clauses, false); + return c_finish_omp_clauses (clauses, C_ORT_ACC); return clauses; } @@ -13468,8 +13468,8 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, if (finish_p) { if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) - return c_finish_omp_clauses (clauses, true, true); - return c_finish_omp_clauses (clauses, true); + return c_finish_omp_clauses (clauses, C_ORT_OMP | C_ORT_DECLARE_SIMD); + return c_finish_omp_clauses (clauses, C_ORT_OMP); } return clauses; @@ -13503,7 +13503,7 @@ c_parser_oacc_cache (location_t loc, c_parser *parser) tree stmt, clauses; clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL); - clauses = c_finish_omp_clauses (clauses, false); + clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); c_parser_skip_to_pragma_eol (parser); @@ -13837,9 +13837,9 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, { clauses = c_oacc_split_loop_clauses (clauses, cclauses); if (*cclauses) - *cclauses = c_finish_omp_clauses (*cclauses, false); + *cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC); if (clauses) - clauses = c_finish_omp_clauses (clauses, false); + clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); } tree block = c_begin_compound_stmt (true); @@ -15015,7 +15015,7 @@ omp_split_clauses (location_t loc, enum tree_code code, c_omp_split_clauses (loc, code, mask, clauses, cclauses); for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) if (cclauses[i]) - cclauses[i] = c_finish_omp_clauses (cclauses[i], true); + cclauses[i] = c_finish_omp_clauses (cclauses[i], C_ORT_OMP); } /* OpenMP 4.0: @@ -16546,7 +16546,7 @@ c_parser_omp_declare_target (c_parser *parser) { clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, clauses); - clauses = c_finish_omp_clauses (clauses, true); + clauses = c_finish_omp_clauses (clauses, C_ORT_OMP); c_parser_skip_to_pragma_eol (parser); } else @@ -17515,7 +17515,7 @@ c_parser_cilk_all_clauses (c_parser *parser) saw_error: c_parser_skip_to_pragma_eol (parser); - return c_finish_omp_clauses (clauses, false, false, true); + return c_finish_omp_clauses (clauses, C_ORT_CILK); } /* This function helps parse the grainsize pragma for a _Cilk_for statement. @@ -17597,7 +17597,7 @@ c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p) 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, false); + clauses = c_finish_omp_clauses (clauses, 0); tree block = c_begin_compound_stmt (true); tree sb = push_stmt_list (); @@ -17663,7 +17663,7 @@ c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p) 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, true); + OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, C_ORT_OMP); add_stmt (omp_par); } diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 4633182..99c757c 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -661,7 +661,7 @@ extern tree c_begin_omp_task (void); extern tree c_finish_omp_task (location_t, tree, tree); extern void c_finish_omp_cancel (location_t, tree); extern void c_finish_omp_cancellation_point (location_t, tree); -extern tree c_finish_omp_clauses (tree, bool, bool = false, bool = false); +extern tree c_finish_omp_clauses (tree, unsigned int); extern tree c_build_va_arg (location_t, tree, location_t, tree); extern tree c_finish_transaction (location_t, tree, int); extern bool c_tree_equal (tree, tree); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 58c2139..283a97e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -12496,8 +12496,7 @@ c_find_omp_placeholder_r (tree *tp, int *, void *data) Remove any elements from the list that are invalid. */ tree -c_finish_omp_clauses (tree clauses, bool is_omp, bool declare_simd, - bool is_cilk) +c_finish_omp_clauses (tree clauses, unsigned int ort) { bitmap_head generic_head, firstprivate_head, lastprivate_head; bitmap_head aligned_head, map_head, map_field_head; @@ -12509,6 +12508,9 @@ c_finish_omp_clauses (tree clauses, bool is_omp, bool declare_simd, tree *nowait_clause = NULL; bool ordered_seen = false; tree schedule_clause = NULL_TREE; + bool is_omp = ort & C_ORT_OMP; + bool declare_simd = ort & C_ORT_DECLARE_SIMD; + bool is_cilk = ort & C_ORT_CILK; bitmap_obstack_initialize (NULL); bitmap_initialize (&generic_head, &bitmap_default_obstack); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4c548c9..d535207 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6396,8 +6396,7 @@ extern tree omp_reduction_id (enum tree_code, tree, tree); extern tree cp_remove_omp_priv_cleanup_stmt (tree *, int *, void *); extern void cp_check_omp_declare_reduction (tree); extern void finish_omp_declare_simd_methods (tree); -extern tree finish_omp_clauses (tree, bool, bool = false, - bool = false); +extern tree finish_omp_clauses (tree, unsigned int); extern tree push_omp_privatization_clauses (bool); extern void pop_omp_privatization_clauses (tree); extern void save_omp_privatization_clauses (vec<tree> &); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7fb3c01..59a35d6 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32261,7 +32261,7 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, cp_parser_skip_to_pragma_eol (parser, pragma_tok); if (finish_p) - return finish_omp_clauses (clauses, false); + return finish_omp_clauses (clauses, C_ORT_ACC); return clauses; } @@ -32580,9 +32580,9 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, if (finish_p) { if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) - return finish_omp_clauses (clauses, false, true); + return finish_omp_clauses (clauses, C_ORT_DECLARE_SIMD); else - return finish_omp_clauses (clauses, true); + return finish_omp_clauses (clauses, C_ORT_OMP); } return clauses; } @@ -33657,7 +33657,7 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses, else c = build_omp_clause (loc, OMP_CLAUSE_LASTPRIVATE); OMP_CLAUSE_DECL (c) = add_private_clause; - c = finish_omp_clauses (c, true); + c = finish_omp_clauses (c, C_ORT_OMP); if (c) { OMP_CLAUSE_CHAIN (c) = clauses; @@ -33809,7 +33809,7 @@ cp_omp_split_clauses (location_t loc, enum tree_code code, c_omp_split_clauses (loc, code, mask, clauses, cclauses); for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) if (cclauses[i]) - cclauses[i] = finish_omp_clauses (cclauses[i], true); + cclauses[i] = finish_omp_clauses (cclauses[i], C_ORT_OMP); } /* OpenMP 4.0: @@ -35092,7 +35092,7 @@ cp_parser_oacc_cache (cp_parser *parser, cp_token *pragma_tok) tree stmt, clauses; clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE__CACHE_, NULL_TREE); - clauses = finish_omp_clauses (clauses, false); + clauses = finish_omp_clauses (clauses, C_ORT_ACC); cp_parser_require_pragma_eol (parser, cp_lexer_peek_token (parser->lexer)); @@ -35417,9 +35417,9 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name, { clauses = c_oacc_split_loop_clauses (clauses, cclauses); if (*cclauses) - *cclauses = finish_omp_clauses (*cclauses, false); + *cclauses = finish_omp_clauses (*cclauses, C_ORT_ACC); if (clauses) - clauses = finish_omp_clauses (clauses, false); + clauses = finish_omp_clauses (clauses, C_ORT_ACC); } tree block = begin_omp_structured_block (); @@ -35786,7 +35786,7 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok) { clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_TO_DECLARE, clauses); - clauses = finish_omp_clauses (clauses, true); + clauses = finish_omp_clauses (clauses, C_ORT_OMP); cp_parser_require_pragma_eol (parser, pragma_tok); } else @@ -37726,7 +37726,7 @@ cp_parser_cilk_simd_all_clauses (cp_parser *parser, cp_token *pragma_token) if (clauses == error_mark_node) return error_mark_node; else - return finish_omp_clauses (clauses, false, false, true); + return finish_omp_clauses (clauses, C_ORT_CILK); } /* Main entry-point for parsing Cilk Plus <#pragma simd> for loops. */ @@ -37771,7 +37771,7 @@ cp_parser_cilk_for (cp_parser *parser, tree grain, bool *if_p) 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 = finish_omp_clauses (clauses, false); + clauses = finish_omp_clauses (clauses, 0); tree ret = cp_parser_omp_for_loop (parser, CILK_FOR, clauses, NULL, if_p); if (ret) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2d033e3..ef17d84 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9585,7 +9585,7 @@ tsubst_attribute (tree t, tree *decl_p, tree args, clauses = tsubst_omp_clauses (clauses, true, false, args, complain, in_decl); c_omp_declare_simd_clauses_to_decls (*decl_p, clauses); - clauses = finish_omp_clauses (clauses, false, true); + clauses = finish_omp_clauses (clauses, C_ORT_DECLARE_SIMD); tree parms = DECL_ARGUMENTS (*decl_p); clauses = c_omp_declare_simd_clauses_to_numbers (parms, clauses); @@ -14749,7 +14749,8 @@ tsubst_omp_clauses (tree clauses, bool declare_simd, bool allow_fields, new_clauses = nreverse (new_clauses); if (!declare_simd) { - new_clauses = finish_omp_clauses (new_clauses, allow_fields); + unsigned int ort = allow_fields ? C_ORT_OMP : 0; + new_clauses = finish_omp_clauses (new_clauses, ort); if (linear_no_step) for (nc = new_clauses; nc; nc = OMP_CLAUSE_CHAIN (nc)) if (nc == linear_no_step) @@ -14970,7 +14971,7 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree orig_declv, { tree c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); OMP_CLAUSE_DECL (c) = decl; - c = finish_omp_clauses (c, true); + c = finish_omp_clauses (c, C_ORT_OMP); if (c) { OMP_CLAUSE_CHAIN (c) = *clauses; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2365a73..6f7f66a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5793,8 +5793,7 @@ cp_finish_omp_clause_depend_sink (tree sink_clause) Remove any elements from the list that are invalid. */ tree -finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd, - bool is_cilk) +finish_omp_clauses (tree clauses, unsigned int ort) { bitmap_head generic_head, firstprivate_head, lastprivate_head; bitmap_head aligned_head, map_head, map_field_head; @@ -5803,6 +5802,9 @@ finish_omp_clauses (tree clauses, bool allow_fields, bool declare_simd, bool branch_seen = false; bool copyprivate_seen = false; bool ordered_seen = false; + bool allow_fields = ort & C_ORT_OMP; + bool declare_simd = ort & C_ORT_DECLARE_SIMD; + bool is_cilk = ort & C_ORT_CILK; bitmap_obstack_initialize (NULL); bitmap_initialize (&generic_head, &bitmap_default_obstack); @@ -8342,7 +8344,7 @@ finish_omp_for (location_t locus, enum tree_code code, tree declv, OMP_CLAUSE_OPERAND (c, 0) = cilk_for_number_of_iterations (omp_for); OMP_CLAUSE_CHAIN (c) = clauses; - OMP_PARALLEL_CLAUSES (omp_par) = finish_omp_clauses (c, false); + OMP_PARALLEL_CLAUSES (omp_par) = finish_omp_clauses (c, 0); add_stmt (omp_par); return omp_par; }