[LLVMdev] Restoring SSA form
Vladimir Prus
ghost at cs.msu.su
Tue Nov 23 07:08:38 PST 2004
Hello,
for some my use case, I'd like to temporary break SSA property and then ask
LLVM to restore it. Here's more details:
if (i < 0) {
i = -i;
}
This is a C code example. I'm trying to create a value range analysis, which
will determine, that after this code, 'i' is non-negative. In SSA form, this
will become
i = 0;
if (i < 0) {
i.2 = -i;
}
i.3 = phi(i, i.2);
I'll assign value ranges to i, i.2, i.3, do some iteration and get necessary
results. Now consider another case:
i = 0;
if (i > 0) {
foo(i);
}
Here's 'foo' is always called with positive value. However, the value range
assigned to 'i' variable can be only [-inf, +inf], because uses of 'i'
outside of condition can get any value. So, I'd like to convert the above to:
i = 0;
if (i > 0) {
i = change_value_range(i);
foo(i);
}
where 'change_value_range' is some artificial instruction. After that, I'd ask
LLVM to restore SSA property, giving:
i = 0;
if (i > 0) {
i.2 = change_value_range(i);
foo(i.2);
}
i.3 = phi(i, i.2)
And then will do my analysis as usual. This is a long-winded background, and
the question is: how to I "restore SSA property"? Sure, both dominance
frontier and dominator tree are available, so I can just try to impelement
the SSA constructon algorithm by hand, but is there a smarter way? The
Mem2Reg pass is too specialised to work here.
Thanks in advance,
Volodya
More information about the llvm-dev
mailing list