From 0889c52f15b21171977ad329ea8e6a096c1af827 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 22 Jul 2015 13:16:50 +0000 Subject: [PATCH] genmatch.c (struct operand): Add location member. 2015-07-22 Richard Biener * genmatch.c (struct operand): Add location member. (predicate, expr, c_expr, capture, if_expr, with_expr): Adjust constructors. (struct simplify): Remove match_location and result_location members. (elsehwere): Adjust. From-SVN: r226067 --- gcc/ChangeLog | 9 ++++ gcc/genmatch.c | 139 ++++++++++++++++++++++++------------------------- 2 files changed, 76 insertions(+), 72 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e6b8485f4d4..e1e93ad9a27 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-07-22 Richard Biener + + * genmatch.c (struct operand): Add location member. + (predicate, expr, c_expr, capture, if_expr, with_expr): Adjust + constructors. + (struct simplify): Remove match_location and result_location + members. + (elsehwere): Adjust. + 2015-07-22 Prachi Godbole * config/mips/m5100.md: New file. diff --git a/gcc/genmatch.c b/gcc/genmatch.c index f543ad74380..169541767d1 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -483,8 +483,10 @@ struct capture_info; struct operand { enum op_type { OP_PREDICATE, OP_EXPR, OP_CAPTURE, OP_C_EXPR, OP_IF, OP_WITH }; - operand (enum op_type type_) : type (type_) {} + operand (enum op_type type_, source_location loc_) + : type (type_), location (loc_) {} enum op_type type; + source_location location; virtual void gen_transform (FILE *, int, const char *, bool, int, const char *, capture_info *, dt_operand ** = 0, @@ -496,7 +498,8 @@ struct operand { struct predicate : public operand { - predicate (predicate_id *p_) : operand (OP_PREDICATE), p (p_) {} + predicate (predicate_id *p_, source_location loc) + : operand (OP_PREDICATE, loc), p (p_) {} predicate_id *p; }; @@ -505,12 +508,12 @@ struct predicate : public operand struct expr : public operand { - expr (id_base *operation_, bool is_commutative_ = false) - : operand (OP_EXPR), operation (operation_), + expr (id_base *operation_, source_location loc, bool is_commutative_ = false) + : operand (OP_EXPR, loc), operation (operation_), ops (vNULL), expr_type (NULL), is_commutative (is_commutative_), is_generic (false), force_single_use (false) {} expr (expr *e) - : operand (OP_EXPR), operation (e->operation), + : operand (OP_EXPR, e->location), operation (e->operation), ops (vNULL), expr_type (e->expr_type), is_commutative (e->is_commutative), is_generic (e->is_generic), force_single_use (e->force_single_use) {} void append_op (operand *op) { ops.safe_push (op); } @@ -546,10 +549,11 @@ struct c_expr : public operand id_tab (const char *id_, const char *oper_): id (id_), oper (oper_) {} }; - c_expr (cpp_reader *r_, vec code_, unsigned nr_stmts_, + c_expr (cpp_reader *r_, source_location loc, + vec code_, unsigned nr_stmts_, vec ids_, cid_map_t *capture_ids_) - : operand (OP_C_EXPR), r (r_), code (code_), capture_ids (capture_ids_), - nr_stmts (nr_stmts_), ids (ids_) {} + : operand (OP_C_EXPR, loc), r (r_), code (code_), + capture_ids (capture_ids_), nr_stmts (nr_stmts_), ids (ids_) {} /* cpplib tokens and state to transform this back to source. */ cpp_reader *r; vec code; @@ -567,8 +571,8 @@ struct c_expr : public operand struct capture : public operand { - capture (unsigned where_, operand *what_) - : operand (OP_CAPTURE), where (where_), what (what_) {} + capture (source_location loc, unsigned where_, operand *what_) + : operand (OP_CAPTURE, loc), where (where_), what (what_) {} /* Identifier index for the value. */ unsigned where; /* The captured value. */ @@ -582,8 +586,8 @@ struct capture : public operand struct if_expr : public operand { - if_expr () : operand (OP_IF), cond (NULL), trueexpr (NULL), - falseexpr (NULL) {} + if_expr (source_location loc) + : operand (OP_IF, loc), cond (NULL), trueexpr (NULL), falseexpr (NULL) {} c_expr *cond; operand *trueexpr; operand *falseexpr; @@ -593,7 +597,8 @@ struct if_expr : public operand struct with_expr : public operand { - with_expr () : operand (OP_WITH), with (NULL), subexpr (NULL) {} + with_expr (source_location loc) + : operand (OP_WITH, loc), with (NULL), subexpr (NULL) {} c_expr *with; operand *subexpr; }; @@ -655,25 +660,20 @@ struct simplify { enum simplify_kind { SIMPLIFY, MATCH }; - simplify (simplify_kind kind_, - operand *match_, source_location match_location_, - struct operand *result_, source_location result_location_, + simplify (simplify_kind kind_, operand *match_, operand *result_, vec > for_vec_, cid_map_t *capture_ids_) - : kind (kind_), match (match_), match_location (match_location_), - result (result_), result_location (result_location_), + : kind (kind_), match (match_), result (result_), for_vec (for_vec_), capture_ids (capture_ids_), capture_max (capture_ids_->elements () - 1) {} simplify_kind kind; /* The expression that is matched against the GENERIC or GIMPLE IL. */ operand *match; - source_location match_location; /* For a (simplify ...) an expression with ifs and withs with the expression produced when the pattern applies in the leafs. For a (match ...) the leafs are either empty if it is a simple predicate or the single expression specifying the matched operands. */ struct operand *result; - source_location result_location; /* Collected 'for' expression operators that have to be replaced in the lowering phase. */ vec > for_vec; @@ -772,7 +772,7 @@ commutate (operand *op) vec v = commutate (c->what); for (unsigned i = 0; i < v.length (); ++i) { - capture *nc = new capture (c->where, v[i]); + capture *nc = new capture (c->location, c->where, v[i]); ret.safe_push (nc); } return ret; @@ -829,8 +829,7 @@ lower_commutative (simplify *s, vec& simplifiers) vec matchers = commutate (s->match); for (unsigned i = 0; i < matchers.length (); ++i) { - simplify *ns = new simplify (s->kind, matchers[i], s->match_location, - s->result, s->result_location, + simplify *ns = new simplify (s->kind, matchers[i], s->result, s->for_vec, s->capture_ids); simplifiers.safe_push (ns); } @@ -846,7 +845,7 @@ lower_opt_convert (operand *o, enum tree_code oper, if (capture *c = dyn_cast (o)) { if (c->what) - return new capture (c->where, + return new capture (c->location, c->where, lower_opt_convert (c->what, oper, to_oper, strip)); else return c; @@ -958,8 +957,7 @@ lower_opt_convert (simplify *s, vec& simplifiers) vec matchers = lower_opt_convert (s->match); for (unsigned i = 0; i < matchers.length (); ++i) { - simplify *ns = new simplify (s->kind, matchers[i], s->match_location, - s->result, s->result_location, + simplify *ns = new simplify (s->kind, matchers[i], s->result, s->for_vec, s->capture_ids); simplifiers.safe_push (ns); } @@ -981,7 +979,7 @@ lower_cond (operand *o) lop = lower_cond (c->what); for (unsigned i = 0; i < lop.length (); ++i) - ro.safe_push (new capture (c->where, lop[i])); + ro.safe_push (new capture (c->location, c->where, lop[i])); return ro; } } @@ -1031,7 +1029,7 @@ lower_cond (operand *o) for (unsigned j = 0; j < ocmp->ops.length (); ++j) cmp->append_op (ocmp->ops[j]); cmp->is_generic = true; - ne->ops[0] = new capture (c->where, cmp); + ne->ops[0] = new capture (c->location, c->where, cmp); } else { @@ -1058,8 +1056,7 @@ lower_cond (simplify *s, vec& simplifiers) vec matchers = lower_cond (s->match); for (unsigned i = 0; i < matchers.length (); ++i) { - simplify *ns = new simplify (s->kind, matchers[i], s->match_location, - s->result, s->result_location, + simplify *ns = new simplify (s->kind, matchers[i], s->result, s->for_vec, s->capture_ids); simplifiers.safe_push (ns); } @@ -1076,7 +1073,8 @@ replace_id (operand *o, user_id *id, id_base *with) { if (!c->what) return c; - return new capture (c->where, replace_id (c->what, id, with)); + return new capture (c->location, c->where, + replace_id (c->what, id, with)); } else if (expr *e = dyn_cast (o)) { @@ -1089,14 +1087,14 @@ replace_id (operand *o, user_id *id, id_base *with) } else if (with_expr *w = dyn_cast (o)) { - with_expr *nw = new with_expr (); + with_expr *nw = new with_expr (w->location); nw->with = as_a (replace_id (w->with, id, with)); nw->subexpr = replace_id (w->subexpr, id, with); return nw; } else if (if_expr *ife = dyn_cast (o)) { - if_expr *nife = new if_expr (); + if_expr *nife = new if_expr (ife->location); nife->cond = as_a (replace_id (ife->cond, id, with)); nife->trueexpr = replace_id (ife->trueexpr, id, with); if (ife->falseexpr) @@ -1110,7 +1108,8 @@ replace_id (operand *o, user_id *id, id_base *with) { vec ids = ce->ids.copy (); ids.safe_push (c_expr::id_tab (id->id, with->id)); - return new c_expr (ce->r, ce->code, ce->nr_stmts, ids, ce->capture_ids); + return new c_expr (ce->r, ce->location, + ce->code, ce->nr_stmts, ids, ce->capture_ids); } return o; @@ -1155,8 +1154,7 @@ lower_for (simplify *sin, vec& simplifiers) if (result_op) result_op = replace_id (result_op, id, oper); } - simplify *ns = new simplify (s->kind, match_op, s->match_location, - result_op, s->result_location, + simplify *ns = new simplify (s->kind, match_op, result_op, vNULL, s->capture_ids); worklist.safe_push (ns); } @@ -2582,7 +2580,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) { fprintf_indent (f, indent, "{\n"); indent += 4; - output_line_directive (f, w->with->code[0].src_loc); + output_line_directive (f, w->location); w->with->gen_transform (f, indent, NULL, true, 1, "type", NULL); gen_1 (f, indent, gimple, w->subexpr); indent -= 4; @@ -2591,7 +2589,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) } else if (if_expr *ife = dyn_cast (result)) { - output_line_directive (f, ife->cond->code[0].src_loc); + output_line_directive (f, ife->location); fprintf_indent (f, indent, "if ("); ife->cond->gen_transform (f, indent, NULL, true, 1, "type", NULL); fprintf (f, ")\n"); @@ -2672,7 +2670,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) fprintf_indent (f, indent, "if (dump_file && (dump_flags & TDF_DETAILS)) " "fprintf (dump_file, \"Applying pattern "); - output_line_directive (f, s->result_location, true); + output_line_directive (f, + result ? result->location : s->match->location, true); fprintf (f, ", %%s:%%d\\n\", __FILE__, __LINE__);\n"); if (!result) @@ -2868,7 +2867,8 @@ dt_simplify::gen (FILE *f, int indent, bool gimple) { fprintf_indent (f, indent, "{\n"); indent += 2; - output_line_directive (f, s->result_location); + output_line_directive (f, + s->result ? s->result->location : s->match->location); if (s->capture_max >= 0) fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = {};\n", s->capture_max + 1); @@ -3045,11 +3045,9 @@ private: void parse_pattern (); operand *parse_result (operand *, predicate_id *); void push_simplify (simplify::simplify_kind, - vec&, operand *, source_location, - operand *, source_location); + vec&, operand *, operand *); void parse_simplify (simplify::simplify_kind, - source_location, vec&, predicate_id *, - operand *); + vec&, predicate_id *, operand *); void parse_for (source_location); void parse_if (source_location); void parse_predicates (source_location); @@ -3269,7 +3267,7 @@ parser::parse_operation () struct operand * parser::parse_capture (operand *op) { - eat_token (CPP_ATSIGN); + source_location src_loc = eat_token (CPP_ATSIGN)->src_loc; const cpp_token *token = peek (); const char *id = NULL; if (token->type == CPP_NUMBER) @@ -3283,7 +3281,7 @@ parser::parse_capture (operand *op) unsigned &num = capture_ids->get_or_insert (id, &existed); if (!existed) num = next_id; - return new capture (num, op); + return new capture (src_loc, num, op); } /* Parse an expression @@ -3292,8 +3290,9 @@ parser::parse_capture (operand *op) struct operand * parser::parse_expr () { - expr *e = new expr (parse_operation ()); const cpp_token *token = peek (); + expr *e = new expr (parse_operation (), token->src_loc); + token = peek (); operand *op; bool is_commutative = false; bool force_capture = false; @@ -3345,7 +3344,7 @@ parser::parse_expr () capture_ids->get_or_insert (xstrdup (id), &existed); if (existed) fatal_at (token, "reserved capture id '%s' already used", id); - op = new capture (num, e); + op = new capture (token->src_loc, num, e); } else op = e; @@ -3386,7 +3385,7 @@ parser::parse_c_expr (cpp_ttype start) unsigned opencnt; vec code = vNULL; unsigned nr_stmts = 0; - eat_token (start); + source_location loc = eat_token (start)->src_loc; if (start == CPP_OPEN_PAREN) end = CPP_CLOSE_PAREN; else if (start == CPP_OPEN_BRACE) @@ -3423,7 +3422,7 @@ parser::parse_c_expr (cpp_ttype start) code.safe_push (*token); } while (1); - return new c_expr (r, code, nr_stmts, vNULL, capture_ids); + return new c_expr (r, loc, code, nr_stmts, vNULL, capture_ids); } /* Parse an operand which is either an expression, a predicate or @@ -3460,7 +3459,7 @@ parser::parse_op () fatal_at (token, "using an operator with operands as predicate"); /* Parse the zero-operand operator "predicates" as expression. */ - op = new expr (opr); + op = new expr (opr, token->src_loc); } else if (user_id *code = dyn_cast (opr)) { @@ -3468,10 +3467,10 @@ parser::parse_op () fatal_at (token, "using an operator with operands as predicate"); /* Parse the zero-operand operator "predicates" as expression. */ - op = new expr (opr); + op = new expr (opr, token->src_loc); } else if (predicate_id *p = dyn_cast (opr)) - op = new predicate (p); + op = new predicate (p, token->src_loc); else fatal_at (token, "using an unsupported operator as predicate"); if (!parsing_match_operand) @@ -3499,15 +3498,14 @@ parser::parse_op () void parser::push_simplify (simplify::simplify_kind kind, vec& simplifiers, - operand *match, source_location match_loc, - operand *result, source_location result_loc) + operand *match, operand *result) { /* Build and push a temporary for operator list uses in expressions. */ if (!oper_lists.is_empty ()) active_fors.safe_push (oper_lists); simplifiers.safe_push - (new simplify (kind, match, match_loc, result, result_loc, + (new simplify (kind, match, result, active_fors.copy (), capture_ids)); if (!oper_lists.is_empty ()) @@ -3531,7 +3529,7 @@ parser::parse_result (operand *result, predicate_id *matcher) if (peek_ident ("if")) { eat_ident ("if"); - if_expr *ife = new if_expr (); + if_expr *ife = new if_expr (token->src_loc); ife->cond = parse_c_expr (CPP_OPEN_PAREN); if (peek ()->type == CPP_OPEN_PAREN) { @@ -3563,7 +3561,7 @@ parser::parse_result (operand *result, predicate_id *matcher) else if (peek_ident ("with")) { eat_ident ("with"); - with_expr *withe = new with_expr (); + with_expr *withe = new with_expr (token->src_loc); /* Parse (with c-expr expr) as (if-with (true) expr). */ withe->with = parse_c_expr (CPP_OPEN_BRACE); withe->with->nr_stmts = 0; @@ -3574,9 +3572,9 @@ parser::parse_result (operand *result, predicate_id *matcher) else if (peek_ident ("switch")) { token = eat_ident ("switch"); - eat_token (CPP_OPEN_PAREN); + source_location ifloc = eat_token (CPP_OPEN_PAREN)->src_loc; eat_ident ("if"); - if_expr *ife = new if_expr (); + if_expr *ife = new if_expr (ifloc); operand *res = ife; ife->cond = parse_c_expr (CPP_OPEN_PAREN); if (peek ()->type == CPP_OPEN_PAREN) @@ -3593,9 +3591,9 @@ parser::parse_result (operand *result, predicate_id *matcher) { if (peek_ident ("if", 2)) { - eat_token (CPP_OPEN_PAREN); + ifloc = eat_token (CPP_OPEN_PAREN)->src_loc; eat_ident ("if"); - ife->falseexpr = new if_expr (); + ife->falseexpr = new if_expr (ifloc); ife = as_a (ife->falseexpr); ife->cond = parse_c_expr (CPP_OPEN_PAREN); if (peek ()->type == CPP_OPEN_PAREN) @@ -3641,7 +3639,6 @@ parser::parse_result (operand *result, predicate_id *matcher) void parser::parse_simplify (simplify::simplify_kind kind, - source_location match_location, vec& simplifiers, predicate_id *matcher, operand *result) { @@ -3668,7 +3665,7 @@ parser::parse_simplify (simplify::simplify_kind kind, if_expr *active_if = NULL; for (int i = active_ifs.length (); i > 0; --i) { - if_expr *ifc = new if_expr (); + if_expr *ifc = new if_expr (active_ifs[i-1]->location); ifc->cond = active_ifs[i-1]; ifc->trueexpr = active_if; active_if = ifc; @@ -3690,8 +3687,7 @@ parser::parse_simplify (simplify::simplify_kind kind, active_if->trueexpr = result; result = outermost_if; } - push_simplify (kind, simplifiers, match, match_location, - result, token->src_loc); + push_simplify (kind, simplifiers, match, result); return; } @@ -3704,8 +3700,7 @@ parser::parse_simplify (simplify::simplify_kind kind, else result = tem; - push_simplify (kind, simplifiers, match, match_location, - result, token->src_loc); + push_simplify (kind, simplifiers, match, result); } /* Parsing of the outer control structures. */ @@ -3930,13 +3925,13 @@ parser::parse_pattern () const char *id = get_ident (); if (strcmp (id, "simplify") == 0) { - parse_simplify (simplify::SIMPLIFY, - token->src_loc, simplifiers, NULL, NULL); + parse_simplify (simplify::SIMPLIFY, simplifiers, NULL, NULL); capture_ids = NULL; } else if (strcmp (id, "match") == 0) { bool with_args = false; + source_location e_loc = peek ()->src_loc; if (peek ()->type == CPP_OPEN_PAREN) { eat_token (CPP_OPEN_PAREN); @@ -3959,7 +3954,7 @@ parser::parse_pattern () if (with_args) { capture_ids = new cid_map_t; - e = new expr (p); + e = new expr (p, e_loc); while (peek ()->type == CPP_ATSIGN) e->append_op (parse_capture (NULL)); eat_token (CPP_CLOSE_PAREN); @@ -3969,7 +3964,7 @@ parser::parse_pattern () || (!e && p->nargs != 0))) fatal_at (token, "non-matching number of match operands"); p->nargs = e ? e->ops.length () : 0; - parse_simplify (simplify::MATCH, token->src_loc, p->matchers, p, e); + parse_simplify (simplify::MATCH, p->matchers, p, e); capture_ids = NULL; } else if (strcmp (id, "for") == 0) -- 2.30.2