From patchwork Wed Nov 9 16:46:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 692844 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 3tDWTT5yfgz9t1L for ; Thu, 10 Nov 2016 03:14:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ncyW/tPn"; 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=hCFkAfwwfFUy2JZFefGjyzB7kjbb1w/8eRA8zevepk8fXuPok/AvR xVDua4bC9c3/xKXORutesXJcGaHNefHiqVUyvpLOrB2H4x5gSKCgZCRAEUTI6++A Qt2QmcA76K4FmdS6iBmAHFywWBF73iMWdn/z7aV4TgLllXkxkxHelc= 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=FPyaCq4RWQM2P98hu/jZVOde8h0=; b=ncyW/tPnXhZYoGt9Fw5h YLATmNs2rTtIt7bzYWP0rYm0ARereIe6b58e4navHcKL/HCO9s8uQXaDp4oKEjlm ZdD2mgogx7AVsQoZapW9pYR2acR5AbLqZG6uHM5ovc278LAnUSgy1ltYF1uLLnM1 5Utqi5CCIRQfbZS4MqRUXj4= Received: (qmail 11815 invoked by alias); 9 Nov 2016 16:14:11 -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 11788 invoked by uid 89); 9 Nov 2016 16:14:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ind, leads, wrapping 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; Wed, 09 Nov 2016 16:14:09 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 AA6AA106E for ; Wed, 9 Nov 2016 16:14:08 +0000 (UTC) Received: from c64.redhat.com (vpn-225-6.phx2.redhat.com [10.3.225.6]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA9GE78r024694; Wed, 9 Nov 2016 11:14:08 -0500 From: David Malcolm To: Bernd Schmidt , gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] (v2) print-rtl-function.c: add (param) directive to dump Date: Wed, 9 Nov 2016 11:46:06 -0500 Message-Id: <1478709966-17333-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: References: X-IsSubscribed: yes On Wed, 2016-11-09 at 12:59 +0100, Bernd Schmidt wrote: > On 11/08/2016 07:03 PM, David Malcolm wrote: > > int __RTL("rtl-combine") f1 (int n) > > { > > (function "f1" > > (param "n" > > (DECL_RTL > > (reg/v:SI %1 [ n ]) > > ) ;; DECL_RTL > > The ;; DECL_RTL etc. comments seem somewhat redundant and add > clutter. > Please remove those. Done. > Also, why is the closing paren on its own line? That doesn't seem > right. It's because of the m_sawclose when calling print_rtx, which leads to a leading newline. I fixed this by introducing a rtx_writer::finish_directive method to unset m_sawclose. (That field seems misnamed; perhaps it should be renamed to m_force_newline or somesuch? That feels like a separate patch though). > Later (not for this patch) I'd really like to see some logic not to > add > linebreaks before simple expressions, so that we'd have (DECL_RTL > (reg:SI xyz)) on a single line. I've been thinking about a patch that would track indentation, which would only insert newlines when close to some column limit, and would line up the open parentheses for siblings. That way you'd get things like: (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars) (const_int -4)) [1 i+0 S4 A32])) where the newline is auto-inserted to fit things within e.g. an 80 char column, and where "const_int" gets indented to be underneath the "reg", since they're both operands of the same "plus". Anyway, the following updated version of the patch eliminates the newlines and comments. Updated examples: aarch64 function taking one argument: (function "times_two" (param "i" (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars) (const_int -4)) [1 i+0 S4 A32])) (DECL_RTL_INCOMING (reg:SI x0 [ i ]))) (insn-chain ;; etc x86_64 function taking three ints: (function "test_1" (param "i" (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars) (const_int -4)) [1 i+0 S4 A32])) (DECL_RTL_INCOMING (reg:SI di [ i ]))) (param "j" (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars) (const_int -8)) [1 j+0 S4 A32])) (DECL_RTL_INCOMING (reg:SI si [ j ]))) (param "k" (DECL_RTL (mem/c:SI (plus:DI (reg/f:DI virtual-stack-vars) (const_int -12)) [1 k+0 S4 A32])) (DECL_RTL_INCOMING (reg:SI dx [ k ]))) (insn-chain ;; etc As before, only lightly tested so far. OK for trunk if it passes bootstrap and regrtest? gcc/ChangeLog: * print-rtl-function.c (print_any_param_name): New function. (print_param): New function. (print_rtx_function): Call print_param for each argument. * print-rtl.c (rtx_writer::finish_directive): New function. * print-rtl.h (rtx_writer::finish_directive): New decl. --- gcc/print-rtl-function.c | 36 ++++++++++++++++++++++++++++++++++++ gcc/print-rtl.c | 9 +++++++++ gcc/print-rtl.h | 2 ++ 3 files changed, 47 insertions(+) diff --git a/gcc/print-rtl-function.c b/gcc/print-rtl-function.c index b62f1b3..f18491a 100644 --- a/gcc/print-rtl-function.c +++ b/gcc/print-rtl-function.c @@ -127,6 +127,38 @@ can_have_basic_block_p (const rtx_insn *insn) return true; } +/* Subroutine of print_param. Write the name of ARG, if any, to OUTFILE. */ + +static void +print_any_param_name (FILE *outfile, tree arg) +{ + if (DECL_NAME (arg)) + fprintf (outfile, " \"%s\"", IDENTIFIER_POINTER (DECL_NAME (arg))); +} + +/* Print a "(param)" directive for ARG to OUTFILE. */ + +static void +print_param (FILE *outfile, rtx_writer &w, tree arg) +{ + fprintf (outfile, " (param"); + print_any_param_name (outfile, arg); + fprintf (outfile, "\n"); + + /* Print the value of DECL_RTL (without lazy-evaluation). */ + fprintf (outfile, " (DECL_RTL "); + rtx decl_rtl = DECL_WRTL_CHECK (arg)->decl_with_rtl.rtl; + w.print_rtx (decl_rtl); + w.finish_directive (); + + /* Print DECL_INCOMING_RTL. */ + fprintf (outfile, " (DECL_RTL_INCOMING "); + w.print_rtx (DECL_INCOMING_RTL (arg)); + fprintf (outfile, ")"); + + w.finish_directive (); +} + /* Write FN to OUTFILE in a form suitable for parsing, with indentation and comments to make the structure easy for a human to grok. Track the basic blocks of insns in the chain, wrapping those that are within @@ -202,6 +234,10 @@ print_rtx_function (FILE *outfile, function *fn, bool compact) fprintf (outfile, "(function \"%s\"\n", dname); + /* Params. */ + for (tree arg = DECL_ARGUMENTS (fdecl); arg; arg = DECL_CHAIN (arg)) + print_param (outfile, w, arg); + /* The instruction chain. */ fprintf (outfile, " (insn-chain\n"); basic_block curr_bb = NULL; diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c index 30ff8fa..3bbd395 100644 --- a/gcc/print-rtl.c +++ b/gcc/print-rtl.c @@ -921,6 +921,15 @@ rtx_writer::print_rtx (const_rtx in_rtx) m_sawclose = 1; } +/* Emit a closing parenthesis and newline. */ + +void +rtx_writer::finish_directive () +{ + fprintf (m_outfile, ")\n"); + m_sawclose = 0; +} + /* Print an rtx on the current line of FILE. Initially indent IND characters. */ diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h index 3e5a975..5f7cefb 100644 --- a/gcc/print-rtl.h +++ b/gcc/print-rtl.h @@ -38,6 +38,8 @@ class rtx_writer void print_rtl (const_rtx rtx_first); int print_rtl_single_with_indent (const_rtx x, int ind); + void finish_directive (); + private: void print_rtx_operand_code_0 (const_rtx in_rtx, int idx); void print_rtx_operand_code_e (const_rtx in_rtx, int idx);