@@ -3,10 +3,12 @@ package transform.localopt
33
44import core .Contexts .Context
55import core .DenotTransformers .IdentityDenotTransformer
6+ import core .Symbols ._
67import core .Types ._
8+ import core .Flags ._
9+ import core .Decorators ._
710import transform .TreeTransforms .{MiniPhaseTransform , TransformerInfo }
811import config .Printers .simplify
9- import core .Flags ._
1012import ast .tpd
1113
1214/** This phase consists of a series of small, simple, local optimisations
@@ -26,14 +28,17 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
2628 override def phaseName : String = " simplify"
2729 override val cpy = tpd.cpy
2830
31+ private [localopt] var SeqFactoryClass : Symbol = null
32+ private [localopt] var CommutativePrimitiveOperations : Set [Symbol ] = null
33+
2934 /** The original intention is to run most optimizations both before and after erasure.
3035 * Erasure creates new inefficiencies as well as new optimization opportunities.
3136 *
3237 * The order of optimizations is tuned to converge faster.
3338 * Reordering them may require quadratically more rounds to finish.
3439 */
3540 private def beforeErasure : List [Optimisation ] =
36- new InlineCaseIntrinsics ::
41+ new InlineCaseIntrinsics ( this ) ::
3742 new RemoveUnnecessaryNullChecks ::
3843 new InlineOptions ::
3944 new InlineLabelsCalledOnce ::
@@ -45,7 +50,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
4550 // new InlineLocalObjects :: // followCases needs to be fixed, see ./tests/pos/rbtree.scala
4651 // new Varify :: // varify could stop other transformations from being applied. postponed.
4752 // new BubbleUpNothing ::
48- new ConstantFold ::
53+ new ConstantFold ( this ) ::
4954 Nil
5055
5156 /** See comment on beforeErasure */
@@ -54,7 +59,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
5459 new Devalify ::
5560 new Jumpjump ::
5661 new DropGoodCasts ::
57- new ConstantFold ::
62+ new ConstantFold ( this ) ::
5863 Nil
5964
6065 /** Optimisation fuel, for debugging. Decremented every time Simplify
@@ -68,6 +73,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
6873 var fuel : Int = - 1
6974
7075 override def prepareForUnit (tree : Tree )(implicit ctx : Context ) = {
76+ SeqFactoryClass = ctx.requiredClass(" scala.collection.generic.SeqFactory" )
77+ CommutativePrimitiveOperations = Set (defn.Boolean_&& , defn.Boolean_|| , defn.Int_+ , defn.Int_* , defn.Long_+ , defn.Long_* )
7178 val maxFuel = ctx.settings.YoptFuel .value
7279 if (fuel < 0 && maxFuel > 0 ) // Both defaults are at -1
7380 fuel = maxFuel
0 commit comments