| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library cps_ir.optimization.inline; | 5 library cps_ir.optimization.inline; |
| 6 | 6 |
| 7 import 'cps_fragment.dart'; | 7 import 'cps_fragment.dart'; |
| 8 import 'cps_ir_builder.dart' show ThisParameterLocal; | 8 import 'cps_ir_builder.dart' show ThisParameterLocal; |
| 9 import 'cps_ir_nodes.dart'; | 9 import 'cps_ir_nodes.dart'; |
| 10 import 'optimizers.dart'; | 10 import 'optimizers.dart'; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 ++nameIndex; | 316 ++nameIndex; |
| 317 } else { | 317 } else { |
| 318 Constant defaultValue = cps.makeConstant( | 318 Constant defaultValue = cps.makeConstant( |
| 319 backend.constants.getConstantValueForVariable(formal)); | 319 backend.constants.getConstantValueForVariable(formal)); |
| 320 defaultValue.type = typeSystem.getParameterType(formal); | 320 defaultValue.type = typeSystem.getParameterType(formal); |
| 321 arguments.add(defaultValue); | 321 arguments.add(defaultValue); |
| 322 } | 322 } |
| 323 outgoingNames.add(formal.name); | 323 outgoingNames.add(formal.name); |
| 324 }); | 324 }); |
| 325 newCallStructure = | 325 newCallStructure = |
| 326 new CallStructure(signature.parameterCount, outgoingNames); | 326 new CallStructure(signature.parameterCount, outgoingNames); |
| 327 } else { | 327 } else { |
| 328 signature.forEachOptionalParameter((ParameterElement formal) { | 328 signature.forEachOptionalParameter((ParameterElement formal) { |
| 329 if (parameterIndex < parameters.length) { | 329 if (parameterIndex < parameters.length) { |
| 330 arguments.add(parameters[parameterIndex++]); | 330 arguments.add(parameters[parameterIndex++]); |
| 331 } else { | 331 } else { |
| 332 Constant defaultValue = cps.makeConstant( | 332 Constant defaultValue = cps.makeConstant( |
| 333 backend.constants.getConstantValueForVariable(formal)); | 333 backend.constants.getConstantValueForVariable(formal)); |
| 334 defaultValue.type = typeSystem.getParameterType(formal); | 334 defaultValue.type = typeSystem.getParameterType(formal); |
| 335 arguments.add(defaultValue); | 335 arguments.add(defaultValue); |
| 336 } | 336 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 if (backend.annotations.noInline(target)) return doNotInline(); | 434 if (backend.annotations.noInline(target)) return doNotInline(); |
| 435 if (isRecursive(target, callStructure)) return doNotInline(); | 435 if (isRecursive(target, callStructure)) return doNotInline(); |
| 436 | 436 |
| 437 FunctionDefinition function; | 437 FunctionDefinition function; |
| 438 if (callStructure != null && | 438 if (callStructure != null && |
| 439 target.functionSignature.parameterCount != | 439 target.functionSignature.parameterCount != |
| 440 callStructure.argumentCount) { | 440 callStructure.argumentCount) { |
| 441 // The argument count at the call site does not match the target's | 441 // The argument count at the call site does not match the target's |
| 442 // formal parameter count. Build the IR term for an adapter function | 442 // formal parameter count. Build the IR term for an adapter function |
| 443 // body. | 443 // body. |
| 444 function = buildAdapter(invoke, target); | 444 if (backend.isNative(target)) { |
| 445 // TODO(25548): Generate correct adaptor for native methods. |
| 446 return doNotInline(); |
| 447 } else { |
| 448 function = buildAdapter(invoke, target); |
| 449 } |
| 445 } else { | 450 } else { |
| 446 function = _inliner.functionCompiler.compileToCpsIr(target); | 451 function = _inliner.functionCompiler.compileToCpsIr(target); |
| 447 void setValue(Variable variable, Reference<Primitive> value) { | 452 void setValue(Variable variable, Reference<Primitive> value) { |
| 448 variable.type = value.definition.type; | 453 variable.type = value.definition.type; |
| 449 } | 454 } |
| 450 if (invoke.callingConvention == CallingConvention.Intercepted) { | 455 if (invoke.callingConvention == CallingConvention.Intercepted) { |
| 451 setValue(function.thisParameter, invoke.receiver); | 456 setValue(function.thisParameter, invoke.receiver); |
| 452 function.parameters[0].type = abstractReceiverInMethod; | 457 function.parameters[0].type = abstractReceiverInMethod; |
| 453 for (int i = 1; i < invoke.arguments.length; ++i) { | 458 for (int i = 1; i < invoke.arguments.length; ++i) { |
| 454 setValue(function.parameters[i], invoke.arguments[i]); | 459 setValue(function.parameters[i], invoke.arguments[i]); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 // We cannot inline a constructor invocation containing type arguments | 539 // We cannot inline a constructor invocation containing type arguments |
| 535 // because CreateInstance in the body does not know the type arguments. | 540 // because CreateInstance in the body does not know the type arguments. |
| 536 // We would incorrectly instantiate a class like A instead of A<B>. | 541 // We would incorrectly instantiate a class like A instead of A<B>. |
| 537 // TODO(kmillikin): try to fix this. | 542 // TODO(kmillikin): try to fix this. |
| 538 GenericType generic = node.dartType; | 543 GenericType generic = node.dartType; |
| 539 if (generic.typeArguments.any((DartType t) => !t.isDynamic)) return null; | 544 if (generic.typeArguments.any((DartType t) => !t.isDynamic)) return null; |
| 540 } | 545 } |
| 541 return tryInlining(node, node.target, null); | 546 return tryInlining(node, node.target, null); |
| 542 } | 547 } |
| 543 } | 548 } |
| OLD | NEW |