I am working on a compiler that uses SSA for a language which contains global variables. I am wondering how i should implement uses and definitions of global variables, for example how should I convert the below code?
Non SSA form:
x;
y;
main () {
x = 0;
foo();
y = x;
x = 2;
foo();
}
foo () {
print x;
x = 1;
}
In SSA form there are some places where I am unsure of the subscripts to use:
main () {
x.0 = 0;
foo()
y.0 = x.?
x.1 = 2;
foo();
}
foo () {
print x.?;
x.? = 1;
}
I have thought about adding in phi-functions but this doesn't seem to solve the problem of what subscripts those phi functions are referring to.
Many thanks, Ben