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

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

Issue 1537663002: dart2js: Initial implementation of inlining. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebaseline test expectations and fix a bug (typo). Created 5 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
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/pkg.status » ('j') | 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 'glue.dart'; 8 import 'glue.dart';
9 import 'codegen.dart'; 9 import 'codegen.dart';
10 import 'unsugar.dart'; 10 import 'unsugar.dart';
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 final FunctionCompiler fallbackCompiler; 59 final FunctionCompiler fallbackCompiler;
60 TypeMaskSystem typeSystem; 60 TypeMaskSystem typeSystem;
61 61
62 Tracer get tracer => compiler.tracer; 62 Tracer get tracer => compiler.tracer;
63 63
64 final IrBuilderTask cpsBuilderTask; 64 final IrBuilderTask cpsBuilderTask;
65 final GenericTask cpsOptimizationTask; 65 final GenericTask cpsOptimizationTask;
66 final GenericTask treeBuilderTask; 66 final GenericTask treeBuilderTask;
67 final GenericTask treeOptimizationTask; 67 final GenericTask treeOptimizationTask;
68 68
69 Inliner inliner;
70
69 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend, 71 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend,
70 SourceInformationStrategy sourceInformationFactory) 72 SourceInformationStrategy sourceInformationFactory)
71 : fallbackCompiler = 73 : fallbackCompiler =
72 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory), 74 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory),
73 cpsBuilderTask = new IrBuilderTask(compiler, sourceInformationFactory), 75 cpsBuilderTask = new IrBuilderTask(compiler, sourceInformationFactory),
74 this.sourceInformationFactory = sourceInformationFactory, 76 sourceInformationFactory = sourceInformationFactory,
75 constantSystem = backend.constantSystem, 77 constantSystem = backend.constantSystem,
76 compiler = compiler, 78 compiler = compiler,
77 glue = new Glue(compiler), 79 glue = new Glue(compiler),
78 cpsOptimizationTask = new GenericTask('CPS optimization', compiler), 80 cpsOptimizationTask = new GenericTask('CPS optimization', compiler),
79 treeBuilderTask = new GenericTask('Tree builder', compiler), 81 treeBuilderTask = new GenericTask('Tree builder', compiler),
80 treeOptimizationTask = new GenericTask('Tree optimization', compiler); 82 treeOptimizationTask = new GenericTask('Tree optimization', compiler) {
83 inliner = new Inliner(this);
84 }
81 85
82 String get name => 'CPS Ir pipeline'; 86 String get name => 'CPS Ir pipeline';
83 87
84 JavaScriptBackend get backend => compiler.backend; 88 JavaScriptBackend get backend => compiler.backend;
85 89
86 DiagnosticReporter get reporter => compiler.reporter; 90 DiagnosticReporter get reporter => compiler.reporter;
87 91
88 /// Generates JavaScript code for `work.element`. 92 /// Generates JavaScript code for `work.element`.
89 js.Fun compile(CodegenWorkItem work) { 93 js.Fun compile(CodegenWorkItem work) {
94 if (typeSystem == null) typeSystem = new TypeMaskSystem(compiler);
90 AstElement element = work.element; 95 AstElement element = work.element;
91 return reporter.withCurrentElement(element, () { 96 return reporter.withCurrentElement(element, () {
92 typeSystem = new TypeMaskSystem(compiler);
93 try { 97 try {
94 // TODO(karlklose): remove this fallback when we do not need it for 98 // TODO(karlklose): remove this fallback when we do not need it for
95 // testing anymore. 99 // testing anymore.
96 if (false) { 100 if (false) {
97 reporter.log('Using SSA compiler for platform element $element'); 101 reporter.log('Using SSA compiler for platform element $element');
98 return fallbackCompiler.compile(work); 102 return fallbackCompiler.compile(work);
99 } 103 }
100 104
101 if (tracer != null) { 105 if (tracer != null) {
102 tracer.traceCompilation(element.name, null); 106 tracer.traceCompilation(element.name, null);
103 } 107 }
104 cps.FunctionDefinition cpsFunction = compileToCpsIr(element); 108 cps.FunctionDefinition cpsFunction = compileToCpsIr(element);
105 cpsFunction = optimizeCpsIr(cpsFunction); 109 optimizeCpsBeforeInlining(cpsFunction);
110 applyCpsPass(inliner, cpsFunction);
111 optimizeCpsAfterInlining(cpsFunction);
106 cpsIntegrityChecker = null; 112 cpsIntegrityChecker = null;
107 tree_ir.FunctionDefinition treeFunction = compileToTreeIr(cpsFunction); 113 tree_ir.FunctionDefinition treeFunction = compileToTreeIr(cpsFunction);
108 treeFunction = optimizeTreeIr(treeFunction); 114 treeFunction = optimizeTreeIr(treeFunction);
109 return compileToJavaScript(work, treeFunction); 115 return compileToJavaScript(work, treeFunction);
110 } on CodegenBailout catch (e) { 116 } on CodegenBailout catch (e) {
111 String message = "Unable to compile $element with the new compiler.\n" 117 String message = "Unable to compile $element with the new compiler.\n"
112 " Reason: ${e.message}"; 118 " Reason: ${e.message}";
113 reporter.internalError(element, message); 119 reporter.internalError(element, message);
114 } 120 }
115 }); 121 });
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 bool checkCpsIntegrity(cps.FunctionDefinition node, String previousPass) { 199 bool checkCpsIntegrity(cps.FunctionDefinition node, String previousPass) {
194 cpsOptimizationTask.measureSubtask('Check integrity', () { 200 cpsOptimizationTask.measureSubtask('Check integrity', () {
195 if (cpsIntegrityChecker == null) { 201 if (cpsIntegrityChecker == null) {
196 cpsIntegrityChecker = new CheckCpsIntegrity(); 202 cpsIntegrityChecker = new CheckCpsIntegrity();
197 } 203 }
198 cpsIntegrityChecker.check(node, previousPass); 204 cpsIntegrityChecker.check(node, previousPass);
199 }); 205 });
200 return true; // So this can be used from assert(). 206 return true; // So this can be used from assert().
201 } 207 }
202 208
203 cps.FunctionDefinition optimizeCpsIr(cps.FunctionDefinition cpsFunction) { 209 void optimizeCpsBeforeInlining(cps.FunctionDefinition cpsFunction) {
204 cpsOptimizationTask.measure(() { 210 cpsOptimizationTask.measure(() {
205 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); 211 applyCpsPass(new RedundantJoinEliminator(), cpsFunction);
206 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); 212 applyCpsPass(new RedundantPhiEliminator(), cpsFunction);
207 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction); 213 applyCpsPass(new InsertRefinements(typeSystem), cpsFunction);
208 applyCpsPass(new TypePropagator(compiler, typeSystem, this), cpsFunction); 214 applyCpsPass(new TypePropagator(this), cpsFunction);
209 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); 215 applyCpsPass(new RedundantJoinEliminator(), cpsFunction);
210 applyCpsPass(new ShrinkingReducer(), cpsFunction); 216 applyCpsPass(new ShrinkingReducer(), cpsFunction);
217 });
218 }
219
220 void optimizeCpsAfterInlining(cps.FunctionDefinition cpsFunction) {
221 cpsOptimizationTask.measure(() {
211 applyCpsPass(new RedundantRefinementEliminator(typeSystem), cpsFunction); 222 applyCpsPass(new RedundantRefinementEliminator(typeSystem), cpsFunction);
212 applyCpsPass(new EagerlyLoadStatics(), cpsFunction); 223 applyCpsPass(new EagerlyLoadStatics(), cpsFunction);
213 applyCpsPass(new GVN(compiler, typeSystem), cpsFunction); 224 applyCpsPass(new GVN(compiler, typeSystem), cpsFunction);
214 applyCpsPass(new UpdateRefinements(typeSystem), cpsFunction); 225 applyCpsPass(new UpdateRefinements(typeSystem), cpsFunction);
215 applyCpsPass(new BoundsChecker(typeSystem, compiler.world), cpsFunction); 226 applyCpsPass(new BoundsChecker(typeSystem, compiler.world), cpsFunction);
216 applyCpsPass(new ShrinkingReducer(), cpsFunction); 227 applyCpsPass(new ShrinkingReducer(), cpsFunction);
217 applyCpsPass(new ScalarReplacer(compiler), cpsFunction); 228 applyCpsPass(new ScalarReplacer(compiler), cpsFunction);
218 applyCpsPass(new MutableVariableEliminator(), cpsFunction); 229 applyCpsPass(new MutableVariableEliminator(), cpsFunction);
219 applyCpsPass(new RedundantJoinEliminator(), cpsFunction); 230 applyCpsPass(new RedundantJoinEliminator(), cpsFunction);
220 applyCpsPass(new RedundantPhiEliminator(), cpsFunction); 231 applyCpsPass(new RedundantPhiEliminator(), cpsFunction);
221 applyCpsPass(new ShrinkingReducer(), cpsFunction); 232 applyCpsPass(new ShrinkingReducer(), cpsFunction);
222 applyCpsPass(new OptimizeInterceptors(backend), cpsFunction); 233 applyCpsPass(new OptimizeInterceptors(backend), cpsFunction);
223 applyCpsPass(new BackwardNullCheckRemover(typeSystem), cpsFunction); 234 applyCpsPass(new BackwardNullCheckRemover(typeSystem), cpsFunction);
224 applyCpsPass(new ShrinkingReducer(), cpsFunction); 235 applyCpsPass(new ShrinkingReducer(), cpsFunction);
225 }); 236 });
226 return cpsFunction;
227 } 237 }
228 238
229 tree_ir.FunctionDefinition compileToTreeIr(cps.FunctionDefinition cpsNode) { 239 tree_ir.FunctionDefinition compileToTreeIr(cps.FunctionDefinition cpsNode) {
230 applyCpsPass(new Finalize(backend), cpsNode); 240 applyCpsPass(new Finalize(backend), cpsNode);
231 tree_builder.Builder builder = new tree_builder.Builder( 241 tree_builder.Builder builder = new tree_builder.Builder(
232 reporter.internalError); 242 reporter.internalError);
233 tree_ir.FunctionDefinition treeNode = 243 tree_ir.FunctionDefinition treeNode =
234 treeBuilderTask.measure(() => builder.buildFunction(cpsNode)); 244 treeBuilderTask.measure(() => builder.buildFunction(cpsNode));
235 assert(treeNode != null); 245 assert(treeNode != null);
236 traceGraph('Tree builder', treeNode); 246 traceGraph('Tree builder', treeNode);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 treeOptimizationTask] 295 treeOptimizationTask]
286 ..addAll(fallbackCompiler.tasks); 296 ..addAll(fallbackCompiler.tasks);
287 } 297 }
288 298
289 js.Node attachPosition(js.Node node, AstElement element) { 299 js.Node attachPosition(js.Node node, AstElement element) {
290 return node.withSourceInformation( 300 return node.withSourceInformation(
291 sourceInformationFactory.createBuilderForContext(element) 301 sourceInformationFactory.createBuilderForContext(element)
292 .buildDeclaration(element)); 302 .buildDeclaration(element));
293 } 303 }
294 } 304 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698