Commit 0b212d8c by Thomas Schwinge Committed by Thomas Schwinge

C/C++: Simplify handling of location information for OpenACC routine directives

	gcc/c/
	* c-parser.c (struct oacc_routine_data): New.
	(c_parser_declaration_or_fndef, c_parser_oacc_routine): Use it.
	Simplify code.
	(c_finish_oacc_routine): Likewise.  Don't attach clauses to "omp
	declare target" attribute.
	gcc/cp/
	* parser.h (struct cp_omp_declare_simd_data): New.
	(struct cp_parser): Use it for oacc_routine member.
	* parser.c (cp_ensure_no_oacc_routine, cp_parser_oacc_routine)
	(cp_parser_late_parsing_oacc_routine, cp_finalize_oacc_routine):
	Use it.  Simplify code.
	(cp_parser_new): Initialize all members pointing to special
	parsing data structures.
	(cp_parser_cilk_simd_fn_vector_attrs): Initialize
	parser->cilk_simd_fn_info->clauses.
	(cp_parser_omp_declare_simd): Initialize
	parser->omp_declare_simd->clauses.
	(cp_parser_late_parsing_omp_declare_simd): Simplify code.

From-SVN: r239127
parent bbc79c0e
2016-08-04 Thomas Schwinge <thomas@codesourcery.com>
* c-parser.c (struct oacc_routine_data): New.
(c_parser_declaration_or_fndef, c_parser_oacc_routine): Use it.
Simplify code.
(c_finish_oacc_routine): Likewise. Don't attach clauses to "omp
declare target" attribute.
2016-08-01 Jan Beulich <jbeulich@suse.com> 2016-08-01 Jan Beulich <jbeulich@suse.com>
* c-fold.c (c_fully_fold_internal): Also emit shift count * c-fold.c (c_fully_fold_internal): Also emit shift count
......
...@@ -1274,11 +1274,17 @@ enum c_parser_prec { ...@@ -1274,11 +1274,17 @@ enum c_parser_prec {
NUM_PRECS NUM_PRECS
}; };
/* Helper data structure for parsing #pragma acc routine. */
struct oacc_routine_data {
tree clauses;
location_t loc;
};
static void c_parser_external_declaration (c_parser *); static void c_parser_external_declaration (c_parser *);
static void c_parser_asm_definition (c_parser *); static void c_parser_asm_definition (c_parser *);
static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool,
bool, bool, tree *, vec<c_token>, bool, bool, tree *, vec<c_token>,
tree = NULL_TREE); struct oacc_routine_data * = NULL);
static void c_parser_static_assert_declaration_no_semi (c_parser *); static void c_parser_static_assert_declaration_no_semi (c_parser *);
static void c_parser_static_assert_declaration (c_parser *); static void c_parser_static_assert_declaration (c_parser *);
static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
...@@ -1370,7 +1376,7 @@ static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *); ...@@ -1370,7 +1376,7 @@ static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *);
static void c_parser_omp_end_declare_target (c_parser *); static void c_parser_omp_end_declare_target (c_parser *);
static void c_parser_omp_declare (c_parser *, enum pragma_context); static void c_parser_omp_declare (c_parser *, enum pragma_context);
static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *); static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *);
static void c_parser_oacc_routine (c_parser *parser, enum pragma_context); static void c_parser_oacc_routine (c_parser *, enum pragma_context);
/* These Objective-C parser functions are only ever called when /* These Objective-C parser functions are only ever called when
compiling Objective-C. */ compiling Objective-C. */
...@@ -1562,7 +1568,8 @@ c_parser_external_declaration (c_parser *parser) ...@@ -1562,7 +1568,8 @@ c_parser_external_declaration (c_parser *parser)
} }
static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>);
static void c_finish_oacc_routine (c_parser *, tree, tree, bool, bool, bool); static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool,
bool, bool);
/* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
6.7, 6.9.1). If FNDEF_OK is true, a function definition is 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
...@@ -1641,7 +1648,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -1641,7 +1648,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
bool nested, bool start_attr_ok, bool nested, bool start_attr_ok,
tree *objc_foreach_object_declaration, tree *objc_foreach_object_declaration,
vec<c_token> omp_declare_simd_clauses, vec<c_token> omp_declare_simd_clauses,
tree oacc_routine_clauses) struct oacc_routine_data *oacc_routine_data)
{ {
struct c_declspecs *specs; struct c_declspecs *specs;
tree prefix_attrs; tree prefix_attrs;
...@@ -1746,9 +1753,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -1746,9 +1753,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
pedwarn (here, 0, "empty declaration"); pedwarn (here, 0, "empty declaration");
} }
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (oacc_routine_clauses) if (oacc_routine_data)
c_finish_oacc_routine (parser, NULL_TREE, c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false, true,
oacc_routine_clauses, false, true, false); false);
return; return;
} }
...@@ -1865,9 +1872,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -1865,9 +1872,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
|| !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
omp_declare_simd_clauses); omp_declare_simd_clauses);
if (oacc_routine_clauses) if (oacc_routine_data)
c_finish_oacc_routine (parser, NULL_TREE, c_finish_oacc_routine (oacc_routine_data, NULL_TREE,
oacc_routine_clauses,
false, first, false); false, first, false);
c_parser_skip_to_end_of_block_or_statement (parser); c_parser_skip_to_end_of_block_or_statement (parser);
return; return;
...@@ -1983,8 +1989,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -1983,8 +1989,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
init = c_parser_initializer (parser); init = c_parser_initializer (parser);
finish_init (); finish_init ();
} }
if (oacc_routine_clauses) if (oacc_routine_data)
c_finish_oacc_routine (parser, d, oacc_routine_clauses, c_finish_oacc_routine (oacc_routine_data, d,
false, first, false); false, first, false);
if (d != error_mark_node) if (d != error_mark_node)
{ {
...@@ -2029,8 +2035,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -2029,8 +2035,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
if (parms) if (parms)
temp_pop_parm_decls (); temp_pop_parm_decls ();
} }
if (oacc_routine_clauses) if (oacc_routine_data)
c_finish_oacc_routine (parser, d, oacc_routine_clauses, c_finish_oacc_routine (oacc_routine_data, d,
false, first, false); false, first, false);
if (d) if (d)
finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, finish_decl (d, UNKNOWN_LOCATION, NULL_TREE,
...@@ -2142,9 +2148,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -2142,9 +2148,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
|| !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
omp_declare_simd_clauses); omp_declare_simd_clauses);
if (oacc_routine_clauses) if (oacc_routine_data)
c_finish_oacc_routine (parser, current_function_decl, c_finish_oacc_routine (oacc_routine_data, current_function_decl,
oacc_routine_clauses, false, first, true); false, first, true);
DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
= c_parser_peek_token (parser)->location; = c_parser_peek_token (parser)->location;
fnbody = c_parser_compound_statement (parser); fnbody = c_parser_compound_statement (parser);
...@@ -14025,9 +14031,9 @@ static void ...@@ -14025,9 +14031,9 @@ static void
c_parser_oacc_routine (c_parser *parser, enum pragma_context context) c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
{ {
tree decl = NULL_TREE; tree decl = NULL_TREE;
/* Create a dummy claue, to record location. */ oacc_routine_data data;
tree c_head = build_omp_clause (c_parser_peek_token (parser)->location, data.clauses = NULL_TREE;
OMP_CLAUSE_SEQ); data.loc = c_parser_peek_token (parser)->location;
if (context != pragma_external) if (context != pragma_external)
c_parser_error (parser, "%<#pragma acc routine%> not at file scope"); c_parser_error (parser, "%<#pragma acc routine%> not at file scope");
...@@ -14062,56 +14068,52 @@ c_parser_oacc_routine (c_parser *parser, enum pragma_context context) ...@@ -14062,56 +14068,52 @@ c_parser_oacc_routine (c_parser *parser, enum pragma_context context)
/* Build a chain of clauses. */ /* Build a chain of clauses. */
parser->in_pragma = true; parser->in_pragma = true;
tree clauses = c_parser_oacc_all_clauses data.clauses
(parser, OACC_ROUTINE_CLAUSE_MASK, "#pragma acc routine"); = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK,
"#pragma acc routine");
/* Force clauses to be non-null, by attaching context to it. */
clauses = tree_cons (c_head, clauses, NULL_TREE);
if (decl) if (decl)
c_finish_oacc_routine (parser, decl, clauses, true, true, false); c_finish_oacc_routine (&data, decl, true, true, false);
else if (c_parser_peek_token (parser)->type == CPP_PRAGMA) else if (c_parser_peek_token (parser)->type == CPP_PRAGMA)
/* This will emit an error. */ /* This will emit an error. */
c_finish_oacc_routine (parser, NULL_TREE, clauses, false, true, false); c_finish_oacc_routine (&data, NULL_TREE, false, true, false);
else else
c_parser_declaration_or_fndef (parser, true, false, false, false, c_parser_declaration_or_fndef (parser, true, false, false, false,
true, NULL, vNULL, clauses); true, NULL, vNULL, &data);
} }
/* Finalize an OpenACC routine pragma, applying it to FNDECL. CLAUSES /* Finalize an OpenACC routine pragma, applying it to FNDECL.
are the parsed clauses. IS_DEFN is true if we're applying it to IS_DEFN is true if we're applying it to the definition. */
the definition (so expect FNDEF to look somewhat defined. */
static void static void
c_finish_oacc_routine (c_parser *ARG_UNUSED (parser), tree fndecl, c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
tree clauses, bool named, bool first, bool is_defn) bool named, bool first, bool is_defn)
{ {
location_t loc = OMP_CLAUSE_LOCATION (TREE_PURPOSE (clauses));
if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL || !first) if (!fndecl || TREE_CODE (fndecl) != FUNCTION_DECL || !first)
{ {
if (fndecl != error_mark_node) if (fndecl != error_mark_node)
error_at (loc, "%<#pragma acc routine%> %s", error_at (data->loc, "%<#pragma acc routine%> %s",
named ? "does not refer to a function" named ? "does not refer to a function"
: "not followed by single function"); : "not followed by single function");
return; return;
} }
if (get_oacc_fn_attrib (fndecl)) if (get_oacc_fn_attrib (fndecl))
error_at (loc, "%<#pragma acc routine%> already applied to %D", fndecl); error_at (data->loc,
"%<#pragma acc routine%> already applied to %D", fndecl);
if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl))) if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl)))
error_at (loc, "%<#pragma acc routine%> must be applied before %s", error_at (data->loc, "%<#pragma acc routine%> must be applied before %s",
TREE_USED (fndecl) ? "use" : "definition"); TREE_USED (fndecl) ? "use" : "definition");
/* Process for function attrib */ /* Process the routine's dimension clauses. */
tree dims = build_oacc_routine_dims (TREE_VALUE (clauses)); tree dims = build_oacc_routine_dims (data->clauses);
replace_oacc_fn_attrib (fndecl, dims); replace_oacc_fn_attrib (fndecl, dims);
/* Also attach as a declare. */ /* Add an "omp declare target" attribute. */
DECL_ATTRIBUTES (fndecl) DECL_ATTRIBUTES (fndecl)
= tree_cons (get_identifier ("omp declare target"), = tree_cons (get_identifier ("omp declare target"),
clauses, DECL_ATTRIBUTES (fndecl)); NULL_TREE, DECL_ATTRIBUTES (fndecl));
} }
/* OpenACC 2.0: /* OpenACC 2.0:
......
2016-08-04 Thomas Schwinge <thomas@codesourcery.com>
* parser.h (struct cp_omp_declare_simd_data): New.
(struct cp_parser): Use it for oacc_routine member.
* parser.c (cp_ensure_no_oacc_routine, cp_parser_oacc_routine)
(cp_parser_late_parsing_oacc_routine, cp_finalize_oacc_routine):
Use it. Simplify code.
(cp_parser_new): Initialize all members pointing to special
parsing data structures.
(cp_parser_cilk_simd_fn_vector_attrs): Initialize
parser->cilk_simd_fn_info->clauses.
(cp_parser_omp_declare_simd): Initialize
parser->omp_declare_simd->clauses.
(cp_parser_late_parsing_omp_declare_simd): Simplify code.
2016-08-04 Marek Polacek <polacek@redhat.com> 2016-08-04 Marek Polacek <polacek@redhat.com>
PR c++/70229 PR c++/70229
......
...@@ -199,7 +199,8 @@ struct GTY (()) cp_parser_context { ...@@ -199,7 +199,8 @@ struct GTY (()) cp_parser_context {
}; };
/* Control structure for #pragma omp declare simd parsing. */ /* Helper data structure for parsing #pragma omp declare simd, and Cilk Plus
SIMD-enabled functions' vector attribute. */
struct cp_omp_declare_simd_data { struct cp_omp_declare_simd_data {
bool error_seen; /* Set if error has been reported. */ bool error_seen; /* Set if error has been reported. */
bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */ bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */
...@@ -207,6 +208,10 @@ struct cp_omp_declare_simd_data { ...@@ -207,6 +208,10 @@ struct cp_omp_declare_simd_data {
tree clauses; tree clauses;
}; };
/* Helper data structure for parsing #pragma acc routine. */
struct cp_oacc_routine_data : cp_omp_declare_simd_data {
location_t loc;
};
/* The cp_parser structure represents the C++ parser. */ /* The cp_parser structure represents the C++ parser. */
...@@ -363,18 +368,16 @@ struct GTY(()) cp_parser { ...@@ -363,18 +368,16 @@ struct GTY(()) cp_parser {
unsigned num_template_parameter_lists; unsigned num_template_parameter_lists;
/* When parsing #pragma omp declare simd, this is a pointer to a /* When parsing #pragma omp declare simd, this is a pointer to a
data structure with everything needed for parsing the clauses. */ helper data structure. */
cp_omp_declare_simd_data * GTY((skip)) omp_declare_simd; cp_omp_declare_simd_data * GTY((skip)) omp_declare_simd;
/* When parsing the vector attribute in Cilk Plus SIMD-enabled function, /* When parsing Cilk Plus SIMD-enabled functions' vector attributes,
this is a pointer to data structure with everything needed for parsing this is a pointer to a helper data structure. */
the clauses. The cp_omp_declare_simd_data struct will hold all the
necessary information, so creating another struct for this is not
necessary. */
cp_omp_declare_simd_data * GTY((skip)) cilk_simd_fn_info; cp_omp_declare_simd_data * GTY((skip)) cilk_simd_fn_info;
/* Parsing information for #pragma acc routine. */ /* When parsing #pragma acc routine, this is a pointer to a helper data
cp_omp_declare_simd_data * GTY((skip)) oacc_routine; structure. */
cp_oacc_routine_data * GTY((skip)) oacc_routine;
/* Nonzero if parsing a parameter list where 'auto' should trigger an implicit /* Nonzero if parsing a parameter list where 'auto' should trigger an implicit
template parameter. */ template parameter. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment