diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-08-10 12:18:25 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-08-10 12:18:25 +0200 |
commit | 77eb117f588686e6fb018d103fc3d1899be9b008 (patch) | |
tree | 9a022bfea1239471ef385682ffd6de3991c16408 /gcc/cp/parser.c | |
parent | 5b7ed762347ea9e82a3982b57975747de0943eb4 (diff) | |
download | gcc-77eb117f588686e6fb018d103fc3d1899be9b008.zip gcc-77eb117f588686e6fb018d103fc3d1899be9b008.tar.gz gcc-77eb117f588686e6fb018d103fc3d1899be9b008.tar.bz2 |
tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DEVICE_TYPE.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DEVICE_TYPE.
(enum omp_clause_device_type_kind): New enum.
(struct tree_omp_clause): Add subcode.device_type_kind.
* tree.h (OMP_CLAUSE_DEVICE_TYPE_KIND): Define.
* tree.c (omp_clause_num_ops, omp_clause_code_name): Add entries
for device_type clause.
(walk_tree_1): Handle OMP_CLAUSE_DEVICE_TYPE.
* tree-pretty-print.c (dump_omp_clause): Likewise.
c-family/
* c-pragma.h (enum pragma_omp_clause): Add
PRAGMA_OMP_CLAUSE_DEVICE_TYPE.
c/
* c-parser.c (c_parser_omp_clause_name): Parse device_type.
(c_parser_omp_clause_device_type): New function.
(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DEVICE_TYPE.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DEVICE_TYPE.
(c_parser_omp_declare_target): Handle device_type clauses. Remove
diagnostics for declare target with clauses nested in clause-less
declare target declaration-definition-seq.
* c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_DEVICE_TYPE.
cp/
* parser.c (cp_parser_omp_clause_name): Parse device_type.
(cp_parser_omp_clause_device_type): New function.
(cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DEVICE_TYPE.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DEVICE_TYPE.
(cp_parser_omp_declare_target): Handle device_type clauses. Remove
diagnostics for declare target with clauses nested in clause-less
declare target declaration-definition-seq.
* semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_DEVICE_TYPE.
testsuite/
* c-c++-common/gomp/declare-target-2.c: Don't expect error for
declare target with clauses in between declare target without clauses
and end declare target.
* c-c++-common/gomp/declare-target-4.c: New test.
From-SVN: r274252
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 100 |
1 files changed, 94 insertions, 6 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b5196f6..b56cc69 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32510,6 +32510,8 @@ cp_parser_omp_clause_name (cp_parser *parser) result = PRAGMA_OACC_CLAUSE_DEVICEPTR; else if (!strcmp ("device_resident", p)) result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT; + else if (!strcmp ("device_type", p)) + result = PRAGMA_OMP_CLAUSE_DEVICE_TYPE; else if (!strcmp ("dist_schedule", p)) result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; break; @@ -35321,6 +35323,56 @@ cp_parser_omp_clause_proc_bind (cp_parser *parser, tree list, return list; } +/* OpenMP 5.0: + device_type ( host | nohost | any ) */ + +static tree +cp_parser_omp_clause_device_type (cp_parser *parser, tree list, + location_t location) +{ + tree c; + enum omp_clause_device_type_kind kind; + + if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) + return list; + + if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) + { + tree id = cp_lexer_peek_token (parser->lexer)->u.value; + const char *p = IDENTIFIER_POINTER (id); + + if (strcmp ("host", p) == 0) + kind = OMP_CLAUSE_DEVICE_TYPE_HOST; + else if (strcmp ("nohost", p) == 0) + kind = OMP_CLAUSE_DEVICE_TYPE_NOHOST; + else if (strcmp ("any", p) == 0) + kind = OMP_CLAUSE_DEVICE_TYPE_ANY; + else + goto invalid_kind; + } + else + goto invalid_kind; + + cp_lexer_consume_token (parser->lexer); + if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_COMMA_CLOSE_PAREN)) + goto resync_fail; + + c = build_omp_clause (location, OMP_CLAUSE_DEVICE_TYPE); + /* check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE_TYPE, "device_type", + location); */ + OMP_CLAUSE_DEVICE_TYPE_KIND (c) = kind; + OMP_CLAUSE_CHAIN (c) = list; + return c; + + invalid_kind: + cp_parser_error (parser, "invalid depend kind"); + resync_fail: + cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + return list; +} + /* OpenACC: async [( int-expr )] */ @@ -35849,6 +35901,11 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask, token->location); c_name = "proc_bind"; break; + case PRAGMA_OMP_CLAUSE_DEVICE_TYPE: + clauses = cp_parser_omp_clause_device_type (parser, clauses, + token->location); + c_name = "device_type"; + break; case PRAGMA_OMP_CLAUSE_SAFELEN: clauses = cp_parser_omp_clause_safelen (parser, clauses, token->location); @@ -39831,12 +39888,15 @@ cp_parser_late_parsing_omp_declare_simd (cp_parser *parser, tree attrs) #define OMP_DECLARE_TARGET_CLAUSE_MASK \ ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ - | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK) \ + | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE)) static void cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok) { tree clauses = NULL_TREE; + int device_type = 0; + bool only_device_type = true; if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) clauses = cp_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK, @@ -39854,17 +39914,18 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok) scope_chain->omp_declare_target_attribute++; return; } - if (scope_chain->omp_declare_target_attribute) - error_at (pragma_tok->location, - "%<#pragma omp declare target%> with clauses in between " - "%<#pragma omp declare target%> without clauses and " - "%<#pragma omp end declare target%>"); + for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE) + device_type |= OMP_CLAUSE_DEVICE_TYPE_KIND (c); for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) { + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEVICE_TYPE) + continue; tree t = OMP_CLAUSE_DECL (c), id; tree at1 = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t)); tree at2 = lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (t)); + only_device_type = false; if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK) { id = get_identifier ("omp declare target link"); @@ -39897,7 +39958,34 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok) } } } + if (TREE_CODE (t) != FUNCTION_DECL) + continue; + if ((device_type & OMP_CLAUSE_DEVICE_TYPE_HOST) != 0) + { + tree at3 = lookup_attribute ("omp declare target host", + DECL_ATTRIBUTES (t)); + if (at3 == NULL_TREE) + { + id = get_identifier ("omp declare target host"); + DECL_ATTRIBUTES (t) + = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); + } + } + if ((device_type & OMP_CLAUSE_DEVICE_TYPE_NOHOST) != 0) + { + tree at3 = lookup_attribute ("omp declare target nohost", + DECL_ATTRIBUTES (t)); + if (at3 == NULL_TREE) + { + id = get_identifier ("omp declare target nohost"); + DECL_ATTRIBUTES (t) + = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); + } + } } + if (device_type && only_device_type) + warning_at (OMP_CLAUSE_LOCATION (clauses), 0, + "directive with only %<device_type%> clauses ignored"); } static void |