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] Print function attributes in rtl dumps


[ Fix ENOPATCH ]

On 03/29/2018 12:17 PM, Tom de Vries wrote:
Hi,

when we compile a function with attributes:
...
int __attribute__((noinline, noclone))
foo (void)
{
   return 2;
}
...

like this:
...
gcc main.c -fdump-tree-all -fdump-rtl-all
...

we find the function attributes starting from foo.c.004t.gimple:
...
__attribute__((noclone, noinline))
foo ()
{
   int D.1961;

   D.1961 = 2;
   return D.1961;
}
...
to foo.c.232t.optimized.


But we don't find the attributes in the rtl dumps:
...
$ grep __attribute__ foo.c.*r.*
$
...

This patch adds printing of the function attributes in the rtl dump, f.i. foo.c.235r.vregs looks like this :
...
;; Function foo (foo, funcdef_no=0, decl_uid=1958, cgraph_uid=0, symbol_order=0)

function foo attributes: __attribute__((noclone, noinline))
(note 1 0 3 NOTE_INSN_DELETED)
(note 3 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 3 5 2 NOTE_INSN_FUNCTION_BEG)
(insn 5 2 8 2 (set (reg:SI 87 [ _1 ])
         (const_int 2 [0x2])) "foo.c":4 86 {*movsi_internal}
      (nil))
(insn 8 5 12 2 (set (reg:SI 88 [ <retval> ])
         (reg:SI 87 [ _1 ])) "foo.c":4 86 {*movsi_internal}
      (nil))
(insn 12 8 13 2 (set (reg/i:SI 0 ax)
         (reg:SI 88 [ <retval> ])) "foo.c":5 86 {*movsi_internal}
      (nil))
(insn 13 12 0 2 (use (reg/i:SI 0 ax)) "foo.c":5 -1
      (nil))
...

I've added the "function foo attributes" prefix because in other rtl dumps there may be quite a number of lines between the ";; Function foo" header and the first insn.

OK for stage1 if bootstrap and reg-test on x86 succeeds?

Thanks,
- Tom

Print function attributes in rtl dump

2018-03-29  Tom de Vries  <tom@codesourcery.com>

	* passes.c (execute_function_dump): Call dump_function_attributes before
	print_rtl_with_bb.
	* tree-cfg.c (dump_function_attributes): New function, factored out of
	...
	(dump_function_to_file): ... here.
	* tree-cfg.h (dump_function_attributes): Declare.

---
 gcc/passes.c   |  5 ++++-
 gcc/tree-cfg.c | 68 ++++++++++++++++++++++++++++++++++------------------------
 gcc/tree-cfg.h |  1 +
 3 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/gcc/passes.c b/gcc/passes.c
index ad0a912..91518bd 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -1761,7 +1761,10 @@ execute_function_dump (function *fn, void *data)
       if (fn->curr_properties & PROP_trees)
         dump_function_to_file (fn->decl, dump_file, dump_flags);
       else
-	print_rtl_with_bb (dump_file, get_insns (), dump_flags);
+	{
+	  dump_function_attributes (fn->decl, dump_file, true);
+	  print_rtl_with_bb (dump_file, get_insns (), dump_flags);
+	}
 
       /* Flush the file.  If verification fails, we won't be able to
 	 close the file before aborting.  */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 9485f73..d0f8b70 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7963,6 +7963,45 @@ print_no_sanitize_attr_value (FILE *file, tree value)
     }
 }
 
+/* Dump function attributes of function FNDECL to FILE.  Print prefix showing
+   the function name if PRINT_PREFIX.  */
+
+void
+dump_function_attributes (tree fndecl, FILE *file, bool print_prefix)
+{
+  if (DECL_ATTRIBUTES (fndecl) == NULL_TREE)
+    return;
+
+  if (print_prefix)
+    fprintf (file, "function %s attributes: ", fndecl_name (fndecl));
+
+  fprintf (file, "__attribute__((");
+
+  bool first = true;
+  tree chain;
+  for (chain = DECL_ATTRIBUTES (fndecl); chain;
+       first = false, chain = TREE_CHAIN (chain))
+    {
+      if (!first)
+	fprintf (file, ", ");
+
+      tree name = get_attribute_name (chain);
+      print_generic_expr (file, name, dump_flags);
+      if (TREE_VALUE (chain) != NULL_TREE)
+	{
+	  fprintf (file, " (");
+
+	  if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
+	    print_no_sanitize_attr_value (file, TREE_VALUE (chain));
+	  else
+	    print_generic_expr (file, TREE_VALUE (chain), dump_flags);
+	  fprintf (file, ")");
+	}
+    }
+
+  fprintf (file, "))\n");
+}
+
 /* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in dumpfile.h)
    */
 
@@ -7978,34 +8017,7 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 		  && decl_is_tm_clone (fndecl));
   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
 
-  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
-    {
-      fprintf (file, "__attribute__((");
-
-      bool first = true;
-      tree chain;
-      for (chain = DECL_ATTRIBUTES (fndecl); chain;
-	   first = false, chain = TREE_CHAIN (chain))
-	{
-	  if (!first)
-	    fprintf (file, ", ");
-
-	  tree name = get_attribute_name (chain);
-	  print_generic_expr (file, name, dump_flags);
-	  if (TREE_VALUE (chain) != NULL_TREE)
-	    {
-	      fprintf (file, " (");
-
-	      if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
-		print_no_sanitize_attr_value (file, TREE_VALUE (chain));
-	      else
-		print_generic_expr (file, TREE_VALUE (chain), dump_flags);
-	      fprintf (file, ")");
-	    }
-	}
-
-      fprintf (file, "))\n");
-    }
+  dump_function_attributes (fndecl, file, false);
 
   current_function_decl = fndecl;
   if (flags & TDF_GIMPLE)
diff --git a/gcc/tree-cfg.h b/gcc/tree-cfg.h
index 73237a6..bd9a7de 100644
--- a/gcc/tree-cfg.h
+++ b/gcc/tree-cfg.h
@@ -81,6 +81,7 @@ extern void fold_loop_internal_call (gimple *, tree);
 extern basic_block move_sese_region_to_fn (struct function *, basic_block,
 				           basic_block, tree);
 extern void dump_function_to_file (tree, FILE *, dump_flags_t);
+extern void dump_function_attributes (tree, FILE *, bool);
 extern void debug_function (tree, int) ;
 extern void print_loops_bb (FILE *, basic_block, int, int);
 extern void print_loops (FILE *, int);

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