This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Allocate all target globals using GC for SWITCHABLE_TARGETs
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, Richard Sandiford <rdsandiford at googlemail dot com>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 10 Jan 2014 00:34:58 +0100
- Subject: Re: [PATCH] Allocate all target globals using GC for SWITCHABLE_TARGETs
- Authentication-results: sourceware.org; auth=none
- References: <DUB122-W8CEA24B3CD3CF0DE08FBAE4F70 at phx dot gbl> <87iotxv211 dot fsf at talisman dot default> <20140107193939 dot GY892 at tucnak dot redhat dot com> <CAFiYyc1CWvKmhf12XRep3AwKGaVxC4QerHsco8kJVkZD7xxa5g at mail dot gmail dot com> <20140108124540 dot GG892 at tucnak dot redhat dot com> <20140108183415 dot GK892 at tucnak dot redhat dot com> <52CECD7B dot 8040707 at redhat dot com> <20140109163539 dot GI892 at tucnak dot redhat dot com> <52CED15B dot 5020401 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Jan 09, 2014 at 08:42:03AM -0800, Richard Henderson wrote:
> On 01/09/2014 08:35 AM, Jakub Jelinek wrote:
> > That would be fine for 1), but would mean 2). It is also fine to GC
> > allocate each structure individually, but some (like bb_reorder) are say
> > just 4 bytes long, so it might be overkill.
>
>
> Hmm.. Perhaps define the whole structure as you do, but somewhere global
> enough that ggc-page.c can see it, and add to the extra_order_size_table?
> I don't know how much memory wastage there would be there, but I can't imagine
> it's as much as 0.5MB.
Here is the solution I was talking about earlier, allocate smaller structs
through GC together and larger separately. Bootstrapped/regtested on
x86_64-linux and i686-linux.
2014-01-09 Jakub Jelinek <jakub@redhat.com>
* target-globals.c (save_target_globals): Allocate < 4KB structs using
GC in payload of target_globals struct instead of allocating them on
the heap and the larger structs separately using GC.
* target-globals.h (struct target_globals): Make regs, hard_regs,
reload, expmed, ira, ira_int and lra_fields GTY((atomic)) instead
of GTY((skip)) and change type to void *.
(reset_target_globals): Cast loads from those fields to corresponding
types.
--- gcc/target-globals.h.jj 2014-01-09 19:24:20.000000000 +0100
+++ gcc/target-globals.h 2014-01-09 19:39:43.879348712 +0100
@@ -41,17 +41,17 @@ extern struct target_lower_subreg *this_
struct GTY(()) target_globals {
struct target_flag_state *GTY((skip)) flag_state;
- struct target_regs *GTY((skip)) regs;
+ void *GTY((atomic)) regs;
struct target_rtl *rtl;
- struct target_hard_regs *GTY((skip)) hard_regs;
- struct target_reload *GTY((skip)) reload;
- struct target_expmed *GTY((skip)) expmed;
+ void *GTY((atomic)) hard_regs;
+ void *GTY((atomic)) reload;
+ void *GTY((atomic)) expmed;
struct target_optabs *GTY((skip)) optabs;
struct target_libfuncs *libfuncs;
struct target_cfgloop *GTY((skip)) cfgloop;
- struct target_ira *GTY((skip)) ira;
- struct target_ira_int *GTY((skip)) ira_int;
- struct target_lra_int *GTY((skip)) lra_int;
+ void *GTY((atomic)) ira;
+ void *GTY((atomic)) ira_int;
+ void *GTY((atomic)) lra_int;
struct target_builtins *GTY((skip)) builtins;
struct target_gcse *GTY((skip)) gcse;
struct target_bb_reorder *GTY((skip)) bb_reorder;
@@ -68,17 +68,17 @@ static inline void
restore_target_globals (struct target_globals *g)
{
this_target_flag_state = g->flag_state;
- this_target_regs = g->regs;
+ this_target_regs = (struct target_regs *) g->regs;
this_target_rtl = g->rtl;
- this_target_hard_regs = g->hard_regs;
- this_target_reload = g->reload;
- this_target_expmed = g->expmed;
+ this_target_hard_regs = (struct target_hard_regs *) g->hard_regs;
+ this_target_reload = (struct target_reload *) g->reload;
+ this_target_expmed = (struct target_expmed *) g->expmed;
this_target_optabs = g->optabs;
this_target_libfuncs = g->libfuncs;
this_target_cfgloop = g->cfgloop;
- this_target_ira = g->ira;
- this_target_ira_int = g->ira_int;
- this_target_lra_int = g->lra_int;
+ this_target_ira = (struct target_ira *) g->ira;
+ this_target_ira_int = (struct target_ira_int *) g->ira_int;
+ this_target_lra_int = (struct target_lra_int *) g->lra_int;
this_target_builtins = g->builtins;
this_target_gcse = g->gcse;
this_target_bb_reorder = g->bb_reorder;
--- gcc/target-globals.c.jj 2014-01-08 17:44:57.551583153 +0100
+++ gcc/target-globals.c 2014-01-09 19:38:21.013760564 +0100
@@ -68,24 +68,44 @@ struct target_globals *
save_target_globals (void)
{
struct target_globals *g;
-
- g = ggc_alloc_target_globals ();
- g->flag_state = XCNEW (struct target_flag_state);
- g->regs = XCNEW (struct target_regs);
+ struct target_globals_extra {
+ struct target_globals g;
+ struct target_flag_state flag_state;
+ struct target_optabs optabs;
+ struct target_cfgloop cfgloop;
+ struct target_builtins builtins;
+ struct target_gcse gcse;
+ struct target_bb_reorder bb_reorder;
+ struct target_lower_subreg lower_subreg;
+ } *p;
+ p = (struct target_globals_extra *)
+ ggc_internal_cleared_alloc_stat (sizeof (struct target_globals_extra)
+ PASS_MEM_STAT);
+ g = (struct target_globals *) p;
+ g->flag_state = &p->flag_state;
+ g->regs = ggc_internal_cleared_alloc_stat (sizeof (struct target_regs)
+ PASS_MEM_STAT);
g->rtl = ggc_alloc_cleared_target_rtl ();
- g->hard_regs = XCNEW (struct target_hard_regs);
- g->reload = XCNEW (struct target_reload);
- g->expmed = XCNEW (struct target_expmed);
- g->optabs = XCNEW (struct target_optabs);
+ g->hard_regs
+ = ggc_internal_cleared_alloc_stat (sizeof (struct target_hard_regs)
+ PASS_MEM_STAT);
+ g->reload = ggc_internal_cleared_alloc_stat (sizeof (struct target_reload)
+ PASS_MEM_STAT);
+ g->expmed = ggc_internal_cleared_alloc_stat (sizeof (struct target_expmed)
+ PASS_MEM_STAT);
+ g->optabs = &p->optabs;
g->libfuncs = ggc_alloc_cleared_target_libfuncs ();
- g->cfgloop = XCNEW (struct target_cfgloop);
- g->ira = XCNEW (struct target_ira);
- g->ira_int = XCNEW (struct target_ira_int);
- g->lra_int = XCNEW (struct target_lra_int);
- g->builtins = XCNEW (struct target_builtins);
- g->gcse = XCNEW (struct target_gcse);
- g->bb_reorder = XCNEW (struct target_bb_reorder);
- g->lower_subreg = XCNEW (struct target_lower_subreg);
+ g->cfgloop = &p->cfgloop;
+ g->ira = ggc_internal_cleared_alloc_stat (sizeof (struct target_ira)
+ PASS_MEM_STAT);
+ g->ira_int = ggc_internal_cleared_alloc_stat (sizeof (struct target_ira_int)
+ PASS_MEM_STAT);
+ g->lra_int = ggc_internal_cleared_alloc_stat (sizeof (struct target_lra_int)
+ PASS_MEM_STAT);
+ g->builtins = &p->builtins;
+ g->gcse = &p->gcse;
+ g->bb_reorder = &p->bb_reorder;
+ g->lower_subreg = &p->lower_subreg;
restore_target_globals (g);
init_reg_sets ();
target_reinit ();
Jakub