From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5837 invoked by alias); 20 Mar 2012 17:18:16 -0000 Received: (qmail 5818 invoked by uid 22791); 20 Mar 2012 17:18:11 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,TW_DJ,TW_GP,TW_JG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from atrey.karlin.mff.cuni.cz (HELO atrey.karlin.mff.cuni.cz) (195.113.26.193) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Mar 2012 17:17:58 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 4018) id 87BB8F05B3; Tue, 20 Mar 2012 18:17:57 +0100 (CET) Date: Tue, 20 Mar 2012 17:18:00 -0000 From: Jan Hubicka To: Richard Guenther Cc: Tristan Gingold , GCC Patches , Eric Botcazou , Jan Hubicka Subject: Re: [Patch/cfgexpand]: also consider assembler_name to call expand_main_function Message-ID: <20120320171757.GD21928@atrey.karlin.mff.cuni.cz> References: <875C6F56-7161-48DF-91FB-3A01891F8289@adacore.com> <6BCCAF3B-005E-449E-917C-4B88B78F1946@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) 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: 2012-03/txt/msg01370.txt.bz2 > On Tue, 20 Mar 2012, Tristan Gingold wrote: > > > > > On Mar 15, 2012, at 10:37 AM, Richard Guenther wrote: > > > > > On Wed, 14 Mar 2012, Tristan Gingold wrote: > > [?] > > > > > > > > Well. To make this work in LTO the "main" function (thus, the program > > > entry point) should be marked at cgraph level and all users of > > > MAIN_NAME_P should instead check a flag on the cgraph node. > > > > > >> Will write a predicate in tree.[ch]. > > > > > > Please instead transition "main-ness" to the graph. Yep, I also agree that it is something cgraph code should care about instead of random placess across the whole middle-end. > > diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c > > index bd21169..7a7a774 100644 > > --- a/gcc/cfgexpand.c > > +++ b/gcc/cfgexpand.c > > @@ -4513,9 +4513,8 @@ gimple_expand_cfg (void) > > > > /* If this function is `main', emit a call to `__main' > > to run global initializers, etc. */ > > - if (DECL_NAME (current_function_decl) > > - && MAIN_NAME_P (DECL_NAME (current_function_decl)) > > - && DECL_FILE_SCOPE_P (current_function_decl)) > > + if (DECL_FILE_SCOPE_P (current_function_decl) > > + && cgraph_main_function_p (cgraph_get_node (current_function_decl))) > > expand_main_function (); > > The DECL_FILE_SCOPE_P check is redundant, please remove them everywhere > you call cgraph_main_function_p. I suppose returning false if the > cgraph node is NULL in cgraph_main_function_p would be good. How do we handle the cases before cgraph is built with this approach? > > +/* Return true iff NODE is the main function (main in C). */ > > +static inline bool > > +cgraph_main_function_p (struct cgraph_node *node) > > +{ > > + return node->local.main_function; > > node && node->local.main_function Well, cgraph strategy is ito ICE when NODE is NULL :) We could have cgraph_main_function_decl_p wrapper that does the NULL handling, but I still don't see how this helps - i.e. when you don't have cgraph node you don't have info whether function is main or not, so you should not even try to ask. In what cases we ICE here? > > > +} > > + > > /* Walk all functions with body defined. */ > > #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \ > > for ((node) = cgraph_first_function_with_gimple_body (); (node); \ > > diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c > > index 516f187..4a59f63 100644 > > --- a/gcc/cgraphunit.c > > +++ b/gcc/cgraphunit.c > > @@ -346,6 +346,10 @@ cgraph_finalize_function (tree decl, bool nested) > > notice_global_symbol (decl); > > node->local.finalized = true; > > node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL; > > + node->local.main_function = > > + DECL_FILE_SCOPE_P (decl) > > + && ((!DECL_ASSEMBLER_NAME_SET_P (decl) && MAIN_NAME_P (DECL_NAME (decl))) > > + || decl_assembler_name_equal (decl, main_identifier_node)); > > If we finalize a function we should always create an assembler name, > thus I'd change the above to > > node->local.main_function = decl_assembler_name_equal (decl, > main_identifier_node); > > btw, decl_assembler_name_equal doesn't seem to remove target-specific > mangling - do some OSes "mangle" main differently (I'm thinking of > leading underscores or complete renames)? Thus, I guess the > targets might want to be able to provide the main_identifier_assember_name > you use here. Yes, name function is mangled, i.e. it is _main on djgpp as long as I remember. This is why we have the main_identifier_node to go through the mandling procedure. Honza