On Wed, Apr 18, 2012 at 10:35 AM, Steven Bosscher <[email protected]> wrote:
> Hello,
>
> If I move GIMPLE_SWITCH lowering from stmt.c to somewhere in the
> GIMPLE pass pipeline, I run into an issue with SJLJ exceptions. The
> problem is that except.c:sjlj_emit_dispatch_table() builts a
> GIMPLE_SWITCH and calls expand_case on it. If I move all non-casesi,
> non-tablejump code out of stmt.c and make it a GIMPLE lowering pass
> (currently I have the code in tree-switch-conversion.c) then two
> things happen:
>
> 1. SJLJ exception dispatch tables can only be expanded as casesi or
> tablejump. This may not be optimal.
AFAIK SJLJ dispatch tables are dense, the switch is for the exeptional
case (heh - the case where SJLJ exceptions are supposed to be fast ...),
and most of the case functions have a single EH receiver(?) we already
have an optimized case for.
> 2. If the target asks for SJLJ exceptions but it has no casesi and no
> tablejump insns or expanders, then the compilation will fail.
>
> I don't think (1) is a big problem, because exceptions should be,
> well, exceptions after all so optimizing them shouldn't be terribly
> important. For (2), I had hoped it would be a requirement to have
> either casesi or tablejump, but that doesn't seem to be the case. But
> I could put in some code to expand it as a series of test-and-branch
> insns instead, in case there is only a small number of num_dispatches.
Can't we always expand a "lowered" tablejump, aka computed goto?
> What is the reason why lowering for SJLJ exceptions is not done in GIMPLE?
Because it completely wrecks loops because we factor the SJLJ site,
thus
fn ()
{
...
for (;;)
{
try { X } catch { Y }
}
becomes
fn ()
{
if (setjmp ())
{
switch (...)
... goto L;
}
for (;;)
{
X;
L:
Y;
}
thus loops with try/catch get another entry preventing it from being analyzed
(you see RTL loop optimizers doing nothing on such non-loops).
Of course that's similar to how we handle computed goto.
> Would it be a problem for anyone if SJLJ exception handling will be
> less efficient, if I move GIMPLE_SWITCH lowering earlier in the pass
> pipeline?
I suppose that's the real question.
Richard.
> Ciao!
> Steven