From patchwork Mon May 7 21:58:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sharad Singhai X-Patchwork-Id: 157476 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 AB3BFB6FA9 for ; Tue, 8 May 2012 07:59:09 +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=1337032752; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:To:Subject:Message-Id:Date: From:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=XHUaxQq iV5wcxEeXbte71nPxi4w=; b=nco1lZjpzWX2sV5fNHUFuu7PkU7RdyR7HFZZkG5 QECeNHnVP1uZbZ9iLLpfAv0jC58+dCb0p2DyzxiRlTFBfh2xArcncdQTBS0pA4bh q+FD1LdEYmlfQLdsDGPfnpkusXNVcAOn0NJ5OK0bFTe8kEm3qRctF37oekqhpBCe gMI0= 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:X-Google-DKIM-Signature:Received:Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OR/6sWnOGS8975LsjxOMq7ssI/nU7suZyVvSNZldK2Yl0aWkinDo3aZzBe81vW w2fVQfYfaqfruW6exepm62WGhLrSnN1pt9Z8iuG7bhJsRyrfJsmZMLhMMSzJMbuR XviReKkXN+U4phR2/FUCZlrHy3uXKSsnm+WAG1oLaWrw8=; Received: (qmail 29668 invoked by alias); 7 May 2012 21:59:03 -0000 Received: (qmail 29659 invoked by uid 22791); 7 May 2012 21:59:01 -0000 X-SWARE-Spam-Status: No, hits=-4.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-qa0-f73.google.com (HELO mail-qa0-f73.google.com) (209.85.216.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 May 2012 21:58:46 +0000 Received: by qafk22 with SMTP id k22so10067qaf.2 for ; Mon, 07 May 2012 14:58:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:message-id:date:from:x-gm-message-state; bh=EQorlEh/fZSOhNxGNhOAj5WJTLbgJpG4Fmmrg5wJkmA=; b=c1QshKLogSeQ+DkORc5W8g7bEKB3TvKi0fdAfLs3V61glGGdcMxvIpH8zIpFjaDbOc 1dQ9NvjcNoQ9JH+LAVWz7VTd/t08vIHNnJHws998fo6HHAmKr5Xpq5okVRX6sFqlGZRB qU8RxqQXjUS4B9NRSagNBWJUGG/oIRft5oJf5SRh6RlCnDcSW17C7WgU1dkw7OgS7Rgt LFg1K4Yrs90a28zpr2vsgAxGGYk6GZUvmkF4g5PNQrCQ6kVZlpFHs2cXFJZW00c/k9R7 5PnwY38V6IsmuAXi4Nj8YhVcsHiRhuCTYipxQirRvCGe9naeGl8YkrU88G/hlOoTOCh3 hBBA== Received: by 10.236.73.131 with SMTP id v3mr21801080yhd.6.1336427925825; Mon, 07 May 2012 14:58:45 -0700 (PDT) Received: by 10.236.73.131 with SMTP id v3mr21801070yhd.6.1336427925770; Mon, 07 May 2012 14:58:45 -0700 (PDT) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id b73si16996160yhh.4.2012.05.07.14.58.45 (version=TLSv1/SSLv3 cipher=AES128-SHA); Mon, 07 May 2012 14:58:45 -0700 (PDT) Received: from nabu.mtv.corp.google.com (nabu.mtv.corp.google.com [172.18.110.53]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 97A2F1E005D; Mon, 7 May 2012 14:58:45 -0700 (PDT) Received: by nabu.mtv.corp.google.com (Postfix, from userid 68019) id 37A25A0719; Mon, 7 May 2012 14:58:45 -0700 (PDT) To: reply@codereview.appspotmail.com, richard.guenther@gmail.com, davidxl@google.com, gcc-patches@gcc.gnu.org Subject: [PATCH] Add option for dumping to stderr (issue6190057) Message-Id: <20120507215845.37A25A0719@nabu.mtv.corp.google.com> Date: Mon, 7 May 2012 14:58:45 -0700 (PDT) From: singhai@google.com (Sharad Singhai) X-Gm-Message-State: ALoCoQlfOEO9JJaAQaWazZhdxnPmnW97GarERtu/+roxhkm1uAICj/2TuChXtd6Z5WvYmgACUw/m+zBOWOR05FZRaIg/NJMeLy78zqRJOMTFHEvLIEqm/ubigDkSFjwnea3yrsa91v+W8/iDH049akchYUnpwMhropNFoc+oSd4+h4assSE0nKc= 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 This is the first patch for planned improvements to dump infrastructure. Please reference the discussion in http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02088.html. The following small patch allows selective tree and rtl dumps on stderr instead of named files. Later -fopt-info can be implemented in form of -fdump-xxx-stderr. Bootstrapped and tested on x86_64 with one added testcase. Okay for trunk? Thanks, Sharad 2012-05-07 Sharad Singhai * doc/invoke.texi: Add documentation for new option. * tree-dump.c (dump_begin): Handle stderr appropriately. (dump_end): Likewise. (dump_switch_p_1): Likewise. * tree-pass.h (enum tree_dump_index): Add new constant. * testsuite/g++.dg/other/dump-stderr-1.C: New test. --- This patch is available for review at http://codereview.appspot.com/6190057 Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 187265) +++ doc/invoke.texi (working copy) @@ -5322,20 +5322,23 @@ Here are some examples showing uses of these optio @item -d@var{letters} @itemx -fdump-rtl-@var{pass} +@itemx -fdump-rtl-@var{pass-stderr} @opindex d Says to make debugging dumps during compilation at times specified by @var{letters}. This is used for debugging the RTL-based passes of the compiler. The file names for most of the dumps are made by appending a pass number and a word to the @var{dumpname}, and the files are -created in the directory of the output file. Note that the pass -number is computed statically as passes get registered into the pass -manager. Thus the numbering is not related to the dynamic order of -execution of passes. In particular, a pass installed by a plugin -could have a number over 200 even if it executed quite early. -@var{dumpname} is generated from the name of the output file, if -explicitly specified and it is not an executable, otherwise it is the -basename of the source file. These switches may have different effects -when @option{-E} is used for preprocessing. +created in the directory of the output file. If the @option{-stderr} is +appended to the longer form of the dump option then the dump is +done on stderr instead of named files. Note that the pass number is +computed statically as passes get registered into the pass manager. +Thus the numbering is not related to the dynamic order of execution of +passes. In particular, a pass installed by a plugin could have a +number over 200 even if it executed quite early. @var{dumpname} is +generated from the name of the output file, if explicitly specified +and it is not an executable, otherwise it is the basename of the +source file. These switches may have different effects when +@option{-E} is used for preprocessing. Debug dumps can be enabled with a @option{-fdump-rtl} switch or some @option{-d} option @var{letters}. Here are the possible @@ -5599,6 +5602,10 @@ These dumps are defined but always produce empty f @opindex fdump-rtl-all Produce all the dumps listed above. +@item -fdump-rtl-all-stderr +@opindex fdump-rtl-all-stderr +Produce all the dumps on stderr. + @item -dA @opindex dA Annotate the assembler output with miscellaneous debugging information. @@ -5723,11 +5730,13 @@ counters for each function compiled. Control the dumping at various stages of processing the intermediate language tree to a file. The file name is generated by appending a switch specific suffix to the source file name, and the file is -created in the same directory as the output file. If the -@samp{-@var{options}} form is used, @var{options} is a list of -@samp{-} separated options which control the details of the dump. Not -all options are applicable to all dumps; those that are not -meaningful are ignored. The following options are available +created in the same directory as the output file unless the option +@option{stderr} is given. In case of @option{stderr}, the dump output is on +the stderr. If the @samp{-@var{options}} form is used, @var{options} +is a list of @samp{-} separated options which control the details or +location of the dump. Not all options are applicable to all dumps; +those that are not meaningful are ignored. The following options are +available @table @samp @item address @@ -5765,9 +5774,42 @@ Enable showing the tree dump for each statement. Enable showing the EH region number holding each statement. @item scev Enable showing scalar evolution analysis details. +@item slim +Inhibit dumping of members of a scope or body of a function merely +because that scope has been reached. Only dump such items when they +are directly reachable by some other path. When dumping pretty-printed +trees, this option inhibits dumping the bodies of control structures. +@item stderr +Instead of dumping into a named file, dump on to stderr. However, note +that the @option{stderr} is considered weak, so in case of two +conflicting dump options, the option to dump into file takes +precedence regardless of the command line ordering. For instance, + +@smallexample +gcc -fdump-tree-pre-stderr -fdump-tree-pre ... +gcc -fdump-tree-pre -fdump-tree-pre-stderr ... +@end smallexample + +Both produce the PRE dump in a file. Similarly, for the following + +@smallexample +gcc -fdump-tree-all-stderr -fdump-tree-pre ... +@end smallexample + +The PRE dump goes into a file while all other dumps are on the +stderr. In the following example, + +@smallexample +gcc -fdump-tree-all -fdump-tree-pre-stderr ... +@end smallexample + +all the dumps are written into named files. The PRE dump is not dumped +on to stderr, because @option{-fdump-tree-pre-stderr} is overridden by +the @option{-fdump-tree-all} on the command line. + @item all -Turn on all options, except @option{raw}, @option{slim}, @option{verbose} -and @option{lineno}. +Turn on all options, except @option{raw}, @option{slim}, @option{verbose}, +@option{lineno}, and @option{stderr}. @end table The following tree dumps are possible: @@ -5913,6 +5955,10 @@ is made by appending @file{.vrp} to the source fil @item all @opindex fdump-tree-all Enable all the available tree dumps with the flags provided in this option. + +@item all-stderr +@opindex fdump-tree-all-stderr +Enable all the available tree dumps on the stderr. @end table @item -ftree-vectorizer-verbose=@var{n} Index: tree-dump.c =================================================================== --- tree-dump.c (revision 187265) +++ tree-dump.c (working copy) @@ -802,7 +802,7 @@ struct dump_option_value_info }; /* Table of dump options. This must be consistent with the TDF_* flags - in tree.h */ + in tree-dump.h */ static const struct dump_option_value_info dump_options[] = { {"address", TDF_ADDRESS}, @@ -825,6 +825,7 @@ static const struct dump_option_value_info dump_op {"nouid", TDF_NOUID}, {"enumerate_locals", TDF_ENUMERATE_LOCALS}, {"scev", TDF_SCEV}, + {"stderr", TDF_STDERR}, {"all", ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_TREE | TDF_RTL | TDF_IPA | TDF_STMTADDR | TDF_GRAPH | TDF_DIAGNOSTIC | TDF_VERBOSE | TDF_RHS_ONLY | TDF_NOUID | TDF_ENUMERATE_LOCALS | TDF_SCEV)}, @@ -926,15 +927,25 @@ dump_begin (int phase, int *flag_ptr) if (phase == TDI_none || !dump_enabled_p (phase)) return NULL; - name = get_dump_file_name (phase); dfi = get_dump_file_info (phase); - stream = fopen (name, dfi->state < 0 ? "w" : "a"); - if (!stream) - error ("could not open dump file %qs: %m", name); + + if (dfi->flags & TDF_STDERR) + { + stream = stderr; + dfi->state = 1; + } else - dfi->state = 1; - free (name); + { + name = get_dump_file_name (phase); + stream = fopen (name, dfi->state < 0 ? "w" : "a"); + if (!stream) + error ("could not open dump file %qs: %m", name); + else + dfi->state = 1; + free (name); + } + if (flag_ptr) *flag_ptr = dfi->flags; @@ -989,7 +1000,8 @@ dump_flag_name (int phase) void dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream) { - fclose (stream); + if (stream != stderr) + fclose (stream); } /* Enable all tree dumps. Return number of enabled tree dumps. */ @@ -1060,7 +1072,10 @@ dump_switch_p_1 (const char *arg, struct dump_file if (strlen (option_ptr->name) == length && !memcmp (option_ptr->name, ptr, length)) { - flags |= option_ptr->value; + /* Consider TDF_STDERR weak and use it only if the state + is uninitialized. */ + if (!((option_ptr->value & TDF_STDERR) && dfi->state)) + flags |= option_ptr->value; goto found; } warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>", @@ -1069,6 +1084,10 @@ dump_switch_p_1 (const char *arg, struct dump_file ptr = end_ptr; } + /* Clear TDF_STDERR in case of same dump without stderr option. */ + if ((dfi->flags & TDF_STDERR) && !(flags & TDF_STDERR)) + dfi->flags &= ~TDF_STDERR; + dfi->state = -1; dfi->flags |= flags; Index: tree-pass.h =================================================================== --- tree-pass.h (revision 187265) +++ tree-pass.h (working copy) @@ -84,6 +84,7 @@ enum tree_dump_index #define TDF_ENUMERATE_LOCALS (1 << 22) /* Enumerate locals by uid. */ #define TDF_CSELIB (1 << 23) /* Dump cselib details. */ #define TDF_SCEV (1 << 24) /* Dump SCEV details. */ +#define TDF_STDERR (1 << 25) /* Dump on stderr. */ /* In tree-dump.c */ Index: testsuite/g++.dg/other/dump-stderr-1.C =================================================================== --- testsuite/g++.dg/other/dump-stderr-1.C (revision 0) +++ testsuite/g++.dg/other/dump-stderr-1.C (revision 0) @@ -0,0 +1,12 @@ +// Test that if we specify both dump to stderr and to a file, there is +// no output on the stderr but a dump file is still produced. +/* { dg-options "-O2 -fdump-tree-pre -fdump-tree-pre-stderr" } */ + +void test (int *b, int *e, int stride) + { + for (int *p = b; p != e; p += stride) + *p = 1; + } + +/* { dg-final { scan-tree-dump-times ";; Function void test" 1 "pre" } } */ +/* { dg-final { cleanup-tree-dump "pre" } } */