diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2021-09-10 11:19:28 +0200 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2021-09-17 09:36:43 +0200 |
commit | 92e0918c6f42223ede5524e3cb91f71728331a9a (patch) | |
tree | f28cc283e76ce110f1afb30330ffc559c066e3f6 /compiler/GHC/CoreToStg.hs | |
parent | 3fb1afea019422292954785575902c62473e93e3 (diff) | |
download | haskell-wip/exec-freq.tar.gz |
Statically estimate execution frequency of CoreAlts (#20378)wip/exec-freq
This patch implements #20378. See `Note [Estimating CoreAlt frequencies]` in the
new module GHC.Core.Opt.ExecFreq for details.
These were the changes:
1. Introduce `newtype Freq = Freq Float` as a type that captures relative
execution frequency and use it as an additional field in `CoreAlt`.
The default when we have no estimate available is `NoFreq`, e.g., NaN.
Otherwise, all `Freq`s of a `Case` should add up to 1.
Then fix up a whole bunch of use sites.
2. Introduce a new enum `Comparison` for the different kinds of comparison
operators (LessThan, GreaterOrEqual, NotEqual, ...). Then make `Compare`
primops also declare what kind of `Comparison` they do. Then introduce a
function `isComparisonApp_maybe` in GHC.Core.Utils that we can use for our
estimates (see below).
3. Write a static analysis pass `estimateAltFreqs`, that annotates `CoreAlt`s
with their relative execution `Freq`. These `Freq`s are determined by
combining the estimates of different branch heuristics, one of which uses
the new `isComparisonApp_maybe`.
The main function `estimateAltFreqs` is currently dead, but that is bound to
change in follow-up MRs.
Fixes #20378.
Diffstat (limited to 'compiler/GHC/CoreToStg.hs')
-rw-r--r-- | compiler/GHC/CoreToStg.hs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/GHC/CoreToStg.hs b/compiler/GHC/CoreToStg.hs index a258a424dc..5d13fc3dc6 100644 --- a/compiler/GHC/CoreToStg.hs +++ b/compiler/GHC/CoreToStg.hs @@ -455,7 +455,7 @@ coreToStgExpr (Case scrut bndr _ alts) ; return (StgCase scrut2 bndr (mkStgAltType bndr alts) alts2) } where vars_alt :: CoreAlt -> CtsM (AltCon, [Var], StgExpr) - vars_alt (Alt con binders rhs) + vars_alt (Alt con _freq binders rhs) | DataAlt c <- con, c == unboxedUnitDataCon = -- This case is a bit smelly. -- See Note [Nullary unboxed tuple] in GHC.Core.Type @@ -506,7 +506,7 @@ mkStgAltType bndr alts -- grabbing the one from a constructor alternative -- if one exists. look_for_better_tycon - | ((Alt (DataAlt con) _ _) : _) <- data_alts = + | ((Alt (DataAlt con) _ _ _) : _) <- data_alts = AlgAlt (dataConTyCon con) | otherwise = assert (null data_alts) |