Commit f0f0ac85 authored by mlen's avatar mlen Committed by Ben Gamari

Fix histograms for ticky code

This patch fixes Cmm generation required to produce histograms when
compiling with -ticky flag, strips dead code from rts/Ticky.c and
reworks it to use a shared constant in both C and Haskell code.

Fixes #8308.

Test Plan: T8308

Reviewers: jstolarek, simonpj, austin

Reviewed By: simonpj

Subscribers: mpickering, simonpj, bgamari, mlen, thomie, jstolarek

Differential Revision: https://phabricator.haskell.org/D931

GHC Trac Issues: #8308
parent fffe3a25
...@@ -680,6 +680,7 @@ cgConApp con stg_args ...@@ -680,6 +680,7 @@ cgConApp con stg_args
-- it only affects profiling (hence the False) -- it only affects profiling (hence the False)
; emit =<< fcode_init ; emit =<< fcode_init
; tickyReturnNewCon (length stg_args)
; emitReturn [idInfoToAmode idinfo] } ; emitReturn [idInfoToAmode idinfo] }
cgIdApp :: Id -> [StgArg] -> FCode ReturnKind cgIdApp :: Id -> [StgArg] -> FCode ReturnKind
......
...@@ -97,7 +97,7 @@ module StgCmmTicky ( ...@@ -97,7 +97,7 @@ module StgCmmTicky (
tickyUpdateBhCaf, tickyUpdateBhCaf,
tickyBlackHole, tickyBlackHole,
tickyUnboxedTupleReturn, tickyVectoredReturn, tickyUnboxedTupleReturn,
tickyReturnOldCon, tickyReturnNewCon, tickyReturnOldCon, tickyReturnNewCon,
tickyKnownCallTooFewArgs, tickyKnownCallExact, tickyKnownCallExtraArgs, tickyKnownCallTooFewArgs, tickyKnownCallExact, tickyKnownCallExtraArgs,
...@@ -376,11 +376,6 @@ tickyUnboxedTupleReturn arity ...@@ -376,11 +376,6 @@ tickyUnboxedTupleReturn arity
= ifTicky $ do { bumpTickyCounter (fsLit "RET_UNBOXED_TUP_ctr") = ifTicky $ do { bumpTickyCounter (fsLit "RET_UNBOXED_TUP_ctr")
; bumpHistogram (fsLit "RET_UNBOXED_TUP_hst") arity } ; bumpHistogram (fsLit "RET_UNBOXED_TUP_hst") arity }
tickyVectoredReturn :: Int -> FCode ()
tickyVectoredReturn family_size
= ifTicky $ do { bumpTickyCounter (fsLit "VEC_RETURN_ctr")
; bumpHistogram (fsLit "RET_VEC_RETURN_hst") family_size }
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Ticky calls -- Ticky calls
...@@ -615,26 +610,15 @@ bumpTickyLitByE lhs e = do ...@@ -615,26 +610,15 @@ bumpTickyLitByE lhs e = do
emit (addToMemE (bWord dflags) (CmmLit lhs) e) emit (addToMemE (bWord dflags) (CmmLit lhs) e)
bumpHistogram :: FastString -> Int -> FCode () bumpHistogram :: FastString -> Int -> FCode ()
bumpHistogram _lbl _n bumpHistogram lbl n = do
-- = bumpHistogramE lbl (CmmLit (CmmInt (fromIntegral n) cLongWidth)) dflags <- getDynFlags
= return () -- TEMP SPJ Apr 07 let offset = n `min` (tICKY_BIN_COUNT dflags - 1)
-- six years passed - still temp? JS Aug 2013 emit (addToMem (cLong dflags)
(cmmIndexExpr dflags
{- (cLongWidth dflags)
bumpHistogramE :: LitString -> CmmExpr -> FCode () (CmmLit (CmmLabel (mkCmmDataLabel rtsUnitId lbl)))
bumpHistogramE lbl n (CmmLit (CmmInt (fromIntegral offset) (cLongWidth dflags))))
= do t <- newTemp cLong 1)
emitAssign (CmmLocal t) n
emit (mkCmmIfThen (CmmMachOp (MO_U_Le cLongWidth) [CmmReg (CmmLocal t), eight])
(mkAssign (CmmLocal t) eight))
emit (addToMem cLong
(cmmIndexExpr cLongWidth
(CmmLit (CmmLabel (mkRtsDataLabel lbl)))
(CmmReg (CmmLocal t)))
1)
where
eight = CmmLit (CmmInt 8 cLongWidth)
-}
------------------------------------------------------------------ ------------------------------------------------------------------
-- Showing the "type category" for ticky-ticky profiling -- Showing the "type category" for ticky-ticky profiling
...@@ -671,7 +655,7 @@ showTypeCategory ty ...@@ -671,7 +655,7 @@ showTypeCategory ty
| otherwise = case tcSplitTyConApp_maybe ty of | otherwise = case tcSplitTyConApp_maybe ty of
Nothing -> '.' Nothing -> '.'
Just (tycon, _) -> Just (tycon, _) ->
(if isUnliftedTyCon tycon then Data.Char.toLower else \x -> x) $ (if isUnliftedTyCon tycon then Data.Char.toLower else id) $
let anyOf us = getUnique tycon `elem` us in let anyOf us = getUnique tycon `elem` us in
case () of case () of
_ | anyOf [funTyConKey] -> '>' _ | anyOf [funTyConKey] -> '>'
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
* *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#ifndef TICKYCOUNTERS_H #ifndef TICKYCOUNTERS_H
#define TICKYCOUNTERS_H #define TICKYCOUNTERS_H
...@@ -180,9 +179,17 @@ EXTERN StgInt RET_OLD_ctr INIT(0); ...@@ -180,9 +179,17 @@ EXTERN StgInt RET_OLD_ctr INIT(0);
EXTERN StgInt RET_UNBOXED_TUP_ctr INIT(0); EXTERN StgInt RET_UNBOXED_TUP_ctr INIT(0);
EXTERN StgInt RET_SEMI_loads_avoided INIT(0); EXTERN StgInt RET_SEMI_loads_avoided INIT(0);
/* End of counter declarations. */ /* End of counter declarations. */
/* How many bins in ticky's histograms */
#define TICKY_BIN_COUNT 9
/* Histogram declarations */
EXTERN StgInt RET_NEW_hst[TICKY_BIN_COUNT] INIT({0});
EXTERN StgInt RET_OLD_hst[TICKY_BIN_COUNT] INIT({0});
EXTERN StgInt RET_UNBOXED_TUP_hst[TICKY_BIN_COUNT] INIT({0});
/* End of histogram declarations */
/* This is ugly, but the story is: /* This is ugly, but the story is:
We got rid of StgTicky.h, which was previously We got rid of StgTicky.h, which was previously
defining these macros for the benefit of C code defining these macros for the benefit of C code
......
...@@ -329,7 +329,10 @@ ...@@ -329,7 +329,10 @@
SymI_HasProto(RET_NEW_ctr) \ SymI_HasProto(RET_NEW_ctr) \
SymI_HasProto(RET_OLD_ctr) \ SymI_HasProto(RET_OLD_ctr) \
SymI_HasProto(RET_UNBOXED_TUP_ctr) \ SymI_HasProto(RET_UNBOXED_TUP_ctr) \
SymI_HasProto(RET_SEMI_loads_avoided) SymI_HasProto(RET_SEMI_loads_avoided) \
SymI_HasProto(RET_NEW_hst) \
SymI_HasProto(RET_OLD_hst) \
SymI_HasProto(RET_UNBOXED_TUP_hst)
// On most platforms, the garbage collector rewrites references // On most platforms, the garbage collector rewrites references
......
This diff is collapsed.
TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk
T8308:
@'$(TEST_HC)' $(TEST_HC_OPTS) -v0 -rtsopts -ticky -O0 T8308.hs
@./T8308 +RTS -rT8308.ticky >/dev/null
@grep RET_NEW_hst_1 T8308.ticky | awk '{ print $$1 }'
.PHONY: T8308
{-# LANGUAGE BangPatterns #-}
data Test = Test !Int
{-# NOINLINE f #-}
f a = Test (a + 1)
main = let (Test x) = f 1 in print x
test('T8308', [extra_clean(['T8308.ticky'])],
run_command, ['$MAKE -s --no-print-directory T8308'])
...@@ -315,6 +315,9 @@ wanteds os = concat ...@@ -315,6 +315,9 @@ wanteds os = concat
,constantWord Both "BLOCKS_PER_MBLOCK" "BLOCKS_PER_MBLOCK" ,constantWord Both "BLOCKS_PER_MBLOCK" "BLOCKS_PER_MBLOCK"
-- could be derived, but better to save doing the calculation twice -- could be derived, but better to save doing the calculation twice
,constantWord Both "TICKY_BIN_COUNT" "TICKY_BIN_COUNT"
-- number of bins for histograms used in ticky code
,fieldOffset Both "StgRegTable" "rR1" ,fieldOffset Both "StgRegTable" "rR1"
,fieldOffset Both "StgRegTable" "rR2" ,fieldOffset Both "StgRegTable" "rR2"
,fieldOffset Both "StgRegTable" "rR3" ,fieldOffset Both "StgRegTable" "rR3"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment