--- unboxed tuple alternatives and let-no-escapes (the two most annoying
--- constructs to generate code for!):
-
-altHeapCheck is_poly is_prim regs tags fail_code (Just ret_addr) code
- = mkTagAssts tags `thenFC` \tag_assts1 ->
- let tag_assts = mkAbstractCs [fail_code, tag_assts1]
- in
- initHeapUsage (\ hHw -> do_heap_chk hHw tag_assts `thenC` code)
- where
- do_heap_chk words_required tag_assts
- = getTickyCtrLabel `thenFC` \ ctr ->
- absC ( if words_required == 0
- then AbsCNop
- else mkAbstractCs
- [ checking_code tag_assts,
- profCtrAbsC FSLIT("TICK_ALLOC_HEAP")
- [ mkIntCLit words_required, CLbl ctr DataPtrRep ]
- ]
- ) `thenC`
- setRealHp words_required
-
- where
- non_void_regs = filter (/= VoidReg) regs
-
- checking_code tag_assts =
- case non_void_regs of
-
-{- no: there might be stuff on top of the retn. addr. on the stack.
- [{-no regs-}] ->
- CCheck HP_CHK_NOREGS
- [mkIntCLit words_required]
- tag_assts
--}
- -- this will cover all cases for x86
- [VanillaReg rep 1#]
-
- | isFollowableRep rep ->
- CCheck HP_CHK_UT_ALT
- [mkIntCLit words_required, mkIntCLit 1, mkIntCLit 0,
- CReg (VanillaReg RetRep 2#),
- CLbl (mkReturnInfoLabel ret_addr) RetRep]
- tag_assts
-
- | otherwise ->
- CCheck HP_CHK_UT_ALT
- [mkIntCLit words_required, mkIntCLit 0, mkIntCLit 1,
- CReg (VanillaReg RetRep 2#),
- CLbl (mkReturnInfoLabel ret_addr) RetRep]
- tag_assts
-
- several_regs ->
- let liveness = mkRegLiveness several_regs
- in
- CCheck HP_CHK_GEN
- [mkIntCLit words_required,
- mkIntCLit (I# (word2Int# liveness)),
- -- HP_CHK_GEN needs a direct return address,
- -- not an info table (might be different if
- -- we're not assembly-mangling/tail-jumping etc.)
- CLbl (mkReturnPtLabel ret_addr) RetRep]
- tag_assts