Thanks a lot. Here I further have a question, which is about the GIMPLE
grammar. Thanks for the help again:
I looked at walk_stmt(), which is basically how I want to walk through the
function body (&DECL_SAVED_TREE(fn) ).
-----------------------------------------------------------------------------
//in tree-nested.c
walk_stmts (struct walk_stmt_info *wi, tree *tp)
{
tree t = *tp;
switch (TREE_CODE (t))
{
case COND_EXPR:
walk_tree (&COND_EXPR_COND (t), wi->callback, wi, NULL);
walk_stmts (wi, &COND_EXPR_THEN (t));
walk_stmts (wi, &COND_EXPR_ELSE (t));
break;
/* Quetion 1, as grammar for COND_EXPR is
if-stmt : COND_EXPR
op0 -> condition
op1 -> compound-stmt
op2 -> compound-stmt
condition : val
| RELOP
op0 -> val
op1 -> val
For my purpose (only searching possible CALL_EXPR node), can I ignore
&COND_EXPR_COND (t) node? i.e, only do something like
walk_stmts (wi, &COND_EXPR_THEN (t));
walk_stmts (wi, &COND_EXPR_ELSE (t));
In other words, can "condition" tree_node include a CALL_EXPR? It seems that
the GIMPLE grammar does not allow that, i.e., there is no chance for
&COND_EXPR_COND (t) to contain CALL_EXPR as its internal content.
*/
case BIND_EXPR:
walk_stmts (wi, &BIND_EXPR_BODY (t));
break;
/* Quetion 2: as grammar for BIND_EXPR is
block : BIND_EXPR
BIND_EXPR_VARS -> chain of DECLs
BIND_EXPR_BLOCK -> BLOCK
BIND_EXPR_BODY -> compound-stmt
why is it safe for the walking procedure to skip "BIND_EXPR_BLOCK"
component? I think BIND_EXPR_BLOCK part can still contain statements.
*/
..........
-------------------------------------------------------------------------------
From: Daniel Berlin <[EMAIL PROTECTED]>
To: sean yang <[EMAIL PROTECTED]>
CC: gcc@gcc.gnu.org
Subject: Re: adding nodes in a tree --after GIMPLIFICATION, before SSA
Date: Tue, 18 Apr 2006 19:51:07 -0700
On Apr 18, 2006, at 7:28 PM, sean yang wrote:
I will appreciate your help. Thanks in advance.
Let me give a concrete example of what I want to do (Please understand I
have other reasons to do this after gimplification, though the example
shows that there is a much simpler way to achieve this): in the example,
I want to add a call of instrument () after each call of foo()
-----------------------
//input source: example.c
main(){
int i=0;
foo();
i++;
bar();
}
-----------------------------
//conceptual source: with my compiler, the output should look like the
output of the following source code
main(){
int i=0;
foo();
instrument(); //i.e, adding a node of CALL_EXPR (instrument) after
each node CALL_EXPR (foo)
i++;
bar();
}
-----------------------------
(2) after the node the call_node has been built, how can I added to the
proper place? It seems that tsi_link_after () can't do what I want under
this situation because it's only used for STATEMENT_LIST, not other type
of nodes, like CALL_EXPR.
Actually, it would work fine, but it's not the right thing.
use bsi_from_stmt to get a bsi for the thing you are isnerting before/
after, and use bsi_insert_before/bsi_insert_after.
You really should be looking at tree-nested, tree-profile, omp-low, etc.
They all do this sort of thing
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/