On Tue, 2013-07-09 at 00:28 -0700, Harie Srinivasa B.R. wrote:
Hi All,
I came across this python based plugin from the dehydra page
and was really excited to learn about this I feel this will be really
powerful and quick way of writing plugins into GCC to do various
things.
Hi - thanks for trying the plugin.
I was trying to play around with GCC python plugin. I noticed
something weird. I just tried to dump gimple I see that I am missing
goto statements,
E.g.
I am created a call back and the callback only proceeds when the pass
is *free_lang_data
There's a chart showing how the passes fit together here:
https://gcc-python-plugin.readthedocs.org/en/latest/tables-of-passes.html
As I understand things, GCC eliminates goto statements when it builds
the CFG, which is the "cfg" pass (tree-cfg.c), which happens near the
beginning (see "The lowering passes"), in fact, only two passes before
the "free_lang_data" pass. [looking through the C code, I *think* the
goto stmts get removed by the call to gsi_remove (&last, true) within
make_goto_expr_edges in tree-cfg.c]
So what I think is happening is that the goto statements have been
removed shortly before your code is being called.
At this stage I get the CFG and in each basic block I try to print
the
Gimple statements in the basic blocks.
I am doing something similar to the following.
def print_gimple_pass_execution_callback(p, fn):
if p.name == '*free_lang_data':
for cgn in gcc.get_callgraph_nodes():
if isinstance(cfn, gcc.Function):
contfg = cfn.cfg
for block in cfg.basic_blocks:
prev = fname + str(block.index) + "$start"
if isinstance(block.gimple, list) and
block.gimple != []:
for gimple in block.gimple:
print gimple
I see gimple statements like
D.1689 = i & 1;
That all looks reasonable, though I think you're missing a line:
cfn = cgn.decl.function
BTW, you don't need to iterate though the callgraph nodes; fn is a
gcc.Function (for gimple passes, at least).
I also see labels but I do not see the goto.
[snip details of your investigation, which appear correct to me]
My program is
#include<stdio.h>
int main()
{
int i=0;
printf("Enter number : ");
scanf("%d",&i);
if(i%2)
goto out;
goto success;
success :
return 0;
out :
return -1;
}
But if I dump the gimple statements with
gcc -fdump-tree-gimple goto.c
I see all the Gimple Goto statements.
That gives you a goto.c.004t.gimple but if you use
-fdump-tree-all
instead, you'll get many more dumpfiles:
oto.c.001t.tu
goto.c.003t.original
goto.c.004t.gimple
goto.c.006t.vcg
goto.c.009t.omplower
goto.c.010t.lower
goto.c.013t.eh
goto.c.014t.cfg
goto.c.018t.ssa
goto.c.019t.veclower
goto.c.020t.inline_param1
goto.c.021t.einline
goto.c.039t.release_ssa
goto.c.040t.inline_param2
goto.c.144t.cplxlower0
goto.c.149t.optimized
goto.c.232t.statistics
and if you look through them you'll see that the goto statements do
indeed get removed as of goto.c.014t.cfg
Given this and the fact that the program does what it is supposed to
be doing I believe I may be using the wrong pass or I may be doing
something wrong inside my plugin. I was hoping someone in this list
can help me with this issue.
As noted above: the pass your callback is attached to is too late in the
pipeline; to see goto statements, you need to run your code before the
"cfg" pass runs.
I am really excited to play around with this tool. I know that the
GimpleGoto is not fully wrapped but I would be able to wrap it once I
can get the Goto statement from GCC.
Excellent; thanks again for trying the plugin.
BTW, why are you interested in the GimpleGoto statement?
Dave