From patchwork Wed Sep 19 01:51:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 184903 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]) by ozlabs.org (Postfix) with SMTP id 2D0562C008A for ; Wed, 19 Sep 2012 11:51:44 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348624305; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:To:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:User-Agent:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=JaaINOxGqUXLu0KEk0BPuHY4i4c=; b=dYa6CG+FAp/u6y/ zJgqQ0e0RiKtCTv+cURWfpDEPkobebEwOe6hpT2uu++GVGHF6F6XIdQS4CH/Ldt1 dfx9Q1tNOhAdN2PpGtXnUtZVg+TBs80An22lAg3i68/cSlrNeo30p3G4rz5TDc/S +TpNlSEvWjiByssPcUhJo/pjsw9c= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=PI0ceOIhGqWPblp9BLDDg6IYgKUj9XP6O7Abe8K14yENDHafNygrHpjXp0JjPd PKzB+VwskM3JQO7EeDm/Zp3Eh9aNPA0m9JNlyHT6TFgy4Dn2iv4x49DMOeZ1NixE R+Rr22fFIwTU9QGcxPYfI4MwBPD20ag8j9OL3ZXaJWelw=; Received: (qmail 20550 invoked by alias); 19 Sep 2012 01:51:39 -0000 Received: (qmail 20428 invoked by uid 22791); 19 Sep 2012 01:51:38 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, MIME_QP_LONG_LINE X-Spam-Check-By: sourceware.org Received: from c62.cesmail.net (HELO c62.cesmail.net) (216.154.195.54) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 19 Sep 2012 01:51:24 +0000 Received: from unknown (HELO epsilon2) ([192.168.1.60]) by c62.cesmail.net with ESMTP; 18 Sep 2012 22:22:18 -0400 Received: from cust213-dsl91-135-11.idnet.net (cust213-dsl91-135-11.idnet.net [91.135.11.213]) by webmail.spamcop.net (Horde MIME library) with HTTP; Tue, 18 Sep 2012 21:51:23 -0400 Message-ID: <20120918215123.xd8ig0fdus4g0c4c-nzlynne@webmail.spamcop.net> Date: Tue, 18 Sep 2012 21:51:23 -0400 From: Joern Rennecke To: gcc-patches@gcc.gnu.org Subject: RFA: Process '*' in '@'-output-template alternatives MIME-Version: 1.0 User-Agent: Internet Messaging Program (IMP) H3 (4.1.4) 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 I am about to submit the ARCompact target port; this port needs a few patches to target-independent code. There is a move pattern with 20 alternatives; a few of them need a simple function call to decide which output pattern to use. With the '@'-syntax for multi-alternative templates, each alternative is still a one-liner. Requiring to transform this into some switch statement would make the thing several times as big, and very hard to take in; besides, it is generally a maintenance issue if you have to completely rewrite a multi-alternative template if you just change one alternative from a constant to some C-code, or vice versa for the last non-literal alternative. The attached patch makes the '*' syntax for C code fragments available for individual alternatives of an '@' multi-alternative output template. It does this by translating the input into a switch statement in the generated file, so in a way this is just syntactic sugar, but it's syntactic sugar that makes some machine descriptions easier to write and change. Bootstrapped in revision 191429 for i686-pc-linux-gnu. I've been wondering if it'd make sense to also support for '{' / '}' , but at least in the ARCompact context, I think the use of that syntax inside a multi-alternative template would reduce rather than improve legibility, so, having no application for the '{' / '}' in that place, there seems to be no use in adding support for that at this point in time. 2008-11-19 J"orn Rennecke * genoutput.c (process_template): Process '*' in '@' alternatives. Index: genoutput.c =================================================================== --- genoutput.c (revision 191429) +++ genoutput.c (working copy) @@ -662,19 +662,55 @@ process_template (struct data *d, const list of assembler code templates, one for each alternative. */ else if (template_code[0] == '@') { - d->template_code = 0; - d->output_format = INSN_OUTPUT_FORMAT_MULTI; + int found_star = 0; - printf ("\nstatic const char * const output_%d[] = {\n", d->code_number); + for (cp = &template_code[1]; *cp; ) + { + while (ISSPACE (*cp)) + cp++; + if (*cp == '*') + found_star = 1; + while (!IS_VSPACE (*cp) && *cp != '\0') + ++cp; + } + d->template_code = 0; + if (found_star) + { + d->output_format = INSN_OUTPUT_FORMAT_FUNCTION; + puts ("\nstatic const char *"); + printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, " + "rtx insn ATTRIBUTE_UNUSED)\n", d->code_number); + puts ("{"); + puts (" switch (which_alternative)\n {"); + } + else + { + d->output_format = INSN_OUTPUT_FORMAT_MULTI; + printf ("\nstatic const char * const output_%d[] = {\n", + d->code_number); + } for (i = 0, cp = &template_code[1]; *cp; ) { - const char *ep, *sp; + const char *ep, *sp, *bp; while (ISSPACE (*cp)) cp++; - printf (" \""); + bp = cp; + if (found_star) + { + printf (" case %d:", i); + if (*cp == '*') + { + printf ("\n "); + cp++; + } + else + printf (" return \""); + } + else + printf (" \""); for (ep = sp = cp; !IS_VSPACE (*ep) && *ep != '\0'; ++ep) if (!ISSPACE (*ep)) @@ -690,7 +726,18 @@ process_template (struct data *d, const cp++; } - printf ("\",\n"); + if (!found_star) + puts ("\","); + else if (*bp != '*') + puts ("\";"); + else + { + /* The usual action will end with a return. + If there is neither break or return at the end, this is + assumed to be intentional; this allows to have multiple + consecutive alternatives share some code. */ + puts (""); + } i++; } if (i == 1) @@ -700,7 +747,10 @@ process_template (struct data *d, const error_with_line (d->lineno, "wrong number of alternatives in the output template"); - printf ("};\n"); + if (found_star) + puts (" default: gcc_unreachable ();\n }\n}"); + else + printf ("};\n"); } else {