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

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

Issue 11411147: Address review comments on issue 11412105. (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 2420 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 assert(selector.isGetter()); 2431 assert(selector.isGetter());
2432 SourceString getterName = selector.name; 2432 SourceString getterName = selector.name;
2433 Set<ClassElement> interceptedClasses = 2433 Set<ClassElement> interceptedClasses =
2434 getInterceptedClassesOn(send, selector); 2434 getInterceptedClassesOn(send, selector);
2435 2435
2436 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector); 2436 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector);
2437 if (interceptedClasses != null) { 2437 if (interceptedClasses != 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 invokeInterceptor(interceptedClasses, receiver, send);
2443 && send.receiver == null) {
2444 instruction = thisInstruction;
2445 } else {
2446 pushInvokeInterceptor(interceptedClasses, receiver);
2447 instruction = pop();
2448 }
2449 instruction = new HInvokeDynamicGetter( 2443 instruction = new HInvokeDynamicGetter(
2450 selector, null, instruction, !hasGetter); 2444 selector, null, instruction, !hasGetter);
2451 // Add the receiver as an argument to the getter call on the 2445 // Add the receiver as an argument to the getter call on the
2452 // interceptor. 2446 // interceptor.
2453 instruction.inputs.add(receiver); 2447 instruction.inputs.add(receiver);
2454 pushWithPosition(instruction, send); 2448 pushWithPosition(instruction, send);
2455 } else { 2449 } else {
2456 pushWithPosition( 2450 pushWithPosition(
2457 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send); 2451 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send);
2458 } 2452 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 HInstruction value) { 2496 HInstruction value) {
2503 assert(Elements.isInstanceSend(send, elements)); 2497 assert(Elements.isInstanceSend(send, elements));
2504 Selector selector = elements.getSelector(send); 2498 Selector selector = elements.getSelector(send);
2505 assert(selector.isSetter()); 2499 assert(selector.isSetter());
2506 SourceString setterName = selector.name; 2500 SourceString setterName = selector.name;
2507 bool hasSetter = compiler.world.hasAnyUserDefinedSetter(selector); 2501 bool hasSetter = compiler.world.hasAnyUserDefinedSetter(selector);
2508 Set<ClassElement> interceptedClasses = 2502 Set<ClassElement> interceptedClasses =
2509 getInterceptedClassesOn(send, selector); 2503 getInterceptedClassesOn(send, selector);
2510 if (interceptedClasses != null) { 2504 if (interceptedClasses != null) {
2511 // If we're using an interceptor class, emit a call to the 2505 // If we're using an interceptor class, emit a call to the
2512 // interceptor method and then the actual dynamic call on the 2506 // getInterceptor method and then the actual dynamic call on the
2513 // interceptor object. 2507 // interceptor object.
2514 HInstruction instruction; 2508 HInstruction instruction =
2515 if (backend.isInterceptorClass(currentElement.getEnclosingClass()) 2509 invokeInterceptor(interceptedClasses, receiver, send);
2516 && send.receiver == null) {
2517 instruction = thisInstruction;
2518 } else {
2519 pushInvokeInterceptor(interceptedClasses, receiver);
2520 instruction = pop();
2521 }
2522 instruction = new HInvokeDynamicSetter( 2510 instruction = new HInvokeDynamicSetter(
2523 selector, null, instruction, receiver, !hasSetter); 2511 selector, null, instruction, receiver, !hasSetter);
2524 // Add the value as an argument to the setter call on the 2512 // Add the value as an argument to the setter call on the
2525 // interceptor. 2513 // interceptor.
2526 instruction.inputs.add(value); 2514 instruction.inputs.add(value);
2527 addWithPosition(instruction, send); 2515 addWithPosition(instruction, send);
2528 } else { 2516 } else {
2529 addWithPosition( 2517 addWithPosition(
2530 new HInvokeDynamicSetter(selector, null, receiver, value, !hasSetter), 2518 new HInvokeDynamicSetter(selector, null, receiver, value, !hasSetter),
2531 send); 2519 send);
(...skipping 29 matching lines...) Expand all
2561 HInstruction checked = potentiallyCheckType( 2549 HInstruction checked = potentiallyCheckType(
2562 value, element.computeType(compiler)); 2550 value, element.computeType(compiler));
2563 if (!identical(checked, value)) { 2551 if (!identical(checked, value)) {
2564 pop(); 2552 pop();
2565 stack.add(checked); 2553 stack.add(checked);
2566 } 2554 }
2567 localsHandler.updateLocal(element, checked); 2555 localsHandler.updateLocal(element, checked);
2568 } 2556 }
2569 } 2557 }
2570 2558
2571 void pushInvokeInterceptor(Set<ClassElement> intercepted, 2559 HInstruction invokeInterceptor(Set<ClassElement> intercepted,
2572 HInstruction receiver) { 2560 HInstruction receiver,
2573 push(new HInterceptor(intercepted, receiver)); 2561 Send send) {
2562 if (send != null
2563 && backend.isInterceptorClass(currentElement.getEnclosingClass())
2564 && send.receiver == null) {
2565 return thisInstruction;
2566 }
2567 HInterceptor interceptor = new HInterceptor(intercepted, receiver);
2568 add(interceptor);
2569 return interceptor;
2574 } 2570 }
2575 2571
2576 void pushInvokeHelper0(Element helper) { 2572 void pushInvokeHelper0(Element helper) {
2577 HInstruction reference = new HStatic(helper); 2573 HInstruction reference = new HStatic(helper);
2578 add(reference); 2574 add(reference);
2579 List<HInstruction> inputs = <HInstruction>[reference]; 2575 List<HInstruction> inputs = <HInstruction>[reference];
2580 HInstruction result = new HInvokeStatic(inputs); 2576 HInstruction result = new HInvokeStatic(inputs);
2581 push(result); 2577 push(result);
2582 } 2578 }
2583 2579
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 2763
2768 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) { 2764 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) {
2769 for (; !link.isEmpty; link = link.tail) { 2765 for (; !link.isEmpty; link = link.tail) {
2770 visit(link.head); 2766 visit(link.head);
2771 list.add(pop()); 2767 list.add(pop());
2772 } 2768 }
2773 } 2769 }
2774 2770
2775 visitDynamicSend(Send node) { 2771 visitDynamicSend(Send node) {
2776 Selector selector = elements.getSelector(node); 2772 Selector selector = elements.getSelector(node);
2777 var inputs = <HInstruction>[];
2778 2773
2779 SourceString dartMethodName; 2774 SourceString dartMethodName;
2780 bool isNotEquals = false; 2775 bool isNotEquals = false;
2781 if (node.isIndex && !node.arguments.tail.isEmpty) { 2776 if (node.isIndex && !node.arguments.tail.isEmpty) {
2782 dartMethodName = Elements.constructOperatorName( 2777 dartMethodName = Elements.constructOperatorName(
2783 const SourceString('[]='), false); 2778 const SourceString('[]='), false);
2784 } else if (node.selector.asOperator() != null) { 2779 } else if (node.selector.asOperator() != null) {
2785 SourceString name = node.selector.asIdentifier().source; 2780 SourceString name = node.selector.asIdentifier().source;
2786 isNotEquals = identical(name.stringValue, '!='); 2781 isNotEquals = identical(name.stringValue, '!=');
2787 dartMethodName = Elements.constructOperatorName( 2782 dartMethodName = Elements.constructOperatorName(
2788 name, node.argumentsNode is Prefix); 2783 name, node.argumentsNode is Prefix);
2789 } else { 2784 } else {
2790 dartMethodName = node.selector.asIdentifier().source; 2785 dartMethodName = node.selector.asIdentifier().source;
2791 } 2786 }
2792 2787
2793 Set<ClassElement> interceptedClasses =
2794 getInterceptedClassesOn(node, selector);
2795
2796 if (interceptedClasses != null) {
2797 if (backend.isInterceptorClass(currentElement.getEnclosingClass())
2798 && node.receiver == null) {
2799 inputs.add(thisInstruction);
2800 inputs.add(localsHandler.readThis());
2801 } else {
2802 visit(node.receiver);
2803 HInstruction receiver = pop();
2804 pushInvokeInterceptor(interceptedClasses, receiver);
2805 inputs.add(pop());
2806 inputs.add(receiver);
2807 }
2808 addDynamicSendArgumentsToList(node, inputs);
2809 // The first entry in the inputs list is the interceptor. The
2810 // second is the receiver, and the others are the arguments.
2811 HInstruction instruction = new HInvokeDynamicMethod(selector, inputs);
2812 pushWithPosition(instruction, node);
2813 return;
2814 }
2815
2816 Element element = elements[node]; 2788 Element element = elements[node];
2817 if (element != null && compiler.world.hasNoOverridingMember(element)) { 2789 if (element != null && compiler.world.hasNoOverridingMember(element)) {
2818 if (tryInlineMethod(element, selector, node.arguments)) { 2790 if (tryInlineMethod(element, selector, node.arguments)) {
2819 return; 2791 return;
2820 } 2792 }
2821 } 2793 }
2822 2794
2795 HInstruction receiver;
2823 if (node.receiver == null) { 2796 if (node.receiver == null) {
2824 inputs.add(localsHandler.readThis()); 2797 receiver = localsHandler.readThis();
2825 } else { 2798 } else {
2826 visit(node.receiver); 2799 visit(node.receiver);
2827 inputs.add(pop()); 2800 receiver = pop();
2828 } 2801 }
2829 2802
2803 List<HInstruction> inputs = <HInstruction>[];
2804 Set<ClassElement> interceptedClasses =
2805 interceptors.getInterceptedClassesOn(selector);
2806 if (interceptedClasses != null) {
2807 inputs.add(invokeInterceptor(interceptedClasses, receiver, node));
2808 }
2809 inputs.add(receiver);
2810
2830 addDynamicSendArgumentsToList(node, inputs); 2811 addDynamicSendArgumentsToList(node, inputs);
2831 2812
2832 // The first entry in the inputs list is the receiver.
2833 pushWithPosition(new HInvokeDynamicMethod(selector, inputs), node); 2813 pushWithPosition(new HInvokeDynamicMethod(selector, inputs), node);
2834 2814
2835 if (isNotEquals) { 2815 if (isNotEquals) {
2836 HNot not = new HNot(popBoolified()); 2816 HNot not = new HNot(popBoolified());
2837 push(not); 2817 push(not);
2838 } 2818 }
2839 } 2819 }
2840 2820
2841 visitClosureSend(Send node) { 2821 visitClosureSend(Send node) {
2842 Selector selector = elements.getSelector(node); 2822 Selector selector = elements.getSelector(node);
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
3821 SourceString iteratorName = const SourceString("iterator"); 3801 SourceString iteratorName = const SourceString("iterator");
3822 Selector selector = 3802 Selector selector =
3823 new Selector.call(iteratorName, work.element.getLibrary(), 0); 3803 new Selector.call(iteratorName, work.element.getLibrary(), 0);
3824 Set<ClassElement> interceptedClasses = 3804 Set<ClassElement> interceptedClasses =
3825 interceptors.getInterceptedClassesOn(selector); 3805 interceptors.getInterceptedClassesOn(selector);
3826 visit(node.expression); 3806 visit(node.expression);
3827 HInstruction receiver = pop(); 3807 HInstruction receiver = pop();
3828 if (interceptedClasses == null) { 3808 if (interceptedClasses == null) {
3829 iterator = new HInvokeDynamicMethod(selector, <HInstruction>[receiver]); 3809 iterator = new HInvokeDynamicMethod(selector, <HInstruction>[receiver]);
3830 } else { 3810 } else {
3831 pushInvokeInterceptor(interceptedClasses, receiver); 3811 HInterceptor interceptor =
3832 HInterceptor interceptor = pop(); 3812 invokeInterceptor(interceptedClasses, receiver, null);
3833 iterator = new HInvokeDynamicMethod( 3813 iterator = new HInvokeDynamicMethod(
3834 selector, <HInstruction>[interceptor, receiver]); 3814 selector, <HInstruction>[interceptor, receiver]);
3835 } 3815 }
3836 add(iterator); 3816 add(iterator);
3837 } 3817 }
3838 HInstruction buildCondition() { 3818 HInstruction buildCondition() {
3839 SourceString name = const SourceString('hasNext'); 3819 SourceString name = const SourceString('hasNext');
3840 Selector selector = new Selector.getter(name, work.element.getLibrary()); 3820 Selector selector = new Selector.getter(name, work.element.getLibrary());
3841 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector); 3821 bool hasGetter = compiler.world.hasAnyUserDefinedGetter(selector);
3842 push(new HInvokeDynamicGetter(selector, null, iterator, !hasGetter)); 3822 push(new HInvokeDynamicGetter(selector, null, iterator, !hasGetter));
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
4910 new HSubGraphBlockInformation(elseBranch.graph)); 4890 new HSubGraphBlockInformation(elseBranch.graph));
4911 4891
4912 HBasicBlock conditionStartBlock = conditionBranch.block; 4892 HBasicBlock conditionStartBlock = conditionBranch.block;
4913 conditionStartBlock.setBlockFlow(info, joinBlock); 4893 conditionStartBlock.setBlockFlow(info, joinBlock);
4914 SubGraph conditionGraph = conditionBranch.graph; 4894 SubGraph conditionGraph = conditionBranch.graph;
4915 HIf branch = conditionGraph.end.last; 4895 HIf branch = conditionGraph.end.last;
4916 assert(branch is HIf); 4896 assert(branch is HIf);
4917 branch.blockInformation = conditionStartBlock.blockFlow; 4897 branch.blockInformation = conditionStartBlock.blockFlow;
4918 } 4898 }
4919 } 4899 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698