From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28584 invoked by alias); 31 Mar 2011 01:22:45 -0000 Received: (qmail 28576 invoked by uid 22791); 31 Mar 2011 01:22:44 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,TW_JC,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 Mar 2011 01:22:39 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 28F6B8E8CC for ; Thu, 31 Mar 2011 03:22:38 +0200 (CEST) Date: Thu, 31 Mar 2011 01:32:00 -0000 From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: Random cleanups [2/4]: canonicalize ctor values Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg02134.txt.bz2 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); } }