This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Adding a function call at the beginning


Thanks, after testing, I found that this performs what I need:

    /* Insert at the beginning */
    edge e = find_edge (ENTRY_BLOCK_PTR, ENTRY_BLOCK_PTR->next_bb);
    basic_block newstart = split_edge(e);
    i = bsi_last(newstart);

    tree call = create_function_call(profile_begin, funcname);
    bsi_insert_before(&i, call, BSI_NEW_STMT);

With my basic testing, this does seem to tell GCC to do what I want,

Thank you for your help,
Jc


On Thu, Mar 12, 2009 at 12:38 PM, Sebastian Pop <sebpop@gmail.com> wrote:
> Hi JC,
>
> On Thu, Mar 12, 2009 at 10:58, fearyourself <fearyourself@gmail.com> wrote:
>> Dear all,
>>
>> I've been trying to add a pass that adds a function call at the
>> beginning of each function. However, my first solution was to simply
>> do something like this:
>>
>> bb = ENTRY_BLOCK_PTR ->next_bb;
>> i = bsi_start (bb);
>> tree call = create_function_call(profile_begin, funcname);
>> bsi_insert_before(&i, call, BSI_SAME_STMT);
>>
>> However, this doesn't work if the function looks like this :
>>
>>
>> void foo(int bar)
>> {
>>    int i;
>>    while(1)
>>    {
>>       printf( "-> %d\n", bar);
>>     }
>> }
>>
>> My call gets inserted into the loop and not before the loop which
>> isn't what I'm looking for.
>>
>> I then tried to do something like :
>>    basic_block tmp = create_empty_bb (ENTRY_BLOCK_PTR);
>>    tree call = create_function_call(profile_begin, funcname);
>>    i = bsi_last(tmp);
>>    bsi_insert_before(&i, call, BSI_NEW_STMT);
>>
>
> You can use split_edge or split_block_after_labels.  That will give
> you an empty BB where you can insert the call.
>
> Sebastian
>
>> But this doesn't work either. Any ideas to insert a function call at
>> the beginning of a function even in the case of a loop ?
>> Thanks,
>> Jc
>>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]