local refs
Matthew Fluet
Matthew Fluet <fluet@CS.Cornell.EDU>
Wed, 5 Dec 2001 21:09:27 -0500 (EST)
> I believe looking for any Thread_ primitive is a bit much, and all you
> need to look for is Thread_switchTo or Thread_switchToCont. If those
> are not present, then there isn't any control-flow that's not in the
> graph. Since there is no longer anything special about
> Thread_switchToCont, I propose to eliminate it, replacing it with
> Thread_switchTo, and to make both (1) and (2) above only look for
> Thread_switchTo.
I think I agree with this.
> On a related point, I believe that local-ref can be improved. At
> present it does two different things:
>
> 1. Move globals refs into functions that only execute once
> 2. Turns local refs into SSA vars
>
> Of course (1) only makes sense if the once computation is correct.
Actually, it only moves localizable global refs into functions that only
execute once.
> But (2) seems like it's OK to do no matter what. So, I guess I'm
> saying that local-ref shouldn't turn off all optimization when it
> determines that a program has threads/conts. It should just turn off
> (1). Does that make sense?
No, unless you're reading a lot more into (2) than I am. What makes a ref
non-localizable is that it escapes. The current model, in a single
threaded world, of "escape" is a ref that is used in any tuple/constructor
construction, control transfer, or primitive that is not a Ref_deref or
Ref_assign. In a multi-threaded world, a ref can also "escape" to the
stack when it is copied, at a Thread_copy. Take a look at callcc3.sml.
The reference rr_0 looks like it is localizable, but it is live accross
the call to Thread_copyShrink. If you try to localize it, then the
program doesn't terminate. So, if you really wanted to do (2) in a
context where Thread primitives existed, you need to do liveness analysis
of the potentially localizable refs, and forbid localization of any live
across a block with a thread copy. (Note, this probably wouldn't be too
bad; there are generally only a few localizable refs, so doing the
propagation isn't too bad.)