This patch teaches the c and c++ front ends to use a common function to split clauses in combined acc parallel loops and acc kernel loops. There's still a little bit of duplicate code inside c_parser_oacc_loop and c_parser_oacc_loop and cp_parser_oacc_loop with their respective calls to c_finish_omp_clauses and finish_omp_clauses. But those are the only two isolated cases. I've also added a c_ prefix to oacc_filter_device_types because that how the other functions in c-omp.c are named.
I've applied this patch to gomp-4_0-branch. Cesar
2015-06-15 Cesar Philippidis <ce...@codesourcery.com> gcc/c-family/ * c-common.h (c_oacc_split_loop_clauses): Declare. (oacc_extract_device_id): Remove declaration. (oacc_filter_device_types): Rename to ... (c_oacc_filter_device_types): ... this. * c-omp.c (oacc_extract_device_id): Rename to ... (c_oacc_extract_device_id): ... this and make static. (oacc_filter_device_types): Rename to ... (c_oacc_filter_device_types): ... this. (c_oacc_split_loop_clauses): New function. gcc/c/ * c-parser.c (c_parser_oacc_all_clauses): Call c_oacc_filter_device_types instead of oacc_filter_device_types. (oacc_split_loop_clauses): Remove. (c_parser_oacc_loop): Call c_oacc_split_loop_clauses instead of oacc_split_loop_clauses. gcc/cp/ * parser.c (cp_parser_oacc_all_clauses): Call c_oacc_filter_device_types instead of oacc_filter_device_types. (oacc_split_loop_clauses): Remove. (cp_parser_oacc_loop): Call c_oacc_split_loop_clauses instead of oacc_split_loop_clauses. diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index fcaebca..28d3252 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1249,8 +1249,8 @@ extern void c_omp_split_clauses (location_t, enum tree_code, omp_clause_mask, extern tree c_omp_declare_simd_clauses_to_numbers (tree, tree); extern void c_omp_declare_simd_clauses_to_decls (tree, tree); extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree); -extern int oacc_extract_device_id (const char *); -extern tree oacc_filter_device_types (tree); +extern tree c_oacc_filter_device_types (tree); +extern tree c_oacc_split_loop_clauses (tree, tree *); /* Return next tree in the chain for chain_next walking of tree nodes. */ static inline tree diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c index bcb6ff4..3909ec8 100644 --- a/gcc/c-family/c-omp.c +++ b/gcc/c-family/c-omp.c @@ -1093,8 +1093,8 @@ c_omp_predetermined_sharing (tree decl) only device_type(nvidia) is supported. All device_type parameters are treated as case-insensitive keywords. */ -int -oacc_extract_device_id (const char *device) +static int +c_oacc_extract_device_id (const char *device) { if (!strcasecmp (device, "nvidia")) return GOMP_DEVICE_NVIDIA_PTX; @@ -1115,7 +1115,7 @@ struct identifier_hasher : ggc_cache_hasher<tree> /* Filter out the list of unsupported OpenACC device_types. */ tree -oacc_filter_device_types (tree clauses) +c_oacc_filter_device_types (tree clauses) { tree c, prev; tree dtype = NULL_TREE; @@ -1141,7 +1141,7 @@ oacc_filter_device_types (tree clauses) goto filter_dtype; } - int code = oacc_extract_device_id (IDENTIFIER_POINTER (t)); + int code = c_oacc_extract_device_id (IDENTIFIER_POINTER (t)); if (code == GOMP_DEVICE_DEFAULT) seen_default = OMP_CLAUSE_DEVICE_TYPE_CLAUSES (c); @@ -1214,3 +1214,49 @@ oacc_filter_device_types (tree clauses) OMP_CLAUSE_CHAIN (prev) = dtype; return clauses; } + +/* Split the 'clauses' into a set of 'loop' clauses and a set of + 'not-loop' clauses. */ + +tree +c_oacc_split_loop_clauses (tree clauses, tree *not_loop_clauses) +{ + tree loop_clauses, next, c; + + loop_clauses = *not_loop_clauses = NULL_TREE; + + for (; clauses ; clauses = next) + { + next = OMP_CLAUSE_CHAIN (clauses); + + switch (OMP_CLAUSE_CODE (clauses)) + { + case OMP_CLAUSE_COLLAPSE: + case OMP_CLAUSE_REDUCTION: + case OMP_CLAUSE_GANG: + case OMP_CLAUSE_VECTOR: + case OMP_CLAUSE_WORKER: + case OMP_CLAUSE_AUTO: + case OMP_CLAUSE_SEQ: + OMP_CLAUSE_CHAIN (clauses) = loop_clauses; + loop_clauses = clauses; + break; + + case OMP_CLAUSE_FIRSTPRIVATE: + case OMP_CLAUSE_PRIVATE: + c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), + OMP_CLAUSE_CODE (clauses)); + OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); + OMP_CLAUSE_CHAIN (c) = loop_clauses; + loop_clauses = c; + /* FALL THROUGH */ + + default: + OMP_CLAUSE_CHAIN (clauses) = *not_loop_clauses; + *not_loop_clauses = clauses; + break; + } + } + + return loop_clauses; +} diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index f37a8f7..e7df751 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -12408,7 +12408,7 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, if (finish_p) { - clauses = oacc_filter_device_types (clauses); + clauses = c_oacc_filter_device_types (clauses); return c_finish_omp_clauses (clauses, true); } @@ -12939,58 +12939,6 @@ c_parser_oacc_declare (c_parser *parser) } } -/* Split the 'clauses' into a set of 'loop' clauses and a set of - 'not-loop' clauses. */ - -static tree -oacc_split_loop_clauses (tree clauses, tree *not_loop_clauses) -{ - tree loop_clauses, next, c; - - loop_clauses = *not_loop_clauses = NULL_TREE; - - for (; clauses ; clauses = next) - { - next = OMP_CLAUSE_CHAIN (clauses); - - switch (OMP_CLAUSE_CODE (clauses)) - { - case OMP_CLAUSE_COLLAPSE: - case OMP_CLAUSE_REDUCTION: - case OMP_CLAUSE_GANG: - case OMP_CLAUSE_VECTOR: - case OMP_CLAUSE_WORKER: - case OMP_CLAUSE_AUTO: - case OMP_CLAUSE_SEQ: - OMP_CLAUSE_CHAIN (clauses) = loop_clauses; - loop_clauses = clauses; - break; - - case OMP_CLAUSE_FIRSTPRIVATE: - case OMP_CLAUSE_PRIVATE: - c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), - OMP_CLAUSE_CODE (clauses)); - OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); - OMP_CLAUSE_CHAIN (c) = loop_clauses; - loop_clauses = c; - /* FALL THROUGH */ - - default: - OMP_CLAUSE_CHAIN (clauses) = *not_loop_clauses; - *not_loop_clauses = clauses; - break; - } - } - - if (*not_loop_clauses) - c_finish_omp_clauses (*not_loop_clauses, true); - - if (loop_clauses) - c_finish_omp_clauses (loop_clauses, true); - - return loop_clauses; -} - /* OpenACC 2.0: # pragma acc enter data oacc-enter-data-clause[optseq] new-line @@ -13127,7 +13075,15 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, OACC_LOOP_CLAUSE_DEVICE_TYPE_MASK, cclauses == NULL); if (cclauses) - clauses = oacc_split_loop_clauses (clauses, cclauses); + { + clauses = c_oacc_split_loop_clauses (clauses, cclauses); + + if (*cclauses) + c_finish_omp_clauses (*cclauses, true); + + if (clauses) + c_finish_omp_clauses (clauses, true); + } block = c_begin_compound_stmt (true); stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 60bc287..78bcb0a1 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -29748,7 +29748,7 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, if (finish_p) { - clauses = oacc_filter_device_types (clauses); + clauses = c_oacc_filter_device_types (clauses); return finish_omp_clauses (clauses, true); } @@ -32339,58 +32339,6 @@ cp_parser_oacc_enter_exit_data (cp_parser *parser, cp_token *pragma_tok, return stmt; } -/* Split the 'clauses' into a set of 'loop' clauses and a set of - 'not-loop' clauses. */ - -static tree -oacc_split_loop_clauses (tree clauses, tree *not_loop_clauses) -{ - tree loop_clauses, next, c; - - loop_clauses = *not_loop_clauses = NULL_TREE; - - for (; clauses ; clauses = next) - { - next = OMP_CLAUSE_CHAIN (clauses); - - switch (OMP_CLAUSE_CODE (clauses)) - { - case OMP_CLAUSE_COLLAPSE: - case OMP_CLAUSE_REDUCTION: - case OMP_CLAUSE_GANG: - case OMP_CLAUSE_VECTOR: - case OMP_CLAUSE_WORKER: - case OMP_CLAUSE_AUTO: - case OMP_CLAUSE_SEQ: - OMP_CLAUSE_CHAIN (clauses) = loop_clauses; - loop_clauses = clauses; - break; - - case OMP_CLAUSE_FIRSTPRIVATE: - case OMP_CLAUSE_PRIVATE: - c = build_omp_clause (OMP_CLAUSE_LOCATION (clauses), - OMP_CLAUSE_CODE (clauses)); - OMP_CLAUSE_DECL (c) = OMP_CLAUSE_DECL (clauses); - OMP_CLAUSE_CHAIN (c) = loop_clauses; - loop_clauses = c; - /* FALL THROUGH */ - - default: - OMP_CLAUSE_CHAIN (clauses) = *not_loop_clauses; - *not_loop_clauses = clauses; - break; - } - } - - if (*not_loop_clauses) - finish_omp_clauses (*not_loop_clauses, true); - - if (loop_clauses) - finish_omp_clauses (loop_clauses, true); - - return loop_clauses; -} - /* OpenACC 2.0: # pragma acc loop oacc-loop-clause[optseq] new-line structured-block */ @@ -32433,7 +32381,15 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name, cclauses == NULL); if (cclauses) - clauses = oacc_split_loop_clauses (clauses, cclauses); + { + clauses = c_oacc_split_loop_clauses (clauses, cclauses); + + if (*cclauses) + finish_omp_clauses (*cclauses, true); + + if (clauses) + finish_omp_clauses (clauses, true); + } block = begin_omp_structured_block (); save = cp_parser_begin_omp_structured_block (parser);