Hi JC,

On Thu, Mar 12, 2009 at 10:58, fearyourself <fearyours...@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
>

Reply via email to