%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
-% $Id: CgHeapery.lhs,v 1.18 1999/06/24 13:04:19 simonmar Exp $
+% $Id: CgHeapery.lhs,v 1.20 2000/01/13 14:33:58 hwloidl Exp $
%
\section[CgHeapery]{Heap management functions}
)
import PrimRep ( PrimRep(..), isFollowableRep )
import Unique ( Unique )
-import CmdLineOpts ( opt_SccProfilingOn )
+import CmdLineOpts ( opt_SccProfilingOn, opt_GranMacros )
import GlaExts
import Outputable
let stk_words = spHw - sp in
initHeapUsage (\ hp_words ->
+ getTickyCtrLabel `thenFC` \ ticky_ctr ->
+
( if all_pointers then -- heap checks are quite easy
+ -- HWL: gran-yield immediately before heap check proper
+ --(if node `elem` regs
+ -- then yield regs True
+ -- else absC AbsCNop ) `thenC`
absC (checking_code stk_words hp_words tag_assts
- free_reg (length regs))
+ free_reg (length regs) ticky_ctr)
else -- they are complicated
absC (checking_code real_stk_words hp_words
(mkAbstractCs [tag_assts, stk_assts, more_tag_assts,
adjust_sp])
- (CReg node) 0)
+ (CReg node) 0 ticky_ctr)
) `thenC`
where
- checking_code stk hp assts ret regs
- | node_points = do_checks_np stk hp assts (regs+1) -- ret not required
- | otherwise = do_checks stk hp assts ret regs
+ checking_code stk hp assts ret regs ctr
+ = mkAbstractCs
+ [ real_check,
+ if hp == 0 then AbsCNop
+ else profCtrAbsC SLIT("TICK_ALLOC_HEAP")
+ [ mkIntCLit hp, CLbl ctr DataPtrRep ]
+ ]
+
+ where real_check
+ | node_points = do_checks_np stk hp assts (regs+1)
+ | otherwise = do_checks stk hp assts ret regs
-- When node points to the closure for the function:
initHeapUsage (\ hHw -> do_heap_chk hHw tag_assts `thenC` code)
where
do_heap_chk words_required tag_assts
- = absC (if words_required == 0
- then AbsCNop
- else checking_code tag_assts) `thenC`
+ = getTickyCtrLabel `thenFC` \ ctr ->
+ absC ( if words_required == 0
+ then AbsCNop
+ else mkAbstractCs
+ [ checking_code tag_assts,
+ profCtrAbsC SLIT("TICK_ALLOC_HEAP")
+ [ mkIntCLit words_required, CLbl ctr DataPtrRep ]
+ ]
+ ) `thenC`
setRealHp words_required
where
altHeapCheck is_fun regs [] AbsCNop Nothing code
= initHeapUsage (\ hHw -> do_heap_chk hHw `thenC` code)
+
where
do_heap_chk :: HeapOffset -> Code
do_heap_chk words_required
- = absC (if words_required == 0
- then AbsCNop
- else checking_code) `thenC`
+ = getTickyCtrLabel `thenFC` \ ctr ->
+ absC ( if words_required == 0
+ then AbsCNop
+ else mkAbstractCs
+ [ checking_code,
+ profCtrAbsC SLIT("TICK_ALLOC_HEAP")
+ [ mkIntCLit words_required, CLbl ctr DataPtrRep ]
+ ]
+ ) `thenC`
setRealHp words_required
where
= ((int2Word# 1#) `shiftL#` (i -# 1#)) `or#` mkRegLiveness regs
mkRegLiveness (_ : regs) = mkRegLiveness regs
+-- The two functions below are only used in a GranSim setup
-- Emit macro for simulating a fetch and then reschedule
fetchAndReschedule :: [MagicId] -- Live registers
-> Bool -- Node reqd?
-> Code
-fetchAndReschedule regs node_reqd =
+fetchAndReschedule regs node_reqd =
if (node `elem` regs || node_reqd)
then fetch_code `thenC` reschedule_code
else absC AbsCNop
where
all_regs = if node_reqd then node:regs else regs
- liveness_mask = 0 {-XXX: mkLiveRegsMask all_regs-}
-
+ liveness_mask = mkRegLiveness regs
reschedule_code = absC (CMacroStmt GRAN_RESCHEDULE [
- mkIntCLit liveness_mask,
+ mkIntCLit (IBOX(word2Int# liveness_mask)),
mkIntCLit (if node_reqd then 1 else 0)])
--HWL: generate GRAN_FETCH macro for GrAnSim
-> Bool -- Node reqd?
-> Code
-yield regs node_reqd =
- -- NB: node is not alive; that's why we use DO_YIELD rather than
- -- GRAN_RESCHEDULE
- yield_code
- where
- all_regs = if node_reqd then node:regs else regs
- liveness_mask = 0 {-XXX: mkLiveRegsMask all_regs-}
-
- yield_code = absC (CMacroStmt GRAN_YIELD [mkIntCLit liveness_mask])
+yield regs node_reqd =
+ if opt_GranMacros && node_reqd
+ then yield_code
+ else absC AbsCNop
+ where
+ -- all_regs = if node_reqd then node:regs else regs
+ liveness_mask = mkRegLiveness regs
+ yield_code =
+ absC (CMacroStmt GRAN_YIELD
+ [mkIntCLit (IBOX(word2Int# liveness_mask))])
\end{code}
%************************************************************************