| 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 final SsaCodeGeneratorTask generator; | 8 final SsaCodeGeneratorTask generator; |
| 9 final SsaBuilderTask builder; | 9 final SsaBuilderTask builder; |
| 10 final SsaOptimizerTask optimizer; | 10 final SsaOptimizerTask optimizer; |
| (...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 return true; | 1526 return true; |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 return false; | 1529 return false; |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 bool get allInlinedFunctionsCalledOnce { | 1532 bool get allInlinedFunctionsCalledOnce { |
| 1533 return inliningStack.isEmpty || inliningStack.last.allFunctionsCalledOnce; | 1533 return inliningStack.isEmpty || inliningStack.last.allFunctionsCalledOnce; |
| 1534 } | 1534 } |
| 1535 | 1535 |
| 1536 bool isCalledOnce(Element element) { | 1536 bool isFunctionCalledOnce(Element element) { |
| 1537 if (!allInlinedFunctionsCalledOnce) return false; | 1537 if (element is ConstructorBodyElement) { |
| 1538 // ConstructorBodyElements are not in the type inference graph. |
| 1539 return false; |
| 1540 } |
| 1538 TypesInferrer inferrer = compiler.typesTask.typesInferrer; | 1541 TypesInferrer inferrer = compiler.typesTask.typesInferrer; |
| 1539 return inferrer.isCalledOnce(element); | 1542 return inferrer.isCalledOnce(element); |
| 1540 } | 1543 } |
| 1541 | 1544 |
| 1545 bool isCalledOnce(Element element) { |
| 1546 return allInlinedFunctionsCalledOnce && isFunctionCalledOnce(element); |
| 1547 } |
| 1548 |
| 1542 inlinedFrom(Element element, f()) { | 1549 inlinedFrom(Element element, f()) { |
| 1543 assert(element is FunctionElement || element is VariableElement); | 1550 assert(element is FunctionElement || element is VariableElement); |
| 1544 return reporter.withCurrentElement(element, () { | 1551 return reporter.withCurrentElement(element, () { |
| 1545 // The [sourceElementStack] contains declaration elements. | 1552 // The [sourceElementStack] contains declaration elements. |
| 1546 SourceInformationBuilder oldSourceInformationBuilder = | 1553 SourceInformationBuilder oldSourceInformationBuilder = |
| 1547 sourceInformationBuilder; | 1554 sourceInformationBuilder; |
| 1548 sourceInformationBuilder = | 1555 sourceInformationBuilder = |
| 1549 sourceInformationBuilder.forContext(element.implementation); | 1556 sourceInformationBuilder.forContext(element.implementation); |
| 1550 sourceElementStack.add(element.declaration); | 1557 sourceElementStack.add(element.declaration); |
| 1551 var result = f(); | 1558 var result = f(); |
| (...skipping 6967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8519 } | 8526 } |
| 8520 | 8527 |
| 8521 /** | 8528 /** |
| 8522 * This method is invoked before inlining the body of [function] into this | 8529 * This method is invoked before inlining the body of [function] into this |
| 8523 * [SsaBuilder]. | 8530 * [SsaBuilder]. |
| 8524 */ | 8531 */ |
| 8525 void enterInlinedMethod(FunctionElement function, | 8532 void enterInlinedMethod(FunctionElement function, |
| 8526 ast.Node _, | 8533 ast.Node _, |
| 8527 List<HInstruction> compiledArguments, | 8534 List<HInstruction> compiledArguments, |
| 8528 {InterfaceType instanceType}) { | 8535 {InterfaceType instanceType}) { |
| 8529 TypesInferrer inferrer = compiler.typesTask.typesInferrer; | |
| 8530 AstInliningState state = new AstInliningState( | 8536 AstInliningState state = new AstInliningState( |
| 8531 function, returnLocal, returnType, elements, stack, localsHandler, | 8537 function, returnLocal, returnType, elements, stack, localsHandler, |
| 8532 inTryStatement, | 8538 inTryStatement, |
| 8533 allInlinedFunctionsCalledOnce && inferrer.isCalledOnce(function)); | 8539 allInlinedFunctionsCalledOnce && isFunctionCalledOnce(function)); |
| 8534 inliningStack.add(state); | 8540 inliningStack.add(state); |
| 8535 | 8541 |
| 8536 // Setting up the state of the (AST) builder is performed even when the | 8542 // Setting up the state of the (AST) builder is performed even when the |
| 8537 // inlined function is in IR, because the irInliner uses the [returnElement] | 8543 // inlined function is in IR, because the irInliner uses the [returnElement] |
| 8538 // of the AST builder. | 8544 // of the AST builder. |
| 8539 setupStateForInlining( | 8545 setupStateForInlining( |
| 8540 function, compiledArguments, instanceType: instanceType); | 8546 function, compiledArguments, instanceType: instanceType); |
| 8541 } | 8547 } |
| 8542 | 8548 |
| 8543 void leaveInlinedMethod() { | 8549 void leaveInlinedMethod() { |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9237 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 9243 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 9238 unaliased.accept(this, builder); | 9244 unaliased.accept(this, builder); |
| 9239 } | 9245 } |
| 9240 | 9246 |
| 9241 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 9247 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 9242 JavaScriptBackend backend = builder.compiler.backend; | 9248 JavaScriptBackend backend = builder.compiler.backend; |
| 9243 ClassElement cls = backend.helpers.DynamicRuntimeType; | 9249 ClassElement cls = backend.helpers.DynamicRuntimeType; |
| 9244 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 9250 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
| 9245 } | 9251 } |
| 9246 } | 9252 } |
| OLD | NEW |