This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Pass manager: add support for termination of pass list
- From: Martin LiÅka <mliska at suse dot cz>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 3 Nov 2015 15:13:59 +0100
- Subject: Re: [PATCH] Pass manager: add support for termination of pass list
- Authentication-results: sourceware.org; auth=none
- References: <56263B07 dot 1010900 at suse dot cz> <CAFiYyc3PozYWSPEJvbBaQNT=UMhJTFS0nh+4AJsfRjjL2E27RA at mail dot gmail dot com> <562758A9 dot 3070309 at suse dot cz> <CAFiYyc0OWMO9ycyfds2rWOmi0j4e9pAhzEwtbKUujnK_xEwOrg at mail dot gmail dot com> <562775F3 dot 1050609 at suse dot cz> <CAFiYyc3gHUH=n7oep2Ynjdqks16rm_LmPXQPf5PNpFB5Go=RCQ at mail dot gmail dot com> <5628C262 dot 8000205 at suse dot cz> <CAFiYyc3GwQu58mmdEdWLGB3+iODREUC-KHBXhAWbz3+_4cJLNQ at mail dot gmail dot com> <562F6FC6 dot 1020200 at suse dot cz> <CAFiYyc2Qh8CjmKCwK8S=K4S33C6gR6AYf86jepzgMLPmZ5r3yA at mail dot gmail dot com> <562F9889 dot 2070704 at suse dot cz> <CAFiYyc1MZsOhgy+s9rmetE5T6w2jLdF0uR6ieuD5eBBjFaDoXg at mail dot gmail dot com> <5631EBA9 dot 2040105 at suse dot cz> <CAFiYyc1=T67BqzaKrE8=g=uf29beTY=xQUQNBBW_P0JAOov=aA at mail dot gmail dot com> <56323219 dot 4060802 at suse dot cz> <CAFiYyc304hRCTumKK=WSQHrYiyr8dAH7+MFUW7Fd-NR-GvpG4w at mail dot gmail dot com> <56335BB5 dot 8090408 at suse dot cz> <CAFiYyc18qFKdvePFHrEJT75pU_T+somDxdwOtp514Dc17OqfBA at mail dot gmail dot com> <56336858 dot 4060905 at suse dot cz> <CAFiYyc1gZoy4ju-jpkLzBaEGcZH0_z559jNnVVz2WGKWciV-YQ at mail dot gmail dot com>
On 11/03/2015 02:46 PM, Richard Biener wrote:
> On Fri, Oct 30, 2015 at 1:53 PM, Martin LiÅka <mliska@suse.cz> wrote:
>> On 10/30/2015 01:13 PM, Richard Biener wrote:
>>> So I suggest to do the push/pop of cfun there.
>>> do_per_function_toporder can be made static btw.
>>>
>>> Richard.
>>
>> Right, I've done that and it works (bootstrap has been currently running),
>> feasible for HSA branch too.
>>
>> tree-pass.h:
>>
>> /* Declare for plugins. */
>> extern void do_per_function_toporder (void (*) (function *, void *), void *);
>>
>> Attaching the patch that I'm going to test.
>
> Err.
>
> + cgraph_node::get (current_function_decl)->release_body ();
> +
> + current_function_decl = NULL;
> + set_cfun (NULL);
>
> I'd have expected
>
> tree fn = cfun->decl;
> pop_cfun ();
> gcc_assert (!cfun);
> cgraph_node::get (fn)->release_body ();
>
> here.
Yeah, that works, but we have to add following hunk:
diff --git a/gcc/function.c b/gcc/function.c
index aaf49a4..4718fe1 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4756,6 +4756,13 @@ push_cfun (struct function *new_cfun)
void
pop_cfun (void)
{
+ if (cfun_stack.is_empty ())
+ {
+ set_cfun (NULL);
+ current_function_decl = NULL_TREE;
+ return;
+ }
+
struct function *new_cfun = cfun_stack.pop ();
/* When in_dummy_function, we do have a cfun but current_function_decl is
NULL. We also allow pushing NULL cfun and subsequently changing
If you are fine with that, looks we've fixed all issues related to the change, right?
Updated version of the is attached.
Martin
>
>> Martin
>>
>From 0921507773eedadca1216a9edca954af240b7a49 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 22 Oct 2015 12:46:16 +0200
Subject: [PATCH] Pass manager: add support for termination of pass list
gcc/ChangeLog:
2015-10-30 Martin Liska <mliska@suse.cz>
* function.c (pop_cfun): Set cfun and current_function_decl to
NULL if the cfun_stack is empty.
* passes.c (do_per_function_toporder): Push to cfun before
calling the pass manager.
(execute_one_pass): Handle TODO_discard_function.
(execute_pass_list_1): Terminate if current function is null.
(execute_pass_list): Do not push and pop function.
* tree-pass.h: Define new TODO_discard_function.
---
gcc/function.c | 7 +++++++
gcc/passes.c | 32 ++++++++++++++++++++++++++++----
gcc/tree-pass.h | 3 +++
4 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/gcc/function.c b/gcc/function.c
index aaf49a4..4718fe1 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4756,6 +4756,13 @@ push_cfun (struct function *new_cfun)
void
pop_cfun (void)
{
+ if (cfun_stack.is_empty ())
+ {
+ set_cfun (NULL);
+ current_function_decl = NULL_TREE;
+ return;
+ }
+
struct function *new_cfun = cfun_stack.pop ();
/* When in_dummy_function, we do have a cfun but current_function_decl is
NULL. We also allow pushing NULL cfun and subsequently changing
diff --git a/gcc/passes.c b/gcc/passes.c
index d9af93a..d764a22 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -1706,7 +1706,12 @@ do_per_function_toporder (void (*callback) (function *, void *data), void *data)
order[i] = NULL;
node->process = 0;
if (node->has_gimple_body_p ())
- callback (DECL_STRUCT_FUNCTION (node->decl), data);
+ {
+ struct function *fn = DECL_STRUCT_FUNCTION (node->decl);
+ push_cfun (fn);
+ callback (fn, data);
+ pop_cfun ();
+ }
}
symtab->remove_cgraph_removal_hook (hook);
}
@@ -2347,6 +2352,23 @@ execute_one_pass (opt_pass *pass)
current_pass = NULL;
+ if (todo_after & TODO_discard_function)
+ {
+ gcc_assert (cfun);
+ /* As cgraph_node::release_body expects release dominators info,
+ we have to release it. */
+ if (dom_info_available_p (CDI_DOMINATORS))
+ free_dominance_info (CDI_DOMINATORS);
+
+ if (dom_info_available_p (CDI_POST_DOMINATORS))
+ free_dominance_info (CDI_POST_DOMINATORS);
+
+ tree fn = cfun->decl;
+ pop_cfun ();
+ gcc_assert (!cfun);
+ cgraph_node::get (fn)->release_body ();
+ }
+
/* Signal this is a suitable GC collection point. */
if (!((todo_after | pass->todo_flags_finish) & TODO_do_not_ggc_collect))
ggc_collect ();
@@ -2361,6 +2383,9 @@ execute_pass_list_1 (opt_pass *pass)
{
gcc_assert (pass->type == GIMPLE_PASS
|| pass->type == RTL_PASS);
+
+ if (cfun == NULL)
+ return;
if (execute_one_pass (pass) && pass->sub)
execute_pass_list_1 (pass->sub);
@@ -2372,14 +2397,13 @@ execute_pass_list_1 (opt_pass *pass)
void
execute_pass_list (function *fn, opt_pass *pass)
{
- push_cfun (fn);
+ gcc_assert (fn == cfun);
execute_pass_list_1 (pass);
- if (fn->cfg)
+ if (cfun && fn->cfg)
{
free_dominance_info (CDI_DOMINATORS);
free_dominance_info (CDI_POST_DOMINATORS);
}
- pop_cfun ();
}
/* Write out all LTO data. */
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index c03e3d8..713f068 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -300,6 +300,9 @@ protected:
/* Rebuild the callgraph edges. */
#define TODO_rebuild_cgraph_edges (1 << 22)
+/* Release function body and stop pass manager. */
+#define TODO_discard_function (1 << 23)
+
/* Internally used in execute_function_todo(). */
#define TODO_update_ssa_any \
(TODO_update_ssa \
--
2.6.2