Quoth [EMAIL PROTECTED]:
> Dan Sugalski <[EMAIL PROTECTED]> wrote:
> 
> > Exceptions and continuations should be the same problem -- the target
> > is the start of a basic block. (Well, more than that, as they're
> > places where calling conventions potentially kick in) This means the
> > instruction immediately after a sub call starts a new block, as does
> > the start of an exception handler.
> 
> Dan, I've already said that there is of course a new basic block. The
> problem arises by the silent generation of loops in the CFG. Within a
> loop the same register can't be reallocated to a different variable.
> There are two possible solutions (AFAIK):
> 
> 1) statically mark the branch target of the loop. Proposed syntax
> constructs:
> 
> 1a) for exceptions:
> 
>      set_eh handler, catch_label
> 
>   This is just a small adaption of the sequence of installing an
>   exception handler.
>   It depends a bit, if exception handlers are inline or nested
>   closures or both.
> 
> 1b) generally
> 
>      RESUMABLE: func_that_might_loop_through_cc()
> 
>   possibly accompanied with another markup of the function call that
>   loops back.

That can't work, because *any* function might loop back, unless you want
to analyse the entire logic flow of the called function, find and
compile all functions it calls, recursively, and see if any of them get
to put the return continuation somewhere where someone else may invoke
it. Even that can't work in the case of methods, 'cos which piece of
code gets called isn;t known until runtime.

> 2) Fetch all from lexicals/globals after a function call.

Can you not make that re-fetch conditional on being invoked from a full
(as opposed to a return) continuation, so it will only happen if
someone's messing about with continuations? You can also avoid
rrefetching if the allocator happens not to have reused that register
elsewhere in the function, which is known at compile time. 

I agree (I think[1]) with you that the allocator should not try to keep
registers unique if that means spilling (this is pessimizing the common
case for the uncommon), but if possible it would be good for it to avoid
reusing registers if this *doesn't* require spilling. Also, for places
where people know they are going to be using continuations a lot such as
the p6 regex engine, it might make sense to have a pragma to get the
allocator to allocate all registers uniquely and damn the spilling...
but this is almost certainly premature optimization :).

Ben

[1] The 'I think' is about whether or not Leo actually thinks this, not
about whether or not I do... :)

-- 
           All persons, living or dead, are entirely coincidental.
[EMAIL PROTECTED]                                                  Kurt Vonnegut

Reply via email to