summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2022-02-22 16:19:40 +0100
committerAndreas Klebinger <klebinger.andreas@gmx.at>2022-02-24 13:34:06 +0100
commit646f8a74e54abcd8c8fe03fc57e896eb0f023949 (patch)
tree71cac9ccdc010f5889d800608cc553becef5b34f
parent78fbc3a364e85dc5f31f865f397cd4000294444f (diff)
downloadhaskell-646f8a74e54abcd8c8fe03fc57e896eb0f023949.tar.gz
Ticky: Gate tag-inference dummy ticky-counters behind a flag.wip/andreask/infer_ticks
Tag inference included a way to collect stats about avoided tag-checks. This was dony by emitting "dummy" ticky entries with counts corresponding to predicted/unpredicated tag checks. This behaviour for ticky is now gated behind -fticky-tag-checks. I also documented ticky-LNE in the process.
-rw-r--r--compiler/GHC/Driver/Config/StgToCmm.hs1
-rw-r--r--compiler/GHC/Driver/Flags.hs1
-rw-r--r--compiler/GHC/Driver/Session.hs2
-rw-r--r--compiler/GHC/Iface/Recomp/Flags.hs2
-rw-r--r--compiler/GHC/StgToCmm/Config.hs1
-rw-r--r--compiler/GHC/StgToCmm/Ticky.hs13
-rw-r--r--docs/users_guide/expected-undocumented-flags.txt1
-rw-r--r--docs/users_guide/profiling.rst25
8 files changed, 39 insertions, 7 deletions
diff --git a/compiler/GHC/Driver/Config/StgToCmm.hs b/compiler/GHC/Driver/Config/StgToCmm.hs
index ab64076a79..4b0e126f98 100644
--- a/compiler/GHC/Driver/Config/StgToCmm.hs
+++ b/compiler/GHC/Driver/Config/StgToCmm.hs
@@ -29,6 +29,7 @@ initStgToCmmConfig dflags mod = StgToCmmConfig
, stgToCmmTickyAllocd = gopt Opt_Ticky_Allocd dflags
, stgToCmmTickyLNE = gopt Opt_Ticky_LNE dflags
, stgToCmmTickyDynThunk = gopt Opt_Ticky_Dyn_Thunk dflags
+ , stgToCmmTickyTag = gopt Opt_Ticky_Tag dflags
-- flags
, stgToCmmLoopification = gopt Opt_Loopification dflags
, stgToCmmAlignCheck = gopt Opt_AlignmentSanitisation dflags
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs
index 759d8b48c0..ca5e5a0548 100644
--- a/compiler/GHC/Driver/Flags.hs
+++ b/compiler/GHC/Driver/Flags.hs
@@ -295,6 +295,7 @@ data GeneralFlag
| Opt_Ticky_Allocd
| Opt_Ticky_LNE
| Opt_Ticky_Dyn_Thunk
+ | Opt_Ticky_Tag
| Opt_RPath
| Opt_RelativeDynlibPaths
| Opt_CompactUnwind -- ^ @-fcompact-unwind@
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 34d34815ce..2de16a6e1e 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -2333,6 +2333,8 @@ dynamic_flags_deps = [
(NoArg (setGeneralFlag Opt_Ticky_LNE))
, make_ord_flag defGhcFlag "ticky-dyn-thunk"
(NoArg (setGeneralFlag Opt_Ticky_Dyn_Thunk))
+ , make_ord_flag defGhcFlag "ticky-tag-checks"
+ (NoArg (setGeneralFlag Opt_Ticky_Tag))
------- recompilation checker --------------------------------------
, make_dep_flag defGhcFlag "recomp"
(NoArg $ unSetGeneralFlag Opt_ForceRecomp)
diff --git a/compiler/GHC/Iface/Recomp/Flags.hs b/compiler/GHC/Iface/Recomp/Flags.hs
index 90f3afebbc..b1f6c66e79 100644
--- a/compiler/GHC/Iface/Recomp/Flags.hs
+++ b/compiler/GHC/Iface/Recomp/Flags.hs
@@ -66,7 +66,7 @@ fingerprintDynFlags hsc_env this_mod nameio =
-- Ticky
ticky =
- map (`gopt` dflags) [Opt_Ticky, Opt_Ticky_Allocd, Opt_Ticky_LNE, Opt_Ticky_Dyn_Thunk]
+ map (`gopt` dflags) [Opt_Ticky, Opt_Ticky_Allocd, Opt_Ticky_LNE, Opt_Ticky_Dyn_Thunk, Opt_Ticky_Tag]
flags = ((mainis, safeHs, lang, cpp), (paths, prof, ticky, debugLevel, callerCcFilters))
diff --git a/compiler/GHC/StgToCmm/Config.hs b/compiler/GHC/StgToCmm/Config.hs
index 28c11e1321..623a7b8f0a 100644
--- a/compiler/GHC/StgToCmm/Config.hs
+++ b/compiler/GHC/StgToCmm/Config.hs
@@ -35,6 +35,7 @@ data StgToCmmConfig = StgToCmmConfig
-- join-points (let-no-escape)
, stgToCmmTickyDynThunk :: !Bool -- ^ True indicates ticky uses name-specific counters for
-- dynamic thunks
+ , stgToCmmTickyTag :: !Bool -- ^ True indicates ticky will count number of avoided tag checks by tag inference.
---------------------------------- Flags --------------------------------------
, stgToCmmLoopification :: !Bool -- ^ Loopification enabled (cf @-floopification@)
, stgToCmmAlignCheck :: !Bool -- ^ Insert alignment check (cf @-falignment-sanitisation@)
diff --git a/compiler/GHC/StgToCmm/Ticky.hs b/compiler/GHC/StgToCmm/Ticky.hs
index 57bf1a97b6..4aec817412 100644
--- a/compiler/GHC/StgToCmm/Ticky.hs
+++ b/compiler/GHC/StgToCmm/Ticky.hs
@@ -319,7 +319,7 @@ emitTickyCounterTag unique (NonVoid id) =
let name = idName id
ctr_lbl = mkTagHitLabel name unique in
(>> return ctr_lbl) $
- ifTicky $ do
+ ifTickyTag $ do
{ platform <- getPlatform
; parent <- getTickyCtrLabel
; mod_name <- getModuleName
@@ -664,18 +664,18 @@ tickyStackCheck = ifTicky $ bumpTickyCounter (fsLit "STK_CHK_ctr")
-- | Predicted a pointer would be tagged correctly (GHC will crash if not so no miss case)
tickyTagged :: FCode ()
-tickyTagged = ifTicky $ bumpTickyCounter (fsLit "TAG_TAGGED_pred")
+tickyTagged = ifTickyTag $ bumpTickyCounter (fsLit "TAG_TAGGED_pred")
-- | Pass a boolean expr indicating if tag was present.
tickyUntagged :: CmmExpr -> FCode ()
tickyUntagged e = do
- ifTicky $ bumpTickyCounter (fsLit "TAG_UNTAGGED_pred")
- ifTicky $ bumpTickyCounterByE (fsLit "TAG_UNTAGGED_miss") e
+ ifTickyTag $ bumpTickyCounter (fsLit "TAG_UNTAGGED_pred")
+ ifTickyTag $ bumpTickyCounterByE (fsLit "TAG_UNTAGGED_miss") e
-- | Called when for `case v of ...` we can avoid entering v based on
-- tag inference information.
tickyTagSkip :: Unique -> Id -> FCode ()
-tickyTagSkip unique id = ifTicky $ do
+tickyTagSkip unique id = ifTickyTag $ do
let ctr_lbl = mkTagHitLabel (idName id) unique
registerTickyCtr ctr_lbl
bumpTickyTagSkip ctr_lbl
@@ -692,6 +692,9 @@ runIfFlag f = whenM (f <$> getStgToCmmConfig)
ifTicky :: FCode () -> FCode ()
ifTicky = runIfFlag stgToCmmDoTicky
+ifTickyTag :: FCode () -> FCode ()
+ifTickyTag = runIfFlag stgToCmmTickyTag
+
ifTickyAllocd :: FCode () -> FCode ()
ifTickyAllocd = runIfFlag stgToCmmTickyAllocd
diff --git a/docs/users_guide/expected-undocumented-flags.txt b/docs/users_guide/expected-undocumented-flags.txt
index 7af6d42080..33958b1578 100644
--- a/docs/users_guide/expected-undocumented-flags.txt
+++ b/docs/users_guide/expected-undocumented-flags.txt
@@ -97,4 +97,3 @@
-rtsopts=some
-syslib
-this-component-id
--ticky-LNE
diff --git a/docs/users_guide/profiling.rst b/docs/users_guide/profiling.rst
index d68c056946..dcfd42b84e 100644
--- a/docs/users_guide/profiling.rst
+++ b/docs/users_guide/profiling.rst
@@ -1740,6 +1740,31 @@ Using “ticky-ticky” profiling (for implementors)
Track allocations of dynamic thunks.
+.. ghc-flag:: -ticky-LNE
+ :shortdesc: Treat join point binders similar to thunks/functions.
+ :type: dynamic
+ :category:
+
+ These are not allocated, and can be very performance sensitive so we usually don't
+ want to run ticky counters for these to avoid even worse performance for tickied builds.
+
+ But sometimes having information about these binders is critical. So we have a flag to ticky them
+ anyway.
+
+.. ghc-flag:: -ticky-tag-checks
+ :shortdesc: Emit dummy ticky counters to record how many tag-inference checks tag inference avoided.
+ :type: dynamic
+ :category:
+
+ These dummy counters contain:
+ * The number of avoided tag checks in the entry count.
+ * "infer" as the argument string to distinguish them from regular counters.
+ * The name of the variable we are casing on, as well as a unique to represent the inspection site as one variable might be cased on multiple times.
+ The unique comes first , with the variable coming at the end. Like this: `u10_s98c (Main) at nofib/spectral/simple/Main.hs:677:1 in u10`
+ where `u10` is the variable and `u10_s98c` the unique associated with the inspection site.
+
+ Note that these counters are currently not processed well be eventlog2html. So if you want to check them you will have to use the text based interface.
+
GHC's ticky-ticky profiler provides a low-level facility for tracking
entry and allocation counts of particular individual closures.
Because ticky-ticky profiling requires a certain familiarity with GHC