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

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

Issue 718043004: cps-ir: Only use fallback compiler for platform functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../js_backend.dart';import '../../dart2jslib.dart'; 8 import '../js_backend.dart';import '../../dart2jslib.dart';
9 import '../../source_file.dart'; 9 import '../../source_file.dart';
10 import '../../cps_ir/cps_ir_nodes.dart' as cps; 10 import '../../cps_ir/cps_ir_nodes.dart' as cps;
(...skipping 10 matching lines...) Expand all
21 import '../../cps_ir/optimizers.dart'; 21 import '../../cps_ir/optimizers.dart';
22 import '../../tracer.dart'; 22 import '../../tracer.dart';
23 import '../../dart_backend/statement_rewriter.dart'; 23 import '../../dart_backend/statement_rewriter.dart';
24 import '../../dart_backend/copy_propagator.dart'; 24 import '../../dart_backend/copy_propagator.dart';
25 import '../../dart_backend/loop_rewriter.dart'; 25 import '../../dart_backend/loop_rewriter.dart';
26 import '../../dart_backend/logical_rewriter.dart'; 26 import '../../dart_backend/logical_rewriter.dart';
27 import '../../js_backend/codegen/codegen.dart'; 27 import '../../js_backend/codegen/codegen.dart';
28 import '../../ssa/ssa.dart' as ssa; 28 import '../../ssa/ssa.dart' as ssa;
29 29
30 class CspFunctionCompiler implements FunctionCompiler { 30 class CspFunctionCompiler implements FunctionCompiler {
31 final IrBuilderTask irBuilderTask;
32 final ConstantSystem constantSystem;
33 final Compiler compiler;
34
35 // TODO(karlklose,sigurm): remove and update dart-doc of [compile].
36 final FunctionCompiler fallbackCompiler;
31 37
32 // TODO(sigurdm): Assign this. 38 // TODO(sigurdm): Assign this.
33 Tracer tracer; 39 Tracer tracer;
34 40
35 String get name => 'CPS Ir pipeline';
36
37 final IrBuilderTask irBuilderTask;
38
39 final ConstantSystem constantSystem;
40
41 final Compiler compiler;
42
43 // Remember to update dart-doc of [compile] when this field is removed.
44 final FunctionCompiler fallbackCompiler;
45
46 CspFunctionCompiler(Compiler compiler, JavaScriptBackend backend) 41 CspFunctionCompiler(Compiler compiler, JavaScriptBackend backend)
47 : irBuilderTask = new IrBuilderTask(compiler), 42 : irBuilderTask = new IrBuilderTask(compiler),
48 fallbackCompiler = new ssa.SsaFunctionCompiler(backend), 43 fallbackCompiler = new ssa.SsaFunctionCompiler(backend),
49 constantSystem = backend.constantSystem, 44 constantSystem = backend.constantSystem,
50 compiler = compiler; 45 compiler = compiler;
51 46
47 String get name => 'CPS Ir pipeline';
48
52 /// Generates JavaScript code for `work.element`. First tries to use the 49 /// Generates JavaScript code for `work.element`. First tries to use the
53 /// Cps Ir -> tree ir -> js pipeline, and if that fails due to language 50 /// Cps Ir -> tree ir -> js pipeline, and if that fails due to language
54 /// features not implemented it will fall back to the ssa pipeline. 51 /// features not implemented it will fall back to the ssa pipeline (for
52 /// platform code) or will cancel compilation (for user code).
55 js.Fun compile(CodegenWorkItem work) { 53 js.Fun compile(CodegenWorkItem work) {
56 AstElement element = work.element; 54 AstElement element = work.element;
57 return compiler.withCurrentElement(element, () { 55 return compiler.withCurrentElement(element, () {
58 try { 56 try {
59 if (tracer != null) { 57 if (tracer != null) {
60 tracer.traceCompilation(element.name, null); 58 tracer.traceCompilation(element.name, null);
61 } 59 }
62 cps.FunctionDefinition cpsFunction = compileToCpsIR(element); 60 cps.FunctionDefinition cpsFunction = compileToCpsIR(element);
63 cpsFunction = optimizeCpsIR(cpsFunction); 61 cpsFunction = optimizeCpsIR(cpsFunction);
64 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction); 62 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction);
65 treeFunction = optimizeTreeIR(treeFunction); 63 treeFunction = optimizeTreeIR(treeFunction);
66 return compileToJavaScript(work, treeFunction); 64 return compileToJavaScript(work, treeFunction);
67 } on CodegenBailout catch (e) { 65 } on CodegenBailout catch (e) {
68 compiler.log('Falling back to SSA compiler for $element' 66 if (element.library.isPlatformLibrary) {
69 ' (${e.message})'); 67 compiler.log('Falling back to SSA compiler for $element'
70 return fallbackCompiler.compile(work); 68 ' (${e.message})');
69 return fallbackCompiler.compile(work);
70 } else {
71 String message = "Unable to compile $element with the new compiler.\n"
72 " Reason: ${e.message}";
73 compiler.internalError(element, message);
74 }
71 } 75 }
72 }); 76 });
73 } 77 }
74 78
75 void giveUp(String reason) { 79 void giveUp(String reason) {
76 throw new CodegenBailout(null, reason); 80 throw new CodegenBailout(null, reason);
77 } 81 }
78 82
79 void traceGraph(String title, var irObject) { 83 void traceGraph(String title, var irObject) {
80 if (tracer != null) { 84 if (tracer != null) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 SourceFile sourceFileOfElement(Element element) { 191 SourceFile sourceFileOfElement(Element element) {
188 return element.implementation.compilationUnit.script.file; 192 return element.implementation.compilationUnit.script.file;
189 } 193 }
190 194
191 js.Fun buildJavaScriptFunction(FunctionElement element, 195 js.Fun buildJavaScriptFunction(FunctionElement element,
192 List<js.Parameter> parameters, 196 List<js.Parameter> parameters,
193 js.Block body) { 197 js.Block body) {
194 return attachPosition(new js.Fun(parameters, body), element); 198 return attachPosition(new js.Fun(parameters, body), element);
195 } 199 }
196 } 200 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698