Thanks for reply.
What I am trying to do is something like counting the times of a particular
function call, i.e., whenever there is a CALL_EXPR in the tree, I want to
look at the id to see if that is the function I want to count during
runtime. If the id is the function name I want to count, I insert a counter
instruction.
It seems that I can mimic the code of dump_generic_node() (which is called
by dump_function() ) to do my instrumentation. However, here I have two
questions:
(1) dump_generic_node() is definietly an overkill to my problem because it
takes care of all the NODE type, even the node I am not interested in, such
as TYPEs, DECLs. Based on what I want to do (described above), is there an
easy and cleaner way than the following pseudo code? i.e, is there a way
that I don't need to go through all the GIMPLE grammar situation (because
this is error-prone)?
pass_function_instrument(){
instrument( &DECL_SAVED_TREE (current_function_decl) );
}
instrument (tree *tp){
switch (TREE_NODE(*tp) ){
case CALL_EXPR:
insert_counter_instruction(tp);
case COND_EXPR:
//COND_EXPR_COND (tp) can't contain stmts any more
instrument (COND_EXPR_THEN (tp));
instrument (COND_EXPR_ELSE (tp));;
case BIND_EXPR:
//BIND_EXPR_VARS (tp) can't contain stmts any more
instrument(BIND_EXPR_BODY (tp) );
case STATEMENT_LIST:
i = tsi_start();
which (!tsi_end_p (i))
{
instrument (tsi_stmt (i));
tsi_next(&i);
}
case: ...
}
}
(2) It seem to me that TREE_LIST and TREE_VEC node is not reachable from
DECL_SAVED_TREE node according to GIMPLE grammar. By I did see case taking
care of them in dump_generic_node().
Can someone explain TREE_LIST and TREE_VEC to me?
Thanks,
Sean
From: Zdenek Dvorak <[EMAIL PROTECTED]>
To: sean yang <[EMAIL PROTECTED]>
CC: gcc@gcc.gnu.org
Subject: Re: traverse the gimple tree
Date: Tue, 11 Apr 2006 13:56:48 +0200
Hello,
> I want to write a pass to walk the gimple tree and add some
intrumentation
> code. I read the chapter 9 of "GCC Internals" document, and it seems not
to
> describe the Macros to do so.
>
> Can I get some information about this? Specifically, if someone can show
me
> which .h file I should look at to find the Macros, that would be great.
Or,
> Is there any other pass do the similar thing(traverse the gimple tree)
that
> I can read (--I did not find)?
depending on what you need, you may use walk_tree and/or combination of
special-handling for structured statements and tsi_ iterators, at that
point. See e.g. pass_lower_cf.
Zdenek
> ------------------------------------------------
> //in gcc.4.0.2, tree-optimize.c
> 323 void
> 324 init_tree_optimization_passes (void)
> 325 {
> 326 struct tree_opt_pass **p;
> 327
> 328 #define NEXT_PASS(PASS) (p = next_pass_1 (p, &PASS))
> 329
> 330 p = &all_passes;
> 331 NEXT_PASS (pass_gimple);
> 332
> 333 NEXT_PASS (MYPASS_code_instrument); //this is what I want to do
> 334 //the reason I want to add the pass here is: both C/C++(any
other
> front end, later) can use this;
> 335 NEXT_PASS (pass_remove_useless_stmts);
> 336 NEXT_PASS (pass_mudflap_1);
> 337 NEXT_PASS (pass_lower_cf);
> 338 NEXT_PASS (pass_lower_eh);
> 339 NEXT_PASS (pass_build_cfg);
> ......
> }
> --------------------------------------------------------
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's
FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
_________________________________________________________________
Dont just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/