[PATCH][RFC] Share variable annotations for globals across functions
Richard Guenther
rguenther@suse.de
Thu May 22 19:50:00 GMT 2008
This removes the per-function variable annotation code we use for
global variables. A scheme like this is only needed if we have aliasing
computed for multiple functions at a time. For which we better find
a different solution. For PR36291 we have tons of referenced global
vars (the usual chaining of global data problem) and tons of functions.
This results in
tree-dfa.c:153 (create_var_ann) 482008296:30.4% 0: 0.0% 0: 0.0% 43818936:30.6% 5477367
and a peak memory usage of about 2GB on x86_64 (without checking but with
mem-stats enabled). If we share the variable annotations of globals
this goes down to
tree-dfa.c:150 (create_var_ann) 206016: 0.0% 15094400: 3.2% 142592: 0.1% 0: 0.0% 241297
and a peak memory usage of about 1GB.
Bootstrapped and tested on x86_64-unknown-linux-gnu for C and C++
(I expect I can remove the tree-ssa-alias.c hunk), full testing will
follow.
Diego, I suppose tuples doesn't change the above picture, so is the
general idea ok?
Thanks,
Richard.
2008-05-22 Richard Guenther <rguenther@suse.de>
PR tree-optimization/36291
* tree-flow-inline.h (var_ann): Simplify.
* tree-ssa-alias.c (compute_may_aliases): Clear alias info
from var_anns of globals.
* tree-dfa.c (create_var_ann): Simplify.
(remove_referenced_var): Clear alias info from var_anns of globals.
* tree-ssa.c (delete_tree_ssa): Likewise.
Index: tree-flow-inline.h
===================================================================
*** tree-flow-inline.h (revision 135753)
--- tree-flow-inline.h (working copy)
*************** var_ann (const_tree t)
*** 192,213 ****
{
var_ann_t ann;
! if (!MTAG_P (t)
! && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
! {
! struct static_var_ann_d *sann
! = ((struct static_var_ann_d *)
! htab_find_with_hash (gimple_var_anns (cfun), t, DECL_UID (t)));
! if (!sann)
! return NULL;
! ann = &sann->ann;
! }
! else
! {
! if (!t->base.ann)
! return NULL;
! ann = (var_ann_t) t->base.ann;
! }
gcc_assert (ann->common.type == VAR_ANN);
--- 192,200 ----
{
var_ann_t ann;
! if (!t->base.ann)
! return NULL;
! ann = (var_ann_t) t->base.ann;
gcc_assert (ann->common.type == VAR_ANN);
Index: tree-ssa-alias.c
===================================================================
*** tree-ssa-alias.c (revision 135753)
--- tree-ssa-alias.c (working copy)
*************** compute_may_aliases (void)
*** 1705,1710 ****
--- 1705,1726 ----
memset (&alias_stats, 0, sizeof (alias_stats));
+ /* Clear var anns of globals. */
+ if (!gimple_aliases_computed_p (cfun))
+ {
+ referenced_var_iterator rvi;
+ tree var;
+
+ FOR_EACH_REFERENCED_VAR (var, rvi)
+ if (!MTAG_P (var)
+ && (TREE_STATIC (var) || DECL_EXTERNAL (var)))
+ {
+ var_ann_t v_ann = var_ann (var);
+ v_ann->mpt = NULL_TREE;
+ v_ann->symbol_mem_tag = NULL_TREE;
+ }
+ }
+
/* Initialize aliasing information. */
ai = init_alias_info ();
Index: tree-dfa.c
===================================================================
--- tree-dfa.c (revision 135713)
+++ tree-dfa.c (working copy)
@@ -142,33 +142,14 @@ var_ann_t
create_var_ann (tree t)
{
var_ann_t ann;
- struct static_var_ann_d *sann = NULL;
gcc_assert (t);
gcc_assert (DECL_P (t));
gcc_assert (!t->base.ann || t->base.ann->common.type == VAR_ANN);
- if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
- {
- sann = GGC_CNEW (struct static_var_ann_d);
- ann = &sann->ann;
- }
- else
- ann = GGC_CNEW (struct var_ann_d);
-
+ ann = GGC_CNEW (struct var_ann_d);
ann->common.type = VAR_ANN;
-
- if (!MTAG_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
- {
- void **slot;
- sann->uid = DECL_UID (t);
- slot = htab_find_slot_with_hash (gimple_var_anns (cfun),
- t, DECL_UID (t), INSERT);
- gcc_assert (!*slot);
- *slot = sann;
- }
- else
- t->base.ann = (tree_ann_t) ann;
+ t->base.ann = (tree_ann_t) ann;
return ann;
}
@@ -765,8 +746,20 @@ remove_referenced_var (tree var)
clear_call_clobbered (var);
if ((v_ann = var_ann (var)))
- ggc_free (v_ann);
- var->base.ann = NULL;
+ {
+ /* Preserve var_anns of globals, but clear their alias info. */
+ if (MTAG_P (var)
+ || (!TREE_STATIC (var) && !DECL_EXTERNAL (var)))
+ {
+ ggc_free (v_ann);
+ var->base.ann = NULL;
+ }
+ else
+ {
+ v_ann->mpt = NULL_TREE;
+ v_ann->symbol_mem_tag = NULL_TREE;
+ }
+ }
gcc_assert (DECL_P (var));
in.uid = uid;
loc = htab_find_slot_with_hash (gimple_referenced_vars (cfun), &in, uid,
Index: tree-ssa.c
===================================================================
*** tree-ssa.c (revision 135753)
--- tree-ssa.c (working copy)
*************** delete_tree_ssa (void)
*** 998,1006 ****
set_phi_nodes (bb, NULL);
}
! /* Remove annotations from every referenced variable. */
FOR_EACH_REFERENCED_VAR (var, rvi)
{
if (var->base.ann)
ggc_free (var->base.ann);
var->base.ann = NULL;
--- 998,1013 ----
set_phi_nodes (bb, NULL);
}
! /* Remove annotations from every referenced local variable. */
FOR_EACH_REFERENCED_VAR (var, rvi)
{
+ if (!MTAG_P (var)
+ && (TREE_STATIC (var) || DECL_EXTERNAL (var)))
+ {
+ var_ann (var)->mpt = NULL_TREE;
+ var_ann (var)->symbol_mem_tag = NULL_TREE;
+ continue;
+ }
if (var->base.ann)
ggc_free (var->base.ann);
var->base.ann = NULL;
More information about the Gcc-patches
mailing list