public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Random cleanups [2/4]: canonicalize ctor values
@ 2011-03-31  1:32 Michael Matz
  2011-03-31  8:13 ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Matz @ 2011-03-31  1:32 UTC (permalink / raw)
  To: gcc-patches

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);
     }
 }
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-04-04 22:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-31  1:32 Random cleanups [2/4]: canonicalize ctor values Michael Matz
2011-03-31  8:13 ` Paolo Bonzini
2011-03-31  9:35   ` Richard Guenther
2011-03-31 16:01     ` Michael Matz
2011-03-31 16:04       ` Richard Guenther
2011-04-03 10:14         ` Michael Matz
2011-04-03 10:45           ` Richard Guenther
2011-04-04 22:00           ` H.J. Lu

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).