Commit 31704adc authored by Christiaan Baaij's avatar Christiaan Baaij Committed by Austin Seipp

Make worker-wrapper optional

Add -fworker-wrapper flag which enables the worker-wrapper transformation. It
is implied by -O.

The expected users of this flag, which includes myself, are GHC API users.  In
my Haskell-to-Hardware compiler, which uses the GHC API, I have seen no
benifits of the worker-wrapper transformation. It does however induce longer
compilation times.

Further discussion can be seen here:
https://mail.haskell.org/pipermail/ghc-devs/2015-October/010096.html

Reviewed By: austin

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

GHC Trac Issues: #11020
parent 166c5972
......@@ -374,6 +374,7 @@ data GeneralFlag
| Opt_DmdTxDictSel -- use a special demand transformer for dictionary selectors
| Opt_Loopification -- See Note [Self-recursive tail calls]
| Opt_CprAnal
| Opt_WorkerWrapper
-- Interface files
| Opt_IgnoreInterfacePragmas
......@@ -3011,7 +3012,8 @@ fFlags = [
flagSpec "unbox-small-strict-fields" Opt_UnboxSmallStrictFields,
flagSpec "unbox-strict-fields" Opt_UnboxStrictFields,
flagSpec "vectorisation-avoidance" Opt_VectorisationAvoidance,
flagSpec "vectorise" Opt_Vectorise
flagSpec "vectorise" Opt_Vectorise,
flagSpec "worker-wrapper" Opt_WorkerWrapper
]
-- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
......@@ -3251,8 +3253,17 @@ default_PIC platform =
-- information.
_ -> []
-- General flags that are switched on/off when other general flags are switched
-- on
impliedGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)]
impliedGFlags = [(Opt_DeferTypeErrors, turnOn, Opt_DeferTypedHoles)]
impliedGFlags = [(Opt_DeferTypeErrors, turnOn, Opt_DeferTypedHoles)
,(Opt_Strictness, turnOn, Opt_WorkerWrapper)
]
-- General flags that are switched on/off when other general flags are switched
-- off
impliedOffGFlags :: [(GeneralFlag, TurnOnFlag, GeneralFlag)]
impliedOffGFlags = [(Opt_Strictness, turnOff, Opt_WorkerWrapper)]
impliedXFlags :: [(ExtensionFlag, TurnOnFlag, ExtensionFlag)]
impliedXFlags
......@@ -3346,6 +3357,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
, ([1,2], Opt_Strictness)
, ([1,2], Opt_UnboxSmallStrictFields)
, ([1,2], Opt_CprAnal)
, ([1,2], Opt_WorkerWrapper)
, ([2], Opt_LiberateCase)
, ([2], Opt_SpecConstr)
......@@ -3613,8 +3625,17 @@ setGeneralFlag' f dflags = foldr ($) (gopt_set dflags f) deps
-- implies further flags
unSetGeneralFlag' :: GeneralFlag -> DynFlags -> DynFlags
unSetGeneralFlag' f dflags = gopt_unset dflags f
-- When you un-set f, however, we don't un-set the things it implies
unSetGeneralFlag' f dflags = foldr ($) (gopt_unset dflags f) deps
where
deps = [ if turn_on then setGeneralFlag' d
else unSetGeneralFlag' d
| (f', turn_on, d) <- impliedOffGFlags, f' == f ]
-- In general, when you un-set f, we don't un-set the things it implies.
-- There are however some exceptions, e.g., -fno-strictness implies
-- -fno-worker-wrapper.
--
-- NB: use unSetGeneralFlag' recursively, in case the implied off flags
-- imply further flags.
--------------------------
setWarningFlag, unSetWarningFlag :: WarningFlag -> DynP ()
......
......@@ -127,6 +127,7 @@ getCoreToDo dflags
static_args = gopt Opt_StaticArgumentTransformation dflags
rules_on = gopt Opt_EnableRewriteRules dflags
eta_expand_on = gopt Opt_DoLambdaEtaExpansion dflags
ww_on = gopt Opt_WorkerWrapper dflags
maybe_rule_check phase = runMaybe rule_check (CoreDoRuleCheck phase)
......@@ -187,12 +188,16 @@ getCoreToDo dflags
-- Don't do case-of-case transformations.
-- This makes full laziness work better
strictness_pass = if ww_on
then [CoreDoStrictness,CoreDoWorkerWrapper]
else [CoreDoStrictness]
-- New demand analyser
demand_analyser = (CoreDoPasses ([
CoreDoStrictness,
CoreDoWorkerWrapper,
simpl_phase 0 ["post-worker-wrapper"] max_iter
]))
demand_analyser = (CoreDoPasses (
strictness_pass ++
[simpl_phase 0 ["post-worker-wrapper"] max_iter]
))
core_todo =
if opt_level == 0 then
......@@ -309,11 +314,10 @@ getCoreToDo dflags
-- Final clean-up simplification:
simpl_phase 0 ["final"] max_iter,
runWhen late_dmd_anal $ CoreDoPasses [
CoreDoStrictness,
CoreDoWorkerWrapper,
simpl_phase 0 ["post-late-ww"] max_iter
],
runWhen late_dmd_anal $ CoreDoPasses (
strictness_pass ++
[simpl_phase 0 ["post-late-ww"] max_iter]
),
maybe_rule_check (Phase 0)
]
......
......@@ -102,6 +102,12 @@ Compiler
``-fcpr-off`` is now removed, run with ``-fno-cpr-anal`` to get the
old ``-fcpr-off`` behaviour.
- Added the option ``-fworker-wrapper``. When enabled, the worker-wrapper
transformation is performed after a strictness analysis pass. It is implied
by ``-O`` and by ``-fstrictness``. It is disabled by ``-fno-strictness``.
Enabling ``-fworker-wrapper`` while strictness analysis is disabled (by
``-fno-strictness``) has no effect.
GHCi
~~~~
......
......@@ -289,7 +289,8 @@ optimizationsOptions =
, flagReverse = "-fno-static-argument-transformation"
}
, flag { flagName = "-fstrictness"
, flagDescription = "Turn on strictness analysis. Implied by ``-O``."
, flagDescription = "Turn on strictness analysis." ++
" Implied by ``-O``. Implies ``-fworker-wrapper``"
, flagType = DynamicFlag
, flagReverse = "-fno-strictness"
}
......@@ -341,4 +342,14 @@ optimizationsOptions =
, flagType = DynamicFlag
, flagReverse = "-fno-vectorise"
}
, flag { flagName = "-fworker-wrapper"
, flagDescription =
"Enable the worker-wrapper transformation after a strictness" ++
" analysis pass. Implied by ``-O``, and by ``-fstrictness``." ++
" Disabled by ``-fno-strictness``. Enabling ``-fworker-wrapper``" ++
" while strictness analysis is disabled (by ``-fno-strictness``)" ++
" has no effect."
, flagType = DynamicFlag
, flagReverse = "-fno-worker-wrapper"
}
]
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