From patchwork Fri Nov 4 19:14:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 691385 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 3t9W0s1WRqz9vF4 for ; Sat, 5 Nov 2016 05:42:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eQLeMeKv"; 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:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=Er6dGVTUReVs+tFNnOFa/qnIcFZCzzRWBnjYNtsKL/u0B7l0J9iEG rbvHP4qVFowzMJOcWlyC01b2yDG+t62tLsTkEnudkAopQnCKWqsOsHvK6kS2TkUM eRf781osZOpvWtAz7km3TT67uPekRyYYqD94Pr/7yRigMRCiuCVBKc= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=cfDNiOQwwTO8YJM4xlxkqNZOyTc=; b=eQLeMeKv+o99cSM2xRUF oJ2XCWfLSSsUjQ2al9SAWtbAkfCXkGccS18ysXF6yfErDQDge5DRXu3ruCSIytqB ZoDkyXcUG6MPDr/VUWxATAHQNi0Qii44YSQWLgpTedC1LBBMoCLtNCETVltFMU5s VW5OCycDCgpnIzhNHHV1Jnk= Received: (qmail 14809 invoked by alias); 4 Nov 2016 18:42:25 -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 14752 invoked by uid 89); 4 Nov 2016 18:42:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=surplus X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Nov 2016 18:42:23 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED7ADC0567B3 for ; Fri, 4 Nov 2016 18:42:21 +0000 (UTC) Received: from c64.redhat.com (vpn-224-189.phx2.redhat.com [10.3.224.189]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA4IgK8g013192; Fri, 4 Nov 2016 14:42:21 -0400 From: David Malcolm To: Bernd Schmidt , gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] rtx_writer: avoid printing trailing default values Date: Fri, 4 Nov 2016 15:14:08 -0400 Message-Id: <1478286848-7165-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: <152fd27d-71fb-9f15-7d0e-065ee141c1be@redhat.com> References: <152fd27d-71fb-9f15-7d0e-065ee141c1be@redhat.com> X-IsSubscribed: yes On Fri, 2016-11-04 at 18:51 +0100, Bernd Schmidt wrote: > Here's something simpler. Only very lightly tested, but isn't > something > like this all that's needed? Could decide whether to apply it to > expr_list etc. as well. > > Index: print-rtl.c > =================================================================== > --- print-rtl.c (revision 241233) > +++ print-rtl.c (working copy) > @@ -697,7 +697,12 @@ print_rtx (const_rtx in_rtx) > > /* Get the format string and skip the first elements if we have > handled > them already. */ > - for (; idx < GET_RTX_LENGTH (GET_CODE (in_rtx)); idx++) > + int limit = GET_RTX_LENGTH (GET_CODE (in_rtx)); > + if (flag_compact (as of r241586 this is now "m_compact") > + && INSN_CHAIN_CODE_P (GET_CODE (in_rtx)) > + && XEXP (in_rtx, limit - 1) == NULL_RTX) > + limit--; > + for (; idx < limit; idx++) > print_rtx_operand (in_rtx, idx); > > switch (GET_CODE (in_rtx)) Thanks. This seems to assume that the final code in the fmt string can be accessed via XEXP (in_rtx, limit - 1), which if RTL checking is enabled requires that the code be either 'e' or 'u'. This isn't the case for JUMP_INSN, JUMP_TABLE_DATA, BARRIER (all code '0'), CODE_LABEL (code 's') and NOTE (code 'i'). Also, we might want to omit the REG_NOTES from, say a JUMP_INSN, which is the *penultimate* operand - for example, it doesn't omit the trailing (nil) from the cjump_insn in test_uncond_jump. That said, this is much simpler than my patch, so I used it as the basis for the following: it uses the same approach as your patch, but loops backwards from the end of the format string (rather than just once) until it finds a non-default value, using a new function "operand_has_default_value_p" to handle the logic for that. With this, compact dumps omit the trailing (nil) for both regular insns and for JUMP_INSNs, and omits the surplus newline seen in my earlier patch. It also appears removes the trailing (nil) from expr_list. Bootstrap®rtest in progress. OK for trunk if it passes? gcc/ChangeLog: * print-rtl.c (operand_has_default_value_p): New function. (rtx_writer::print_rtx): In compact mode, omit trailing operands that have the default values. * rtl-tests.c (selftest::test_dumping_insns): Remove empty label string from expected dump. (seltest::test_uncond_jump): Remove trailing "(nil)" for REG_NOTES from expected dump. --- gcc/print-rtl.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- gcc/rtl-tests.c | 5 ++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c index 341ecdf..493aa68 100644 --- a/gcc/print-rtl.c +++ b/gcc/print-rtl.c @@ -564,6 +564,40 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx) } } +/* Subroutine of rtx_writer::print_rtx. + In compact mode, determine if operand IDX of IN_RTX is interesting + to dump, or (if in a trailing position) it can be omitted. */ + +static bool +operand_has_default_value_p (const_rtx in_rtx, int idx) +{ + const char *format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx)); + + switch (format_ptr[idx]) + { + case 'e': + case 'u': + return XEXP (in_rtx, idx) == NULL_RTX; + + case 's': + return XSTR (in_rtx, idx) == NULL; + + case '0': + switch (GET_CODE (in_rtx)) + { + case JUMP_INSN: + return JUMP_LABEL (in_rtx) == NULL_RTX; + + default: + return false; + + } + + default: + return false; + } +} + /* Print IN_RTX onto m_outfile. This is the recursive part of printing. */ void @@ -681,9 +715,18 @@ rtx_writer::print_rtx (const_rtx in_rtx) fprintf (m_outfile, " %d", INSN_UID (in_rtx)); } + /* Determine which is the final operand to print. + In compact mode, skip trailing operands that have the default values + e.g. trailing "(nil)" values. */ + int limit = GET_RTX_LENGTH (GET_CODE (in_rtx)); + if (m_compact) + while (limit > idx && operand_has_default_value_p (in_rtx, limit - 1)) + limit--; + /* Get the format string and skip the first elements if we have handled them already. */ - for (; idx < GET_RTX_LENGTH (GET_CODE (in_rtx)); idx++) + + for (; idx < limit; idx++) print_rtx_operand (in_rtx, idx); switch (GET_CODE (in_rtx)) diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c index cf5239f..228226b 100644 --- a/gcc/rtl-tests.c +++ b/gcc/rtl-tests.c @@ -122,7 +122,7 @@ test_dumping_insns () /* Labels. */ rtx_insn *label = gen_label_rtx (); CODE_LABEL_NUMBER (label) = 42; - ASSERT_RTL_DUMP_EQ ("(clabel 0 42 \"\")\n", label); + ASSERT_RTL_DUMP_EQ ("(clabel 0 42)\n", label); LABEL_NAME (label)= "some_label"; ASSERT_RTL_DUMP_EQ ("(clabel 0 42 (\"some_label\"))\n", label); @@ -176,8 +176,7 @@ test_uncond_jump () ASSERT_TRUE (control_flow_insn_p (jump_insn)); ASSERT_RTL_DUMP_EQ ("(cjump_insn 1 (set (pc)\n" - " (label_ref 0))\n" - " (nil))\n", + " (label_ref 0)))\n", jump_insn); }