2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[CgUpdate]{Manipulating update frames}
7 module CgUpdate ( pushUpdateFrame, reserveSeqFrame, pushSeqFrame ) where
9 #include "HsVersions.h"
14 import PrimRep ( PrimRep(..) )
15 import CgStackery ( allocStackTop, updateFrameSize, seqFrameSize )
16 import CgUsages ( getVirtSp, getSpRelOffset )
17 import CmdLineOpts ( opt_SccProfilingOn )
18 import Panic ( assertPanic )
22 %********************************************************
24 %* Setting up update frames *
26 %********************************************************
27 \subsection[setting-update-frames]{Setting up update frames}
29 @pushUpdateFrame@ $updatee$ pushes a general update frame which
30 points to $updatee$ as the thing to be updated. It is only used
31 when a thunk has just been entered, so the (real) stack pointers
32 are guaranteed to be nicely aligned with the top of stack.
33 @pushUpdateFrame@ adjusts the virtual and tail stack pointers
34 to reflect the frame pushed.
37 pushUpdateFrame :: CAddrMode -> Code -> Code
39 pushUpdateFrame updatee code
42 getEndOfBlockInfo `thenFC` \ eob_info ->
43 ASSERT(case eob_info of { EndOfBlockInfo _ (OnStack _) -> True;
47 allocStackTop updateFrameSize `thenFC` \ _ ->
48 getVirtSp `thenFC` \ vsp ->
50 setEndOfBlockInfo (EndOfBlockInfo vsp UpdateCode) (
52 -- Emit the push macro
53 absC (CMacroStmt PUSH_UPD_FRAME [
55 int_CLit0 -- we just entered a closure, so must be zero
60 int_CLit0 = mkIntCLit 0 -- out here to avoid pushUpdateFrame CAF (sigh)
63 We push a SEQ frame just before evaluating the scrutinee of a case, if
64 the scrutinee has a polymorphic or function type. The SEQ frame acts
65 as a barrier in case the scrutinee evaluates to a partial application.
67 reserveSeqFrame takes the EndOfBlockInfo for the case expression and
68 updates the sequel to a SeqFrame, reserving room for the frame at
69 args_sp. When the scrutinee comes around to pushing a return address,
70 it will also push the SEQ frame, using pushSeqFrame.
73 reserveSeqFrame :: EndOfBlockInfo -> EndOfBlockInfo
74 reserveSeqFrame (EndOfBlockInfo args_sp (CaseAlts amode stuff))
75 = EndOfBlockInfo (args_sp + seqFrameSize) (SeqFrame amode stuff)
77 pushSeqFrame :: VirtualSpOffset -> FCode VirtualSpOffset
79 = getSpRelOffset args_sp `thenFC` \ sp_rel ->
80 absC (CMacroStmt PUSH_SEQ_FRAME [CAddr sp_rel]) `thenC`
81 returnFC (args_sp - seqFrameSize)