summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-11-10 11:47:38 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2015-11-10 11:55:41 +0100
commit9fa3783a11079ce48afc42d8da633c0b8c9f7526 (patch)
tree7bc694bdcc0f43e4d2dcc57abd80427bf281eddb /src
parent29d772d0655a3a5af79c3d8eca91bb33a82c7194 (diff)
downloadscala-9fa3783a11079ce48afc42d8da633c0b8c9f7526.tar.gz
scala-9fa3783a11079ce48afc42d8da633c0b8c9f7526.tar.bz2
scala-9fa3783a11079ce48afc42d8da633c0b8c9f7526.zip
Clean up optimizer settings.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala18
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala22
3 files changed, 19 insertions, 23 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala
index 35e4db33bc..b0ec37db97 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala
@@ -237,7 +237,7 @@ abstract class GenBCode extends BCodeSyncAndTry {
}
if (settings.YoptInlinerEnabled)
bTypes.inliner.runInliner()
- if (settings.YoptClosureElimination)
+ if (settings.YoptClosureInvocations)
closureOptimizer.rewriteClosureApplyInvocations()
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
index 5ad6910d5e..b4868a03ef 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
@@ -198,14 +198,14 @@ class LocalOpt[BT <: BTypes](val btypes: BT) {
def removalRound(runDCE: Boolean, runCopyProp: Boolean, maxRecursion: Int = 10): Boolean = {
if (maxRecursion == 0) return false
- val (codeRemoved, liveLabels) = if (runDCE) removeUnreachableCodeImpl(method, ownerClassName) else (false, Set.empty[LabelNode])
+ // Both AliasingAnalyzer (used in copyProp) and ProdConsAnalyzer (used in eliminateStaleStores)
+ // require not having unreachable instructions (null frames).
+ val dceRequired = runDCE || compilerSettings.YoptCopyPropagation
+ val (codeRemoved, liveLabels) = if (dceRequired) removeUnreachableCodeImpl(method, ownerClassName) else (false, Set.empty[LabelNode])
// runCopyProp is only true in the first iteration; there's no optimization below that enables
// further copy propagation. it is still part of the fixpoint loop because it needs to run after DCE.
- val copyPropChanged = if (runCopyProp) {
- if (!runDCE) minimalRemoveUnreachableCode(method, ownerClassName) // copyProp (AliasingAnalyzer) requires DCE
- copyProp(method, ownerClassName)
- } else false
+ val copyPropChanged = if (runCopyProp) copyProp(method, ownerClassName) else false
val storesRemoved = if (compilerSettings.YoptCopyPropagation) eliminateStaleStores(method, ownerClassName) else false
@@ -213,7 +213,7 @@ class LocalOpt[BT <: BTypes](val btypes: BT) {
val storeLoadRemoved = if (compilerSettings.YoptCopyPropagation) eliminateStoreLoad(method) else false
- val removedHandlers = if (runDCE) removeEmptyExceptionHandlers(method) else Set.empty[TryCatchBlockNode]
+ val removedHandlers = if (dceRequired) removeEmptyExceptionHandlers(method) else Set.empty[TryCatchBlockNode]
val handlersRemoved = removedHandlers.nonEmpty
val liveHandlerRemoved = removedHandlers.exists(h => liveLabels(h.start))
@@ -233,7 +233,7 @@ class LocalOpt[BT <: BTypes](val btypes: BT) {
val dceCopyPropHandlersOrJumpsChanged = if (AsmAnalyzer.sizeOKForBasicValue(method)) {
// we run DCE even if the method is already in the `unreachableCodeEliminated` map: the DCE
- // here is more thorough than `minimalRemoveUnreachableCode`
+ // here is more thorough than `minimalRemoveUnreachableCode` that run before inlining.
val r = removalRound(
runDCE = compilerSettings.YoptUnreachableCode,
runCopyProp = compilerSettings.YoptCopyPropagation)
@@ -247,9 +247,9 @@ class LocalOpt[BT <: BTypes](val btypes: BT) {
else if (compilerSettings.YoptUnreachableCode) removeUnusedLocalVariableNodes(method)() // (*)
else false
- val lineNumbersRemoved = if (compilerSettings.YoptEmptyLineNumbers) removeEmptyLineNumbers(method) else false
+ val lineNumbersRemoved = if (compilerSettings.YoptUnreachableCode) removeEmptyLineNumbers(method) else false
- val labelsRemoved = if (compilerSettings.YoptEmptyLabels) removeEmptyLabelNodes(method) else false
+ val labelsRemoved = if (compilerSettings.YoptUnreachableCode) removeEmptyLabelNodes(method) else false
// assert that local variable annotations are empty (we don't emit them) - otherwise we'd have
// to eliminate those covering an empty range, similar to removeUnusedLocalVariableNodes.
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index cbd9ee1a55..794c0ba324 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -225,23 +225,21 @@ trait ScalaSettings extends AbsScalaSettings
val YskipInlineInfoAttribute = BooleanSetting("-Yskip-inline-info-attribute", "Do not add the ScalaInlineInfo attribute to classfiles generated by -Ybackend:GenASM")
object YoptChoices extends MultiChoiceEnumeration {
- val unreachableCode = Choice("unreachable-code", "Eliminate unreachable code, exception handlers protecting no instructions, debug information of eliminated variables.")
+ val unreachableCode = Choice("unreachable-code", "Eliminate unreachable code, exception handlers guarding no instructions, redundant metadata (debug information, line numbers).")
val simplifyJumps = Choice("simplify-jumps", "Simplify branching instructions, eliminate unnecessary ones.")
- val emptyLineNumbers = Choice("empty-line-numbers", "Eliminate unnecessary line number information.")
- val emptyLabels = Choice("empty-labels", "Eliminate and collapse redundant labels in the bytecode.")
val compactLocals = Choice("compact-locals", "Eliminate empty slots in the sequence of local variables.")
- val copyPropagation = Choice("copy-propagation", "Eliminate redundant local variables (locals that are copies of others).")
+ val copyPropagation = Choice("copy-propagation", "Eliminate redundant local variables and unused values (including closures). Enables unreachable-code.")
val nullnessTracking = Choice("nullness-tracking", "Track nullness / non-nullness of local variables and apply optimizations.")
- val closureElimination = Choice("closure-elimination" , "Rewrite closure invocations to the implementation method and eliminate closures.")
- val inlineProject = Choice("inline-project", "Inline only methods defined in the files being compiled.")
- val inlineGlobal = Choice("inline-global", "Inline methods from any source, including classfiles on the compile classpath.")
+ val closureInvocations = Choice("closure-invocations" , "Rewrite closure invocations to the implementation method.")
+ val inlineProject = Choice("inline-project", "Inline only methods defined in the files being compiled. Enables unreachable-code.")
+ val inlineGlobal = Choice("inline-global", "Inline methods from any source, including classfiles on the compile classpath. Enables unreachable-code.")
val lNone = Choice("l:none", "Don't enable any optimizations.")
private val defaultChoices = List(unreachableCode)
val lDefault = Choice("l:default", "Enable default optimizations: "+ defaultChoices.mkString(","), expandsTo = defaultChoices)
- private val methodChoices = List(unreachableCode, simplifyJumps, emptyLineNumbers, emptyLabels, compactLocals, copyPropagation, nullnessTracking, closureElimination)
+ private val methodChoices = List(unreachableCode, simplifyJumps, compactLocals, copyPropagation, nullnessTracking, closureInvocations)
val lMethod = Choice("l:method", "Enable intra-method optimizations: "+ methodChoices.mkString(","), expandsTo = methodChoices)
private val projectChoices = List(lMethod, inlineProject)
@@ -260,19 +258,17 @@ trait ScalaSettings extends AbsScalaSettings
def YoptNone = Yopt.isSetByUser && Yopt.value.isEmpty
def YoptUnreachableCode = !Yopt.isSetByUser || Yopt.contains(YoptChoices.unreachableCode)
def YoptSimplifyJumps = Yopt.contains(YoptChoices.simplifyJumps)
- def YoptEmptyLineNumbers = Yopt.contains(YoptChoices.emptyLineNumbers)
- def YoptEmptyLabels = Yopt.contains(YoptChoices.emptyLabels)
def YoptCompactLocals = Yopt.contains(YoptChoices.compactLocals)
def YoptCopyPropagation = Yopt.contains(YoptChoices.copyPropagation)
def YoptNullnessTracking = Yopt.contains(YoptChoices.nullnessTracking)
- def YoptClosureElimination = Yopt.contains(YoptChoices.closureElimination)
+ def YoptClosureInvocations = Yopt.contains(YoptChoices.closureInvocations)
def YoptInlineProject = Yopt.contains(YoptChoices.inlineProject)
def YoptInlineGlobal = Yopt.contains(YoptChoices.inlineGlobal)
def YoptInlinerEnabled = YoptInlineProject || YoptInlineGlobal
- def YoptBuildCallGraph = YoptInlinerEnabled || YoptClosureElimination
- def YoptAddToBytecodeRepository = YoptBuildCallGraph || YoptInlinerEnabled || YoptClosureElimination
+ def YoptBuildCallGraph = YoptInlinerEnabled || YoptClosureInvocations
+ def YoptAddToBytecodeRepository = YoptBuildCallGraph || YoptInlinerEnabled || YoptClosureInvocations
val YoptInlineHeuristics = ChoiceSetting(
name = "-Yopt-inline-heuristics",