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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 11412105: - Move length getter and setter interceptors to the new interceptor scheme. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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
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 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector); 2436 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector);
2437 if (interceptor == backend.getInterceptorMethod && interceptor != null) { 2437 if (interceptor == backend.getInterceptorMethod && interceptor != null) {
2438 // If we're using an interceptor class, emit a call to the 2438 // If we're using an interceptor class, emit a call to the
2439 // interceptor method and then the actual dynamic call on the 2439 // interceptor method and then the actual dynamic call on the
2440 // interceptor object. 2440 // interceptor object.
2441 HInstruction instruction; 2441 HInstruction instruction;
2442 if (backend.isInterceptorClass(currentElement.getEnclosingClass()) 2442 if (backend.isInterceptorClass(currentElement.getEnclosingClass())
2443 && send.receiver == null) { 2443 && send.receiver == null) {
2444 instruction = thisInstruction; 2444 instruction = thisInstruction;
2445 } else { 2445 } else {
2446 HStatic target = new HStatic(interceptor); 2446 pushInvokeInterceptor(interceptor, receiver);
2447 add(target); 2447 instruction = pop();
2448 instruction = new HInvokeStatic(<HInstruction>[target, receiver]);
2449 add(instruction);
2450 } 2448 }
2451 instruction = new HInvokeDynamicGetter( 2449 instruction = new HInvokeDynamicGetter(
2452 selector, null, instruction, !hasGetter); 2450 selector, null, instruction, !hasGetter);
2453 // Add the receiver as an argument to the getter call on the 2451 // Add the receiver as an argument to the getter call on the
2454 // interceptor. 2452 // interceptor.
2455 instruction.inputs.add(receiver); 2453 instruction.inputs.add(receiver);
2456 pushWithPosition(instruction, send); 2454 pushWithPosition(instruction, send);
2457 } else if (elements[send] == null && interceptor != null) {
2458 // Use the old, deprecated interceptor mechanism.
2459 HStatic target = new HStatic(interceptor);
2460 add(target);
2461 List<HInstruction> inputs = <HInstruction>[target, receiver];
2462 pushWithPosition(new HInvokeInterceptor(selector, inputs, !hasGetter),
2463 send);
2464 } else { 2455 } else {
2465 pushWithPosition( 2456 pushWithPosition(
2466 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send); 2457 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send);
2467 } 2458 }
2468 } 2459 }
2469 2460
2470 void generateGetter(Send send, Element element) { 2461 void generateGetter(Send send, Element element) {
2471 if (Elements.isStaticOrTopLevelField(element)) { 2462 if (Elements.isStaticOrTopLevelField(element)) {
2472 Constant value; 2463 Constant value;
2473 if (element.isField() && !element.isAssignable()) { 2464 if (element.isField() && !element.isAssignable()) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 void generateInstanceSetterWithCompiledReceiver(Send send, 2500 void generateInstanceSetterWithCompiledReceiver(Send send,
2510 HInstruction receiver, 2501 HInstruction receiver,
2511 HInstruction value) { 2502 HInstruction value) {
2512 assert(Elements.isInstanceSend(send, elements)); 2503 assert(Elements.isInstanceSend(send, elements));
2513 Selector selector = elements.getSelector(send); 2504 Selector selector = elements.getSelector(send);
2514 assert(selector.isSetter()); 2505 assert(selector.isSetter());
2515 SourceString setterName = selector.name; 2506 SourceString setterName = selector.name;
2516 Element interceptor = getInterceptor(send, selector); 2507 Element interceptor = getInterceptor(send, selector);
2517 bool hasSetter = compiler.world.hasAnyUserDefinedSetter(selector); 2508 bool hasSetter = compiler.world.hasAnyUserDefinedSetter(selector);
2518 if (interceptor != null && interceptor == backend.getInterceptorMethod) { 2509 if (interceptor != null && interceptor == backend.getInterceptorMethod) {
2519 compiler.internalError( 2510 // If we're using an interceptor class, emit a call to the
2520 'Unimplemented intercepted setter call with interceptor classes'); 2511 // interceptor method and then the actual dynamic call on the
ahe 2012/11/23 06:51:23 interceptor method -> "getInterceptor" method
ngeoffray 2012/11/23 12:01:17 Done.
2521 } else if (interceptor != null && elements[send] == null) { 2512 // interceptor object.
2522 HStatic target = new HStatic(interceptor); 2513 HInstruction instruction;
2523 add(target); 2514 if (backend.isInterceptorClass(currentElement.getEnclosingClass())
ahe 2012/11/23 06:51:23 Shouldn't this be part of pushInvokeInterceptor?
ngeoffray 2012/11/23 12:01:17 Done.
2524 List<HInstruction> inputs = <HInstruction>[target, receiver, value]; 2515 && send.receiver == null) {
2525 addWithPosition(new HInvokeInterceptor(selector, inputs), send); 2516 instruction = thisInstruction;
2517 } else {
2518 pushInvokeInterceptor(interceptor, receiver);
2519 instruction = pop();
2520 }
2521 instruction = new HInvokeDynamicSetter(
2522 selector, null, instruction, receiver, !hasSetter);
2523 // Add the value as an argument to the setter call on the
2524 // interceptor.
2525 instruction.inputs.add(value);
2526 addWithPosition(instruction, send);
2526 } else { 2527 } else {
2527 addWithPosition( 2528 addWithPosition(
2528 new HInvokeDynamicSetter(selector, null, receiver, value, !hasSetter), 2529 new HInvokeDynamicSetter(selector, null, receiver, value, !hasSetter),
2529 send); 2530 send);
2530 } 2531 }
2531 stack.add(value); 2532 stack.add(value);
2532 } 2533 }
2533 2534
2534 void generateSetter(SendSet send, Element element, HInstruction value) { 2535 void generateSetter(SendSet send, Element element, HInstruction value) {
2535 if (Elements.isStaticOrTopLevelField(element)) { 2536 if (Elements.isStaticOrTopLevelField(element)) {
(...skipping 23 matching lines...) Expand all
2559 HInstruction checked = potentiallyCheckType( 2560 HInstruction checked = potentiallyCheckType(
2560 value, element.computeType(compiler)); 2561 value, element.computeType(compiler));
2561 if (!identical(checked, value)) { 2562 if (!identical(checked, value)) {
2562 pop(); 2563 pop();
2563 stack.add(checked); 2564 stack.add(checked);
2564 } 2565 }
2565 localsHandler.updateLocal(element, checked); 2566 localsHandler.updateLocal(element, checked);
2566 } 2567 }
2567 } 2568 }
2568 2569
2570 void pushInvokeInterceptor(Element element, HInstruction receiver) {
2571 HInstruction interceptor = new HStatic(element);
2572 add(interceptor);
2573 List<HInstruction> inputs = <HInstruction>[interceptor, receiver];
2574 HInstruction result = new HInvokeStatic(inputs);
2575 result.isSideEffectFree = true;
2576 push(result);
2577 }
2578
2569 void pushInvokeHelper0(Element helper) { 2579 void pushInvokeHelper0(Element helper) {
2570 HInstruction reference = new HStatic(helper); 2580 HInstruction reference = new HStatic(helper);
2571 add(reference); 2581 add(reference);
2572 List<HInstruction> inputs = <HInstruction>[reference]; 2582 List<HInstruction> inputs = <HInstruction>[reference];
2573 HInstruction result = new HInvokeStatic(inputs); 2583 HInstruction result = new HInvokeStatic(inputs);
2574 push(result); 2584 push(result);
2575 } 2585 }
2576 2586
2577 void pushInvokeHelper1(Element helper, HInstruction a0) { 2587 void pushInvokeHelper1(Element helper, HInstruction a0) {
2578 HInstruction reference = new HStatic(helper); 2588 HInstruction reference = new HStatic(helper);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 2795
2786 Element interceptor = getInterceptor(node, selector); 2796 Element interceptor = getInterceptor(node, selector);
2787 2797
2788 if (interceptor != null) { 2798 if (interceptor != null) {
2789 if (interceptor == backend.getInterceptorMethod) { 2799 if (interceptor == backend.getInterceptorMethod) {
2790 if (backend.isInterceptorClass(currentElement.getEnclosingClass()) 2800 if (backend.isInterceptorClass(currentElement.getEnclosingClass())
2791 && node.receiver == null) { 2801 && node.receiver == null) {
2792 inputs.add(thisInstruction); 2802 inputs.add(thisInstruction);
2793 inputs.add(localsHandler.readThis()); 2803 inputs.add(localsHandler.readThis());
2794 } else { 2804 } else {
2795 HStatic target = new HStatic(interceptor);
2796 add(target);
2797 visit(node.receiver); 2805 visit(node.receiver);
2798 HInstruction receiver = pop(); 2806 HInstruction receiver = pop();
2799 HInstruction instruction = 2807 pushInvokeInterceptor(interceptor, receiver);
ahe 2012/11/23 06:51:23 Why don't you need to reuse this here? Is it beca
ngeoffray 2012/11/23 12:01:17 Not sure I understand. The handling of an implicit
2800 new HInvokeStatic(<HInstruction>[target, receiver]); 2808 inputs.add(pop());
2801 add(instruction);
2802 inputs.add(instruction);
2803 inputs.add(receiver); 2809 inputs.add(receiver);
2804 } 2810 }
2805 addDynamicSendArgumentsToList(node, inputs); 2811 addDynamicSendArgumentsToList(node, inputs);
2806 // The first entry in the inputs list is the interceptor. The 2812 // The first entry in the inputs list is the interceptor. The
2807 // second is the receiver, and the others are the arguments. 2813 // second is the receiver, and the others are the arguments.
2808 HInstruction instruction = new HInvokeDynamicMethod(selector, inputs); 2814 HInstruction instruction = new HInvokeDynamicMethod(selector, inputs);
2809 pushWithPosition(instruction, node); 2815 pushWithPosition(instruction, node);
2810 return; 2816 return;
2811 } else if (elements[node] == null) {
2812 HStatic target = new HStatic(interceptor);
2813 add(target);
2814 inputs.add(target);
2815 visit(node.receiver);
2816 inputs.add(pop());
2817 addGenericSendArgumentsToList(node.arguments, inputs);
2818 pushWithPosition(new HInvokeInterceptor(selector, inputs), node);
2819 return;
2820 } 2817 }
2821 } 2818 }
2822 2819
2823 Element element = elements[node]; 2820 Element element = elements[node];
2824 if (element != null && compiler.world.hasNoOverridingMember(element)) { 2821 if (element != null && compiler.world.hasNoOverridingMember(element)) {
2825 if (tryInlineMethod(element, selector, node.arguments)) { 2822 if (tryInlineMethod(element, selector, node.arguments)) {
2826 return; 2823 return;
2827 } 2824 }
2828 } 2825 }
2829 2826
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
3864 3861
3865 // The iterator is shared between initializer, condition and body. 3862 // The iterator is shared between initializer, condition and body.
3866 HInstruction iterator; 3863 HInstruction iterator;
3867 void buildInitializer() { 3864 void buildInitializer() {
3868 SourceString iteratorName = const SourceString("iterator"); 3865 SourceString iteratorName = const SourceString("iterator");
3869 Selector selector = 3866 Selector selector =
3870 new Selector.call(iteratorName, work.element.getLibrary(), 0); 3867 new Selector.call(iteratorName, work.element.getLibrary(), 0);
3871 Element element = interceptors.getStaticInterceptor(selector); 3868 Element element = interceptors.getStaticInterceptor(selector);
3872 visit(node.expression); 3869 visit(node.expression);
3873 HInstruction receiver = pop(); 3870 HInstruction receiver = pop();
3874 pushInvokeHelper1(element, receiver); 3871 if (element == null) {
ahe 2012/11/23 06:51:23 When can this happen?
ngeoffray 2012/11/23 12:01:17 In unit tests.
3875 HInstruction interceptor = pop(); 3872 iterator = new HInvokeDynamicMethod(selector, <HInstruction>[receiver]);
3876 iterator = new HInvokeDynamicMethod( 3873 } else {
3877 selector, <HInstruction>[interceptor, receiver]); 3874 pushInvokeInterceptor(element, receiver);
3875 HInvokeStatic interceptor = pop();
3876 iterator = new HInvokeDynamicMethod(
3877 selector, <HInstruction>[interceptor, receiver]);
3878 }
3878 add(iterator); 3879 add(iterator);
3879 } 3880 }
3880 HInstruction buildCondition() { 3881 HInstruction buildCondition() {
3881 SourceString name = const SourceString('hasNext'); 3882 SourceString name = const SourceString('hasNext');
3882 Selector selector = new Selector.getter(name, work.element.getLibrary()); 3883 Selector selector = new Selector.getter(name, work.element.getLibrary());
3883 if (interceptors.getStaticInterceptor(selector) != null) { 3884 if (interceptors.getStaticInterceptor(selector) != null) {
3884 compiler.internalError("hasNext getter must not be intercepted", 3885 compiler.internalError("hasNext getter must not be intercepted",
3885 node: node); 3886 node: node);
3886 } 3887 }
3887 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector); 3888 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector);
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 new HSubGraphBlockInformation(elseBranch.graph)); 4957 new HSubGraphBlockInformation(elseBranch.graph));
4957 4958
4958 HBasicBlock conditionStartBlock = conditionBranch.block; 4959 HBasicBlock conditionStartBlock = conditionBranch.block;
4959 conditionStartBlock.setBlockFlow(info, joinBlock); 4960 conditionStartBlock.setBlockFlow(info, joinBlock);
4960 SubGraph conditionGraph = conditionBranch.graph; 4961 SubGraph conditionGraph = conditionBranch.graph;
4961 HIf branch = conditionGraph.end.last; 4962 HIf branch = conditionGraph.end.last;
4962 assert(branch is HIf); 4963 assert(branch is HIf);
4963 branch.blockInformation = conditionStartBlock.blockFlow; 4964 branch.blockInformation = conditionStartBlock.blockFlow;
4964 } 4965 }
4965 } 4966 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698