Commit 3c2ae514 authored by Simon Marlow's avatar Simon Marlow
Browse files

Document the fact that Areas overlap, and why.

parent ea5da609
......@@ -50,6 +50,7 @@ data CmmExpr
| CmmMachOp MachOp [CmmExpr] -- Machine operation (+, -, *, etc.)
| CmmStackSlot Area {-# UNPACK #-} !Int
-- addressing expression of a stack slot
-- See Note [CmmStackSlot aliasing]
| CmmRegOff !CmmReg Int
-- CmmRegOff reg i
-- ** is shorthand only, meaning **
......@@ -94,6 +95,74 @@ necessarily at the young end of the Old area.
End of note -}
{- Note [CmmStackSlot aliasing]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When do two CmmStackSlots alias?
- T[old+N] aliases with U[young(L)+M] for all T, U, L, N and M
- T[old+N] aliases with U[old+M] only if the areas actually overlap
Or more informally, different Areas may overlap with each other.
An alternative semantics, that we previously had, was that different
Areas do not overlap. The problem that lead to redefining the
semantics of stack areas is described below.
e.g. if we had
x = Sp[old + 8]
y = Sp[old + 16]
Sp[young(L) + 8] = L
Sp[young(L) + 16] = y
Sp[young(L) + 24] = x
call f() returns to L
if areas semantically do not overlap, then we might optimise this to
Sp[young(L) + 8] = L
Sp[young(L) + 16] = Sp[old + 8]
Sp[young(L) + 24] = Sp[old + 16]
call f() returns to L
and now young(L) cannot be allocated at the same place as old, and we
are doomed to use more stack.
- old+8 conflicts with young(L)+8
- old+16 conflicts with young(L)+16 and young(L)+8
so young(L)+8 == old+24 and we get
Sp[-8] = L
Sp[-16] = Sp[8]
Sp[-24] = Sp[0]
Sp -= 24
call f() returns to L
However, if areas are defined to be "possibly overlapping" in the
semantics, then we cannot commute any loads/stores of old with
young(L), and we will be able to re-use both old+8 and old+16 for
young(L).
x = Sp[8]
y = Sp[0]
Sp[8] = L
Sp[0] = y
Sp[-8] = x
Sp = Sp - 8
call f() returns to L
Now, the assignments of y go away,
x = Sp[8]
Sp[8] = L
Sp[-8] = x
Sp = Sp - 8
call f() returns to L
-}
data CmmLit
= CmmInt !Integer Width
-- Interpretation: the 2's complement representation of the value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment