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]

[PATCH 4/4] Print pass metadata at the start and end of dumpfiles


This patch adds information to the top and bottom of dumpfiles giving
metadata on the pass that they're associated with e.g.:

; start of dump from pass_forwprop (../../src/gcc/tree-ssa-forwprop.c:2103)

(dump goes here)

; end of dump from pass_forwprop (../../src/gcc/tree-ssa-forwprop.c:2103)

My initial implementation of this led to these testsuite regressions:

 PASS -> FAIL : gcc.dg/pr34027-1.c scan-tree-dump-times optimized "/" 0
 PASS -> FAIL : gcc.dg/strlenopt-1.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-10.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-11.c scan-tree-dump-times strlen "strlen \\(" 3
 PASS -> FAIL : gcc.dg/strlenopt-13.c scan-tree-dump-times strlen "strlen \\(" 4
 PASS -> FAIL : gcc.dg/strlenopt-14g.c scan-tree-dump-times strlen "strlen \\(" 4
 PASS -> FAIL : gcc.dg/strlenopt-14gf.c scan-tree-dump-times strlen "strlen \\(" 4
 PASS -> FAIL : gcc.dg/strlenopt-15.c scan-tree-dump-times strlen "strlen \\(" 3
 PASS -> FAIL : gcc.dg/strlenopt-16g.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-17g.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-18g.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-19.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-1f.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-2.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-20.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-21.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-22.c scan-tree-dump-times strlen "strlen \\(" 3
 PASS -> FAIL : gcc.dg/strlenopt-22g.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-24.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-25.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-26.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-27.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-2f.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-3.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-4.c scan-tree-dump-times strlen "strlen \\(" 3
 PASS -> FAIL : gcc.dg/strlenopt-4g.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-4gf.c scan-tree-dump-times strlen "strlen \\(" 1
 PASS -> FAIL : gcc.dg/strlenopt-5.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-6.c scan-tree-dump-times strlen "strlen \\(" 2
 PASS -> FAIL : gcc.dg/strlenopt-7.c scan-tree-dump-times strlen "strlen \\(" 0
 PASS -> FAIL : gcc.dg/strlenopt-9.c scan-tree-dump-times strlen "strlen \\(" 3
 PASS -> FAIL : gcc.dg/tree-ssa/forwprop-31.c scan-tree-dump-times forwprop1 "-" 0
 PASS -> FAIL : gcc.dg/tree-ssa/loop-22.c scan-tree-dump-times optimized "/" 0
 PASS -> FAIL : gcc.dg/tree-ssa/pr32044.c scan-tree-dump-times optimized "/" 0
 PASS -> FAIL : gcc.dg/tree-ssa/reassoc-16.c scan-tree-dump-times reassoc1 "/" 1
 PASS -> FAIL : gcc.dg/tree-ssa/reassoc-17.c scan-tree-dump-times reassoc1 "/" 1
 PASS -> FAIL : gcc.dg/tree-ssa/sra-4.c scan-tree-dump-times optimized "st" 0

due to the metadata lines matching the given regexes.

This version of the patch adds a new -fno-dump-metadata option for
suppressing the metadata, and this is used automatically by the
testsuite if its sees any usage of scan-tree-dump-times.

gcc/ChangeLog:
	* common.opt (fdump-metadata): New option.
	* doc/invoke.texi: Add -fno-dump-metadata.
	* passes.c (pass_init_dump_file): Add information
	on the classname and source location of the pass to the top of
	the dumpfile.
	(pass_fini_dump_file): Likewise to the end of the dumpfile.

gcc/testsuite/ChangeLog:
	* lib/gcc-dg.exp (gcc-dg-test-1): Determine if any
	scan-tree-dump-times actions were registered, and if so,
	add -fno-dump-metadata.
---
 gcc/common.opt               |  4 ++++
 gcc/doc/invoke.texi          | 21 +++++++++++++++++++++
 gcc/passes.c                 |  7 +++++++
 gcc/testsuite/lib/gcc-dg.exp | 18 ++++++++++++++++++
 4 files changed, 50 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index 32b416a..7b19487 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1177,6 +1177,10 @@ fdump-internal-locations
 Common Var(flag_dump_locations) Init(0)
 Dump detailed information on GCC's internal representation of source code locations
 
+fdump-metadata
+Common Var(flag_dump_metadata) Init(1)
+Include metadata about the relevant pass at the start and end of dumpfiles
+
 fdump-passes
 Common Var(flag_dump_passes) Init(0)
 Dump optimization passes
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b99ab1c..e2c5fed 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -324,6 +324,7 @@ Objective-C and Objective-C++ Dialects}.
 -fdump-translation-unit@r{[}-@var{n}@r{]} @gol
 -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
 -fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline @gol
+-fno-dump-metadata @gol
 -fdump-passes @gol
 -fdump-statistics @gol
 -fdump-tree-all @gol
@@ -6863,6 +6864,26 @@ Dump after function inlining.
 Dump the list of optimization passes that are turned on and off by
 the current command-line options.
 
+@item -fno-dump-metadata
+@opindex fno-dump-metadata
+By default, gcc dump files contain header lines of the form:
+
+@smallexample
+
+; start of dump from pass_forwprop (../../src/gcc/tree-ssa-forwprop.c:2103)
+
+(dump goes here)
+
+; end of dump from pass_forwprop (../../src/gcc/tree-ssa-forwprop.c:2103)
+
+@end smallexample
+
+at the top and bottom, identifying the C++ class implementing the
+pass, and its location within GCC's source tree.
+
+This option suppresses these metadata lines, for use by gcc's testsuite
+when looking for regexes in the dump files.
+
 @item -fdump-statistics-@var{option}
 @opindex fdump-statistics
 Enable and control dumping of pass statistics in a separate file.  The
diff --git a/gcc/passes.c b/gcc/passes.c
index b9e548b..8c11fd6 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -2114,6 +2114,9 @@ pass_init_dump_file (opt_pass *pass)
 	!dumps->dump_initialized_p (pass->static_pass_number);
       dump_file_name = dumps->get_dump_file_name (pass->static_pass_number);
       dumps->dump_start (pass->static_pass_number, &dump_flags);
+      if (dump_file && flag_dump_metadata)
+	fprintf (dump_file, "; start of dump from %s (%s:%i)\n",
+		 pass->classname, pass->filename, pass->line_num);
       if (dump_file && current_function_decl)
         dump_function_header (dump_file, current_function_decl, dump_flags);
       if (initializing_dump
@@ -2138,6 +2141,10 @@ pass_fini_dump_file (opt_pass *pass)
 {
   timevar_push (TV_DUMP);
 
+  if (dump_file && flag_dump_metadata)
+    fprintf (dump_file, "; end of dump from %s (%s:%i)\n",
+	     pass->classname, pass->filename, pass->line_num);
+
   /* Flush and close dump file.  */
   if (dump_file_name)
     {
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 9e4ecce..745eaf1 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -278,6 +278,24 @@ proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
 	}
     }
 
+    # Determine if any { dg-final { scan-tree-dump-times } } actions were
+    # registered.
+    set will_scan_dump 0
+    foreach x [split $finalcode "\n"] {
+	set finalcmd [lindex $x 0]
+	if { ${finalcmd} == "scan-tree-dump-times" } {
+	    set will_scan_dump 1
+	}
+    }
+    # If so, add -fno-dump-metadata to the options to prevent the dumpfiles
+    # from containing lines like:
+    #   ; start of dump from pass_forwprop (../../src/gcc/tree-ssa-forwprop.c:2103)
+    # which could potentially match a regexp (e.g. if the path to the
+    # source tree contains strings of interest).
+    if { ${will_scan_dump} } {
+	lappend extra_tool_flags "-fno-dump-metadata"
+    }
+
     append finalcode [schedule-cleanups "$options $extra_tool_flags"]
     if { $extra_tool_flags != "" } {
 	lappend options "additional_flags=$extra_tool_flags"
-- 
1.8.5.3


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