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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1117223002: dart2js: Inline across deferred output units if that leads to reduced size. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 class SsaFunctionCompiler implements FunctionCompiler { 7 class SsaFunctionCompiler implements FunctionCompiler {
8 SsaCodeGeneratorTask generator; 8 SsaCodeGeneratorTask generator;
9 SsaBuilderTask builder; 9 SsaBuilderTask builder;
10 SsaOptimizerTask optimizer; 10 SsaOptimizerTask optimizer;
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 FunctionElement function = element; 1286 FunctionElement function = element;
1287 bool insideLoop = loopNesting > 0 || graph.calledInLoop; 1287 bool insideLoop = loopNesting > 0 || graph.calledInLoop;
1288 1288
1289 // Bail out early if the inlining decision is in the cache and we can't 1289 // Bail out early if the inlining decision is in the cache and we can't
1290 // inline (no need to check the hard constraints). 1290 // inline (no need to check the hard constraints).
1291 bool cachedCanBeInlined = 1291 bool cachedCanBeInlined =
1292 backend.inlineCache.canInline(function, insideLoop: insideLoop); 1292 backend.inlineCache.canInline(function, insideLoop: insideLoop);
1293 if (cachedCanBeInlined == false) return false; 1293 if (cachedCanBeInlined == false) return false;
1294 1294
1295 bool meetsHardConstraints() { 1295 bool meetsHardConstraints() {
1296 // Don't inline from one output unit to another. If something is deferred
1297 // it is to save space in the loading code.
floitsch 2015/05/04 23:32:58 this comment is incomplete: we must not inline cod
herhut 2015/05/05 14:19:12 I changed it to not inline across deferred imports
1298 if (!compiler.deferredLoadTask
1299 .inSameOutputUnit(element,compiler.currentElement)) {
1300 return false;
1301 }
1302 if (compiler.disableInlining) return false; 1296 if (compiler.disableInlining) return false;
1303 1297
1304 assert(selector != null 1298 assert(selector != null
1305 || Elements.isStaticOrTopLevel(element) 1299 || Elements.isStaticOrTopLevel(element)
1306 || element.isGenerativeConstructorBody); 1300 || element.isGenerativeConstructorBody);
1307 if (selector != null && !selector.applies(function, compiler.world)) { 1301 if (selector != null && !selector.applies(function, compiler.world)) {
1308 return false; 1302 return false;
1309 } 1303 }
1310 1304
1311 // Don't inline operator== methods if the parameter can be null. 1305 // Don't inline operator== methods if the parameter can be null.
(...skipping 25 matching lines...) Expand all
1337 return false; 1331 return false;
1338 } 1332 }
1339 } 1333 }
1340 1334
1341 return true; 1335 return true;
1342 } 1336 }
1343 1337
1344 bool reductiveHeuristic() { 1338 bool reductiveHeuristic() {
1345 // The call is on a path which is executed rarely, so inline only if it 1339 // The call is on a path which is executed rarely, so inline only if it
1346 // does not make the program larger. 1340 // does not make the program larger.
1347 if (isCalledOnce(element)) { 1341 if (isCalledOnce(element)) {
floitsch 2015/05/04 23:34:44 I guess we could inline empty methods from deferre
herhut 2015/05/05 14:19:12 Acknowledged.
1348 return InlineWeeder.canBeInlined(function, -1, false); 1342 return InlineWeeder.canBeInlined(function, -1, false);
1349 } 1343 }
1350 // TODO(sra): Measure if inlining would 'reduce' the size. One desirable 1344 // TODO(sra): Measure if inlining would 'reduce' the size. One desirable
1351 // case we miss my doing nothing is inlining very simple constructors 1345 // case we miss by doing nothing is inlining very simple constructors
1352 // where all fields are initialized with values from the arguments at this 1346 // where all fields are initialized with values from the arguments at this
1353 // call site. The code is slightly larger (`new Foo(1)` vs `Foo$(1)`) but 1347 // call site. The code is slightly larger (`new Foo(1)` vs `Foo$(1)`) but
1354 // that usually means the factory constructor is left unused and not 1348 // that usually means the factory constructor is left unused and not
1355 // emitted. 1349 // emitted.
1356 return false; 1350 // We at least inline bodies that are empty (and thus have a size of 1).
1351 return InlineWeeder.canBeInlined(function, 1, true);
1357 } 1352 }
1358 1353
1359 bool heuristicSayGoodToGo() { 1354 bool heuristicSayGoodToGo() {
1360 // Don't inline recursively 1355 // Don't inline recursively
1361 if (inliningStack.any((entry) => entry.function == function)) { 1356 if (inliningStack.any((entry) => entry.function == function)) {
1362 return false; 1357 return false;
1363 } 1358 }
1364 1359
1365 if (element.isSynthesized) return true; 1360 if (element.isSynthesized) return true;
1366 1361
1367 if (inExpressionOfThrow || inLazyInitializerExpression) { 1362 // Don't inline from one output unit to another, unless it reduces size.
1363 // Similarly do not inline code that is rarely executed.
1364 bool fromDifferentOutputUnit = !compiler.deferredLoadTask
1365 .inSameOutputUnit(element,compiler.currentElement);
1366
1367 if (inExpressionOfThrow ||
1368 inLazyInitializerExpression ||
1369 fromDifferentOutputUnit) {
1368 return reductiveHeuristic(); 1370 return reductiveHeuristic();
1369 } 1371 }
1370 1372
1371 if (cachedCanBeInlined == true) { 1373 if (cachedCanBeInlined == true) {
1372 // We may have forced the inlining of some methods. Therefore check 1374 // We may have forced the inlining of some methods. Therefore check
1373 // if we can inline this method regardless of size. 1375 // if we can inline this method regardless of size.
1374 assert(InlineWeeder.canBeInlined(function, -1, false, 1376 assert(InlineWeeder.canBeInlined(function, -1, false,
1375 allowLoops: true)); 1377 allowLoops: true));
1376 return true; 1378 return true;
1377 } 1379 }
(...skipping 6209 matching lines...) Expand 10 before | Expand all | Expand 10 after
7587 if (unaliased is TypedefType) throw 'unable to unalias $type'; 7589 if (unaliased is TypedefType) throw 'unable to unalias $type';
7588 unaliased.accept(this, builder); 7590 unaliased.accept(this, builder);
7589 } 7591 }
7590 7592
7591 void visitDynamicType(DynamicType type, SsaBuilder builder) { 7593 void visitDynamicType(DynamicType type, SsaBuilder builder) {
7592 JavaScriptBackend backend = builder.compiler.backend; 7594 JavaScriptBackend backend = builder.compiler.backend;
7593 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 7595 ClassElement cls = backend.findHelper('DynamicRuntimeType');
7594 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 7596 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
7595 } 7597 }
7596 } 7598 }
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