| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 tracer.traceGraph(title, irObject); | 122 tracer.traceGraph(title, irObject); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void applyCpsPass(cps_opt.Pass pass, cps.FunctionDefinition cpsFunction) { | 126 void applyCpsPass(cps_opt.Pass pass, cps.FunctionDefinition cpsFunction) { |
| 127 cpsOptimizationTask.measureSubtask(pass.passName, () { | 127 cpsOptimizationTask.measureSubtask(pass.passName, () { |
| 128 pass.rewrite(cpsFunction); | 128 pass.rewrite(cpsFunction); |
| 129 }); | 129 }); |
| 130 traceGraph(pass.passName, cpsFunction); | 130 traceGraph(pass.passName, cpsFunction); |
| 131 dumpTypedIr(pass.passName, cpsFunction); | 131 dumpTypedIr(pass.passName, cpsFunction); |
| 132 assert(checkCpsIntegrity(cpsFunction)); | 132 assert(checkCpsIntegrity(cpsFunction, pass.passName)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 cps.FunctionDefinition compileToCpsIr(AstElement element) { | 135 cps.FunctionDefinition compileToCpsIr(AstElement element) { |
| 136 cps.FunctionDefinition cpsFunction = cpsBuilderTask.buildNode(element); | 136 cps.FunctionDefinition cpsFunction = cpsBuilderTask.buildNode(element); |
| 137 if (cpsFunction == null) { | 137 if (cpsFunction == null) { |
| 138 if (cpsBuilderTask.bailoutMessage == null) { | 138 if (cpsBuilderTask.bailoutMessage == null) { |
| 139 giveUp('unable to build cps definition of $element'); | 139 giveUp('unable to build cps definition of $element'); |
| 140 } else { | 140 } else { |
| 141 giveUp(cpsBuilderTask.bailoutMessage); | 141 giveUp(cpsBuilderTask.bailoutMessage); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 ParentVisitor.setParents(cpsFunction); |
| 144 traceGraph('IR Builder', cpsFunction); | 145 traceGraph('IR Builder', cpsFunction); |
| 145 dumpTypedIr('IR Builder', cpsFunction); | 146 dumpTypedIr('IR Builder', cpsFunction); |
| 146 // Eliminating redundant phis before the unsugaring pass will make it | 147 // Eliminating redundant phis before the unsugaring pass will make it |
| 147 // insert fewer getInterceptor calls. | 148 // insert fewer getInterceptor calls. |
| 148 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); | 149 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); |
| 149 applyCpsPass(new UnsugarVisitor(glue), cpsFunction); | 150 applyCpsPass(new UnsugarVisitor(glue), cpsFunction); |
| 150 return cpsFunction; | 151 return cpsFunction; |
| 151 } | 152 } |
| 152 | 153 |
| 153 static const Pattern PRINT_TYPED_IR_FILTER = null; | 154 static const Pattern PRINT_TYPED_IR_FILTER = null; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 177 return node is cps.Variable && node.type != null | 178 return node is cps.Variable && node.type != null |
| 178 ? '$s:${formatTypeMask(node.type)}' | 179 ? '$s:${formatTypeMask(node.type)}' |
| 179 : s; | 180 : s; |
| 180 } | 181 } |
| 181 DEBUG_MODE = true; | 182 DEBUG_MODE = true; |
| 182 print(';;; ==== After $passName ===='); | 183 print(';;; ==== After $passName ===='); |
| 183 print(new SExpressionStringifier(printType).visit(cpsFunction)); | 184 print(new SExpressionStringifier(printType).visit(cpsFunction)); |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 static bool checkCpsIntegrity(cps.FunctionDefinition node) { | 188 static bool checkCpsIntegrity(cps.FunctionDefinition node, String pass) { |
| 188 new CheckCpsIntegrity().check(node); | 189 new CheckCpsIntegrity().check(node, pass); |
| 189 return true; // So this can be used from assert(). | 190 return true; // So this can be used from assert(). |
| 190 } | 191 } |
| 191 | 192 |
| 192 cps.FunctionDefinition optimizeCpsIr(cps.FunctionDefinition cpsFunction) { | 193 cps.FunctionDefinition optimizeCpsIr(cps.FunctionDefinition cpsFunction) { |
| 193 TypeMaskSystem typeSystem = new TypeMaskSystem(compiler); | 194 TypeMaskSystem typeSystem = new TypeMaskSystem(compiler); |
| 194 | 195 |
| 195 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); | 196 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); |
| 196 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); | 197 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); |
| 197 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction); | 198 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction); |
| 198 applyCpsPass(new TypePropagator(compiler, typeSystem, this), cpsFunction); | 199 applyCpsPass(new TypePropagator(compiler, typeSystem, this), cpsFunction); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 treeOptimizationTask] | 264 treeOptimizationTask] |
| 264 ..addAll(fallbackCompiler.tasks); | 265 ..addAll(fallbackCompiler.tasks); |
| 265 } | 266 } |
| 266 | 267 |
| 267 js.Node attachPosition(js.Node node, AstElement element) { | 268 js.Node attachPosition(js.Node node, AstElement element) { |
| 268 return node.withSourceInformation( | 269 return node.withSourceInformation( |
| 269 sourceInformationFactory.createBuilderForContext(element) | 270 sourceInformationFactory.createBuilderForContext(element) |
| 270 .buildDeclaration(element)); | 271 .buildDeclaration(element)); |
| 271 } | 272 } |
| 272 } | 273 } |
| OLD | NEW |