| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
| 8 String get name; | 8 String get name; |
| 9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
| 10 } | 10 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 }); | 66 }); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { | 69 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { |
| 70 if (work.element.isField()) { | 70 if (work.element.isField()) { |
| 71 // Lazy initializers may not have bailout methods. | 71 // Lazy initializers may not have bailout methods. |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 JavaScriptItemCompilationContext context = work.compilationContext; | 74 JavaScriptItemCompilationContext context = work.compilationContext; |
| 75 return measure(() { | 75 return measure(() { |
| 76 SsaTypeGuardInserter inserter = new SsaTypeGuardInserter(compiler, work); |
| 77 |
| 76 // Run the phases that will generate type guards. | 78 // Run the phases that will generate type guards. |
| 77 List<OptimizationPhase> phases = <OptimizationPhase>[ | 79 List<OptimizationPhase> phases = <OptimizationPhase>[ |
| 78 new SsaTypeGuardInserter(compiler, work), | 80 inserter, |
| 79 new SsaEnvironmentBuilder(compiler), | 81 new SsaEnvironmentBuilder(compiler), |
| 80 // Then run the [SsaCheckInserter] because the type propagator also | 82 // Then run the [SsaCheckInserter] because the type propagator also |
| 81 // propagated types non-speculatively. For example, it might have | 83 // propagated types non-speculatively. For example, it might have |
| 82 // propagated the type array for a call to the List constructor. | 84 // propagated the type array for a call to the List constructor. |
| 83 new SsaCheckInserter(backend, work, context.boundsChecked)]; | 85 new SsaCheckInserter(backend, work, context.boundsChecked)]; |
| 84 runPhases(graph, phases); | 86 runPhases(graph, phases); |
| 87 |
| 88 if (work.guards.isEmpty && inserter.hasInsertedChecks) { |
| 89 // If there is no guard, and we have inserted type checks |
| 90 // instead, we can do the optimizations right away and avoid |
| 91 // the bailout method. |
| 92 optimize(work, graph, false); |
| 93 } |
| 85 return !work.guards.isEmpty; | 94 return !work.guards.isEmpty; |
| 86 }); | 95 }); |
| 87 } | 96 } |
| 88 | 97 |
| 89 void prepareForSpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { | 98 void prepareForSpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { |
| 90 JavaScriptItemCompilationContext context = work.compilationContext; | 99 JavaScriptItemCompilationContext context = work.compilationContext; |
| 91 measure(() { | 100 measure(() { |
| 92 // In order to generate correct code for the bailout version, we did not | 101 // In order to generate correct code for the bailout version, we did not |
| 93 // propagate types from the instruction to the type guard. We do it | 102 // propagate types from the instruction to the type guard. We do it |
| 94 // now to be able to optimize further. | 103 // now to be able to optimize further. |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 HBasicBlock block = user.block; | 1706 HBasicBlock block = user.block; |
| 1698 block.addAfter(user, interceptor); | 1707 block.addAfter(user, interceptor); |
| 1699 block.rewrite(user, interceptor); | 1708 block.rewrite(user, interceptor); |
| 1700 block.remove(user); | 1709 block.remove(user); |
| 1701 | 1710 |
| 1702 // The interceptor will be removed in the dead code elimination | 1711 // The interceptor will be removed in the dead code elimination |
| 1703 // phase. Note that removing it here would not work because of how | 1712 // phase. Note that removing it here would not work because of how |
| 1704 // the [visitBasicBlock] is implemented. | 1713 // the [visitBasicBlock] is implemented. |
| 1705 } | 1714 } |
| 1706 } | 1715 } |
| OLD | NEW |