limit check insertion

Stephen Weeks MLton@sourcelight.com
Tue, 11 Dec 2001 09:47:50 -0800


> > One other thing to keep in mind is the other hidden arithmetic in the
> > ArrayNoPointers and ArrayPointers macros (and somewhere in the
> > x86codegen).  So in the following
> > 
> > > L_S (n:int)
> > >  size = 2 * (8 + 4 * n) + 12
> > >  L_S1 (GC_limitCheck(size))
> > > L_S1 ()
> > >  a1 = Array_array(int) n
> > >  a2 = Array_array(int) n
> > >  t = (a1,a2)
> > >  t
> > 
> > there are some hidden 4 * n computations in the Array_array calls.
> 
> More than the onese that I pulled out and put into the size calculation?
> An array of n integers should require 8 + 4 * n bytes (length word +
> header word + array elements), right?

Right.  I just wanted to make clear that more than size needed to be
available.  We should make all of the arithmetic for LimitCheck and
Array explicit or none of it.

> Limit checks and machine, though, have this strange chicken/egg
> problem.  We need to know where we might insert limit checks to do
> stack vs. pseudo-reg allocation.  But, it would be nice to have
> coalesced limit checks before doing allocation, to avoid spilling
> variables to stack locations.

Agreed.  What that argues for is an RSSA language with explicit
representations, byte layouts, pointer arithmetic, limit checks, and
frontier munging, but still with function calls.  Then we can make all
representation decisions and insert (and coalesce) limit checks, and
at a later pass implement calling conventions and pseudo-reg
allocation.

It's difficult to know if we should merge RSSA with SSA so that we can
reuse stuff like common subexpression elimination and loop invariant
code motion.  I would argue for going with a new language to start so
that we don't feel constrained from making changes by all the existing
SSA code.

The SSA -> RSSA pass will also be a nice place to put
ImplementHandlers.  That way, we can take all the exnStack stuff out
of SSA.

I am willing to punt on making RSSA type safe for now if it helps us
get off the ground faster.  Since machine is already not type safe,
it's really not any worse than we are now.  But, I would like to at
least be able to check correctness of exnStacks (as we do now in SSA)
and limit checks.