| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 interface OptimizationPhase { | 5 interface OptimizationPhase { |
| 6 String get name(); | 6 String get name(); |
| 7 void visitGraph(HGraph graph); | 7 void visitGraph(HGraph graph); |
| 8 } | 8 } |
| 9 | 9 |
| 10 class SsaOptimizerTask extends CompilerTask { | 10 class SsaOptimizerTask extends CompilerTask { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 new SsaDeadPhiEliminator(), | 28 new SsaDeadPhiEliminator(), |
| 29 new SsaGlobalValueNumberer(compiler), | 29 new SsaGlobalValueNumberer(compiler), |
| 30 new SsaCodeMotion(), | 30 new SsaCodeMotion(), |
| 31 new SsaDeadCodeEliminator()]; | 31 new SsaDeadCodeEliminator()]; |
| 32 runPhases(graph, phases); | 32 runPhases(graph, phases); |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) { | 36 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) { |
| 37 return measure(() { | 37 return measure(() { |
| 38 // Run the phases that will generate type guards. We must also run | 38 // Run the phases that will generate type guards. |
| 39 // [SsaCheckInserter] because the type propagator also propagates | |
| 40 // types non-speculatively. For example, it propagates the type | |
| 41 // array for a call to the List constructor. | |
| 42 List<OptimizationPhase> phases = <OptimizationPhase>[ | 39 List<OptimizationPhase> phases = <OptimizationPhase>[ |
| 43 new SsaSpeculativeTypePropagator(compiler), | 40 new SsaSpeculativeTypePropagator(compiler), |
| 44 new SsaTypeGuardBuilder(compiler, work), | 41 new SsaTypeGuardBuilder(compiler, work), |
| 42 // Change the propagated types back to what they were before we |
| 43 // speculatively propagated, so that we can generate the bailout |
| 44 // version. |
| 45 // Note that we do this even if there were no guards inserted. If a |
| 46 // guard is not beneficial enough we don't emit one, but there might |
| 47 // still be speculative types on the instructions. |
| 48 new SsaTypePropagator(compiler), |
| 49 // Then run the [SsaCheckInserter] because the type propagator also |
| 50 // propagated types non-speculatively. For example, it might have |
| 51 // propagated the type array for a call to the List constructor. |
| 45 new SsaCheckInserter(compiler)]; | 52 new SsaCheckInserter(compiler)]; |
| 46 runPhases(graph, phases); | 53 runPhases(graph, phases); |
| 47 return !work.guards.isEmpty(); | 54 return !work.guards.isEmpty(); |
| 48 }); | 55 }); |
| 49 } | 56 } |
| 50 | 57 |
| 51 void prepareForSpeculativeOptimizations(WorkItem work, HGraph graph) { | 58 void prepareForSpeculativeOptimizations(WorkItem work, HGraph graph) { |
| 52 measure(() { | 59 measure(() { |
| 53 // In order to generate correct code for the bailout version, we did not | 60 // In order to generate correct code for the bailout version, we did not |
| 54 // propagate types from the instruction to the type guard. We do it | 61 // propagate types from the instruction to the type guard. We do it |
| 55 // now to be able to optimize further. | 62 // now to be able to optimize further. |
| 56 work.guards.forEach((HTypeGuard guard) { | 63 work.guards.forEach((HTypeGuard guard) { guard.isOn = true; }); |
| 57 guard.propagatedType = guard.guarded.propagatedType; | |
| 58 guard.guarded.propagatedType = HType.UNKNOWN; | |
| 59 }); | |
| 60 // We also need to insert range and integer checks for the type guards, | 64 // We also need to insert range and integer checks for the type guards, |
| 61 // now that they know their type. We did not need to do that | 65 // now that they know their type. We did not need to do that |
| 62 // before because instructions that reference a guard would | 66 // before because instructions that reference a guard would |
| 63 // have not tried to use, e.g. native array access, since the | 67 // have not tried to use, e.g. native array access, since the |
| 64 // guard was not typed. | 68 // guard was not typed. |
| 65 runPhases(graph, <OptimizationPhase>[new SsaCheckInserter(compiler)]); | 69 runPhases(graph, <OptimizationPhase>[new SsaCheckInserter(compiler)]); |
| 66 }); | 70 }); |
| 67 } | 71 } |
| 68 } | 72 } |
| 69 | 73 |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 716 } |
| 713 } | 717 } |
| 714 if (!canBeMoved) continue; | 718 if (!canBeMoved) continue; |
| 715 | 719 |
| 716 // This is safe because we are running after GVN. | 720 // This is safe because we are running after GVN. |
| 717 // TODO(ngeoffray): ensure GVN has been run. | 721 // TODO(ngeoffray): ensure GVN has been run. |
| 718 set_.add(current); | 722 set_.add(current); |
| 719 } | 723 } |
| 720 } | 724 } |
| 721 } | 725 } |
| OLD | NEW |