aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorSandra Loosemore <sandra@codesourcery.com>2023-11-19 00:56:47 +0000
committerSandra Loosemore <sandra@codesourcery.com>2023-12-19 20:06:58 +0000
commit82b32adaa7f9cf3be71a9d41d80570b9efb4c2f0 (patch)
treec22f35d46cbdd0c04ed059cd84afd7d08593668d /gcc/cp
parent1502d724df85163b14b04e8f67072ca88eac411d (diff)
downloadgcc-82b32adaa7f9cf3be71a9d41d80570b9efb4c2f0.zip
gcc-82b32adaa7f9cf3be71a9d41d80570b9efb4c2f0.tar.gz
gcc-82b32adaa7f9cf3be71a9d41d80570b9efb4c2f0.tar.bz2
OpenMP: Introduce accessor macros and constructors for context selectors.
This patch hides the underlying nested TREE_LIST structure of context selectors behind accessor macros that have more meaningful names than the generic TREE_PURPOSE/TREE_VALUE accessors. There is a slight change to the representation in that the score expression in trait-selectors has a distinguished tag and is separated from the ordinary properties, although internally it is still represented as the first item in the TREE_VALUE of the selector. This patch also renames some local variables with slightly more descriptive names so it is easier to track whether something is a selector-set, selector, or property. gcc/ChangeLog * omp-general.h (OMP_TS_SCORE_NODE): New. (OMP_TSS_ID, OMP_TSS_TRAIT_SELECTORS): New. (OMP_TS_ID, OMP_TS_SCORE, OMP_TS_PROPERTIES): New. (OMP_TP_NAME, OMP_TP_VALUE): New. (make_trait_set_selector): Declare. (make_trait_selector): Declare. (make_trait_property): Declare. (omp_constructor_traits_to_codes): Rename to omp_construct_traits_to_codes. * omp-general.cc (omp_constructor_traits_to_codes): Rename to omp_construct_traits_to_codes. Use new accessors. (omp_check_context_selector): Use new accessors. (make_trait_set_selector): New. (make_trait_selector): New. (make_trait_property): New. (omp_context_name_list_prop): Use new accessors. (omp_context_selector_matches): Use new accessors. (omp_context_selector_props_compare): Use new accessors. (omp_context_selector_set_compare): Use new accessors. (omp_get_context_selector): Use new accessors. (omp_context_compute_score): Use new accessors. * gimplify.cc (omp_construct_selector_matches): Adjust for renaming of omp_constructor_traits_to_codes. gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Use new constructors. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_context_selector): Use new constructors. * pt.cc: Include omp-general.h. (tsubst_attribute): Use new context selector accessors and constructors. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Use new constructors.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/parser.cc30
-rw-r--r--gcc/cp/pt.cc82
2 files changed, 67 insertions, 45 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 1e2d520..5a91637 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47432,7 +47432,10 @@ static const char *const omp_user_selectors[] = {
trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])]
trait-score:
- score(score-expression) */
+ score(score-expression)
+
+ Note that this function returns a list of trait selectors for the
+ trait-selector-set SET. */
static tree
cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
@@ -47451,6 +47454,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
}
tree properties = NULL_TREE;
+ tree scoreval = NULL_TREE;
const char *const *selectors = NULL;
bool allow_score = true;
bool allow_user = false;
@@ -47557,8 +47561,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
{
score = fold_non_dependent_expr (score);
if (value_dependent_expression_p (score))
- properties = tree_cons (get_identifier (" score"),
- score, properties);
+ scoreval = score;
else if (!INTEGRAL_TYPE_P (TREE_TYPE (score))
|| TREE_CODE (score) != INTEGER_CST)
error_at (token->location, "score argument must be "
@@ -47567,8 +47570,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
error_at (token->location, "score argument must be "
"non-negative");
else
- properties = tree_cons (get_identifier (" score"),
- score, properties);
+ scoreval = score;
}
}
else
@@ -47588,7 +47590,8 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
{
t = fold_non_dependent_expr (t);
if (TREE_CODE (t) == STRING_CST)
- properties = tree_cons (NULL_TREE, t, properties);
+ 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)))
@@ -47596,7 +47599,8 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
"constant integer expression or string "
"literal");
else
- properties = tree_cons (NULL_TREE, t, properties);
+ properties = make_trait_property (NULL_TREE, t,
+ properties);
}
else
return error_mark_node;
@@ -47614,7 +47618,8 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
{
tree prop = cp_lexer_peek_token (parser->lexer)->u.value;
cp_lexer_consume_token (parser->lexer);
- properties = tree_cons (prop, NULL_TREE, properties);
+ properties = make_trait_property (prop, NULL_TREE,
+ properties);
}
else
{
@@ -47643,7 +47648,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
return error_mark_node;
}
- properties = tree_cons (prop, value, properties);
+ properties = make_trait_property (prop, value, properties);
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
cp_lexer_consume_token (parser->lexer);
@@ -47663,7 +47668,8 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
error_at (token->location, "property must be "
"constant integer expression");
else
- properties = tree_cons (NULL_TREE, t, properties);
+ properties = make_trait_property (NULL_TREE, t,
+ properties);
}
else
return error_mark_node;
@@ -47698,7 +47704,7 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
return error_mark_node;
}
- ret = tree_cons (selector, properties, ret);
+ ret = make_trait_selector (selector, scoreval, properties, ret);
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
cp_lexer_consume_token (parser->lexer);
@@ -47780,7 +47786,7 @@ cp_parser_omp_context_selector_specification (cp_parser *parser,
ret = error_mark_node;
}
else if (ret != error_mark_node)
- ret = tree_cons (set, selectors, ret);
+ ret = make_trait_set_selector (set, selectors, ret);
braces.require_close (parser);
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 7208c72..a752dcf 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see
#include "selftest.h"
#include "target.h"
#include "builtins.h"
+#include "omp-general.h"
/* The type of functions taking a tree, and some additional data, and
returning an int. */
@@ -11888,50 +11889,72 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
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 score = get_identifier (" score");
tree condition = get_identifier ("condition");
- for (tree t1 = ctx; t1; t1 = TREE_CHAIN (t1))
+ for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
{
- const char *set = IDENTIFIER_POINTER (TREE_PURPOSE (t1));
- TREE_VALUE (t1) = copy_list (TREE_VALUE (t1));
- for (tree t2 = TREE_VALUE (t1); t2; t2 = TREE_CHAIN (t2))
+ const char *set = IDENTIFIER_POINTER (OMP_TSS_ID (tss));
+ tree selectors = NULL_TREE;
+ for (tree ts = OMP_TSS_TRAIT_SELECTORS (tss); ts;
+ ts = TREE_CHAIN (ts))
{
- if (TREE_PURPOSE (t2) == simd && set[0] == 'c')
+ tree properties = NULL_TREE;
+ tree scoreval = NULL_TREE;
+ if (OMP_TS_ID (ts) == simd && set[0] == 'c')
{
- tree clauses = TREE_VALUE (t2);
+ tree clauses = OMP_TS_PROPERTIES (ts);
clauses = tsubst_omp_clauses (clauses,
C_ORT_OMP_DECLARE_SIMD, args,
complain, in_decl);
c_omp_declare_simd_clauses_to_decls (*decl_p, clauses);
clauses = finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD);
- TREE_VALUE (t2) = clauses;
+ properties = clauses;
}
else
{
- TREE_VALUE (t2) = copy_list (TREE_VALUE (t2));
- for (tree t3 = TREE_VALUE (t2); t3; t3 = TREE_CHAIN (t3))
- if (TREE_VALUE (t3))
+ tree v = OMP_TS_SCORE (ts);
+ if (v)
+ {
+ v = tsubst_expr (v, args, complain, in_decl);
+ v = fold_non_dependent_expr (v);
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (v))
+ || TREE_CODE (v) != INTEGER_CST)
+ {
+ location_t loc
+ = cp_expr_loc_or_loc (OMP_TS_SCORE (ts),
+ match_loc);
+ error_at (loc, "score argument must be "
+ "constant integer expression");
+ return NULL_TREE;
+ }
+ else if (tree_int_cst_sgn (v) < 0)
+ {
+ location_t loc
+ = cp_expr_loc_or_loc (OMP_TS_SCORE (ts),
+ match_loc);
+ error_at (loc, "score argument must be "
+ "non-negative");
+ return NULL_TREE;
+ }
+ scoreval = v;
+ }
+ properties = copy_list (OMP_TS_PROPERTIES (ts));
+ for (tree p = properties; p; p = TREE_CHAIN (p))
+ if (OMP_TP_VALUE (p))
{
bool allow_string
- = ((TREE_PURPOSE (t2) != condition || set[0] != 'u')
- && TREE_PURPOSE (t3) != score);
- tree v = TREE_VALUE (t3);
+ = (OMP_TS_ID (ts) != condition || set[0] != 'u');
+ tree v = OMP_TP_VALUE (p);
if (TREE_CODE (v) == STRING_CST && allow_string)
continue;
v = tsubst_expr (v, args, complain, in_decl);
v = fold_non_dependent_expr (v);
if (!INTEGRAL_TYPE_P (TREE_TYPE (v))
- || (TREE_PURPOSE (t3) == score
- ? TREE_CODE (v) != INTEGER_CST
- : !tree_fits_shwi_p (v)))
+ || !tree_fits_shwi_p (v))
{
location_t loc
- = cp_expr_loc_or_loc (TREE_VALUE (t3),
+ = cp_expr_loc_or_loc (OMP_TP_VALUE (p),
match_loc);
- if (TREE_PURPOSE (t3) == score)
- error_at (loc, "score argument must be "
- "constant integer expression");
- else if (allow_string)
+ if (allow_string)
error_at (loc, "property must be constant "
"integer expression or string "
"literal");
@@ -11940,20 +11963,13 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
"integer expression");
return NULL_TREE;
}
- else if (TREE_PURPOSE (t3) == score
- && tree_int_cst_sgn (v) < 0)
- {
- location_t loc
- = cp_expr_loc_or_loc (TREE_VALUE (t3),
- match_loc);
- error_at (loc, "score argument must be "
- "non-negative");
- return NULL_TREE;
- }
- TREE_VALUE (t3) = v;
+ OMP_TP_VALUE (p) = v;
}
}
+ selectors = make_trait_selector (OMP_TS_ID (ts), scoreval,
+ properties, selectors);
}
+ OMP_TSS_TRAIT_SELECTORS (tss) = nreverse (selectors);
}
val = tree_cons (varid, ctx, chain);
}