Draft: Statically estimate execution frequency of CoreAlts (#20378)
This patch implements #20378. See Note [Estimating CoreAlt frequencies]
in the
new module GHC.Core.Opt.ExecFreq for details.
These were the changes:
- Introduce
newtype Freq = Freq Float
as a type that captures relative execution frequency and use it as an additional field inCoreAlt
. The default when we have no estimate available isNoFreq
, e.g., NaN. Otherwise, allFreq
s of aCase
should add up to 1. Then fix up a whole bunch of use sites. - Introduce a new enum
Comparison
for the different kinds of comparison operators (LessThan, GreaterOrEqual, NotEqual, ...). Then makeCompare
primops also declare what kind ofComparison
they do. Then introduce a functionisComparisonApp_maybe
in GHC.Core.Utils that we can use for our estimates (see below). - Write a static analysis pass
estimateAltFreqs
, that annotatesCoreAlt
s with their relative executionFreq
. TheseFreq
s are determined by combining the estimates of different branch heuristics, one of which uses the newisComparisonApp_maybe
.
The main function estimateAltFreqs
is currently dead, but that is bound to
change in follow-up MRs.
Fixes #20378.