[tree-ssa] variables being dragged out of their lexical scopes
Diego Novillo
dnovillo@redhat.com
Thu May 1 14:24:00 GMT 2003
Given this program:
foo ()
{
int i, k;
{
int j;
j = i + 1;
}
k = i + 1;
return i;
}
the conversion into SSA form is currently converting it into:
foo ()
{
int i;
int k;
# BLOCK 0 (a.c:6). PRED: -1. SUCC: -2.
{
int j;
j_2 = i_1 + 1
};
k_3 = j_2;
return i_1;
}
Notice how j_2 is now used outside of its original lexical scope.
Apparently, this is a problem because moving variables outside
their scope affects debuggability (and maybe it has other side
effects? I don't know).
Jason suggested that we could create additional temporaries in
the gimplifier so that we always convert assignments 'VAR = EXPR'
into 'TEMP = EXPR; VAR = TEMP':
foo ()
{
int i;
int k;
int T.1;
# BLOCK 0 (a.c:6). PRED: -1. SUCC: -2.
{
int j;
T.1_5 = i_1 + 1;
j_2 = T.1_5;
};
k_3 = T.1_5;
return i_1;
}
Which works, but as Andrew pointed out, it could later be munged
again by copy-prop into:
foo ()
{
int i;
int k;
int T.1;
# BLOCK 0 (a.c:6). PRED: -1. SUCC: -2.
{
int j;
T.1_5 = i_1 + 1;
j_2 = T.1_5;
};
k_3 = j_2;
return i_1;
}
I see two ways of handling this:
1- Never allow copy propagation in expressions of the form 'VAR = TEMP'
(where 'VAR' is a program variable and 'TEMP' a compiler
temporary). This could work but I'm not sure if it would be a
valid long term approach.
2- While building the flowgraph, emit a group-clobber instruction
for all the variables that were declared inside a lexical
scope. The clobber instruction would be a new GIMPLE
statement of the form CLOBBER_EXPR <var1, var2, ..., varN>.
This would avoid any code movement that tries to take
variables outside of their original scope (and it would also
avoid having to generate all those temporaries in the
gimplifier).
Thoughts?
Diego.
More information about the Gcc
mailing list