From: Michael Matz <matz@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: Random cleanups [2/4]: canonicalize ctor values
Date: Thu, 31 Mar 2011 01:32:00 -0000 [thread overview]
Message-ID: <Pine.LNX.4.64.1103310317210.19760@wotan.suse.de> (raw)
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);
}
}
next reply other threads:[~2011-03-31 1:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-31 1:32 Michael Matz [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.1103310317210.19760@wotan.suse.de \
--to=matz@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).