diff mbox

[PR70185] Only finalize dot files that have been initialized

Message ID 56E93C26.7070400@mentor.com
State New
Headers show

Commit Message

Tom de Vries March 16, 2016, 10:57 a.m. UTC
Hi,

Atm, using fdump-tree-all-graph produces invalid dot files:
...
$ rm *.c.* ; gcc test.c -O2 -S -fdump-tree-all-graph
$ for f in *.dot; do dot -Tpdf $f -o dot.pdf; done
Warning: test.c.006t.omplower.dot: syntax error in line 1 near '}'
Warning: test.c.007t.lower.dot: syntax error in line 1 near '}'
Warning: test.c.010t.eh.dot: syntax error in line 1 near '}'
Warning: test.c.292t.statistics.dot: syntax error in line 1 near '}'
$ cat test.c.006t.omplower.dot
}
$
...
These dot files are finalized, but never initialized or used.

The 006/007/010 files are not used because '(fn->curr_properties & 
PROP_cfg) == 0' at the corresponding passes.

And the file test.c.292t.statistics.dot is not used, because it doesn't 
belong to a single pass.

The current finalization code doesn't handle these cases:
...
   /* Do whatever is necessary to finish printing the graphs.  */
   for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
     if (dumps->dump_initialized_p (i)
         && (dfi->pflags & TDF_GRAPH) != 0
         && (name = dumps->get_dump_file_name (i)) != NULL)
       {
        	finish_graph_dump_file (name);
         free (name);
       }
...

The patch fixes this by simply testing for pass->graph_dump_initialized 
instead.

[ That fix exposes the lack of initialization of graph_dump_initialized. 
It seems to be initialized for static passes, but for dynamically added 
passes, such as f.i. vzeroupper the value is uninitialized. The patch 
also fixes this. ]

Bootstrapped and reg-tested on x86_64.

OK for stage1?

Thanks,
- Tom

Comments

Richard Biener March 16, 2016, 11:34 a.m. UTC | #1
On Wed, Mar 16, 2016 at 11:57 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> Hi,
>
> Atm, using fdump-tree-all-graph produces invalid dot files:
> ...
> $ rm *.c.* ; gcc test.c -O2 -S -fdump-tree-all-graph
> $ for f in *.dot; do dot -Tpdf $f -o dot.pdf; done
> Warning: test.c.006t.omplower.dot: syntax error in line 1 near '}'
> Warning: test.c.007t.lower.dot: syntax error in line 1 near '}'
> Warning: test.c.010t.eh.dot: syntax error in line 1 near '}'
> Warning: test.c.292t.statistics.dot: syntax error in line 1 near '}'
> $ cat test.c.006t.omplower.dot
> }
> $
> ...
> These dot files are finalized, but never initialized or used.
>
> The 006/007/010 files are not used because '(fn->curr_properties & PROP_cfg)
> == 0' at the corresponding passes.
>
> And the file test.c.292t.statistics.dot is not used, because it doesn't
> belong to a single pass.
>
> The current finalization code doesn't handle these cases:
> ...
>   /* Do whatever is necessary to finish printing the graphs.  */
>   for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
>     if (dumps->dump_initialized_p (i)
>         && (dfi->pflags & TDF_GRAPH) != 0
>         && (name = dumps->get_dump_file_name (i)) != NULL)
>       {
>         finish_graph_dump_file (name);
>         free (name);
>       }
> ...
>
> The patch fixes this by simply testing for pass->graph_dump_initialized
> instead.
>
> [ That fix exposes the lack of initialization of graph_dump_initialized. It
> seems to be initialized for static passes, but for dynamically added passes,
> such as f.i. vzeroupper the value is uninitialized. The patch also fixes
> this. ]
>
> Bootstrapped and reg-tested on x86_64.
>
> OK for stage1?

Seeing this I wonder if it makes more sense to move ->graph_dump_initialized
from pass to dump_file_info?  Also in the above shouldn't it use
dfi->pfilename rather than dumps->get_dump_file_name (i)?

Richard.

> Thanks,
> - Tom
diff mbox

Patch

Only finalize dot files that have been initialized

2016-03-16  Tom de Vries  <tom@codesourcery.com>

	PR other/70185
	* passes.c (opt_pass::opt_pass): Add missing initialization of
	graph_dump_initialized.
	(finish_optimization_passes): Only call finish_graph_dump_file if
	pass->graph_dump_initialized.

---
 gcc/passes.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/gcc/passes.c b/gcc/passes.c
index 9d90251..5aa2b32 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -105,6 +105,7 @@  opt_pass::opt_pass (const pass_data &data, context *ctxt)
     sub (NULL),
     next (NULL),
     static_pass_number (0),
+    graph_dump_initialized (false),
     m_ctxt (ctxt)
 {
 }
@@ -363,14 +364,18 @@  finish_optimization_passes (void)
     }
 
   /* Do whatever is necessary to finish printing the graphs.  */
+  gcc::pass_manager *passes = g->get_passes ();
   for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
-    if (dumps->dump_initialized_p (i)
-	&& (dfi->pflags & TDF_GRAPH) != 0
-	&& (name = dumps->get_dump_file_name (i)) != NULL)
-      {
-	finish_graph_dump_file (name);
-	free (name);
-      }
+    {
+      opt_pass *pass = passes->get_pass_for_id (i);
+      if (pass == NULL
+	  || !pass->graph_dump_initialized)
+	continue;
+
+      name = dumps->get_dump_file_name (i);
+      finish_graph_dump_file (name);
+      free (name);
+    }
 
   timevar_pop (TV_DUMP);
 }