Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/task.dart

Issue 735253003: Add CPS IR transformation to make the JavaScript backend specific semantics explicit in the tree. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11
11 import '../js_backend.dart'; 12 import '../js_backend.dart';
12 import '../../dart2jslib.dart'; 13 import '../../dart2jslib.dart';
13 import '../../source_file.dart'; 14 import '../../source_file.dart';
14 import '../../cps_ir/cps_ir_nodes.dart' as cps; 15 import '../../cps_ir/cps_ir_nodes.dart' as cps;
15 import '../../cps_ir/cps_ir_builder.dart'; 16 import '../../cps_ir/cps_ir_builder.dart';
16 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 17 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
17 import '../../tree/tree.dart' as ast; 18 import '../../tree/tree.dart' as ast;
18 import '../../scanner/scannerlib.dart' as scanner; 19 import '../../scanner/scannerlib.dart' as scanner;
19 import '../../elements/elements.dart'; 20 import '../../elements/elements.dart';
20 import '../../closure.dart'; 21 import '../../closure.dart';
21 import '../../js/js.dart' as js; 22 import '../../js/js.dart' as js;
22 import '../../source_map_builder.dart'; 23 import '../../source_map_builder.dart';
23 import '../../tree_ir/tree_ir_builder.dart' as tree_builder; 24 import '../../tree_ir/tree_ir_builder.dart' as tree_builder;
24 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter; 25 import '../../dart_backend/backend_ast_emitter.dart' as backend_ast_emitter;
25 import '../../cps_ir/optimizers.dart'; 26 import '../../cps_ir/optimizers.dart';
26 import '../../tracer.dart'; 27 import '../../tracer.dart';
27 import '../../js_backend/codegen/codegen.dart'; 28 import '../../js_backend/codegen/codegen.dart';
28 import '../../ssa/ssa.dart' as ssa; 29 import '../../ssa/ssa.dart' as ssa;
29 import '../../tree_ir/optimization/optimization.dart'; 30 import '../../tree_ir/optimization/optimization.dart';
30 import '../../common.dart' show SelectorKind;
31 import '../../constants/expressions.dart';
32 import '../../constants/values.dart';
33
34 class JsBackendTreeBuilder extends tree_builder.Builder {
35 final Glue glue;
36
37 JsBackendTreeBuilder(Compiler compiler, this.glue) : super(compiler);
38
39 Selector get identicalSelector {
40 return new Selector(SelectorKind.CALL, 'identical', null, 2);
41 }
42
43 /// TOOD(karlklose): cache this?
44 tree_ir.Constant get constantTrue {
45 ConstantExpression trueValue =
46 new PrimitiveConstantExpression(new TrueConstantValue());
47 return new tree_ir.Constant(trueValue);
48 }
49
50 /**
51 * Boolean conversion maps any object o into a boolean. Boolean conversion is
52 * defined by the function application
53 * (bool v){
54 * assert(v != null);
55 * return identical(v, true);
56 * }(o)
57 */
58 tree_ir.Expression visitIsTrue(cps.IsTrue node) {
59 tree_ir.Expression value = getVariableReference(node.value);
60 /// TODO(karlklose): implement the assert(v != null) check.
61 return new tree_ir.InvokeStatic(
62 glue.identicalFunction,
63 identicalSelector,
64 <tree_ir.Expression>[value, constantTrue]);
65 }
66
67 }
68 31
69 class CspFunctionCompiler implements FunctionCompiler { 32 class CspFunctionCompiler implements FunctionCompiler {
70 final IrBuilderTask irBuilderTask; 33 final IrBuilderTask irBuilderTask;
71 final ConstantSystem constantSystem; 34 final ConstantSystem constantSystem;
72 final Compiler compiler; 35 final Compiler compiler;
73 final Glue glue; 36 final Glue glue;
74 37
75 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. 38 // TODO(karlklose,sigurm): remove and update dart-doc of [compile].
76 final FunctionCompiler fallbackCompiler; 39 final FunctionCompiler fallbackCompiler;
77 40
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (element.isGenerativeConstructorBody || 95 if (element.isGenerativeConstructorBody ||
133 element.enclosingClass is ClosureClassElement || 96 element.enclosingClass is ClosureClassElement ||
134 element.isNative) { 97 element.isNative) {
135 giveUp('unsupported element kind: ${element.name}:${element.kind}'); 98 giveUp('unsupported element kind: ${element.name}:${element.kind}');
136 } 99 }
137 100
138 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); 101 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element);
139 if (cpsNode == null) { 102 if (cpsNode == null) {
140 giveUp('unable to build cps definition of $element'); 103 giveUp('unable to build cps definition of $element');
141 } 104 }
105 const UnsugarVisitor().rewrite(cpsNode);
142 return cpsNode; 106 return cpsNode;
143 } 107 }
144 108
145 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) { 109 cps.FunctionDefinition optimizeCpsIR(cps.FunctionDefinition cpsNode) {
146 // Transformations on the CPS IR. 110 // Transformations on the CPS IR.
147 traceGraph("IR Builder", cpsNode); 111 traceGraph("IR Builder", cpsNode);
148 new ConstantPropagator(compiler, constantSystem) 112 new ConstantPropagator(compiler, constantSystem)
149 .rewrite(cpsNode); 113 .rewrite(cpsNode);
150 traceGraph("Sparse constant propagation", cpsNode); 114 traceGraph("Sparse constant propagation", cpsNode);
151 new RedundantPhiEliminator().rewrite(cpsNode); 115 new RedundantPhiEliminator().rewrite(cpsNode);
152 traceGraph("Redundant phi elimination", cpsNode); 116 traceGraph("Redundant phi elimination", cpsNode);
153 new ShrinkingReducer().rewrite(cpsNode); 117 new ShrinkingReducer().rewrite(cpsNode);
154 traceGraph("Shrinking reductions", cpsNode); 118 traceGraph("Shrinking reductions", cpsNode);
155 119
156 // Do not rewrite the IR after variable allocation. Allocation 120 // Do not rewrite the IR after variable allocation. Allocation
157 // makes decisions based on an approximation of IR variable live 121 // makes decisions based on an approximation of IR variable live
158 // ranges that can be invalidated by transforming the IR. 122 // ranges that can be invalidated by transforming the IR.
159 new cps.RegisterAllocator().visit(cpsNode); 123 new cps.RegisterAllocator().visit(cpsNode);
160 return cpsNode; 124 return cpsNode;
161 } 125 }
162 126
163 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) { 127 tree_ir.FunctionDefinition compileToTreeIR(cps.FunctionDefinition cpsNode) {
164 tree_builder.Builder builder = new JsBackendTreeBuilder(compiler, glue); 128 tree_builder.Builder builder = new tree_builder.Builder(compiler);
165 tree_ir.FunctionDefinition treeNode = builder.build(cpsNode); 129 tree_ir.FunctionDefinition treeNode = builder.build(cpsNode);
166 assert(treeNode != null); 130 assert(treeNode != null);
167 traceGraph('Tree builder', treeNode); 131 traceGraph('Tree builder', treeNode);
168 return treeNode; 132 return treeNode;
169 } 133 }
170 134
171 tree_ir.FunctionDefinition optimizeTreeIR( 135 tree_ir.FunctionDefinition optimizeTreeIR(
172 tree_ir.FunctionDefinition treeNode) { 136 tree_ir.FunctionDefinition treeNode) {
173 // Transformations on the Tree IR. 137 // Transformations on the Tree IR.
174 new StatementRewriter().rewrite(treeNode); 138 new StatementRewriter().rewrite(treeNode);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 new TokenSourceFileLocation(sourceFile, endToken, name); 188 new TokenSourceFileLocation(sourceFile, endToken, name);
225 } 189 }
226 return node.withPosition(sourcePosition, endSourcePosition); 190 return node.withPosition(sourcePosition, endSourcePosition);
227 } 191 }
228 192
229 SourceFile sourceFileOfElement(Element element) { 193 SourceFile sourceFileOfElement(Element element) {
230 return element.implementation.compilationUnit.script.file; 194 return element.implementation.compilationUnit.script.file;
231 } 195 }
232 196
233 } 197 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/shrinking_reductions.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/unsugar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698