From patchwork Mon Feb 1 18:11:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jesper_Broge_J=C3=B8rgensen?= X-Patchwork-Id: 576660 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 CE75A140317 for ; Tue, 2 Feb 2016 05:12:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yFcY+7Ur; 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=WYKa984PnTtvSSs/6 LgmcM0W1+zrmhdIDXNBqznHEZqlsqFGPAzGRWcyHJFnUJqNpjZsywAn4133/fpGa FxTW8cWrxmpyjcUKgzECrzAMp0b8XUm8WQteqqUYWIR/fToCkYnH2BHCajRVwMUF jkheUleMbu2cxCOdtmwSZFqgaE= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=2G+ibrorWbqRwgYy0dHhB+F Jir4=; b=yFcY+7Ur4BJGAimzhiJlbDoTXFtqdpPoPNpS8z/sCI3M5iRLYZmzayu +KeM+GCK3QGkf6cfCyB7NMw7bmEMHgXrqPOmxdwwYxv6rVA2ddZ9OFI+dW7GLjiv fcSuPzgeBUQZkE3YFiglPf3haQBlqffcAtquIM9OrQaffLdK+Vek= Received: (qmail 42717 invoked by alias); 1 Feb 2016 18:11:57 -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 42699 invoked by uid 89); 1 Feb 2016 18:11:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=damage, atlantic, xstr, XSTR X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 01 Feb 2016 18:11:53 +0000 Received: by mail-wm0-f46.google.com with SMTP id p63so83899314wmp.1 for ; Mon, 01 Feb 2016 10:11:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=8Lbxq55DNr9q+cUaCvUh+iRsJZZaispDU9YJxz9Ick0=; b=AkdTQ5i1ppwFG98tC5cHsiKrAiMxlmFo5EFhjoluCDSS90Uitp1n1+jloHZcTqmoCV U5SrB8RRer0Ll6MFitHNczNODrxW/4pLGszhDF+vacMrSd89EY5mZQ5G2E0vVUpIP3j0 slgW4YjfPfaM+x1RnS6214VoLYwMI+ejvvrT7AHd97aoX/RVOzcwZYQIAPkx+H0biACg uqGygspEGBjIbq6YcpMjdMSww/oOIaEcMbsXQqejFhaITADU/jEMxddCqH1CD9EES8BW +tpzjOwn76XqxZ8mCF7DYizQkBDX53Htczp86ydnzSZ5kGhxk6aWF/zLOd9g3+4imLHd 9BLQ== X-Gm-Message-State: AG10YOSLxpFP+P29CPvXXB16W2tSGd5mBpVkJUdDWQ7E0FE6oAxadV3xL8ZUeFDhTtv5VQ== X-Received: by 10.28.132.74 with SMTP id g71mr13951640wmd.100.1454350310568; Mon, 01 Feb 2016 10:11:50 -0800 (PST) Received: from Jespers-MacBook-Pro.local ([178.157.250.73]) by smtp.googlemail.com with ESMTPSA id kb5sm30427806wjc.22.2016.02.01.10.11.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Feb 2016 10:11:49 -0800 (PST) Message-ID: <56AF9FE2.9050209@gmail.com> Date: Mon, 01 Feb 2016 19:11:46 +0100 From: =?windows-1252?Q?Jesper_Broge_J=F8rgensen?= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Bernd Schmidt , =?windows-1252?Q?Manuel_L=F3pe?= =?windows-1252?Q?z-Ib=E1=F1ez?= , gcc-patches@gcc.gnu.org Subject: Re: genattrab.c generate switch References: <56959FF8.9070908@gmail.com> <569CF36C.5090302@redhat.com> <569CF90C.8030307@gmail.com> <569D2356.3050905@gmail.com> <569D6AD7.7050400@gmail.com> <569E2996.4070200@redhat.com> In-Reply-To: <569E2996.4070200@redhat.com> On 19/01/16 13:18, Bernd Schmidt wrote: > On 01/18/2016 11:44 PM, Jesper Broge Jørgensen wrote: >> I found a formatting tool called uncrustify that comes with a gnu style >> config >> https://github.com/bengardner/uncrustify/blob/master/etc/gnu-indent.cfg >> that needed a few tweaks to format code that looked what is already in >> gcc/genattrtab.c >> >> The tweaks was: >> >> indent_with_tabs = 2 // instead of 0 >> sp_func_def_paren = add // instead of remove >> sp_func_proto_paren = add // instead of remove >> sp_func_call_paren = add // instead of remove >> >> So now the code should be correctly formatted. > > Best to get that right when editing, though. emacs defaults to GNU > style and other editors can also be tweaked. > >> Do i send in a new patch or just respond to the old one with the new >> changes? > > Usually best to send updated patches (as text/plain attachment to > avoid word-wrapping and other whitespace damage). > >> I have also followed instructions at >> https://gcc.gnu.org/ml/gcc/2003-06/txt00010.txt to get copyright >> assignment though i have not yet received a reply. > > Ok, we'll have to wait for that. > > > Bernd > I have finally received the copyright assignment it is currently on its way over the atlantic via snail mail. In the meantime i have attached the the refomatted patch here hoping it could be reviewed while we wait. gcc/ChangeLog: 2016-01-19 Jesper Broge Jørgensen * genattrtab.c (check_attr_set_switch): New function (write_attr_set): Write a switch instead of if condition if possible diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c index 2caf8f6..8e7f9e6 100644 --- a/gcc/genattrtab.c +++ b/gcc/genattrtab.c @@ -4113,6 +4113,103 @@ eliminate_known_true (rtx known_true, rtx exp, int insn_code, int insn_index) return exp; } +/* Check if exp contains a series of IOR conditions on the same attr_name. + If it does it can be turned into a switch statement and returns true. + If write_cases is true it will write the cases of the switch to outf. */ + +static int +check_attr_set_switch (FILE *outf, rtx exp, unsigned int attrs_cached, + int write_cases, int indent) +{ + if (GET_CODE (exp) != IOR) + return 0; + if (GET_CODE (XEXP (exp, 0)) != EQ_ATTR) + return 0; + + rtx next = exp; + int ior_depth = 0; + int is_first = 1; + + const char *attr_name_cmp = XSTR (XEXP (exp, 0), 0); + + while (1) + { + rtx op1 = XEXP (next, 0); + rtx op2 = XEXP (next, 1); + + if (GET_CODE (op1) != EQ_ATTR) + return 0; + + const char *attr_name = XSTR (op1, 0); + const char *cmp_val = XSTR (op1, 1); + + /* pointer compare is enough. */ + if (attr_name_cmp != attr_name) + return 0; + + if (write_cases) + { + struct attr_desc *attr = find_attr (&attr_name, 0); + gcc_assert (attr); + if (is_first) + { + fprintf (outf, "("); + is_first = 0; + int i; + for (i = 0; i < cached_attr_count; i++) + if (attr->name == cached_attrs[i]) + break; + + if (i < cached_attr_count && (attrs_cached & (1U << i)) != 0) + fprintf (outf, "cached_%s", attr->name); + else if (i < cached_attr_count && + (attrs_to_cache & (1U << i)) != 0) + fprintf (outf, "(cached_%s = get_attr_%s (insn))", attr->name, + attr->name); + else + fprintf (outf, "get_attr_%s (insn)", attr->name); + fprintf (outf, ")\n"); + write_indent (outf, indent); + fprintf (outf, "{\n"); + } + write_indent (outf, indent); + fprintf (outf, "case "); + write_attr_valueq (outf, attr, cmp_val); + fprintf (outf, ":\n"); + } + + const int code = GET_CODE (op2); + if (code != IOR) + { + if (code == EQ_ATTR) + { + const char *attr_name = XSTR (op2, 0); + const char *cmp_val = XSTR (op2, 1); + + if (attr_name == alternative_name) + return 0; + + struct attr_desc *attr = find_attr (&attr_name, 0); + gcc_assert (attr); + + if (attr->is_const) + return 0; + else if (write_cases) + { + write_indent (outf, indent); + fprintf (outf, "case "); + write_attr_valueq (outf, attr, cmp_val); + fprintf (outf, ":\n"); + } + } + break; + } + next = op2; + ior_depth++; + } + return ior_depth > 2; +} + /* Write out a series of tests and assignment statements to perform tests and sets of an attribute value. We are passed an indentation amount and prefix and suffix strings to write around each attribute value (e.g., "return" @@ -4123,6 +4220,7 @@ write_attr_set (FILE *outf, struct attr_desc *attr, int indent, rtx value, const char *prefix, const char *suffix, rtx known_true, int insn_code, int insn_index, unsigned int attrs_cached) { + int n_switches = 0; if (GET_CODE (value) == COND) { /* Assume the default value will be the default of the COND unless we @@ -4132,6 +4230,7 @@ write_attr_set (FILE *outf, struct attr_desc *attr, int indent, rtx value, rtx newexp; int first_if = 1; int i; + int is_switch = 0; if (cached_attr_count) { @@ -4176,40 +4275,68 @@ write_attr_set (FILE *outf, struct attr_desc *attr, int indent, rtx value, if (inner_true == false_rtx) continue; + is_switch = check_attr_set_switch (outf, testexp, attrs_cached, 0, + indent); + attrs_cached_inside = attrs_cached; attrs_cached_after = attrs_cached; write_indent (outf, indent); - fprintf (outf, "%sif ", first_if ? "" : "else "); - first_if = 0; - write_test_expr (outf, testexp, attrs_cached, - (FLG_AFTER | FLG_INSIDE | FLG_OUTSIDE_AND)); - attrs_cached = attrs_cached_after; - fprintf (outf, "\n"); - write_indent (outf, indent + 2); - fprintf (outf, "{\n"); + if (is_switch) + { + fprintf (outf, "switch "); + n_switches++; + first_if = 1; + check_attr_set_switch (outf, testexp, attrs_cached, 1, indent); + indent += 4; + } + else + { + fprintf (outf, "%sif ", first_if ? "" : "else "); + first_if = 0; + write_test_expr (outf, testexp, attrs_cached, + (FLG_AFTER | FLG_INSIDE | FLG_OUTSIDE_AND)); + attrs_cached = attrs_cached_after; + fprintf (outf, "\n"); + } + if (!is_switch) + { + write_indent (outf, indent + 2); + fprintf (outf, "{\n"); + } + write_attr_set (outf, attr, indent + 4, XVECEXP (value, 0, i + 1), prefix, suffix, inner_true, insn_code, insn_index, attrs_cached_inside); write_indent (outf, indent + 2); - fprintf (outf, "}\n"); + if (is_switch) + { + fprintf (outf, "break;\n"); + write_indent (outf, indent); + fprintf (outf, "default:\n"); + indent += 4; + } + else + fprintf (outf, "}\n"); our_known_true = newexp; } - if (! first_if) + if (! first_if && ! is_switch) { write_indent (outf, indent); fprintf (outf, "else\n"); write_indent (outf, indent + 2); fprintf (outf, "{\n"); } + else if (is_switch) + write_indent (outf, indent); - write_attr_set (outf, attr, first_if ? indent : indent + 4, default_val, + write_attr_set (outf, attr, (first_if || is_switch) ? indent : indent + 4, default_val, prefix, suffix, our_known_true, insn_code, insn_index, attrs_cached); - if (! first_if) + if (! first_if && ! is_switch) { write_indent (outf, indent + 2); fprintf (outf, "}\n"); @@ -4222,6 +4349,12 @@ write_attr_set (FILE *outf, struct attr_desc *attr, int indent, rtx value, write_attr_value (outf, attr, value); fprintf (outf, "%s\n", suffix); } + while (n_switches--) + { + indent -= 2; + write_indent (outf, indent); + fprintf (outf, "}\n"); + } } /* Write a series of case statements for every instruction in list IE.