| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Generate code using the cps-based IR pipeline. | 5 /// Generate code using the cps-based IR pipeline. |
| 6 library code_generator_task; | 6 library code_generator_task; |
| 7 | 7 |
| 8 import 'glue.dart'; | 8 import 'glue.dart'; |
| 9 import 'codegen.dart'; | 9 import 'codegen.dart'; |
| 10 import 'unsugar.dart'; | 10 import 'unsugar.dart'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 void applyCpsPass(cps_opt.Pass pass, cps.FunctionDefinition cpsFunction) { | 134 void applyCpsPass(cps_opt.Pass pass, cps.FunctionDefinition cpsFunction) { |
| 135 cpsOptimizationTask.measureSubtask(pass.passName, () { | 135 cpsOptimizationTask.measureSubtask(pass.passName, () { |
| 136 pass.rewrite(cpsFunction); | 136 pass.rewrite(cpsFunction); |
| 137 }); | 137 }); |
| 138 traceGraph(pass.passName, cpsFunction); | 138 traceGraph(pass.passName, cpsFunction); |
| 139 dumpTypedIr(pass.passName, cpsFunction); | 139 dumpTypedIr(pass.passName, cpsFunction); |
| 140 assert(checkCpsIntegrity(cpsFunction, pass.passName)); | 140 assert(checkCpsIntegrity(cpsFunction, pass.passName)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 cps.FunctionDefinition compileToCpsIr(AstElement element) { | 143 cps.FunctionDefinition compileToCpsIr(AstElement element) { |
| 144 cps.FunctionDefinition cpsFunction = | 144 cps.FunctionDefinition cpsFunction = inliner.cache.getUnoptimized(element); |
| 145 cpsBuilderTask.buildNode(element, typeSystem); | 145 if (cpsFunction != null) return cpsFunction; |
| 146 |
| 147 cpsFunction = cpsBuilderTask.buildNode(element, typeSystem); |
| 146 if (cpsFunction == null) { | 148 if (cpsFunction == null) { |
| 147 if (cpsBuilderTask.bailoutMessage == null) { | 149 if (cpsBuilderTask.bailoutMessage == null) { |
| 148 giveUp('unable to build cps definition of $element'); | 150 giveUp('unable to build cps definition of $element'); |
| 149 } else { | 151 } else { |
| 150 giveUp(cpsBuilderTask.bailoutMessage); | 152 giveUp(cpsBuilderTask.bailoutMessage); |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 ParentVisitor.setParents(cpsFunction); | 155 ParentVisitor.setParents(cpsFunction); |
| 154 traceGraph('IR Builder', cpsFunction); | 156 traceGraph('IR Builder', cpsFunction); |
| 155 dumpTypedIr('IR Builder', cpsFunction); | 157 dumpTypedIr('IR Builder', cpsFunction); |
| 156 // Eliminating redundant phis before the unsugaring pass will make it | 158 // Eliminating redundant phis before the unsugaring pass will make it |
| 157 // insert fewer getInterceptor calls. | 159 // insert fewer getInterceptor calls. |
| 158 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); | 160 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); |
| 159 applyCpsPass(new UnsugarVisitor(glue), cpsFunction); | 161 applyCpsPass(new UnsugarVisitor(glue), cpsFunction); |
| 162 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); |
| 163 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); |
| 164 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction); |
| 165 |
| 166 inliner.cache.putUnoptimized(element, cpsFunction); |
| 160 return cpsFunction; | 167 return cpsFunction; |
| 161 } | 168 } |
| 162 | 169 |
| 163 static const Pattern PRINT_TYPED_IR_FILTER = null; | 170 static const Pattern PRINT_TYPED_IR_FILTER = null; |
| 164 | 171 |
| 165 String formatTypeMask(TypeMask type) { | 172 String formatTypeMask(TypeMask type) { |
| 166 if (type is UnionTypeMask) { | 173 if (type is UnionTypeMask) { |
| 167 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; | 174 return '[${type.disjointMasks.map(formatTypeMask).join(', ')}]'; |
| 168 } else if (type is FlatTypeMask) { | 175 } else if (type is FlatTypeMask) { |
| 169 if (type.isEmpty) { | 176 if (type.isEmpty) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (cpsIntegrityChecker == null) { | 208 if (cpsIntegrityChecker == null) { |
| 202 cpsIntegrityChecker = new CheckCpsIntegrity(); | 209 cpsIntegrityChecker = new CheckCpsIntegrity(); |
| 203 } | 210 } |
| 204 cpsIntegrityChecker.check(node, previousPass); | 211 cpsIntegrityChecker.check(node, previousPass); |
| 205 }); | 212 }); |
| 206 return true; // So this can be used from assert(). | 213 return true; // So this can be used from assert(). |
| 207 } | 214 } |
| 208 | 215 |
| 209 void optimizeCpsBeforeInlining(cps.FunctionDefinition cpsFunction) { | 216 void optimizeCpsBeforeInlining(cps.FunctionDefinition cpsFunction) { |
| 210 cpsOptimizationTask.measure(() { | 217 cpsOptimizationTask.measure(() { |
| 211 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); | |
| 212 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); | |
| 213 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction); | |
| 214 applyCpsPass(new TypePropagator(this), cpsFunction); | 218 applyCpsPass(new TypePropagator(this), cpsFunction); |
| 215 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); | 219 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); |
| 216 applyCpsPass(new ShrinkingReducer(), cpsFunction); | 220 applyCpsPass(new ShrinkingReducer(), cpsFunction); |
| 217 }); | 221 }); |
| 218 } | 222 } |
| 219 | 223 |
| 220 void optimizeCpsAfterInlining(cps.FunctionDefinition cpsFunction) { | 224 void optimizeCpsAfterInlining(cps.FunctionDefinition cpsFunction) { |
| 221 cpsOptimizationTask.measure(() { | 225 cpsOptimizationTask.measure(() { |
| 222 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); | 226 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); |
| 223 applyCpsPass(new ShrinkingReducer(), cpsFunction); | 227 applyCpsPass(new ShrinkingReducer(), cpsFunction); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 treeOptimizationTask] | 306 treeOptimizationTask] |
| 303 ..addAll(fallbackCompiler.tasks); | 307 ..addAll(fallbackCompiler.tasks); |
| 304 } | 308 } |
| 305 | 309 |
| 306 js.Node attachPosition(js.Node node, AstElement element) { | 310 js.Node attachPosition(js.Node node, AstElement element) { |
| 307 return node.withSourceInformation( | 311 return node.withSourceInformation( |
| 308 sourceInformationFactory.createBuilderForContext(element) | 312 sourceInformationFactory.createBuilderForContext(element) |
| 309 .buildDeclaration(element)); | 313 .buildDeclaration(element)); |
| 310 } | 314 } |
| 311 } | 315 } |
| OLD | NEW |