diff options
author | Jan Stolarek <jan.stolarek@p.lodz.pl> | 2014-02-01 11:32:25 +0100 |
---|---|---|
committer | Jan Stolarek <jan.stolarek@p.lodz.pl> | 2014-02-01 14:37:09 +0100 |
commit | ea584ab634b17b499138bc44dbec777de7357c19 (patch) | |
tree | af63e9004cd5219febd48e7e7ec70b5c9e2180ce /compiler/codeGen/StgCmmBind.hs | |
parent | a2269bf81c8e95ad9a1bc3c32e425fdba7c3686a (diff) | |
download | haskell-ea584ab634b17b499138bc44dbec777de7357c19.tar.gz |
Loopification jump between stack and heap checks
Fixes #8585
When emmiting label of a self-recursive tail call (ie. when
performing loopification optimization) we emit the loop header
label after a stack check but before the heap check. The reason is
that tail-recursive functions use constant amount of stack space
so we don't need to repeat the check in every loop. But they can
grow the heap so heap check must be repeated in every call.
See Note [Self-recursive tail calls] and [Self-recursive loop header].
Diffstat (limited to 'compiler/codeGen/StgCmmBind.hs')
-rw-r--r-- | compiler/codeGen/StgCmmBind.hs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/compiler/codeGen/StgCmmBind.hs b/compiler/codeGen/StgCmmBind.hs index 23367926c7..344e80a497 100644 --- a/compiler/codeGen/StgCmmBind.hs +++ b/compiler/codeGen/StgCmmBind.hs @@ -472,25 +472,21 @@ closureCodeBody top_lvl bndr cl_info cc args arity body fv_details \(_offset, node, arg_regs) -> do -- Emit slow-entry code (for entering a closure through a PAP) { mkSlowEntryCode bndr cl_info arg_regs - ; dflags <- getDynFlags ; let node_points = nodeMustPointToIt dflags lf_info node' = if node_points then Just node else Nothing - -- Emit new label that might potentially be a header - -- of a self-recursive tail call. See Note - -- [Self-recursive tail calls] in StgCmmExpr ; loop_header_id <- newLabelC - ; emitLabel loop_header_id - ; when node_points (ldvEnterClosure cl_info (CmmLocal node)) -- Extend reader monad with information that -- self-recursive tail calls can be optimized into local - -- jumps + -- jumps. See Note [Self-recursive tail calls] in StgCmmExpr. ; withSelfLoop (bndr, loop_header_id, arg_regs) $ do { -- Main payload ; entryHeapCheck cl_info node' arity arg_regs $ do - { -- ticky after heap check to avoid double counting - tickyEnterFun cl_info + { -- emit LDV code when profiling + when node_points (ldvEnterClosure cl_info (CmmLocal node)) + -- ticky after heap check to avoid double counting + ; tickyEnterFun cl_info ; enterCostCentreFun cc (CmmMachOp (mo_wordSub dflags) [ CmmReg (CmmLocal node) -- See [NodeReg clobbered with loopification] |