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 import '../common/codegen.dart' show CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenWorkItem; |
6 import '../common/tasks.dart' show CompilerTask; | 6 import '../common/tasks.dart' show CompilerTask; |
7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../core_types.dart' show CoreClasses; | 10 import '../core_types.dart' show CoreClasses; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 if (folded != null) return folded; | 443 if (folded != null) return folded; |
444 } else { | 444 } else { |
445 // TODO(ngeoffray): If the method has optional parameters, | 445 // TODO(ngeoffray): If the method has optional parameters, |
446 // we should pass the default values. | 446 // we should pass the default values. |
447 FunctionSignature parameters = method.functionSignature; | 447 FunctionSignature parameters = method.functionSignature; |
448 if (parameters.optionalParameterCount == 0 || | 448 if (parameters.optionalParameterCount == 0 || |
449 parameters.parameterCount == node.selector.argumentCount) { | 449 parameters.parameterCount == node.selector.argumentCount) { |
450 node.element = element; | 450 node.element = element; |
451 } | 451 } |
452 } | 452 } |
| 453 return node; |
453 } | 454 } |
| 455 |
| 456 // Replace method calls through fields with a closure call on the value of |
| 457 // the field. This usually removes the demand for the call-through stub and |
| 458 // makes the field load available to further optimization, e.g. LICM. |
| 459 |
| 460 if (element != null && |
| 461 element.isField && |
| 462 element.name == node.selector.name) { |
| 463 if (!backend.isNative(element) && !node.isCallOnInterceptor(compiler)) { |
| 464 HInstruction receiver = node.getDartReceiver(compiler); |
| 465 TypeMask type = |
| 466 TypeMaskFactory.inferredTypeForElement(element, compiler); |
| 467 HInstruction load = new HFieldGet(element, receiver, type); |
| 468 node.block.addBefore(node, load); |
| 469 Selector callSelector = new Selector.callClosureFrom(node.selector); |
| 470 List<HInstruction> inputs = <HInstruction>[load] |
| 471 ..addAll(node.inputs.skip(node.isInterceptedCall ? 2 : 1)); |
| 472 HInstruction closureCall = |
| 473 new HInvokeClosure(callSelector, inputs, node.instructionType) |
| 474 ..sourceInformation = node.sourceInformation; |
| 475 node.block.addAfter(load, closureCall); |
| 476 return closureCall; |
| 477 } |
| 478 } |
| 479 |
454 return node; | 480 return node; |
455 } | 481 } |
456 | 482 |
457 HInstruction tryInlineNativeMethod( | 483 HInstruction tryInlineNativeMethod( |
458 HInvokeDynamicMethod node, FunctionElement method) { | 484 HInvokeDynamicMethod node, FunctionElement method) { |
459 // Enable direct calls to a native method only if we don't run in checked | 485 // Enable direct calls to a native method only if we don't run in checked |
460 // mode, where the Dart version may have type annotations on parameters and | 486 // mode, where the Dart version may have type annotations on parameters and |
461 // return type that it should check. | 487 // return type that it should check. |
462 // Also check that the parameters are not functions: it's the callee that | 488 // Also check that the parameters are not functions: it's the callee that |
463 // will translate them to JS functions. | 489 // will translate them to JS functions. |
(...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 | 2407 |
2382 keyedValues.forEach((receiver, values) { | 2408 keyedValues.forEach((receiver, values) { |
2383 result.keyedValues[receiver] = | 2409 result.keyedValues[receiver] = |
2384 new Map<HInstruction, HInstruction>.from(values); | 2410 new Map<HInstruction, HInstruction>.from(values); |
2385 }); | 2411 }); |
2386 | 2412 |
2387 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2413 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2388 return result; | 2414 return result; |
2389 } | 2415 } |
2390 } | 2416 } |
OLD | NEW |