aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorSandra Loosemore <sandra@codesourcery.com>2023-12-18 23:16:53 +0000
committerSandra Loosemore <sandra@codesourcery.com>2023-12-19 20:07:13 +0000
commit9f9b3d67323ac690f75fad86a5b711ba3d9c6aae (patch)
tree4c246eb0db09687a86ceca2ace6b8da1cfc959af /gcc/cp
parent9b8fdcbf2105c65de231ea3db10aaf38e3f68530 (diff)
downloadgcc-9f9b3d67323ac690f75fad86a5b711ba3d9c6aae.zip
gcc-9f9b3d67323ac690f75fad86a5b711ba3d9c6aae.tar.gz
gcc-9f9b3d67323ac690f75fad86a5b711ba3d9c6aae.tar.bz2
OpenMP: Use enumerators for names of trait-sets and traits
This patch introduces enumerators to represent trait-set names and trait names, which makes it easier to use tables to control other behavior and for switch statements to dispatch on the tags. The tags are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or OMP_TS_ID) and are encoded there as integer constants. gcc/ChangeLog * omp-selectors.h: New file. * omp-general.h: Include omp-selectors.h. (OMP_TSS_CODE, OMP_TSS_NAME): New. (OMP_TS_CODE, OMP_TS_NAME): New. (make_trait_set_selector, make_trait_selector): Adjust declarations. (omp_construct_traits_to_codes): Likewise. (omp_context_selector_set_compare): Likewise. (omp_get_context_selector): Likewise. (omp_get_context_selector_list): New. * omp-general.cc (omp_construct_traits_to_codes): Pass length in as argument instead of returning it. Make it table-driven. (omp_tss_map): New. (kind_properties, vendor_properties, extension_properties): New. (atomic_default_mem_order_properties): New. (omp_ts_map): New. (omp_check_context_selector): Simplify lookup and dispatch logic. (omp_mark_declare_variant): Ignore variants with unknown construct selectors. Adjust for new representation. (make_trait_set_selector, make_trait_selector): Adjust for new representations. (omp_context_selector_matches): Simplify dispatch logic. Avoid fixed-sized buffers and adjust call to omp_construct_traits_to_codes. (omp_context_selector_props_compare): Adjust for new representations and simplify dispatch logic. (omp_context_selector_set_compare): Likewise. (omp_context_selector_compare): Likewise. (omp_get_context_selector): Adjust for new representations, and split out... (omp_get_context_selector_list): New function. (omp_lookup_tss_code): New. (omp_lookup_ts_code): New. (omp_context_compute_score): Adjust for new representations. Avoid fixed-sized buffers and magic numbers. Adjust call to omp_construct_traits_to_codes. * gimplify.cc (omp_construct_selector_matches): Avoid use of fixed-size buffer. Adjust call to omp_construct_traits_to_codes. gcc/c/ChangeLog * c-parser.cc (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (c_parser_omp_context_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. Adjust error messages for extraneous/incorrect score. (c_parser_omp_context_selector_specification): Likewise. (c_finish_omp_declare_variant): Adjust for new representations. gcc/cp/ChangeLog * decl.cc (omp_declare_variant_finalize_one): Adjust for new representations. * parser.cc (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (cp_parser_omp_context_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. Adjust error messages for extraneous/incorrect score. (cp_parser_omp_context_selector_specification): Likewise. * pt.cc (tsubst_attribute): Adjust for new representations. gcc/fortran/ChangeLog * gfortran.h: Include omp-selectors.h. (enum gfc_omp_trait_property_kind): Delete, and replace all references with equivalent omp_tp_type enumerators. (struct gfc_omp_trait_property): Update for omp_tp_type. (struct gfc_omp_selector): Replace string name with new enumerator. (struct gfc_omp_set_selector): Likewise. * openmp.cc (gfc_free_omp_trait_property_list): Update for omp_tp_type. (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (gfc_ignore_trait_property_extension): New. (gfc_ignore_trait_property_extension_list): New. (gfc_match_omp_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. (gfc_match_omp_context_selector): Adjust for new representations. Adjust error messages for extraneous/incorrect score. (gfc_match_omp_context_selector_specification): Likewise. * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for new representations. gcc/testsuite/ * c-c++-common/gomp/declare-variant-1.c: Expect warning on unknown selectors. * c-c++-common/gomp/declare-variant-2.c: Likewise. Also adjust messages for score errors. * c-c++-common/gomp/declare-variant-no-score.c: New. * gfortran.dg/gomp/declare-variant-1.f90: Expect warning on unknown selectors. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. Also adjust messages for score errors. * gfortran.dg/gomp/declare-variant-no-score.f90: New.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/decl.cc8
-rw-r--r--gcc/cp/parser.cc229
-rw-r--r--gcc/cp/pt.cc15
3 files changed, 91 insertions, 161 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 1ffe4c8..27f1780 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8097,12 +8097,13 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
}
tree ctx = TREE_VALUE (TREE_VALUE (attr));
- tree simd = omp_get_context_selector (ctx, "construct", "simd");
+ tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
+ OMP_TRAIT_CONSTRUCT_SIMD);
if (simd)
{
TREE_VALUE (simd)
= c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
- TREE_VALUE (simd));
+ OMP_TS_PROPERTIES (simd));
/* FIXME, adjusting simd args unimplemented. */
return true;
}
@@ -8195,7 +8196,8 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
}
else
{
- tree construct = omp_get_context_selector (ctx, "construct", NULL);
+ tree construct
+ = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
omp_mark_declare_variant (match_loc, variant, construct);
if (!omp_context_selector_matches (ctx))
return true;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 3250b0b..cb1dcd8 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47416,16 +47416,6 @@ cp_parser_omp_declare_simd (cp_parser *parser, cp_token *pragma_tok,
}
}
-static const char *const omp_construct_selectors[] = {
- "simd", "target", "teams", "parallel", "for", NULL };
-static const char *const omp_device_selectors[] = {
- "kind", "isa", "arch", NULL };
-static const char *const omp_implementation_selectors[] = {
- "vendor", "extension", "atomic_default_mem_order", "unified_address",
- "unified_shared_memory", "dynamic_allocators", "reverse_offload", NULL };
-static const char *const omp_user_selectors[] = {
- "condition", NULL };
-
/* OpenMP 5.0:
trait-selector:
@@ -47438,7 +47428,8 @@ static const char *const omp_user_selectors[] = {
trait-selector-set SET. */
static tree
-cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
+cp_parser_omp_context_selector (cp_parser *parser, enum omp_tss_code set,
+ bool has_parms_p)
{
tree ret = NULL_TREE;
do
@@ -47453,78 +47444,44 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
return error_mark_node;
}
- tree properties = NULL_TREE;
- tree scoreval = NULL_TREE;
- const char *const *selectors = NULL;
- bool allow_score = true;
- bool allow_user = false;
- int property_limit = 0;
- enum { CTX_PROPERTY_NONE, CTX_PROPERTY_USER, CTX_PROPERTY_NAME_LIST,
- CTX_PROPERTY_ID, CTX_PROPERTY_EXPR,
- CTX_PROPERTY_SIMD } property_kind = CTX_PROPERTY_NONE;
- switch (IDENTIFIER_POINTER (set)[0])
- {
- case 'c': /* construct */
- selectors = omp_construct_selectors;
- allow_score = false;
- property_limit = 1;
- property_kind = CTX_PROPERTY_SIMD;
- break;
- case 'd': /* device */
- selectors = omp_device_selectors;
- allow_score = false;
- allow_user = true;
- property_limit = 3;
- property_kind = CTX_PROPERTY_NAME_LIST;
- break;
- case 'i': /* implementation */
- selectors = omp_implementation_selectors;
- allow_user = true;
- property_limit = 3;
- property_kind = CTX_PROPERTY_NAME_LIST;
- break;
- case 'u': /* user */
- selectors = omp_user_selectors;
- property_limit = 1;
- property_kind = CTX_PROPERTY_EXPR;
- break;
- default:
- gcc_unreachable ();
- }
- for (int i = 0; ; i++)
+ enum omp_ts_code sel
+ = omp_lookup_ts_code (set, IDENTIFIER_POINTER (selector));
+
+ if (sel == OMP_TRAIT_INVALID)
{
- if (selectors[i] == NULL)
+ /* Per the spec, "Implementations can ignore specified selectors
+ that are not those described in this section"; however, we
+ must record such selectors because they cause match failures. */
+ warning_at (cp_lexer_peek_token (parser->lexer)->location,
+ OPT_Wopenmp,
+ "unknown selector %qs for context selector set %qs",
+ IDENTIFIER_POINTER (selector), omp_tss_map[set]);
+ cp_lexer_consume_token (parser->lexer);
+ ret = make_trait_selector (sel, NULL_TREE, NULL_TREE, ret);
+ if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
+ for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 1;
+ n; --n)
+ cp_lexer_consume_token (parser->lexer);
+ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
{
- if (allow_user)
- {
- property_kind = CTX_PROPERTY_USER;
- break;
- }
- else
- {
- error ("selector %qs not allowed for context selector "
- "set %qs", IDENTIFIER_POINTER (selector),
- IDENTIFIER_POINTER (set));
- cp_lexer_consume_token (parser->lexer);
- return error_mark_node;
- }
+ cp_lexer_consume_token (parser->lexer);
+ continue;
}
- if (i == property_limit)
- property_kind = CTX_PROPERTY_NONE;
- if (strcmp (selectors[i], IDENTIFIER_POINTER (selector)) == 0)
+ else
break;
}
- if (property_kind == CTX_PROPERTY_NAME_LIST
- && IDENTIFIER_POINTER (set)[0] == 'i'
- && strcmp (IDENTIFIER_POINTER (selector),
- "atomic_default_mem_order") == 0)
- property_kind = CTX_PROPERTY_ID;
cp_lexer_consume_token (parser->lexer);
+ tree properties = NULL_TREE;
+ tree scoreval = NULL_TREE;
+ enum omp_tp_type property_kind = omp_ts_map[sel].tp_type;
+ bool allow_score = omp_ts_map[sel].allow_score;
+ tree t;
+
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- if (property_kind == CTX_PROPERTY_NONE)
+ if (property_kind == OMP_TRAIT_PROPERTY_NONE)
{
error ("selector %qs does not accept any properties",
IDENTIFIER_POINTER (selector));
@@ -47535,8 +47492,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
parens.consume_open (parser);
cp_token *token = cp_lexer_peek_token (parser->lexer);
- if (allow_score
- && cp_lexer_next_token_is (parser->lexer, CPP_NAME)
+ if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
&& strcmp (IDENTIFIER_POINTER (token->u.value), "score") == 0
&& cp_lexer_nth_token_is (parser->lexer, 2, CPP_OPEN_PAREN))
{
@@ -47557,18 +47513,23 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
cp_parser_skip_to_closing_parenthesis (parser, true,
false, true);
cp_parser_require (parser, CPP_COLON, RT_COLON);
- if (score != error_mark_node)
+ if (!allow_score)
+ error_at (token->location,
+ "%<score%> cannot be specified in traits "
+ "in the %qs trait-selector-set",
+ omp_tss_map[set]);
+ else if (score != error_mark_node)
{
score = fold_non_dependent_expr (score);
if (value_dependent_expression_p (score))
scoreval = score;
else if (!INTEGRAL_TYPE_P (TREE_TYPE (score))
|| TREE_CODE (score) != INTEGER_CST)
- error_at (token->location, "score argument must be "
- "constant integer expression");
+ error_at (token->location, "%<score%> argument must "
+ "be constant integer expression");
else if (tree_int_cst_sgn (score) < 0)
- error_at (token->location, "score argument must be "
- "non-negative");
+ error_at (token->location, "%<score%> argument must "
+ "be non-negative");
else
scoreval = score;
}
@@ -47581,38 +47542,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
switch (property_kind)
{
- tree t;
- case CTX_PROPERTY_USER:
- do
- {
- t = cp_parser_constant_expression (parser);
- if (t != error_mark_node)
- {
- t = fold_non_dependent_expr (t);
- if (TREE_CODE (t) == STRING_CST)
- properties = make_trait_property (NULL_TREE, t,
- properties);
- else if (!value_dependent_expression_p (t)
- && (!INTEGRAL_TYPE_P (TREE_TYPE (t))
- || !tree_fits_shwi_p (t)))
- error_at (token->location, "property must be "
- "constant integer expression or string "
- "literal");
- else
- properties = make_trait_property (NULL_TREE, t,
- properties);
- }
- else
- return error_mark_node;
-
- if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
- cp_lexer_consume_token (parser->lexer);
- else
- break;
- }
- while (1);
- break;
- case CTX_PROPERTY_ID:
+ case OMP_TRAIT_PROPERTY_ID:
if (cp_lexer_next_token_is (parser->lexer, CPP_KEYWORD)
|| cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
@@ -47627,7 +47557,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
return error_mark_node;
}
break;
- case CTX_PROPERTY_NAME_LIST:
+ case OMP_TRAIT_PROPERTY_NAME_LIST:
do
{
tree prop = OMP_TP_NAMELIST_NODE;
@@ -47658,7 +47588,9 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
}
while (1);
break;
- case CTX_PROPERTY_EXPR:
+ case OMP_TRAIT_PROPERTY_EXPR:
+ /* FIXME: this is bogus, the expression need
+ not be constant. */
t = cp_parser_constant_expression (parser);
if (t != error_mark_node)
{
@@ -47675,18 +47607,32 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
else
return error_mark_node;
break;
- case CTX_PROPERTY_SIMD:
- if (!has_parms_p)
+ case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
+ if (sel == OMP_TRAIT_CONSTRUCT_SIMD)
+ {
+ if (!has_parms_p)
+ {
+ error_at (token->location, "properties for %<simd%> "
+ "selector may not be specified in "
+ "%<metadirective%>");
+ return error_mark_node;
+ }
+ properties
+ = cp_parser_omp_all_clauses (parser,
+ OMP_DECLARE_SIMD_CLAUSE_MASK,
+ "simd", NULL, true, 2);
+ }
+ else if (sel == OMP_TRAIT_IMPLEMENTATION_REQUIRES)
{
- error_at (token->location, "properties for %<simd%> "
- "selector may not be specified in "
- "%<metadirective%>");
+ /* FIXME: The "requires" selector was added in OpenMP 5.1.
+ Currently only the now-deprecated syntax
+ from OpenMP 5.0 is supported. */
+ sorry_at (token->location,
+ "%<requires%> selector is not supported yet");
return error_mark_node;
}
- properties
- = cp_parser_omp_all_clauses (parser,
- OMP_DECLARE_SIMD_CLAUSE_MASK,
- "simd", NULL, true, 2);
+ else
+ gcc_unreachable ();
break;
default:
gcc_unreachable ();
@@ -47697,15 +47643,15 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
properties = nreverse (properties);
}
- else if (property_kind == CTX_PROPERTY_NAME_LIST
- || property_kind == CTX_PROPERTY_ID
- || property_kind == CTX_PROPERTY_EXPR)
+ else if (property_kind != OMP_TRAIT_PROPERTY_NONE
+ && property_kind != OMP_TRAIT_PROPERTY_CLAUSE_LIST
+ && property_kind != OMP_TRAIT_PROPERTY_EXTENSION)
{
cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
return error_mark_node;
}
- ret = make_trait_selector (selector, scoreval, properties, ret);
+ ret = make_trait_selector (sel, scoreval, properties, ret);
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
cp_lexer_consume_token (parser->lexer);
@@ -47741,35 +47687,14 @@ cp_parser_omp_context_selector_specification (cp_parser *parser,
if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
setp
= IDENTIFIER_POINTER (cp_lexer_peek_token (parser->lexer)->u.value);
- switch (setp[0])
- {
- case 'c':
- if (strcmp (setp, "construct") == 0)
- setp = NULL;
- break;
- case 'd':
- if (strcmp (setp, "device") == 0)
- setp = NULL;
- break;
- case 'i':
- if (strcmp (setp, "implementation") == 0)
- setp = NULL;
- break;
- case 'u':
- if (strcmp (setp, "user") == 0)
- setp = NULL;
- break;
- default:
- break;
- }
- if (setp)
+ enum omp_tss_code set = omp_lookup_tss_code (setp);
+
+ if (set == OMP_TRAIT_SET_INVALID)
{
- cp_parser_error (parser, "expected %<construct%>, %<device%>, "
- "%<implementation%> or %<user%>");
+ cp_parser_error (parser, "expected context selector set name");
return error_mark_node;
}
- tree set = cp_lexer_peek_token (parser->lexer)->u.value;
cp_lexer_consume_token (parser->lexer);
if (!cp_parser_require (parser, CPP_EQ, RT_EQ))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ef280e4..f7063e0 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11888,18 +11888,20 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
tree chain = TREE_CHAIN (val);
location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
tree ctx = copy_list (TREE_VALUE (val));
- tree simd = get_identifier ("simd");
- tree condition = get_identifier ("condition");
for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
{
- const char *set = IDENTIFIER_POINTER (OMP_TSS_ID (tss));
+ enum omp_tss_code set = OMP_TSS_CODE (tss);
tree selectors = NULL_TREE;
for (tree ts = OMP_TSS_TRAIT_SELECTORS (tss); ts;
ts = TREE_CHAIN (ts))
{
tree properties = NULL_TREE;
tree scoreval = NULL_TREE;
- if (OMP_TS_ID (ts) == simd && set[0] == 'c')
+ /* FIXME: The body of this loop should really be dispatching
+ according to omp_ts_map[OMP_TS_CODE (TS)].tp_type instead
+ of having hard-wired knowledge of specific selectors. */
+ if (OMP_TS_CODE (ts) == OMP_TRAIT_CONSTRUCT_SIMD
+ && set == OMP_TRAIT_SET_CONSTRUCT)
{
tree clauses = OMP_TS_PROPERTIES (ts);
clauses = tsubst_omp_clauses (clauses,
@@ -11944,7 +11946,8 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
else if (OMP_TP_VALUE (p))
{
bool allow_string
- = (OMP_TS_ID (ts) != condition || set[0] != 'u');
+ = (OMP_TS_CODE (ts) != OMP_TRAIT_USER_CONDITION
+ || set != OMP_TRAIT_SET_USER);
tree v = OMP_TP_VALUE (p);
if (TREE_CODE (v) == STRING_CST && allow_string)
continue;
@@ -11968,7 +11971,7 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
OMP_TP_VALUE (p) = v;
}
}
- selectors = make_trait_selector (OMP_TS_ID (ts), scoreval,
+ selectors = make_trait_selector (OMP_TS_CODE (ts), scoreval,
properties, selectors);
}
OMP_TSS_TRAIT_SELECTORS (tss) = nreverse (selectors);