From patchwork Thu Jul 30 10:30:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 502047 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 9F1A4140788 for ; Thu, 30 Jul 2015 20:30:25 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qXb7IEuk; dkim-atps=neutral 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=CYVq5x/IyX3lQ2L7IFCAtP0ZJRySepmAQpfZ+43mwjYW49pYQxa7M JxfC7L/JbstLnGtMAEHxoOJ6OYDUvXB2eC5ywew+CH2uWRfhkT42fszp6muxyQx7 Zu3x2q4psZdSt/R9YgB/lhC5hwQ2EkpVhme8x0GOWz5zTCem1cee/w= 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=r4Zx5u8mEVMatKZ4cl5E2onZAaU=; b=qXb7IEuk+RPqwP557PHy b62M9UuDaPCp61yT76d+VhSAmS7ekwKA3C84b44wE7y4dtbWR1jIHC8kLAwpmfUa 2rSfHFo5UH0kLmEZLq8VfDPYJloSJuFp3/5tGiN/0RGfrWMYruQ0zUdv1R9U5LaZ S/7Q8UzZRwSyR3NoQo19Az8= Received: (qmail 48670 invoked by alias); 30 Jul 2015 10:30:16 -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 48606 invoked by uid 89); 30 Jul 2015 10:30:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.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, 30 Jul 2015 10:30:09 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B2342AAC2 for ; Thu, 30 Jul 2015 10:30:05 +0000 (UTC) Date: Thu, 30 Jul 2015 12:30:05 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Merge decision_tree::gen_{gimple,generic} Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 This refactors things to remove duplicated code and make it easier to add more of it. Bootstrap on x86_64-unknown-linux-gnu running, no changes in generated code. Richard. 2015-07-30 Richard Biener * genmatch.c (decision_tree::gen_gimple): Merge with ... (decision_tree::gen_generic): ... this into ... (decision_tree::gen): ... this. (main): Adjust callers. Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 226393) +++ gcc/genmatch.c (working copy) @@ -1310,8 +1310,7 @@ struct decision_tree dt_node *root; void insert (struct simplify *, unsigned); - void gen_gimple (FILE *f = stderr); - void gen_generic (FILE *f = stderr); + void gen (FILE *f, bool gimple); void print (FILE *f = stderr); decision_tree () { root = new dt_node (dt_node::DT_NODE); } @@ -2997,92 +2996,14 @@ dt_simplify::gen (FILE *f, int indent, b tree. */ void -decision_tree::gen_gimple (FILE *f) +decision_tree::gen (FILE *f, bool gimple) { root->analyze (); - fprintf (stderr, "GIMPLE decision tree has %u leafs, maximum depth %u and " - "a total number of %u nodes\n", root->num_leafs, root->max_level, - root->total_size); - - for (unsigned n = 1; n <= 3; ++n) - { - /* First generate split-out functions. */ - for (unsigned i = 0; i < root->kids.length (); i++) - { - dt_operand *dop = static_cast(root->kids[i]); - expr *e = static_cast(dop->op); - if (e->ops.length () != n) - continue; - - fprintf (f, "\nstatic bool\n" - "gimple_simplify_%s (code_helper *res_code, tree *res_ops,\n" - " gimple_seq *seq, tree (*valueize)(tree) " - "ATTRIBUTE_UNUSED,\n" - " code_helper ARG_UNUSED (code), tree " - "ARG_UNUSED (type)\n", - e->operation->id); - for (unsigned i = 0; i < n; ++i) - fprintf (f, ", tree op%d", i); - fprintf (f, ")\n"); - fprintf (f, "{\n"); - dop->gen_kids (f, 2, true); - fprintf (f, " return false;\n"); - fprintf (f, "}\n"); - } - - /* Then generate the main entry with the outermost switch and - tail-calls to the split-out functions. */ - fprintf (f, "\nstatic bool\n" - "gimple_simplify (code_helper *res_code, tree *res_ops,\n" - " gimple_seq *seq, tree (*valueize)(tree),\n" - " code_helper code, tree type"); - for (unsigned i = 0; i < n; ++i) - fprintf (f, ", tree op%d", i); - fprintf (f, ")\n"); - fprintf (f, "{\n"); - - fprintf (f, " switch (code.get_rep())\n" - " {\n"); - for (unsigned i = 0; i < root->kids.length (); i++) - { - dt_operand *dop = static_cast(root->kids[i]); - expr *e = static_cast(dop->op); - if (e->ops.length () != n) - continue; - - if (*e->operation == CONVERT_EXPR - || *e->operation == NOP_EXPR) - fprintf (f, " CASE_CONVERT:\n"); - else - fprintf (f, " case %s%s:\n", - is_a (e->operation) ? "-" : "", - e->operation->id); - fprintf (f, " return gimple_simplify_%s (res_code, res_ops, " - "seq, valueize, code, type", e->operation->id); - for (unsigned i = 0; i < n; ++i) - fprintf (f, ", op%d", i); - fprintf (f, ");\n"); - } - fprintf (f, " default:;\n" - " }\n"); - - fprintf (f, " return false;\n"); - fprintf (f, "}\n"); - } -} - -/* Main entry to generate code for matching GENERIC IL off the decision - tree. */ - -void -decision_tree::gen_generic (FILE *f) -{ - root->analyze (); - - fprintf (stderr, "GENERIC decision tree has %u leafs, maximum depth %u and " - "a total number of %u nodes\n", root->num_leafs, root->max_level, - root->total_size); + fprintf (stderr, "%s decision tree has %u leafs, maximum depth %u and " + "a total number of %u nodes\n", + gimple ? "GIMPLE" : "GENERIC", + root->num_leafs, root->max_level, root->total_size); for (unsigned n = 1; n <= 3; ++n) { @@ -3093,64 +3014,97 @@ decision_tree::gen_generic (FILE *f) expr *e = static_cast(dop->op); if (e->ops.length () != n /* Builtin simplifications are somewhat premature on - GENERIC. The following drops patterns with outermost + GENERIC. The following drops patterns with outermost calls. It's easy to emit overloads for function code though if necessary. */ - || e->operation->kind != id_base::CODE) + || (!gimple + && e->operation->kind != id_base::CODE)) continue; - fprintf (f, "\nstatic tree\n" - "generic_simplify_%s (location_t ARG_UNUSED (loc), enum " - "tree_code ARG_UNUSED (code), tree ARG_UNUSED (type)", - e->operation->id); + if (gimple) + fprintf (f, "\nstatic bool\n" + "gimple_simplify_%s (code_helper *res_code, tree *res_ops,\n" + " gimple_seq *seq, tree (*valueize)(tree) " + "ATTRIBUTE_UNUSED,\n" + " code_helper ARG_UNUSED (code), tree " + "ARG_UNUSED (type)\n", + e->operation->id); + else + fprintf (f, "\nstatic tree\n" + "generic_simplify_%s (location_t ARG_UNUSED (loc), enum " + "tree_code ARG_UNUSED (code), tree ARG_UNUSED (type)", + e->operation->id); for (unsigned i = 0; i < n; ++i) fprintf (f, ", tree op%d", i); fprintf (f, ")\n"); fprintf (f, "{\n"); - dop->gen_kids (f, 2, false); - fprintf (f, " return NULL_TREE;\n"); + dop->gen_kids (f, 2, gimple); + if (gimple) + fprintf (f, " return false;\n"); + else + fprintf (f, " return NULL_TREE;\n"); fprintf (f, "}\n"); } /* Then generate the main entry with the outermost switch and tail-calls to the split-out functions. */ - fprintf (f, "\ntree\n" - "generic_simplify (location_t loc, enum tree_code code, " - "tree type ATTRIBUTE_UNUSED"); + if (gimple) + fprintf (f, "\nstatic bool\n" + "gimple_simplify (code_helper *res_code, tree *res_ops,\n" + " gimple_seq *seq, tree (*valueize)(tree),\n" + " code_helper code, tree type"); + else + fprintf (f, "\ntree\n" + "generic_simplify (location_t loc, enum tree_code code, " + "tree type ATTRIBUTE_UNUSED"); for (unsigned i = 0; i < n; ++i) fprintf (f, ", tree op%d", i); fprintf (f, ")\n"); fprintf (f, "{\n"); - fprintf (f, " switch (code)\n" - " {\n"); + if (gimple) + fprintf (f, " switch (code.get_rep())\n" + " {\n"); + else + fprintf (f, " switch (code)\n" + " {\n"); for (unsigned i = 0; i < root->kids.length (); i++) { dt_operand *dop = static_cast(root->kids[i]); expr *e = static_cast(dop->op); if (e->ops.length () != n /* Builtin simplifications are somewhat premature on - GENERIC. The following drops patterns with outermost + GENERIC. The following drops patterns with outermost calls. It's easy to emit overloads for function code though if necessary. */ - || e->operation->kind != id_base::CODE) + || (!gimple + && e->operation->kind != id_base::CODE)) continue; - operator_id *op_id = static_cast (e->operation); - if (op_id->code == NOP_EXPR || op_id->code == CONVERT_EXPR) + if (*e->operation == CONVERT_EXPR + || *e->operation == NOP_EXPR) fprintf (f, " CASE_CONVERT:\n"); else - fprintf (f, " case %s:\n", e->operation->id); - fprintf (f, " return generic_simplify_%s (loc, code, type", - e->operation->id); + fprintf (f, " case %s%s:\n", + is_a (e->operation) ? "-" : "", + e->operation->id); + if (gimple) + fprintf (f, " return gimple_simplify_%s (res_code, res_ops, " + "seq, valueize, code, type", e->operation->id); + else + fprintf (f, " return generic_simplify_%s (loc, code, type", + e->operation->id); for (unsigned i = 0; i < n; ++i) fprintf (f, ", op%d", i); fprintf (f, ");\n"); } - fprintf (f, " default:;\n" - " }\n"); + fprintf (f, " default:;\n" + " }\n"); - fprintf (f, " return NULL_TREE;\n"); + if (gimple) + fprintf (f, " return false;\n"); + else + fprintf (f, " return NULL_TREE;\n"); fprintf (f, "}\n"); } } @@ -4317,10 +4271,7 @@ add_operator (VIEW_CONVERT2, "VIEW_CONVE if (verbose == 2) dt.print (stderr); - if (gimple) - dt.gen_gimple (stdout); - else - dt.gen_generic (stdout); + dt.gen (stdout, gimple); /* Finalize. */ cpp_finish (r, NULL);