Patchwork [(for,next,stage,1)] Add return type to gimple function dumps

login
register
mail settings
Submitter David Malcolm
Date March 10, 2014, 7:22 p.m.
Message ID <1394479369.26367.17.camel@surprise>
Download mbox | patch
Permalink /patch/328717/
State New
Headers show

Comments

David Malcolm - March 10, 2014, 7:22 p.m.
Gimple function dumps contain the types of parameters, but not of the
return type.

The attached patch fixes this omission; here's an example of the
before/after diff:
$ diff -up /tmp/pr23401.c.004t.gimple.old /tmp/pr23401.c.004t.gimple.new


Successfully bootstrapped and regrtested on x86_64 Linux (Fedora 20).

A couple of test cases needed tweaking, since they were counting the
number of occurrences of "int" in the gimple dump, which thus changed
for functions returning int (like the one above).

OK for next stage 1?

[motivation: am generating code in my JIT from other program's
representations, and have been debugging type mismatches in function
calls; the precise return types would otherwise have been non-obvious]
Richard Guenther - March 11, 2014, 11:22 a.m.
On Mon, Mar 10, 2014 at 8:22 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> Gimple function dumps contain the types of parameters, but not of the
> return type.
>
> The attached patch fixes this omission; here's an example of the
> before/after diff:
> $ diff -up /tmp/pr23401.c.004t.gimple.old /tmp/pr23401.c.004t.gimple.new
> --- /tmp/pr23401.c.004t.gimple.old      2014-03-10 13:40:08.972063541 -0400
> +++ /tmp/pr23401.c.004t.gimple.new      2014-03-10 13:39:49.346515464 -0400
> @@ -1,3 +1,4 @@
> +int
>  ffff (int i)
>  {
>    int D.1731;
>
>
> Successfully bootstrapped and regrtested on x86_64 Linux (Fedora 20).
>
> A couple of test cases needed tweaking, since they were counting the
> number of occurrences of "int" in the gimple dump, which thus changed
> for functions returning int (like the one above).
>
> OK for next stage 1?

ISTR doing that and giving up because of the sheer number of
testsuite FAILs this causes.  Did you properly test all languages
(I specifically remember Fortran here).

You also want to pass dump_flags | TDF_SLIM here otherwise
you'll get struct types expanded.

Richard.

> [motivation: am generating code in my JIT from other program's
> representations, and have been debugging type mismatches in function
> calls; the precise return types would otherwise have been non-obvious]
Jeff Law - April 24, 2014, 9:46 p.m.
On 03/10/14 13:22, David Malcolm wrote:
> Gimple function dumps contain the types of parameters, but not of the
> return type.
>
> The attached patch fixes this omission; here's an example of the
> before/after diff:
> $ diff -up /tmp/pr23401.c.004t.gimple.old /tmp/pr23401.c.004t.gimple.new
> --- /tmp/pr23401.c.004t.gimple.old      2014-03-10 13:40:08.972063541 -0400
> +++ /tmp/pr23401.c.004t.gimple.new      2014-03-10 13:39:49.346515464 -0400
> @@ -1,3 +1,4 @@
> +int
>   ffff (int i)
>   {
>     int D.1731;
>
>
> Successfully bootstrapped and regrtested on x86_64 Linux (Fedora 20).
>
> A couple of test cases needed tweaking, since they were counting the
> number of occurrences of "int" in the gimple dump, which thus changed
> for functions returning int (like the one above).
>
> OK for next stage 1?
Conceptually OK.  As Richi notes, the work here is in fixing up the 
testsuite.  I didn't see a reply to Richi's question, particularly WRT 
the Fortran testsuite.

jeff

Patch

commit cfef58ecb0d81e6b9c691217ad9efdce376fc0a5
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Mon Mar 10 13:52:44 2014 -0400

    Dump the return type of functions in gimple dumps
    
    gcc/
    	* tree-cfg.c (dump_function_to_file): Dump the return type of
    	functions, in a line to itself before the function body, mimicking
    	the layout of a C function.
    
    gcc/testsuite/
    	* gcc.dg/tree-ssa/pr23401.c: Update the expected number of
    	occurrences of "int" in the gimple dump to reflect that the return
    	types of functions now show up in such dumps.
    	* gcc.dg/tree-ssa/pr27810.c: Likwise.

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr23401.c b/gcc/testsuite/gcc.dg/tree-ssa/pr23401.c
index 1d30ac7..3940692 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr23401.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr23401.c
@@ -19,6 +19,6 @@  int ffff(int i)
 
 /* We should not use extra temporaries apart from for i1 + i2.  */
 
-/* { dg-final { scan-tree-dump-times "int" 5 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "int" 6 "gimple" } } */
 /* { dg-final { scan-tree-dump-times "int D\\\." 1 "gimple" } } */
 /* { dg-final { cleanup-tree-dump "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr27810.c b/gcc/testsuite/gcc.dg/tree-ssa/pr27810.c
index c7da3bd..6d0904b 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr27810.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr27810.c
@@ -13,6 +13,6 @@  int qqq (int a)
 /* We should not use an extra temporary for the result of the
    function call.  */
 
-/* { dg-final { scan-tree-dump-times "int" 3 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "int" 4 "gimple" } } */
 /* { dg-final { scan-tree-dump-times "int D\\\." 1 "gimple" } } */
 /* { dg-final { cleanup-tree-dump "gimple" } } */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 325285c..9335f4c 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7075,6 +7075,11 @@  dump_function_to_file (tree fndecl, FILE *file, int flags)
   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
 
   current_function_decl = fndecl;
+
+  /* Print the return type of the function: */
+  print_generic_expr (file, TREE_TYPE (TREE_TYPE (fun->decl)), dump_flags);
+  fprintf (file, "\n");
+
   fprintf (file, "%s %s(", function_name (fun), tmclone ? "[tm-clone] " : "");
 
   arg = DECL_ARGUMENTS (fndecl);