This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add option for dumping to stderr (issue6190057)


On Tue, May 8, 2012 at 11:46 PM, Sharad Singhai <singhai@google.com> wrote:
> In response to comments, I have updated the patch to support dumps in
> user provided files via the option -fdump-xxx=<filename>. The
> filenames stdout/stderr are treated specially, and are considered
> standard streams.

I think - should also be treated as special (or maybe the only one
which should be treated as special).

Thanks,
Andrew Pinski

>
> Also updated documentation and a testcase. Okay for trunk?
>
> Thanks,
> Sharad
>
> 2012-05-08 Â Sharad Singhai Â<singhai@google.com>
>
> Â Â Â Â* doc/invoke.texi: Add documentation for new option.
> Â Â Â Â* tree-dump.c (dump_stream_p): New function.
> Â Â Â Â(dump_files): Update for new field.
> Â Â Â Â(dump_switch_p_1): Handle user provided filenames.
> Â Â Â Â(dump_begin): Likewise.
> Â Â Â Â(get_dump_file_name): Likewise.
> Â Â Â Â(dump_enable_all): Add new parameter USER_FILENAME.
> Â Â Â ÂAll callers updated.
> Â Â Â Â(dump_end): Remove attribute.
> Â Â Â Â* tree-pass.h (enum tree_dump_index): Add new constant.
> Â Â Â Â(struct dump_file_info): Add new field USER_FILENAME.
> Â Â Â Â* testsuite/g++.dg/other/dump-userfile-1.C: New test.
>
> Index: doc/invoke.texi
> ===================================================================
> --- doc/invoke.texi   (revision 187265)
> +++ doc/invoke.texi   (working copy)
> @@ -5322,20 +5322,24 @@ Here are some examples showing uses of these optio
>
> Â@item -d@var{letters}
> Â@itemx -fdump-rtl-@var{pass}
> +@itemx -fdump-rtl-@var{pass}=@var{filename}
> Â@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{=@var{filename}} is appended to the longer form of the dump
> +option then the dump is done on that file instead of numbered
> +files. The filenames stdout and stderr are treated specially. 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 +5603,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 RTL dumps on stderr.
> +
> Â@item -dA
> Â@opindex dA
> ÂAnnotate the assembler output with miscellaneous debugging information.
> @@ -5719,15 +5727,19 @@ counters for each function compiled.
>
> Â@item -fdump-tree-@var{switch}
> Â@itemx -fdump-tree-@var{switch}-@var{options}
> +@itemx -fdump-tree-@var{switch}-@var{options}=@var{filename}
> Â@opindex fdump-tree
> Â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. In case of
> +@option{=@var{filename}}, the dump output is on the given file. Note
> +that the filenames stdout and stderr are treated specially and dumps
> +are done on standard streams. 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 +5777,56 @@ 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 =@var{filename}
> +Instead of using an auto generated name for a dump file, use the
> +provided name. For example:
> +
> +@smallexample
> +gcc -O2 -fdump-tree-pre=foobar.dump
> +@end smallexample
> +
> +produces PRE dump in a file named foobar.dump. Similarly
> +
> +@smallexample
> +gcc -O2 -fdump-tree-all=all.dump
> +@end smallexample
> +
> +produces all tree dumps in a file named all.dump.
> +
> +Note that stdout and stderr are treated specially, and the dumps are
> +done on standard streams. In case of any conflicts, the user provided
> +filename takes precedence. For example:
> +
> +@smallexample
> +gcc -O2 -fdump-tree-pre=stderr -fdump-tree-pre ...
> +gcc -O2 -fdump-tree-pre -fdump-tree-pre=stderr ...
> +@end smallexample
> +
> +Both invocations produce the PRE dump on stderr. Similarly, for the
> +following
> +
> +@smallexample
> +gcc -O2 -fdump-tree-all=stderr -fdump-tree-pre ...
> +@end smallexample
> +
> +All the dumps are output on stderr. In the following example,
> +
> +@smallexample
> +gcc -fdump-tree-all -fdump-tree-pre=stderr ...
> +@end smallexample
> +
> +all the dumps are written into named files except the PRE dump, which
> +is output on stderr, because @option{-fdump-tree-pre=stderr} takes
> +precedence.
> +
> Â@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}.
> Â@end table
>
> ÂThe following tree dumps are possible:
> @@ -5913,6 +5972,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)
> @@ -773,20 +773,20 @@ dump_node (const_tree t, int flags, FILE *stream)
> Â Âtree_dump_index enumeration in tree-pass.h. Â*/
> Âstatic struct dump_file_info dump_files[TDI_end] =
> Â{
> - Â{NULL, NULL, NULL, 0, 0, 0},
> - Â{".cgraph", "ipa-cgraph", NULL, TDF_IPA, 0, Â0},
> - Â{".tu", "translation-unit", NULL, TDF_TREE, 0, 1},
> - Â{".class", "class-hierarchy", NULL, TDF_TREE, 0, 2},
> - Â{".original", "tree-original", NULL, TDF_TREE, 0, 3},
> - Â{".gimple", "tree-gimple", NULL, TDF_TREE, 0, 4},
> - Â{".nested", "tree-nested", NULL, TDF_TREE, 0, 5},
> - Â{".vcg", "tree-vcg", NULL, TDF_TREE, 0, 6},
> - Â{".ads", "ada-spec", NULL, 0, 0, 7},
> + Â{NULL, NULL, NULL, NULL, 0, 0, 0},
> + Â{".cgraph", "ipa-cgraph", NULL, NULL, TDF_IPA, 0, Â0},
> + Â{".tu", "translation-unit", NULL, NULL, TDF_TREE, 0, 1},
> + Â{".class", "class-hierarchy", NULL, NULL, TDF_TREE, 0, 2},
> + Â{".original", "tree-original", NULL, NULL, TDF_TREE, 0, 3},
> + Â{".gimple", "tree-gimple", NULL, NULL, TDF_TREE, 0, 4},
> + Â{".nested", "tree-nested", NULL, NULL, TDF_TREE, 0, 5},
> + Â{".vcg", "tree-vcg", NULL, NULL, TDF_TREE, 0, 6},
> + Â{".ads", "ada-spec", NULL, NULL, 0, 0, 7},
> Â#define FIRST_AUTO_NUMBERED_DUMP 8
>
> - Â{NULL, "tree-all", NULL, TDF_TREE, 0, 0},
> - Â{NULL, "rtl-all", NULL, TDF_RTL, 0, 0},
> - Â{NULL, "ipa-all", NULL, TDF_IPA, 0, 0},
> + Â{NULL, "tree-all", NULL, NULL, TDF_TREE, 0, 0},
> + Â{NULL, "rtl-all", NULL, NULL, TDF_RTL, 0, 0},
> + Â{NULL, "ipa-all", NULL, NULL, TDF_IPA, 0, 0},
> Â};
>
> Â/* Dynamically registered tree dump files and switches. Â*/
> @@ -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-pass.h */
> Âstatic const struct dump_option_value_info dump_options[] =
> Â{
> Â {"address", TDF_ADDRESS},
> @@ -892,6 +892,9 @@ get_dump_file_name (int phase)
> Â if (dfi->state == 0)
> Â Â return NULL;
>
> + Âif (dfi->user_filename)
> + Â Âreturn xstrdup (dfi->user_filename);
> +
> Â if (dfi->num < 0)
> Â Â dump_id[0] = '\0';
> Â else
> @@ -911,6 +914,19 @@ get_dump_file_name (int phase)
> Â return concat (dump_base_name, dump_id, dfi->suffix, NULL);
> Â}
>
> +/* Return non-zero iff the USER_FILENAME corresponds to stdout or
> + Â stderr stream. Â*/
> +
> +static int
> +dump_stream_p (const char *user_filename)
> +{
> + Âif (user_filename)
> + Â Âreturn !strncmp ("stderr", user_filename, 6) ||
> + Â Â Â!strncmp ("stdout", user_filename, 6);
> + Âelse
> + Â Âreturn 0;
> +}
> +
> Â/* Begin a tree dump for PHASE. Stores any user supplied flag in
> Â Â*FLAG_PTR and returns a stream to write to. If the dump is not
> Â Âenabled, returns NULL.
> @@ -926,14 +942,28 @@ 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 (dump_stream_p (dfi->user_filename))
> + Â Â{
> + Â Â Âif (!strncmp ("stderr", dfi->user_filename, 6))
> + Â Â Â Âstream = stderr;
> + Â Â Âelse
> + Â Â Â Âif (!strncmp ("stdout", dfi->user_filename, 6))
> + Â Â Â Â Âstream = stdout;
> + Â Â Â Âelse
> + Â Â Â Â Âerror ("unknown stream: %qs: %m", dfi->user_filename);
> + Â Â Â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;
> @@ -987,35 +1017,45 @@ dump_flag_name (int phase)
> Â Âdump_begin. Â*/
>
> Âvoid
> -dump_end (int phase ATTRIBUTE_UNUSED, FILE *stream)
> +dump_end (int phase, FILE *stream)
> Â{
> - Âfclose (stream);
> + Âstruct dump_file_info *dfi = get_dump_file_info (phase);
> + Âif (!dump_stream_p (dfi->user_filename))
> + Â Âfclose (stream);
> Â}
>
> Â/* Enable all tree dumps. ÂReturn number of enabled tree dumps. Â*/
>
> Âstatic int
> -dump_enable_all (int flags)
> +dump_enable_all (int flags, const char *user_filename)
> Â{
> Â int ir_dump_type = (flags & (TDF_TREE | TDF_RTL | TDF_IPA));
> Â int n = 0;
> Â size_t i;
>
> Â for (i = TDI_none + 1; i < (size_t) TDI_end; i++)
> - Â Âif ((dump_files[i].flags & ir_dump_type))
> - Â Â Â{
> - Â Â Â Âdump_files[i].state = -1;
> - Â Â Â Âdump_files[i].flags |= flags;
> - Â Â Â Ân++;
> - Â Â Â}
> + Â Â{
> + Â Â Âif ((dump_files[i].flags & ir_dump_type))
> + Â Â Â Â{
> + Â Â Â Â Âdump_files[i].state = -1;
> + Â Â Â Â Âdump_files[i].flags |= flags;
> + Â Â Â Â Ân++;
> + Â Â Â Â}
> + Â Â Âif (user_filename)
> + Â Â Â Âdump_files[i].user_filename = user_filename;
> + Â Â}
>
> Â for (i = 0; i < extra_dump_files_in_use; i++)
> - Â Âif ((extra_dump_files[i].flags & ir_dump_type))
> - Â Â Â{
> - Â Â Â Âextra_dump_files[i].state = -1;
> - Â Â Â Âextra_dump_files[i].flags |= flags;
> - Â Â Â n++;
> - Â Â Â}
> + Â Â{
> + Â Â Âif ((extra_dump_files[i].flags & ir_dump_type))
> + Â Â Â Â{
> + Â Â Â Â Âextra_dump_files[i].state = -1;
> + Â Â Â Â Âextra_dump_files[i].flags |= flags;
> + Â Â Â Â Ân++;
> + Â Â Â Â}
> + Â Â Âif (user_filename)
> + Â Â Â Âextra_dump_files[i].user_filename = user_filename;
> + Â Â}
>
> Â return n;
> Â}
> @@ -1037,7 +1077,7 @@ dump_switch_p_1 (const char *arg, struct dump_file
> Â if (!option_value)
> Â Â return 0;
>
> - Âif (*option_value && *option_value != '-')
> + Âif (*option_value && *option_value != '-' && *option_value != '=')
> Â Â return 0;
>
> Â ptr = option_value;
> @@ -1052,17 +1092,30 @@ dump_switch_p_1 (const char *arg, struct dump_file
> Â Â Â while (*ptr == '-')
> Â Â Â Âptr++;
> Â Â Â end_ptr = strchr (ptr, '-');
> +
> Â Â Â if (!end_ptr)
> Â Â Â Âend_ptr = ptr + strlen (ptr);
> Â Â Â length = end_ptr - ptr;
>
> + Â Â Âif (*ptr == '=')
> + Â Â Â Â{
> + Â Â Â Â Â/* Interpret rest of the argument as a dump filename. ÂThe
> + Â Â Â Â Â Â user provided filename overrides generated dump names as
> + Â Â Â Â Â Â well as other command line filenames. Â*/
> + Â Â Â Â Âflags |= TDF_USER_FILENAME;
> + Â Â Â Â Âif (dfi->user_filename)
> + Â Â Â Â Â Âfree (dfi->user_filename);
> + Â Â Â Â Âdfi->user_filename = xstrdup (ptr + 1);
> + Â Â Â Â Âbreak;
> + Â Â Â Â}
> +
> Â Â Â for (option_ptr = dump_options; option_ptr->name; option_ptr++)
> Â Â Â Âif (strlen (option_ptr->name) == length
> Â Â Â Â Â Â&& !memcmp (option_ptr->name, ptr, length))
> - Â Â Â Â {
> - Â Â Â Â Â flags |= option_ptr->value;
> + Â Â Â Â Â{
> + Â Â Â Â Â Âflags |= option_ptr->value;
> Â Â Â Â Â Âgoto found;
> - Â Â Â Â }
> + Â Â Â Â Â}
> Â Â Â warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
> Â Â Â Â Â Â Â length, ptr, dfi->swtch);
> Â Â found:;
> @@ -1075,7 +1128,7 @@ dump_switch_p_1 (const char *arg, struct dump_file
> Â /* Process -fdump-tree-all and -fdump-rtl-all, by enabling all the
> Â Â Âknown dumps. Â*/
> Â if (dfi->suffix == NULL)
> - Â Âdump_enable_all (dfi->flags);
> + Â Âdump_enable_all (dfi->flags, dfi->user_filename);
>
> Â return 1;
> Â}
> @@ -1124,5 +1177,5 @@ dump_function (int phase, tree fn)
> Âbool
> Âenable_rtl_dump_file (void)
> Â{
> - Âreturn dump_enable_all (TDF_RTL | TDF_DETAILS | TDF_BLOCKS) > 0;
> + Âreturn dump_enable_all (TDF_RTL | TDF_DETAILS | TDF_BLOCKS, NULL) > 0;
> Â}
> Index: tree-pass.h
> ===================================================================
> --- tree-pass.h (revision 187265)
> +++ tree-pass.h (working copy)
> @@ -84,8 +84,9 @@ 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_USER_FILENAME Â Â(1 << 25) /* Dump on user provided filename,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â instead of constructing one. */
>
> -
> Â/* In tree-dump.c */
>
> Âextern char *get_dump_file_name (int);
> @@ -222,6 +223,8 @@ struct dump_file_info
> Â const char *suffix; Â Â Â Â Â /* suffix to give output file. Â*/
> Â const char *swtch; Â Â Â Â Â Â/* command line switch */
> Â const char *glob; Â Â Â Â Â Â /* command line glob Â*/
> + Âconst char *user_filename; Â Â/* user provided filename instead of making
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â up one using dump_base_name + suffix. Â*/
> Â int flags; Â Â Â Â Â Â Â Â Â Â/* user flags */
> Â int state; Â Â Â Â Â Â Â Â Â Â/* state of play */
> Â int num; Â Â Â Â Â Â Â Â Â Â Â/* dump file number */
> Index: testsuite/g++.dg/other/dump-userfile-1.C
> ===================================================================
> --- testsuite/g++.dg/other/dump-userfile-1.C Â Â(revision 0)
> +++ testsuite/g++.dg/other/dump-userfile-1.C Â Â(revision 0)
> @@ -0,0 +1,11 @@
> +// Test that the dump to a user-defined file works correctly.
> +/* { dg-options "-O2 -fdump-tree-original=foobar.dump" } */
> +
> +void test (int *b, int *e, int stride)
> + Â{
> + Â Âfor (int *p = b; p != e; p += stride)
> + Â Â Â*p = 1;
> + Â}
> +
> +/* { dg-final { scan-file foobar.dump ";; Function void test" } } */
> +/* { dg-final { remove-build-file "foobar.dump" } } */
>
> --
> This patch is available for review at http://codereview.appspot.com/6190057


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]