Sinking memory accesses

Simon Marlow marlowsd at gmail.com
Mon Mar 28 10:44:14 CEST 2011


On 25/03/2011 17:32, Edward Z. Yang wrote:
> We are investigating sinking memory accesses, and Simon Peyton Jones
> stated that CmmSpillReload ought to be sinking everything, and not
> just spilled calls.  Unfortunately, this is not the case:
>
>      middleAvail :: CmmNode O O ->  AvailRegs ->  AvailRegs
>      middleAvail (CmmAssign (CmmLocal r) (CmmLoad l _)) avail
>                     | l `isStackSlotOf` r = extendAvail avail r
>      middleAvail (CmmAssign lhs _)        avail = foldRegsDefd delFromAvail avail lhs
>      middleAvail (CmmStore l (CmmReg (CmmLocal r))) avail
>                     | l `isStackSlotOf` r = avail
>      middleAvail (CmmStore (CmmStackSlot (RegSlot r) _) _) avail = delFromAvail avail r
>      middleAvail (CmmStore {})            avail = avail
>      middleAvail (CmmUnsafeForeignCall {}) _    = AvailRegs emptyRegSet
>      middleAvail (CmmComment {})          avail = avail
>
> In particular we notice that we must be storing values in things that are
> stack slots, so normal memory references are not affected.
>
> Indeed, sinking arbitrary memory accesses would be kind of risky (for example,
> if the memory gets overwritten in the meantime), unless we have some delicate
> invariants established we cannot in general sink willy nilly (probably some of
> these are already valid, since we haven't manifested the stack pointer, but I
> don't see them documented anywhere so I don't know what they are).  Sinking
> the reloads are OK because we only ever spill to a specific region once, but for
> example expressions involving the heap pointer need to be done carefully.
>
>  From here, I can either:
>
>      - Try to generalize the sinking code to work in more cases
>      - Write another pass dedicated to sinking general accesses, and have
>        that run as early as possible.

I suggest writing a general pass, since we'll need it eventually anyway.

Cheers,
	Simon



More information about the Cvs-ghc mailing list