This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Random cleanups [2/4]: canonicalize ctor values
- From: Michael Matz <matz at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 31 Mar 2011 03:22:37 +0200 (CEST)
- Subject: Random cleanups [2/4]: canonicalize ctor values
Hi,
this came up when looking into why the static ctors contain useless trees
(like casts). We can simply canonicalize them while varpool analyzes
pending decls. It'll look at initialzers once, where we can "gimplify"
them. This requires making canonicalize_constructor_val be able to be
called outside of functions. And it requires the java frontend not
leaving a dangling function decl as current (for the static ctor function
it generates).
Regstrapped on x86_64-linux with the other three cleanups. Okay for
trunk?
Ciao,
Michael.
--
* cgraphbuild.c (record_reference): Canonicalize constructor
values.
* gimple-fold.c (canonicalize_constructor_val): Accept being called
without function context.
java/
* jcf-parse.c (java_emit_static_constructor): Clear cfun and
current_function_decl.
Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c (revision 171537)
+++ cgraphbuild.c (working copy)
@@ -53,6 +53,8 @@ record_reference (tree *tp, int *walk_su
tree decl;
struct record_reference_ctx *ctx = (struct record_reference_ctx *)data;
+restart:
+
switch (TREE_CODE (t))
{
case VAR_DECL:
@@ -98,6 +100,15 @@ record_reference (tree *tp, int *walk_su
break;
}
+ t = canonicalize_constructor_val (t);
+ if (t && t != *tp)
+ {
+ *tp = t;
+ goto restart;
+ }
+ else
+ t = *tp;
+
if ((unsigned int) TREE_CODE (t) >= LAST_AND_UNUSED_TREE_CODE)
return lang_hooks.callgraph.analyze_expr (tp, walk_subtrees);
break;
Index: gimple-fold.c
===================================================================
--- gimple-fold.c (revision 171537)
+++ gimple-fold.c (working copy)
@@ -106,7 +106,7 @@ can_refer_decl_in_current_unit_p (tree d
return true;
}
-/* CVAL is value taken from DECL_INITIAL of variable. Try to transorm it into
+/* CVAL is value taken from DECL_INITIAL of variable. Try to transform it into
acceptable form for is_gimple_min_invariant. */
tree
@@ -131,7 +131,7 @@ canonicalize_constructor_val (tree cval)
|| TREE_CODE (base) == FUNCTION_DECL)
&& !can_refer_decl_in_current_unit_p (base))
return NULL_TREE;
- if (base && TREE_CODE (base) == VAR_DECL)
+ if (cfun && base && TREE_CODE (base) == VAR_DECL)
add_referenced_var (base);
/* We never have the chance to fixup types in global initializers
during gimplification. Do so here. */
Index: java/jcf-parse.c
===================================================================
--- java/jcf-parse.c.orig 2011-03-26 02:19:03.000000000 +0100
+++ java/jcf-parse.c 2011-03-28 06:16:43.000000000 +0200
@@ -1725,6 +1725,8 @@ java_emit_static_constructor (void)
DECL_STATIC_CONSTRUCTOR (decl) = 1;
java_genericize (decl);
cgraph_finalize_function (decl, false);
+ current_function_decl = NULL;
+ set_cfun (NULL);
}
}