| 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 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 { |
| 11 final JavaScriptBackend backend; | 11 final JavaScriptBackend backend; |
| 12 SsaOptimizerTask(JavaScriptBackend backend) | 12 SsaOptimizerTask(JavaScriptBackend backend) |
| 13 : this.backend = backend, | 13 : this.backend = backend, |
| 14 super(backend.compiler); | 14 super(backend.compiler); |
| 15 String get name() => 'SSA optimizer'; | 15 String get name => 'SSA optimizer'; |
| 16 Compiler get compiler() => backend.compiler; | 16 Compiler get compiler => backend.compiler; |
| 17 | 17 |
| 18 void runPhases(HGraph graph, List<OptimizationPhase> phases) { | 18 void runPhases(HGraph graph, List<OptimizationPhase> phases) { |
| 19 for (OptimizationPhase phase in phases) { | 19 for (OptimizationPhase phase in phases) { |
| 20 runPhase(graph, phase); | 20 runPhase(graph, phase); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 | 23 |
| 24 void runPhase(HGraph graph, OptimizationPhase phase) { | 24 void runPhase(HGraph graph, OptimizationPhase phase) { |
| 25 phase.visitGraph(graph); | 25 phase.visitGraph(graph); |
| 26 compiler.tracer.traceGraph(phase.name, graph); | 26 compiler.tracer.traceGraph(phase.name, graph); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 /** | 101 /** |
| 102 * If both inputs to known operations are available execute the operation at | 102 * If both inputs to known operations are available execute the operation at |
| 103 * compile-time. | 103 * compile-time. |
| 104 */ | 104 */ |
| 105 class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { | 105 class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { |
| 106 final String name = "SsaConstantFolder"; | 106 final String name = "SsaConstantFolder"; |
| 107 final JavaScriptBackend backend; | 107 final JavaScriptBackend backend; |
| 108 final WorkItem work; | 108 final WorkItem work; |
| 109 final HTypeMap types; | 109 final HTypeMap types; |
| 110 HGraph graph; | 110 HGraph graph; |
| 111 Compiler get compiler() => backend.compiler; | 111 Compiler get compiler => backend.compiler; |
| 112 | 112 |
| 113 SsaConstantFolder(this.backend, this.work, this.types); | 113 SsaConstantFolder(this.backend, this.work, this.types); |
| 114 | 114 |
| 115 void visitGraph(HGraph visitee) { | 115 void visitGraph(HGraph visitee) { |
| 116 graph = visitee; | 116 graph = visitee; |
| 117 visitDominatorTree(visitee); | 117 visitDominatorTree(visitee); |
| 118 } | 118 } |
| 119 | 119 |
| 120 visitBasicBlock(HBasicBlock block) { | 120 visitBasicBlock(HBasicBlock block) { |
| 121 HInstruction instruction = block.first; | 121 HInstruction instruction = block.first; |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 } | 1181 } |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 | 1184 |
| 1185 // Base class for the handling of recompilation based on inferred | 1185 // Base class for the handling of recompilation based on inferred |
| 1186 // field types. | 1186 // field types. |
| 1187 class BaseRecompilationVisitor extends HBaseVisitor { | 1187 class BaseRecompilationVisitor extends HBaseVisitor { |
| 1188 final JavaScriptBackend backend; | 1188 final JavaScriptBackend backend; |
| 1189 final WorkItem work; | 1189 final WorkItem work; |
| 1190 final HTypeMap types; | 1190 final HTypeMap types; |
| 1191 Compiler get compiler() => backend.compiler; | 1191 Compiler get compiler => backend.compiler; |
| 1192 | 1192 |
| 1193 BaseRecompilationVisitor(this.backend, this.work, this.types); | 1193 BaseRecompilationVisitor(this.backend, this.work, this.types); |
| 1194 | 1194 |
| 1195 abstract void handleFieldGet(HFieldGet node, HType type); | 1195 abstract void handleFieldGet(HFieldGet node, HType type); |
| 1196 abstract void handleFieldNumberOperation(HFieldGet field, HType type); | 1196 abstract void handleFieldNumberOperation(HFieldGet field, HType type); |
| 1197 | 1197 |
| 1198 // Checks if the binary invocation operates on a field and a | 1198 // Checks if the binary invocation operates on a field and a |
| 1199 // constant number. If it does [handleFieldNumberOperation] is | 1199 // constant number. If it does [handleFieldNumberOperation] is |
| 1200 // called with the field and the type inferred for the field so far. | 1200 // called with the field and the type inferred for the field so far. |
| 1201 void checkFieldNumberOperation(HInvokeBinary node) { | 1201 void checkFieldNumberOperation(HInvokeBinary node) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 // this type for the field is still a strong signal | 1331 // this type for the field is still a strong signal |
| 1332 // indicating the expected type of the field. | 1332 // indicating the expected type of the field. |
| 1333 types[field] = type; | 1333 types[field] = type; |
| 1334 } else { | 1334 } else { |
| 1335 // If there are no invoked setters we know the type of | 1335 // If there are no invoked setters we know the type of |
| 1336 // this field for sure. | 1336 // this field for sure. |
| 1337 field.guaranteedType = type; | 1337 field.guaranteedType = type; |
| 1338 } | 1338 } |
| 1339 } | 1339 } |
| 1340 } | 1340 } |
| OLD | NEW |