public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Thomas Schwinge	<thomas@codesourcery.com>,
	Jakub Jelinek <jakub@redhat.com>
Subject: Don't dump low gimple functions in gimple dump
Date: Tue, 20 May 2014 08:17:00 -0000	[thread overview]
Message-ID: <537B0F6D.7060808@mentor.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

Honza,

Consider this program:
...
int
main(void)
{
#pragma omp parallel
  {
    extern void foo(void);
    foo ();
  }
  return 0;
}
...

When compiling this program with -fopenmp, the ompexp pass splits off a new
function called main._omp_fn.0 containing the call to foo.  The new function is
then dumped into the gimple dump by analyze_function.

There are two problems with this:
- the new function is in low gimple, and is dumped next to high gimple
  functions
- since it's already low, the new function is not lowered, and 'goes missing'
  in the dumps following the gimple dump, until it reappears again after the
  last lowering dump.
  [ http://gcc.gnu.org/ml/gcc/2014-03/msg00312.html ]

This patch fixes the problems by ensuring that analyze_function only dumps the
new function to the gimple dump after gimplification (specifically, by moving
the dump_function call into gimplify_function_tree.  That makes the call to
dump_function in finalize_size_functions superfluous).

That also requires us to add a call to dump_function in finalize_task_copyfn,
where we split off a new high gimple function.

And in expand_omp_taskreg and expand_omp_target, where we split off a new low
gimple function, we now dump the new function into the current (ompexp) dump
file, which is the last lowering dump.

Finally, we dump an information statement at the start of
cgraph_add_new_function to give a better idea when and what kind of function is
created.

Bootstrapped and reg-tested on x86_64.

OK for trunk ?

Thanks,
- Tom

[-- Attachment #2: 0001-Don-t-dump-already-lowered-functions-in-gimple-dump.patch --]
[-- Type: text/x-patch, Size: 5713 bytes --]

2014-05-19  Tom de Vries  <tom@codesourcery.com>

	* cgraphunit.c (cgraph_add_new_function): Dump message on new function.
	(analyze_function): Don't dump function to gimple dump file.
	* gimplify.c: Add tree-dump.h include.
	(gimplify_function_tree): Dump function to gimple dump file.
	* omp-low.c: Add tree-dump.h include.
	(finalize_task_copyfn): Dump new function to gimple dump file.
	(expand_omp_taskreg, expand_omp_target): Dump new function to dump file.
	* stor-layout.c (finalize_size_functions): Don't dump function to gimple
	dump file.

	* gcc.dg/gomp/dump-task.c: New test.
---
 gcc/cgraphunit.c                      | 15 ++++++++++++++-
 gcc/gimplify.c                        |  3 +++
 gcc/omp-low.c                         |  6 ++++++
 gcc/stor-layout.c                     |  1 -
 gcc/testsuite/gcc.dg/gomp/dump-task.c | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/dump-task.c

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 9b51135..2ff4079 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -491,6 +491,20 @@ cgraph_add_new_function (tree fndecl, bool lowered)
 {
   gcc::pass_manager *passes = g->get_passes ();
   struct cgraph_node *node;
+
+  if (dump_file)
+    {
+      const char *function_type = ((gimple_has_body_p (fndecl))
+				   ? (lowered
+				      ? "low gimple"
+				      : "high gimple")
+				   : "to-be-gimplified");
+      fprintf (dump_file,
+	       "Added new %s function %s to callgraph\n",
+	       function_type,
+	       fndecl_name (fndecl));
+    }
+
   switch (cgraph_state)
     {
       case CGRAPH_STATE_PARSING:
@@ -647,7 +661,6 @@ analyze_function (struct cgraph_node *node)
 	 body.  */
       if (!gimple_has_body_p (decl))
 	gimplify_function_tree (decl);
-      dump_function (TDI_generic, decl);
 
       /* Lower the function.  */
       if (!node->lowered)
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 3241633..065bf2c 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "omp-low.h"
 #include "gimple-low.h"
 #include "cilk.h"
+#include "tree-dump.h"
 
 #include "langhooks-def.h"	/* FIXME: for lhd_set_decl_assembler_name */
 #include "tree-pass.h"		/* FIXME: only for PROP_gimple_any */
@@ -8864,6 +8865,8 @@ gimplify_function_tree (tree fndecl)
   cfun->curr_properties = PROP_gimple_any;
 
   pop_cfun ();
+
+  dump_function (TDI_generic, fndecl);
 }
 
 /* Return a dummy expression of type TYPE in order to keep going after an
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index a2a64ad..0c497e9 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -71,6 +71,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-prop.h"
 #include "tree-nested.h"
 #include "tree-eh.h"
+#include "tree-dump.h"
 
 
 /* Lowering of OpenMP parallel and workshare constructs proceeds in two
@@ -1396,6 +1397,7 @@ finalize_task_copyfn (gimple task_stmt)
   pop_cfun ();
 
   /* Inform the callgraph about the new function.  */
+  dump_function (TDI_generic, child_fn);
   cgraph_add_new_function (child_fn, false);
 }
 
@@ -4843,6 +4845,8 @@ expand_omp_taskreg (struct omp_region *region)
       /* Inform the callgraph about the new function.  */
       DECL_STRUCT_FUNCTION (child_fn)->curr_properties = cfun->curr_properties;
       cgraph_add_new_function (child_fn, true);
+      if (dump_file)
+	dump_function_to_file (child_fn, dump_file, dump_flags);
 
       /* Fix the callgraph edges for child_cfun.  Those for cfun will be
 	 fixed in a following pass.  */
@@ -7963,6 +7967,8 @@ expand_omp_target (struct omp_region *region)
       /* Inform the callgraph about the new function.  */
       DECL_STRUCT_FUNCTION (child_fn)->curr_properties = cfun->curr_properties;
       cgraph_add_new_function (child_fn, true);
+      if (dump_file)
+	dump_function_to_file (child_fn, dump_file, dump_flags);
 
       /* Fix the callgraph edges for child_cfun.  Those for cfun will be
 	 fixed in a following pass.  */
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 8fa4dc8..368541c 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -297,7 +297,6 @@ finalize_size_functions (void)
       set_cfun (NULL);
       dump_function (TDI_original, fndecl);
       gimplify_function_tree (fndecl);
-      dump_function (TDI_generic, fndecl);
       cgraph_finalize_function (fndecl, false);
     }
 
diff --git a/gcc/testsuite/gcc.dg/gomp/dump-task.c b/gcc/testsuite/gcc.dg/gomp/dump-task.c
new file mode 100644
index 0000000..08ae5c3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/dump-task.c
@@ -0,0 +1,33 @@
+/* https://gcc.gnu.org/ml/gcc/2014-03/msg00312.html
+   https://gcc.gnu.org/ml/gcc/2014-05/msg00117.html */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp -fdump-tree-gimple -fdump-tree-ompexp" } */
+
+int
+main(void)
+{
+#pragma omp parallel
+  {
+    extern void foo(void);
+    foo ();
+  }
+  return 0;
+}
+
+
+/* Check that low gimple representation does not end up in high gimple
+   dump.  */
+/* { dg-final { scan-tree-dump-not "main._omp_fn.0" "gimple" } } */
+
+/* Check for 3 references in ompexp dump: new function notification, function
+   dump and reference in main.  */
+/* { dg-final { scan-tree-dump-times "main._omp_fn.0" 3 "ompexp" } } */
+
+/* Check for function dump of main._omp_fn.0.  */
+/* { dg-final { scan-tree-dump-times "main._omp_fn.0 \\(void" 1 "ompexp" } } */
+
+/* Check for presence of function body of main._omp_fn.0.  */
+/* { dg-final { scan-tree-dump-times "foo \\(\\)" 1 "ompexp" } } */
+
+/* { dg-final { cleanup-tree-dump "gimple" } } */
+/* { dg-final { cleanup-tree-dump "ompexp" } } */
-- 
1.9.1


             reply	other threads:[~2014-05-20  8:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20  8:17 Tom de Vries [this message]
     [not found] ` <87k3bnecq3.fsf@schwinge.name>
2015-05-21 15:45   ` Thomas Schwinge
2015-05-22 10:11     ` Richard Biener
2015-06-04 15:14       ` Tom de Vries
2015-06-08  8:14         ` Richard Biener
2015-10-22 12:39         ` Jakub Jelinek
2015-10-22 12:52           ` Tom de Vries
2015-10-22 13:15             ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=537B0F6D.7060808@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jakub@redhat.com \
    --cc=thomas@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).