[Mono-devel-list] SSA and try/catch/finally regions

Massimiliano Mantione massi at ximian.com
Mon Apr 4 10:29:59 EDT 2005

On Mon, 2005-04-04 at 14:28 +0200, Zoltan Varga wrote:
>   A simpler solution would be to mark those variables used in
> catch/finally blocks as volatile.
> This is already done.

Thanks for reminding me this issue (I really forgot it!).

It is a simpler approach, but it also prevents optimizations on
those variables in the *whole* method.

A different approach would be to flag them as MONO_INST_INDIRECT
instead of MONO_INST_VOLATILE (to still prevent them from being
allocated in registers) and use the OP_DUMMY_STORE trick to mark
the places where they behave as "volatile", like I described.

I think this would still produce correct code, but enable more
optimizations opportunities.
So, my preference would go to the OP_DUMMY_STORE "trick", but
flagging catch/finally vars as MONO_INST_INDIRECT.

By the way, currently it seems to me that this flagging is done
in "mono_analyze_liveness", but what if we had some optimization
pass that runs *before* liveness has been computed but needs to
take this issue into account?

I know we have not this problem now, but the scenario is possible.
Suppose we go to semi-pruned SSA (which does not require liveness)
and also enable SSA in the presence of try/catch/finally clauses,
relying on the MONO_INST_VOLATILE flag to mark variables used in
catch/finally regions.
The flag will not be set, so the optimizations relying on it to
produce correct code would not work.

So, if we choose the MONO_INST_VOLATILE way, wouldn't it be better
to perform the flagging in a pass that we are *sure* will happen
before all the optimizations that need it?
Now we do one full code scan (handle_exception_clauses) just for
this purpose, but we do it inside mono_analyze_liveness...


More information about the Mono-devel-list mailing list