From: Tristan Gingold <gingold@adacore.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Richard Guenther <rguenther@suse.de>,
GCC Patches <gcc-patches@gcc.gnu.org>,
Eric Botcazou <ebotcazou@adacore.com>, Jan Hubicka <jh@suse.de>
Subject: Re: [Patch/cfgexpand]: also consider assembler_name to call expand_main_function
Date: Wed, 21 Mar 2012 08:40:00 -0000 [thread overview]
Message-ID: <3B64D52C-0DAA-4672-B68E-25EA58862613@adacore.com> (raw)
In-Reply-To: <20120320171757.GD21928@atrey.karlin.mff.cuni.cz>
On Mar 20, 2012, at 6:17 PM, Jan Hubicka wrote:
>> 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?
Only front-end code need to check wether a function is main before they add
it in cgraph. As each front-end should know which function is main, this is
not an issue for them.
>>> +/* 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?
We don't ICE here - as long as graph_main_function_p is called after front-end.
>>> +}
>>> +
>>> /* 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.
USER_LABEL_PREFIX is handled by decl_assembler_name_equal.
One way to simplify that is to change the NESTED argument of cgraph_finalize_function
to LEVEL, which could be either main, top or nested. With this mechanism, every
front-end will explicitly tell to the middle-end which function is the main entry point.
Thoughts ?
Tristan.
whic
prev parent reply other threads:[~2012-03-21 8:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-14 16:04 Tristan Gingold
2012-03-14 16:09 ` Richard Guenther
2012-03-14 16:25 ` Tristan Gingold
2012-03-15 9:38 ` Richard Guenther
2012-03-15 12:51 ` Tristan Gingold
2012-03-20 12:07 ` Tristan Gingold
2012-03-20 12:22 ` Richard Guenther
2012-03-20 14:12 ` Tristan Gingold
2012-03-20 14:20 ` Richard Guenther
2012-03-20 16:00 ` Tristan Gingold
2012-03-20 16:02 ` Richard Guenther
2012-03-20 16:06 ` Tristan Gingold
2012-03-21 7:44 ` Richard Guenther
2012-03-20 17:18 ` Jan Hubicka
2012-03-21 8:40 ` Tristan Gingold [this message]
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=3B64D52C-0DAA-4672-B68E-25EA58862613@adacore.com \
--to=gingold@adacore.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=jh@suse.de \
--cc=rguenther@suse.de \
/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).