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 20 matching lines...) Expand all Loading... |
31 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; | 31 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; |
32 import '../../cps_ir/optimizers.dart'; | 32 import '../../cps_ir/optimizers.dart'; |
33 import '../../cps_ir/optimizers.dart' as cps_opt; | 33 import '../../cps_ir/optimizers.dart' as cps_opt; |
34 import '../../tracer.dart'; | 34 import '../../tracer.dart'; |
35 import '../../js_backend/codegen/codegen.dart'; | 35 import '../../js_backend/codegen/codegen.dart'; |
36 import '../../ssa/ssa.dart' as ssa; | 36 import '../../ssa/ssa.dart' as ssa; |
37 import '../../tree_ir/optimization/optimization.dart'; | 37 import '../../tree_ir/optimization/optimization.dart'; |
38 import '../../tree_ir/optimization/optimization.dart' as tree_opt; | 38 import '../../tree_ir/optimization/optimization.dart' as tree_opt; |
39 import '../../tree_ir/tree_ir_integrity.dart'; | 39 import '../../tree_ir/tree_ir_integrity.dart'; |
40 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; | 40 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; |
| 41 import '../../cps_ir/type_mask_system.dart'; |
41 | 42 |
42 class CpsFunctionCompiler implements FunctionCompiler { | 43 class CpsFunctionCompiler implements FunctionCompiler { |
43 final ConstantSystem constantSystem; | 44 final ConstantSystem constantSystem; |
44 // TODO(karlklose): remove the compiler. | 45 // TODO(karlklose): remove the compiler. |
45 final Compiler compiler; | 46 final Compiler compiler; |
46 final Glue glue; | 47 final Glue glue; |
47 final SourceInformationStrategy sourceInformationFactory; | 48 final SourceInformationStrategy sourceInformationFactory; |
48 | 49 |
49 // TODO(karlklose,sigurdm): remove and update dart-doc of [compile]. | 50 // TODO(karlklose,sigurdm): remove and update dart-doc of [compile]. |
50 final FunctionCompiler fallbackCompiler; | 51 final FunctionCompiler fallbackCompiler; |
(...skipping 11 matching lines...) Expand all Loading... |
62 compiler = compiler, | 63 compiler = compiler, |
63 glue = new Glue(compiler); | 64 glue = new Glue(compiler); |
64 | 65 |
65 String get name => 'CPS Ir pipeline'; | 66 String get name => 'CPS Ir pipeline'; |
66 | 67 |
67 JavaScriptBackend get backend => compiler.backend; | 68 JavaScriptBackend get backend => compiler.backend; |
68 | 69 |
69 /// Generates JavaScript code for `work.element`. | 70 /// Generates JavaScript code for `work.element`. |
70 js.Fun compile(CodegenWorkItem work) { | 71 js.Fun compile(CodegenWorkItem work) { |
71 AstElement element = work.element; | 72 AstElement element = work.element; |
72 JavaScriptBackend backend = compiler.backend; | |
73 return compiler.withCurrentElement(element, () { | 73 return compiler.withCurrentElement(element, () { |
74 try { | 74 try { |
75 // TODO(karlklose): remove this fallback when we do not need it for | 75 // TODO(karlklose): remove this fallback when we do not need it for |
76 // testing anymore. | 76 // testing anymore. |
77 if (false) { | 77 if (false) { |
78 compiler.log('Using SSA compiler for platform element $element'); | 78 compiler.log('Using SSA compiler for platform element $element'); |
79 return fallbackCompiler.compile(work); | 79 return fallbackCompiler.compile(work); |
80 } | 80 } |
81 | 81 |
82 if (tracer != null) { | 82 if (tracer != null) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 | 164 |
165 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) { | 165 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) { |
166 // Transformations on the CPS IR. | 166 // Transformations on the CPS IR. |
167 void applyCpsPass(cps_opt.Pass pass) { | 167 void applyCpsPass(cps_opt.Pass pass) { |
168 pass.rewrite(cpsNode); | 168 pass.rewrite(cpsNode); |
169 traceGraph(pass.passName, cpsNode); | 169 traceGraph(pass.passName, cpsNode); |
170 assert(checkCpsIntegrity(cpsNode)); | 170 assert(checkCpsIntegrity(cpsNode)); |
171 } | 171 } |
172 | 172 |
| 173 TypeMaskSystem typeSystem = new TypeMaskSystem(compiler); |
| 174 |
173 applyCpsPass(new RedundantJoinEliminator()); | 175 applyCpsPass(new RedundantJoinEliminator()); |
174 applyCpsPass(new RedundantPhiEliminator()); | 176 applyCpsPass(new RedundantPhiEliminator()); |
175 applyCpsPass(new InsertRefinements(compiler.typesTask, compiler.world)); | 177 applyCpsPass(new InsertRefinements(typeSystem)); |
176 TypePropagator typePropagator = new TypePropagator(compiler, this); | 178 TypePropagator typePropagator = |
| 179 new TypePropagator(compiler, typeSystem, this); |
177 applyCpsPass(typePropagator); | 180 applyCpsPass(typePropagator); |
178 dumpTypedIR(cpsNode, typePropagator); | 181 dumpTypedIR(cpsNode, typePropagator); |
179 applyCpsPass(new RemoveRefinements()); | 182 applyCpsPass(new RemoveRefinements()); |
180 applyCpsPass(new ShrinkingReducer()); | 183 applyCpsPass(new ShrinkingReducer()); |
181 applyCpsPass(new ScalarReplacer(compiler)); | 184 applyCpsPass(new ScalarReplacer(compiler)); |
182 applyCpsPass(new MutableVariableEliminator()); | 185 applyCpsPass(new MutableVariableEliminator()); |
183 applyCpsPass(new RedundantJoinEliminator()); | 186 applyCpsPass(new RedundantJoinEliminator()); |
184 applyCpsPass(new RedundantPhiEliminator()); | 187 applyCpsPass(new RedundantPhiEliminator()); |
185 applyCpsPass(new ShrinkingReducer()); | 188 applyCpsPass(new ShrinkingReducer()); |
186 applyCpsPass(new LoopInvariantCodeMotion()); | 189 applyCpsPass(new LoopInvariantCodeMotion()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // TODO(sigurdm): Make a better list of tasks. | 240 // TODO(sigurdm): Make a better list of tasks. |
238 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 241 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
239 } | 242 } |
240 | 243 |
241 js.Node attachPosition(js.Node node, AstElement element) { | 244 js.Node attachPosition(js.Node node, AstElement element) { |
242 return node.withSourceInformation( | 245 return node.withSourceInformation( |
243 sourceInformationFactory.createBuilderForContext(element) | 246 sourceInformationFactory.createBuilderForContext(element) |
244 .buildDeclaration(element)); | 247 .buildDeclaration(element)); |
245 } | 248 } |
246 } | 249 } |
OLD | NEW |