[PATCH 6/8] ipa-inline.c/tree-inline.c: port from fprintf to dump API

David Malcolm dmalcolm@redhat.com
Thu Jun 14 19:50:00 GMT 2018


This patch ports from fprintf to using the dump API in a few places

Doing so makes this information appear in -fopt-info, remarks,
and optimization records, rather than just in the dump_file.

In early_inline_small_functions I experimented with two approaches:
simply porting from fprintf to dump_printf_loc, and also breaking
things out into dump_symtab_node calls.  The results are identical
for the dump file and for -fopt-info.  For remarks, the node names
are quoted in the diagnostic output; for optimization records, the
fact that they are symtab nodes is captured, along with metadata
such as the locations of the functions.  Though this approach is
less amenable to translation (if we want to translate these messages).

gcc/ChangeLog:
	* ipa-inline.c: Include "optinfo.h".
	(report_inline_failed_reason): Port from fprintf to dump API.
	(flatten_function): Likewise.
	(early_inline_small_functions): Likewise, experimenting with two
	approaches.
	* tree-inline.c (expand_call_inline): Port from fprintf to dump
	API.
---
 gcc/ipa-inline.c  | 57 +++++++++++++++++++++++++++++++++++++++----------------
 gcc/tree-inline.c | 18 +++++++++++-------
 2 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 7e4468a..1aeaa95 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -120,6 +120,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stringpool.h"
 #include "attribs.h"
 #include "asan.h"
+#include "optinfo.h"
 
 typedef fibonacci_heap <sreal, cgraph_edge> edge_heap_t;
 typedef fibonacci_node <sreal, cgraph_edge> edge_heap_node_t;
@@ -227,20 +228,21 @@ caller_growth_limits (struct cgraph_edge *e)
 static void
 report_inline_failed_reason (struct cgraph_edge *e)
 {
-  if (dump_file)
+  if (dump_enabled_p ())
     {
-      fprintf (dump_file, "  not inlinable: %s -> %s, %s\n",
-	       e->caller->dump_name (),
-	       e->callee->dump_name (),
-	       cgraph_inline_failed_string (e->inline_failed));
+      dump_printf_loc (MSG_MISSED_OPTIMIZATION, e->call_stmt,
+		       "  not inlinable: %s -> %s, %s\n",
+		       e->caller->dump_name (),
+		       e->callee->dump_name (),
+		       cgraph_inline_failed_string (e->inline_failed));
       if ((e->inline_failed == CIF_TARGET_OPTION_MISMATCH
 	   || e->inline_failed == CIF_OPTIMIZATION_MISMATCH)
 	  && e->caller->lto_file_data
 	  && e->callee->ultimate_alias_target ()->lto_file_data)
 	{
-	  fprintf (dump_file, "  LTO objects: %s, %s\n",
-		   e->caller->lto_file_data->file_name,
-		   e->callee->ultimate_alias_target ()->lto_file_data->file_name);
+	  dump_printf (MSG_MISSED_OPTIMIZATION, "  LTO objects: %s, %s\n",
+		       e->caller->lto_file_data->file_name,
+		       e->callee->ultimate_alias_target ()->lto_file_data->file_name);
 	}
       if (e->inline_failed == CIF_TARGET_OPTION_MISMATCH)
 	cl_target_option_print_diff
@@ -2172,10 +2174,11 @@ flatten_function (struct cgraph_node *node, bool early)
 
       /* Inline the edge and flatten the inline clone.  Avoid
          recursing through the original node if the node was cloned.  */
-      if (dump_file)
-	fprintf (dump_file, " Inlining %s into %s.\n",
-		 xstrdup_for_dump (callee->name ()),
-		 xstrdup_for_dump (e->caller->name ()));
+      if (dump_enabled_p ())
+	dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, e->call_stmt,
+			 " Inlining %s into %s.\n",
+			 xstrdup_for_dump (callee->name ()),
+			 xstrdup_for_dump (e->caller->name ()));
       orig_callee = callee;
       inline_call (e, true, NULL, NULL, false);
       if (e->callee != orig_callee)
@@ -2682,10 +2685,32 @@ early_inline_small_functions (struct cgraph_node *node)
       if (!want_early_inline_function_p (e))
 	continue;
 
-      if (dump_file)
-	fprintf (dump_file, " Inlining %s into %s.\n",
-		 xstrdup_for_dump (callee->name ()),
-		 xstrdup_for_dump (e->caller->name ()));
+      /* FIXME:  if (dump_enabled_p ()) would be simpler.  */
+      if (optinfo_guard guard = optinfo_guard (e->call_stmt,
+					       OPTINFO_IMPL_LOCATION))
+	{
+	  if (1)
+	    {
+	      /* Use of dump_symtab_node, which thus captures the nodes
+		 in the optimization record.  */
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, e->call_stmt,
+			       " Inlining ");
+	      dump_symtab_node (MSG_OPTIMIZED_LOCATIONS, callee);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS,
+			       " into ");
+	      dump_symtab_node (MSG_OPTIMIZED_LOCATIONS, e->caller);
+	      dump_printf (MSG_OPTIMIZED_LOCATIONS, ".\n");
+	    }
+	  else
+	    {
+	      /* printf-style printing, which doesn't capture the
+		 symtab_nodes themselves.  */
+	      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, e->call_stmt,
+			       " Inlining %s into %s.\n",
+			       xstrdup_for_dump (callee->name ()),
+			       xstrdup_for_dump (e->caller->name ()));
+	    }
+	}
       inline_call (e, true, NULL, NULL, false);
       inlined = true;
     }
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index ca4dc32..45027dc 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -4627,14 +4627,18 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id)
   /* Add local vars in this inlined callee to caller.  */
   add_local_variables (id->src_cfun, cfun, id);
 
-  if (dump_file && (dump_flags & TDF_DETAILS))
+  if (dump_enabled_p ())
     {
-      fprintf (dump_file, "Inlining %s to %s with frequency %4.2f\n",
-	       id->src_node->dump_name (),
-	       id->dst_node->dump_name (),
-	       cg_edge->sreal_frequency ().to_double ());
-      id->src_node->dump (dump_file);
-      id->dst_node->dump (dump_file);
+      dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, call_stmt,
+		       "Inlining %s to %s with frequency %4.2f\n",
+		       id->src_node->dump_name (),
+		       id->dst_node->dump_name (),
+		       cg_edge->sreal_frequency ().to_double ());
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	{
+	  id->src_node->dump (dump_file);
+	  id->dst_node->dump (dump_file);
+	}
     }
 
   /* This is it.  Duplicate the callee body.  Assume callee is
-- 
1.8.5.3



More information about the Gcc-patches mailing list