OLD | NEW |
---|---|
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 Loading... | |
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. | |
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 29 matching lines...) Expand all Loading... | |
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)) { |
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); | |
sra1
2015/05/06 20:49:56
Call doesNotContainCode below?
herhut
2015/05/26 14:26:29
Done in https://codereview.chromium.org/1159813002
| |
1352 } | |
1353 | |
1354 bool doesNotContainCode() { | |
1355 // A function with size 1 does not contain any code. | |
1356 return InlineWeeder.canBeInlined(function, 1, true); | |
1357 } | 1357 } |
1358 | 1358 |
1359 bool heuristicSayGoodToGo() { | 1359 bool heuristicSayGoodToGo() { |
1360 // Don't inline recursively | 1360 // Don't inline recursively |
1361 if (inliningStack.any((entry) => entry.function == function)) { | 1361 if (inliningStack.any((entry) => entry.function == function)) { |
1362 return false; | 1362 return false; |
1363 } | 1363 } |
1364 | 1364 |
1365 if (element.isSynthesized) return true; | 1365 if (element.isSynthesized) return true; |
1366 | 1366 |
1367 // Don't inline across deferred import to prevent leaking code. The only | |
1368 // exception is an empty function (which does not contain code). | |
1369 bool hasOnlyNonDeferredImportPaths = compiler.deferredLoadTask | |
1370 .hasOnlyNonDeferredImportPaths(compiler.currentElement, element); | |
1371 | |
1372 if (!hasOnlyNonDeferredImportPaths) { | |
1373 return doesNotContainCode(); | |
1374 } | |
1375 | |
1376 // Do not inline code that is rarely executed unless it reduces size. | |
1367 if (inExpressionOfThrow || inLazyInitializerExpression) { | 1377 if (inExpressionOfThrow || inLazyInitializerExpression) { |
1368 return reductiveHeuristic(); | 1378 return reductiveHeuristic(); |
1369 } | 1379 } |
1370 | 1380 |
1371 if (cachedCanBeInlined == true) { | 1381 if (cachedCanBeInlined == true) { |
1372 // We may have forced the inlining of some methods. Therefore check | 1382 // We may have forced the inlining of some methods. Therefore check |
1373 // if we can inline this method regardless of size. | 1383 // if we can inline this method regardless of size. |
1374 assert(InlineWeeder.canBeInlined(function, -1, false, | 1384 assert(InlineWeeder.canBeInlined(function, -1, false, |
1375 allowLoops: true)); | 1385 allowLoops: true)); |
1376 return true; | 1386 return true; |
(...skipping 6229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7606 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7616 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
7607 unaliased.accept(this, builder); | 7617 unaliased.accept(this, builder); |
7608 } | 7618 } |
7609 | 7619 |
7610 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7620 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
7611 JavaScriptBackend backend = builder.compiler.backend; | 7621 JavaScriptBackend backend = builder.compiler.backend; |
7612 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 7622 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
7613 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 7623 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
7614 } | 7624 } |
7615 } | 7625 } |
OLD | NEW |