I spent several hours yesterday and today hunting bugs in the IR that
somehow went unnoticed until now. Notably, the constant propagation
algorithm would produce infinite loops over programs containing infinite
loops (I had to reread the IBM paper on the topic to figure out what was
wrong). This is now fixed, and I have improved the implementation a little
bit to deal with more cases.
I have also decided to change the implementation of IIR constants, which
you all seemed puzzled and displeased with. I implemented small primitive
functions that will dynamically cast boxed integers into the desired types
(eg: pint, i32, u16, i16). The constant propagation algorithm is able to
convert those to constants at compile time when the input to the functions
is constant. This deals with negative constant without hacks, without the
need for constant propagation over the AST, and I also took the
opportunity to lighten the syntax.
Before the change: iir.cst special form, essentially serves as a macro to
generate typed constants. May be confusing as it looks like a function
call or an iir instruction, but it is neither.
for (var i = iir.cst(IRType.pint, 0); i < STR_TBL_INIT_SIZE; i +=
iir.cst(IRType.pint, 1))
{
...
}
Now: call the function "pint" to get the pint value of an integer. This
call becomes a pint constant after constant propagation. Similarly, i16,
u16 and i32 are defined for those other types.
for (var i = pint(0); i < STR_TBL_INIT_SIZE; i += pint(1))
{
...
}
- Maxime