diff options
Diffstat (limited to 'compiler/GHC/Core/Opt/Pipeline.hs')
-rw-r--r-- | compiler/GHC/Core/Opt/Pipeline.hs | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/compiler/GHC/Core/Opt/Pipeline.hs b/compiler/GHC/Core/Opt/Pipeline.hs index 6ed1adf84a..214e7620c2 100644 --- a/compiler/GHC/Core/Opt/Pipeline.hs +++ b/compiler/GHC/Core/Opt/Pipeline.hs @@ -15,7 +15,7 @@ import GHC.Driver.Plugins ( withPlugins, installCoreToDos ) import GHC.Driver.Env import GHC.Driver.Config.Core.Lint ( endPass ) import GHC.Driver.Config.Core.Opt.LiberateCase ( initLiberateCaseOpts ) -import GHC.Driver.Config.Core.Opt.Simplify ( initSimplifyOpts, initSimplMode, initGentleSimplMode ) +import GHC.Driver.Config.Core.Opt.Simplify ( initSimplifyOpts, initSimplMode ) import GHC.Driver.Config.Core.Opt.WorkWrap ( initWorkWrapOpts ) import GHC.Driver.Config.Core.Rules ( initRuleOpts ) import GHC.Platform.Ways ( hasWay, Way(WayProf) ) @@ -28,6 +28,7 @@ import GHC.Core.Utils ( dumpIdInfoOfProgram ) import GHC.Core.Lint ( lintAnnots ) import GHC.Core.Lint.Interactive ( interactiveInScope ) import GHC.Core.Opt.Simplify ( simplifyExpr, simplifyPgm ) +import GHC.Core.Opt.Simplify.Env( SimplMode(..) ) import GHC.Core.Opt.Simplify.Monad import GHC.Core.Opt.Monad import GHC.Core.Opt.Pipeline.Types @@ -154,32 +155,45 @@ getCoreToDo dflags rule_base extra_vars maybe_strictness_before _ = CoreDoNothing - simpl_phase phase name iter - = CoreDoPasses - $ [ maybe_strictness_before phase - , CoreDoSimplify $ initSimplifyOpts dflags extra_vars iter - (initSimplMode dflags phase name) rule_base - , maybe_rule_check phase ] + ---------------------------- + base_simpl_mode :: SimplMode + base_simpl_mode = initSimplMode dflags - -- Run GHC's internal simplification phase, after all rules have run. - -- See Note [Compiler phases] in GHC.Types.Basic - simplify name = simpl_phase FinalPhase name max_iter - - -- initial simplify: mk specialiser happy: minimum effort please + -- gentle_mode: make specialiser happy: minimum effort please -- See Note [Inline in InitialPhase] -- See Note [RULEs enabled in InitialPhase] - simpl_gently = CoreDoSimplify $ initSimplifyOpts dflags extra_vars max_iter - (initGentleSimplMode dflags) rule_base + gentle_mode = base_simpl_mode { sm_names = ["Gentle"] + , sm_phase = InitialPhase + , sm_case_case = False } + + simpl_mode phase name + = base_simpl_mode { sm_names = [name], sm_phase = phase } + + keep_exits :: SimplMode -> SimplMode + -- See Note [Be selective about not-inlining exit join points] + -- in GHC.Core.Opt.Exitify + keep_exits mode = mode { sm_keep_exits = True } + + ---------------------------- + run_simplifier mode iter + = CoreDoSimplify $ initSimplifyOpts dflags extra_vars iter mode rule_base + simpl_phase phase name iter = CoreDoPasses $ + [ maybe_strictness_before phase + , run_simplifier (simpl_mode phase name) iter + , maybe_rule_check phase ] + + -- Run GHC's internal simplification phase, after all rules have run. + -- See Note [Compiler phases] in GHC.Types.Basic + simpl_gently = run_simplifier gentle_mode max_iter + simplify_final name = run_simplifier ( simpl_mode FinalPhase name) max_iter + simpl_keep_exits name = run_simplifier (keep_exits $ simpl_mode FinalPhase name) max_iter + + ---------------------------- dmd_cpr_ww = if ww_on then [CoreDoDemand True,CoreDoCpr,CoreDoWorkerWrapper] else [CoreDoDemand False] -- NB: No CPR! See Note [Don't change boxity without worker/wrapper] - demand_analyser = (CoreDoPasses ( - dmd_cpr_ww ++ - [simplify "post-worker-wrapper"] - )) - -- Static forms are moved to the top level with the FloatOut pass. -- See Note [Grand plan for static forms] in GHC.Iface.Tidy.StaticPtrTable. static_ptrs_float_outwards = @@ -269,14 +283,16 @@ getCoreToDo dflags rule_base extra_vars runWhen call_arity $ CoreDoPasses [ CoreDoCallArity - , simplify "post-call-arity" + , simplify_final "post-call-arity" ], -- Strictness analysis - runWhen strictness demand_analyser, + runWhen strictness $ CoreDoPasses + (dmd_cpr_ww ++ [simplify_final "post-worker-wrapper"]), runWhen exitification CoreDoExitify, -- See Note [Placement of the exitification pass] + -- in GHC.Core.Opt.Exitify runWhen full_laziness $ CoreDoFloatOutwards FloatOutSwitches { @@ -298,7 +314,17 @@ getCoreToDo dflags rule_base extra_vars runWhen do_float_in CoreDoFloatInwards, - simplify "final", -- Final tidy-up + -- Final tidy-up run of the simplifier + simpl_keep_exits "final tidy up", + -- Keep exit join point because this is the first + -- Simplifier run after Exitify. Subsequent runs will + -- re-inline those exit join points; their work is done. + -- See Note [Be selective about not-inlining exit join points] + -- in GHC.Core.Opt.Exitify + -- + -- Annoyingly, we only /have/ a subsequent run with -O2. With + -- plain -O we'll still have those exit join points hanging around. + -- Oh well. maybe_rule_check FinalPhase, @@ -308,31 +334,31 @@ getCoreToDo dflags rule_base extra_vars -- Case-liberation for -O2. This should be after -- strictness analysis and the simplification which follows it. runWhen liberate_case $ CoreDoPasses - [ CoreLiberateCase, simplify "post-liberate-case" ], + [ CoreLiberateCase, simplify_final "post-liberate-case" ], -- Run the simplifier after LiberateCase to vastly -- reduce the possibility of shadowing -- Reason: see Note [Shadowing] in GHC.Core.Opt.SpecConstr runWhen spec_constr $ CoreDoPasses - [ CoreDoSpecConstr, simplify "post-spec-constr"], + [ CoreDoSpecConstr, simplify_final "post-spec-constr"], -- See Note [Simplify after SpecConstr] maybe_rule_check FinalPhase, runWhen late_specialise $ CoreDoPasses - [ CoreDoSpecialising, simplify "post-late-spec"], + [ CoreDoSpecialising, simplify_final "post-late-spec"], -- LiberateCase can yield new CSE opportunities because it peels -- off one layer of a recursive function (concretely, I saw this -- in wheel-sieve1), and I'm guessing that SpecConstr can too -- And CSE is a very cheap pass. So it seems worth doing here. runWhen ((liberate_case || spec_constr) && cse) $ CoreDoPasses - [ CoreCSE, simplify "post-final-cse" ], + [ CoreCSE, simplify_final "post-final-cse" ], --------- End of -O2 passes -------------- runWhen late_dmd_anal $ CoreDoPasses ( - dmd_cpr_ww ++ [simplify "post-late-ww"] + dmd_cpr_ww ++ [simplify_final "post-late-ww"] ), -- Final run of the demand_analyser, ensures that one-shot thunks are |