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

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

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