summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-03-30 16:19:25 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-04-01 08:35:32 +0200
commit638ed9108f10bcbebb69f2fefe05c7423c8bdfd7 (patch)
tree5d5f091be9e720df20ba18df87090ca4a95de19c /src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
parenteb43d62b4e0665b6b509a04d4ec2edae53c9256b (diff)
downloadscala-638ed9108f10bcbebb69f2fefe05c7423c8bdfd7.tar.gz
scala-638ed9108f10bcbebb69f2fefe05c7423c8bdfd7.tar.bz2
scala-638ed9108f10bcbebb69f2fefe05c7423c8bdfd7.zip
Clean up the way compiler settings are accessed in the backend.
Many backend components don't have access to the compiler instance holding the settings. Before this change, individual settings required in these parts of the backend were made available as members of trait BTypes, implemented in the subclass BTypesFromSymbols (which has access to global). This change exposes a single value of type ScalaSettings in the super trait BTypes, which gives access to all compiler settings.
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala23
1 files changed, 14 insertions, 9 deletions
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 fb5cfeb167..5f51a94673 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
@@ -14,7 +14,6 @@ import scala.tools.asm.tree._
import scala.collection.convert.decorateAsScala._
import scala.tools.nsc.backend.jvm.BTypes.InternalName
import scala.tools.nsc.backend.jvm.opt.BytecodeUtils._
-import scala.tools.nsc.settings.ScalaSettings
/**
* Optimizations within a single method.
@@ -47,7 +46,10 @@ import scala.tools.nsc.settings.ScalaSettings
* stale labels
* - eliminate labels that are not referenced, merge sequences of label definitions.
*/
-class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mutable.Set[MethodNode]) {
+class LocalOpt[BT <: BTypes](val btypes: BT) {
+ import LocalOptImpls._
+ import btypes._
+
/**
* Remove unreachable code from a method.
*
@@ -88,7 +90,7 @@ class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mu
* @return `true` if unreachable code was eliminated in some method, `false` otherwise.
*/
def methodOptimizations(clazz: ClassNode): Boolean = {
- !settings.YoptNone && clazz.methods.asScala.foldLeft(false) {
+ !compilerSettings.YoptNone && clazz.methods.asScala.foldLeft(false) {
case (changed, method) => methodOptimizations(method, clazz.name) || changed
}
}
@@ -137,7 +139,7 @@ class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mu
def removalRound(): Boolean = {
// unreachable-code, empty-handlers and simplify-jumps run until reaching a fixpoint (see doc on class LocalOpt)
- val (codeRemoved, handlersRemoved, liveHandlerRemoved) = if (settings.YoptUnreachableCode) {
+ val (codeRemoved, handlersRemoved, liveHandlerRemoved) = if (compilerSettings.YoptUnreachableCode) {
val (removedInstructions, liveLabels) = removeUnreachableCodeImpl(method, ownerClassName)
val removedHandlers = removeEmptyExceptionHandlers(method)
(removedInstructions.nonEmpty, removedHandlers.nonEmpty, removedHandlers.exists(h => liveLabels(h.start)))
@@ -145,7 +147,7 @@ class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mu
(false, false, false)
}
- val jumpsChanged = if (settings.YoptSimplifyJumps) simplifyJumps(method) else false
+ val jumpsChanged = if (compilerSettings.YoptSimplifyJumps) simplifyJumps(method) else false
// Eliminating live handlers and simplifying jump instructions may render more code
// unreachable, so we need to run another round.
@@ -158,13 +160,13 @@ class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mu
// (*) Removing stale local variable descriptors is required for correctness of unreachable-code
val localsRemoved =
- if (settings.YoptCompactLocals) compactLocalVariables(method) // also removes unused
- else if (settings.YoptUnreachableCode) removeUnusedLocalVariableNodes(method)() // (*)
+ if (compilerSettings.YoptCompactLocals) compactLocalVariables(method) // also removes unused
+ else if (compilerSettings.YoptUnreachableCode) removeUnusedLocalVariableNodes(method)() // (*)
else false
- val lineNumbersRemoved = if (settings.YoptEmptyLineNumbers) removeEmptyLineNumbers(method) else false
+ val lineNumbersRemoved = if (compilerSettings.YoptEmptyLineNumbers) removeEmptyLineNumbers(method) else false
- val labelsRemoved = if (settings.YoptEmptyLabels) removeEmptyLabelNodes(method) else false
+ val labelsRemoved = if (compilerSettings.YoptEmptyLabels) 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.
@@ -177,6 +179,9 @@ class LocalOpt(settings: ScalaSettings, unreachableCodeEliminated: collection.mu
codeHandlersOrJumpsChanged || localsRemoved || lineNumbersRemoved || labelsRemoved
}
+}
+
+object LocalOptImpls {
/**
* Removes unreachable basic blocks.
*