Inserting instrument calls before and after a function

2010-02-16 Thread Saleel Kudchadker
Hi

I am working on modifying gcc so that I can add custom functions
before the start  and after the end of every function call in gcc.
Much liek __cyg_profile_func_enter and exit but  not when the function
call has already been made.

Is there a easy way to do it? I was concentrating on modifying the
gimplify_function_tree in gimplify.c but that isnt working good for
me. Can somebody put a snippet on how I can go about doing it. Any
help would be appreciated. Thank you.


ps: I am seriously liking this challenging domain of working on gcc.
Thanks to all you guys!

-- 
Regards,

Saleel Kudchadker
Graduate Student
School of Computing , Informatics and Decision Systems
Arizona State University


Segfault inserting a pass

2010-02-17 Thread Saleel Kudchadker
Hi I am working on calling the instrument function before every
function call automatically. I tried inserting this pass which would
add my function to every edge

//

static unsigned int spmm_insert(void){


  struct cgraph_edge *e;
  struct cgraph_node *node = cgraph_node (current_function_decl);

tree x, bind,spmm_type,spmm_decl,ctr_ptr;
x = implicit_built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER];
x = build_call_expr (x, 0);

 for (e = node->callees; e; e = e->next_callee){
bsi_insert_on_edge(e, x);
}


/***/

This throws me a Segfault error when compiling the code. i am applying
this pass before pass_apply_inline in passes.c
I am new to GCC, Can someone hint me documents or materials I can look
upon to insert this pass.


-- 
Regards,

Saleel Kudchadker
Graduate Student
School of Computing , Informatics and Decision Systems
Arizona State University


Adding a statement to statement list before pass_cfg_build

2010-02-19 Thread Saleel Kudchadker
Hi

I've been trying to add a statement before the statement list before
the basic blocks are created. I am planning to add a function call
statement before a user function is called and I use the instrument
function definition as a statement . The code and the pass compiles
properly but  no function is called when the actual program runs.

Can someone hint me where I am going wrong?


static void spmm_init_function(tree *tp)
{
tree func_decl;
tree x,spmm_decl,bind;
  tree_stmt_iterator i = tsi_start (*tp);
  tree_stmt_iterator last_i;
  tree stmt=NULL;
  enum tree_code code;
while (!tsi_end_p (i))
{
  tree prev_stmt;

  prev_stmt = stmt;
  stmt = tsi_stmt (i);
   code = TREE_CODE (stmt);
  switch (code)
  {
case CALL_EXPR:
print_
x = implicit_built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER];
x = build_call_expr (x, 0);
tsi_link_after(&i,x,TSI_NEW_STMT);
break;

default:
break;
}
tsi_next(&i);
}

}

-- 
Regards,

Saleel Kudchadker
Graduate Student
School of Computing , Informatics and Decision Systems
Arizona State University


Re: Adding a statement to statement list before pass_cfg_build

2010-02-19 Thread Saleel Kudchadker
Thank you Richard. I think I will try to add them on the edges once
the basic blocks are created.

On Fri, Feb 19, 2010 at 12:19 PM, Richard Guenther
 wrote:
> On Fri, Feb 19, 2010 at 8:07 PM, Saleel Kudchadker  wrote:
>> Hi
>>
>> I've been trying to add a statement before the statement list before
>> the basic blocks are created. I am planning to add a function call
>> statement before a user function is called and I use the instrument
>> function definition as a statement . The code and the pass compiles
>> properly but  no function is called when the actual program runs.
>>
>> Can someone hint me where I am going wrong?
>
> Before CFG creation we are in gimple and inserting trees to the
> tree stmt list is useless.
>
>>
>> static void spmm_init_function(tree *tp)
>> {
>> tree func_decl;
>> tree x,spmm_decl,bind;
>>  tree_stmt_iterator i = tsi_start (*tp);
>>  tree_stmt_iterator last_i;
>>  tree stmt=NULL;
>>  enum tree_code code;
>>while (!tsi_end_p (i))
>>{
>>  tree prev_stmt;
>>
>>  prev_stmt = stmt;
>>  stmt = tsi_stmt (i);
>>   code = TREE_CODE (stmt);
>>  switch (code)
>>  {
>>case CALL_EXPR:
>>print_
>>x = implicit_built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER];
>>x = build_call_expr (x, 0);
>>    tsi_link_after(&i,x,TSI_NEW_STMT);
>>break;
>>
>>default:
>>    break;
>>}
>>tsi_next(&i);
>> }
>>
>> }
>>
>> --
>> Regards,
>>
>> Saleel Kudchadker
>> Graduate Student
>> School of Computing , Informatics and Decision Systems
>> Arizona State University
>>
>



-- 
Regards,

Saleel Kudchadker
Graduate Teaching Assistant
School of Computing , Informatics and Decision Systems
Arizona State University


Adding function calls before and after a CALL_EXPR

2010-05-05 Thread Saleel Kudchadker
Hi

I am trying to add two function calls before and after a CALL_EXPR
To do this I use bsi_insert_before and bsi_insert_after

But I am having an issue having both of these working in the same pass.
I can make bsi_insert_before or bsi_insert_after work independently.


To make them work together I use
if (fndecl)
{
bsi_insert_before (&block_iterator1, fndecl, BSI_SAME_STMT);
}

if (fndecl2)
{
bsi_insert_after (&block_iterator1, fndecl2, BSI_NEW_STMT);
}

in the basic block iterator loop

Can someone suggest what may be going wrong?



-- 
Regards,

Saleel Kudchadker
Graduate Student
School of Computing , Informatics and Decision Systems
Arizona State University