diff options
author | Gergo ERDI <gergo@erdi.hu> | 2021-11-15 16:59:27 +0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-12-09 22:14:24 -0500 |
commit | 6d0319220ebc63a29b941483a6c40ed4f972dc24 (patch) | |
tree | 6903084e761ff12c92f57604f45fbeadab1bb0d8 | |
parent | 2fca50d42b14a8f51e9805cdd2ef8fbc4a67259d (diff) | |
download | haskell-6d0319220ebc63a29b941483a6c40ed4f972dc24.tar.gz |
Add `Opt_CoreConstantFolding` to turn on constant folding (#20500)
Previously, `-O1` and `-O2`, by way of their effect on the compilation
pipeline, they implicitly turned on constant folding
-rw-r--r-- | compiler/GHC/Core/Opt/Pipeline.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Driver/Config/CmmToAsm.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Driver/Flags.hs | 1 | ||||
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 3 | ||||
-rw-r--r-- | docs/users_guide/using-optimisation.rst | 11 |
5 files changed, 19 insertions, 3 deletions
diff --git a/compiler/GHC/Core/Opt/Pipeline.hs b/compiler/GHC/Core/Opt/Pipeline.hs index 770d68ecc9..7062865ed7 100644 --- a/compiler/GHC/Core/Opt/Pipeline.hs +++ b/compiler/GHC/Core/Opt/Pipeline.hs @@ -130,6 +130,7 @@ getCoreToDo logger dflags phases = simplPhases dflags max_iter = maxSimplIterations dflags rule_check = ruleCheck dflags + const_fold = gopt Opt_CoreConstantFolding dflags call_arity = gopt Opt_CallArity dflags exitification = gopt Opt_Exitification dflags strictness = gopt Opt_Strictness dflags @@ -150,7 +151,7 @@ getCoreToDo logger dflags profiling = ways dflags `hasWay` WayProf do_presimplify = do_specialise -- TODO: any other optimizations benefit from pre-simplification? - do_simpl3 = rules_on -- TODO: any other optimizations benefit from three-phase simplification? + do_simpl3 = const_fold || rules_on -- TODO: any other optimizations benefit from three-phase simplification? maybe_rule_check phase = runMaybe rule_check (CoreDoRuleCheck phase) diff --git a/compiler/GHC/Driver/Config/CmmToAsm.hs b/compiler/GHC/Driver/Config/CmmToAsm.hs index 3e075ee049..edf82a37cc 100644 --- a/compiler/GHC/Driver/Config/CmmToAsm.hs +++ b/compiler/GHC/Driver/Config/CmmToAsm.hs @@ -32,9 +32,9 @@ initNCGConfig dflags this_mod = NCGConfig , ncgCfgBlockLayout = gopt Opt_CfgBlocklayout dflags , ncgCfgWeightlessLayout = gopt Opt_WeightlessBlocklayout dflags - -- With -O1 and greater, the cmmSink pass does constant-folding, so + -- When constant-folding is enabled, the cmmSink pass does constant-folding, so -- we don't need to do it again in the native code generator. - , ncgDoConstantFolding = optLevel dflags < 1 + , ncgDoConstantFolding = not (gopt Opt_CoreConstantFolding dflags || gopt Opt_CmmSink dflags) , ncgDumpRegAllocStages = dopt Opt_D_dump_asm_regalloc_stages dflags , ncgDumpAsmStats = dopt Opt_D_dump_asm_stats dflags diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs index e7205a8620..c66cb85bfe 100644 --- a/compiler/GHC/Driver/Flags.hs +++ b/compiler/GHC/Driver/Flags.hs @@ -228,6 +228,7 @@ data GeneralFlag | Opt_AlignmentSanitisation | Opt_CatchBottoms | Opt_NumConstantFolding + | Opt_CoreConstantFolding | Opt_FastPAPCalls -- #6084 -- PreInlining is on by default. The option is there just to see how diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index f7d24d1fd5..def183b62b 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -3378,6 +3378,7 @@ fFlagsDeps = [ flagSpec "catch-bottoms" Opt_CatchBottoms, flagSpec "alignment-sanitisation" Opt_AlignmentSanitisation, flagSpec "num-constant-folding" Opt_NumConstantFolding, + flagSpec "core-constant-folding" Opt_CoreConstantFolding, flagSpec "fast-pap-calls" Opt_FastPAPCalls, flagSpec "cmm-control-flow" Opt_CmmControlFlow, flagSpec "show-warning-groups" Opt_ShowWarnGroups, @@ -3847,6 +3848,8 @@ optLevelFlags -- see Note [Documenting optimisation flags] , ([0], Opt_IgnoreInterfacePragmas) , ([0], Opt_OmitInterfacePragmas) + , ([1,2], Opt_CoreConstantFolding) + , ([1,2], Opt_CallArity) , ([1,2], Opt_Exitification) , ([1,2], Opt_CaseMerge) diff --git a/docs/users_guide/using-optimisation.rst b/docs/users_guide/using-optimisation.rst index 5fa9a81a5e..36fc057890 100644 --- a/docs/users_guide/using-optimisation.rst +++ b/docs/users_guide/using-optimisation.rst @@ -121,6 +121,17 @@ on by default are enabled by ``-O``, and as such you shouldn't need to set any of them explicitly. A flag ``-fwombat`` can be negated by saying ``-fno-wombat``. +.. ghc-flag:: -fcore-constant-folding + :shortdesc: Enable constant folding in Core. Implied by :ghc-flag:`-O`. + :type: dynamic + :reverse: -fno-core-constant-folding + :category: + + :default: on + + Enables Core-level constant folding, i.e. propagation of values + that can be computed at compile time. + .. ghc-flag:: -fcase-merge :shortdesc: Enable case-merging. Implied by :ghc-flag:`-O`. :type: dynamic |