From patchwork Thu Sep 25 14:17:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 393354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2F2AB14017F for ; Fri, 26 Sep 2014 00:21:33 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Pua9xgI6fqlFyjHwZatLdGljcJ8DOHMmjMiovqF5SPFW9Pr7NFYJa HVvP1vGwoZ/dbXNRAHYtnxHo71/a97eRqCGdQBYuLdu1+nIYoi+EfSWLWwqU8FHC v5Y770fAeUT42hLaIAnCT4sliW8dzvQ/aykQ96Lqp18l6UeFFqOU1M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=mgsW+eGpsskq6Lr0cT8UY3HxrGg=; b=SXHBt7s7IJYbwQRVOD12 BWDhp6VwiXuAUGHXXEysOrvYBe5GryNNxU8P1YUtc3zcMZ34mye3ggGvFX+lcLx1 kwAngdaS8Wv7s371CI0XtYd2mpdeY/PqjD3Fh4SNKTsnZbhSaWRyrrNzuyvumMXe tm6xB69CuqlDB+JS0qko8cc= Received: (qmail 3472 invoked by alias); 25 Sep 2014 14:21:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3461 invoked by uid 89); 25 Sep 2014 14:21:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 25 Sep 2014 14:21:22 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5D42AAD6F for ; Thu, 25 Sep 2014 14:21:19 +0000 (UTC) Date: Thu, 25 Sep 2014 16:17:36 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][match-and-simplify] Fix capture change Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Of course I missed c-exprs... The following patch fixes that. Now bootstrapped (building stage3 target libs now). Applied. Richard. 2014-09-25 Richard Biener * genmatch.c (struct c_expr): Also record capture identifier to index map. (c_expr::gen_transform): Use it. Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 215598) +++ gcc/genmatch.c (working copy) @@ -408,12 +408,13 @@ struct c_expr : public operand }; c_expr (cpp_reader *r_, vec code_, unsigned nr_stmts_, - vec ids_ = vNULL) - : operand (OP_C_EXPR), r (r_), code (code_), + vec ids_, std::map *capture_ids_) + : operand (OP_C_EXPR), 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; + std::map *capture_ids; /* The number of statements parsed (well, the number of ';'s). */ unsigned nr_stmts; /* The identifier replacement vector. */ @@ -487,11 +488,11 @@ struct simplify simplify (operand *match_, source_location match_location_, struct operand *result_, source_location result_location_, vec ifexpr_vec_, vec > for_vec_, - int capture_max_) + std::map *capture_ids_) : match (match_), match_location (match_location_), result (result_), result_location (result_location_), ifexpr_vec (ifexpr_vec_), for_vec (for_vec_), - capture_max (capture_max_) {} + capture_ids (capture_ids_), capture_max (capture_ids_->size ()) {} /* The expression that is matched against the GENERIC or GIMPLE IL. */ operand *match; @@ -507,7 +508,8 @@ struct simplify /* Collected 'for' expression operators that have to be replaced in the lowering phase. */ vec > for_vec; - /* The maximum capture index seen. */ + /* A map of capture identifiers to indexes. */ + std::map *capture_ids; int capture_max; }; @@ -657,7 +659,7 @@ lower_commutative (simplify *s, vecmatch_location, s->result, s->result_location, s->ifexpr_vec, - s->for_vec, s->capture_max); + s->for_vec, s->capture_ids); simplifiers.safe_push (ns); } } @@ -787,7 +789,7 @@ lower_opt_convert (simplify *s, vecmatch_location, s->result, s->result_location, s->ifexpr_vec, - s->for_vec, s->capture_max); + s->for_vec, s->capture_ids); simplifiers.safe_push (ns); } } @@ -820,7 +822,7 @@ replace_id (operand *o, user_id *id, id_ { 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); + return new c_expr (ce->r, ce->code, ce->nr_stmts, ids, ce->capture_ids); } return o; @@ -872,7 +874,7 @@ lower_for (simplify *sin, vecmatch_location, result_op, s->result_location, - ifexpr_vec, vNULL, s->capture_max); + ifexpr_vec, vNULL, s->capture_ids); worklist.safe_push (ns); } } @@ -1399,12 +1401,18 @@ c_expr::gen_transform (FILE *f, const ch if (token->type == CPP_ATSIGN) { const cpp_token *n = &code[i+1]; - if (n->type == CPP_NUMBER + if ((n->type == CPP_NUMBER + || n->type == CPP_NAME) && !(n->flags & PREV_WHITE)) { if (token->flags & PREV_WHITE) fputc (' ', f); - fprintf (f, "captures[%s]", n->val.str.text); + const char *id; + if (n->type == CPP_NUMBER) + id = (const char *)n->val.str.text; + else + id = (const char *)CPP_HASHNODE (n->val.node.node)->ident.str; + fprintf (f, "captures[%u]", (*capture_ids)[id]); ++i; continue; } @@ -2284,7 +2292,6 @@ private: vec active_ifs; vec > active_fors; - int capture_max; std::map *capture_ids; public: @@ -2461,11 +2468,9 @@ parser::parse_capture (operand *op) id = get_ident (); else fatal_at (token, "expected number or identifier"); + unsigned next_id = capture_ids->size (); std::pair::iterator, bool> res - = capture_ids->insert - (std::pair(id, capture_max + 1)); - if (res.second) - capture_max++; + = capture_ids->insert (std::pair(id, next_id)); return new capture ((*res.first).second, op); } @@ -2571,7 +2576,7 @@ parser::parse_c_expr (cpp_ttype start) code.safe_push (*token); } while (1); - return new c_expr (r, code, nr_stmts); + return new c_expr (r, code, nr_stmts, vNULL, capture_ids); } /* Parse an operand which is either an expression, a predicate or @@ -2645,10 +2650,8 @@ void parser::parse_simplify (source_location match_location, vec& simplifiers, predicate_id *matcher) { - /* Reset the maximum capture number seen. */ - std::map cids; - capture_max = -1; - capture_ids = &cids; + /* Reset the capture map. */ + capture_ids = new std::map; const cpp_token *loc = peek (); struct operand *match = parse_op (); @@ -2673,7 +2676,7 @@ parser::parse_simplify (source_location simplifiers.safe_push (new simplify (match, match_location, NULL, token->src_loc, active_ifs.copy (), active_fors.copy (), - capture_max)); + capture_ids)); return; } @@ -2703,7 +2706,7 @@ parser::parse_simplify (source_location simplifiers.safe_push (new simplify (match, match_location, NULL, paren_loc, active_ifs.copy (), - active_fors.copy (), capture_max)); + active_fors.copy (), capture_ids)); } } else if (peek_ident ("with")) @@ -2732,7 +2735,7 @@ parser::parse_simplify (source_location simplifiers.safe_push (new simplify (match, match_location, op, token->src_loc, active_ifs.copy (), - active_fors.copy (), capture_max)); + active_fors.copy (), capture_ids)); eat_token (CPP_CLOSE_PAREN); /* A "default" result closes the enclosing scope. */ if (active_ifs.length () > active_ifs_len) @@ -2763,7 +2766,7 @@ parser::parse_simplify (source_location simplifiers.safe_push (new simplify (match, match_location, parse_op (), token->src_loc, active_ifs.copy (), - active_fors.copy (), capture_max)); + active_fors.copy (), capture_ids)); /* A "default" result closes the enclosing scope. */ if (active_ifs.length () > active_ifs_len) {