summaryrefslogtreecommitdiff
path: root/compiler/codeGen/StgCmmExpr.hs
diff options
context:
space:
mode:
authorJan Stolarek <jan.stolarek@p.lodz.pl>2014-02-01 11:32:25 +0100
committerJan Stolarek <jan.stolarek@p.lodz.pl>2014-02-01 14:37:09 +0100
commitea584ab634b17b499138bc44dbec777de7357c19 (patch)
treeaf63e9004cd5219febd48e7e7ec70b5c9e2180ce /compiler/codeGen/StgCmmExpr.hs
parenta2269bf81c8e95ad9a1bc3c32e425fdba7c3686a (diff)
downloadhaskell-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/StgCmmExpr.hs')
-rw-r--r--compiler/codeGen/StgCmmExpr.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/codeGen/StgCmmExpr.hs b/compiler/codeGen/StgCmmExpr.hs
index cc32a1445b..d94eca493e 100644
--- a/compiler/codeGen/StgCmmExpr.hs
+++ b/compiler/codeGen/StgCmmExpr.hs
@@ -737,10 +737,16 @@ cgIdApp fun_id args = do
--
-- * Whenever we are compiling a function, we set that information to reflect
-- the fact that function currently being compiled can be jumped to, instead
--- of called. We also have to emit a label to which we will be jumping. Both
--- things are done in closureCodyBody in StgCmmBind.
+-- of called. This is done in closureCodyBody in StgCmmBind.
--
--- * When we began compilation of another closure we remove the additional
+-- * We also have to emit a label to which we will be jumping. We make sure
+-- that the label is placed after a stack check but before the heap
+-- check. The reason is that making a recursive tail-call does not increase
+-- the stack so we only need to check once. But it may grow the heap, so we
+-- have to repeat the heap check in every self-call. This is done in
+-- do_checks in StgCmmHeap.
+--
+-- * When we begin compilation of another closure we remove the additional
-- information from the environment. This is done by forkClosureBody
-- in StgCmmMonad. Other functions that duplicate the environment -
-- forkLneBody, forkAlts, codeOnly - duplicate that information. In other
@@ -755,8 +761,8 @@ cgIdApp fun_id args = do
-- arity. (d) loopification is turned on via -floopification command-line
-- option.
--
--- * Command line option to control turn loopification on and off is
--- implemented in DynFlags
+-- * Command line option to turn loopification on and off is implemented in
+-- DynFlags.
--