[commit: ghc] master: Deduplicate decision to count thunks in `-ticky` (f10df65)

git at git.haskell.org git at git.haskell.org
Fri Nov 30 16:19:06 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f10df65fa2c9a5ec2f4c09b97e02e87c377beac3/ghc

>---------------------------------------------------------------

commit f10df65fa2c9a5ec2f4c09b97e02e87c377beac3
Author: Sebastian Graf <sebastian.graf at kit.edu>
Date:   Fri Nov 30 17:18:45 2018 +0100

    Deduplicate decision to count thunks in `-ticky`
    
    Summary:
    Previously, the logic that checks whether a thunk has a counter or not
    was duplicated in multiple functions.
    
    This led to thunk enters being accounted to their enclosing functions in
    `StgCmmTicky.tickyEnterThunk`, because the outer call to
    `withNewTickyCounterThunk` didn't set the counter label for the thunk.
    And rightly so! `tickyEnterThunk` should only account thunk enters to a
    counter if `-ticky-dyn-thunk` is on.
    
    This patch extracts the logic that was already present in its most
    general form in `withNewTickyCounterThunk` into its own functions and
    lets all other call sites checking for `-ticky-dyn-thunk` call this new
    function named `thunkHasCounter` instead.
    
    Reviewers: bgamari, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, carter
    
    Differential Revision: https://phabricator.haskell.org/D5392


>---------------------------------------------------------------

f10df65fa2c9a5ec2f4c09b97e02e87c377beac3
 compiler/codeGen/StgCmmTicky.hs | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/compiler/codeGen/StgCmmTicky.hs b/compiler/codeGen/StgCmmTicky.hs
index 8f30748..e673d21 100644
--- a/compiler/codeGen/StgCmmTicky.hs
+++ b/compiler/codeGen/StgCmmTicky.hs
@@ -136,7 +136,7 @@ import TyCon
 
 import Data.Maybe
 import qualified Data.Char
-import Control.Monad ( unless, when )
+import Control.Monad ( when )
 
 -----------------------------------------------------------------------------
 --
@@ -161,6 +161,11 @@ withNewTickyCounterLNE nm args code = do
   b <- tickyLNEIsOn
   if not b then code else withNewTickyCounter TickyLNE nm args code
 
+thunkHasCounter :: Bool -> FCode Bool
+thunkHasCounter isStatic = do
+  b <- tickyDynThunkIsOn
+  pure (not isStatic && b)
+
 withNewTickyCounterThunk
   :: Bool -- ^ static
   -> Bool -- ^ updateable
@@ -168,8 +173,8 @@ withNewTickyCounterThunk
   -> FCode a
   -> FCode a
 withNewTickyCounterThunk isStatic isUpdatable name code = do
-    b <- tickyDynThunkIsOn
-    if isStatic || not b -- ignore static thunks
+    has_ctr <- thunkHasCounter isStatic
+    if not has_ctr
       then code
       else withNewTickyCounter (TickyThunk isUpdatable False) name [] code
 
@@ -179,8 +184,8 @@ withNewTickyCounterStdThunk
   -> FCode a
   -> FCode a
 withNewTickyCounterStdThunk isUpdatable name code = do
-    b <- tickyDynThunkIsOn
-    if not b
+    has_ctr <- thunkHasCounter False
+    if not has_ctr
       then code
       else withNewTickyCounter (TickyThunk isUpdatable True) name [] code
 
@@ -189,8 +194,8 @@ withNewTickyCounterCon
   -> FCode a
   -> FCode a
 withNewTickyCounterCon name code = do
-    b <- tickyDynThunkIsOn
-    if not b
+    has_ctr <- thunkHasCounter False
+    if not has_ctr
       then code
       else withNewTickyCounter TickyCon name [] code
 
@@ -277,7 +282,8 @@ tickyEnterThunk :: ClosureInfo -> FCode ()
 tickyEnterThunk cl_info
   = ifTicky $ do
     { bumpTickyCounter ctr
-    ; unless static $ do
+    ; has_ctr <- thunkHasCounter static
+    ; when has_ctr $ do
       ticky_ctr_lbl <- getTickyCtrLabel
       registerTickyCtrAtEntryDyn ticky_ctr_lbl
       bumpTickyEntryCount ticky_ctr_lbl }



More information about the ghc-commits mailing list