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 /** | 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 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2577 } | 2577 } |
2578 | 2578 |
2579 HInstruction getRuntimeTypeInfo(HInstruction target) { | 2579 HInstruction getRuntimeTypeInfo(HInstruction target) { |
2580 pushInvokeHelper1(backend.getGetRuntimeTypeInfo(), target, HType.UNKNOWN); | 2580 pushInvokeHelper1(backend.getGetRuntimeTypeInfo(), target, HType.UNKNOWN); |
2581 return pop(); | 2581 return pop(); |
2582 } | 2582 } |
2583 | 2583 |
2584 // TODO(karlklose): change construction of the representations to be GVN'able | 2584 // TODO(karlklose): change construction of the representations to be GVN'able |
2585 // (dartbug.com/7182). | 2585 // (dartbug.com/7182). |
2586 List<HInstruction> buildTypeArgumentRepresentations(DartType type) { | 2586 List<HInstruction> buildTypeArgumentRepresentations(DartType type) { |
2587 HInstruction createForeignArray(String code, inputs) { | |
2588 return createForeign(code, HType.READABLE_ARRAY, inputs); | |
2589 } | |
2590 | |
2591 // Compute the representation of the type arguments, including access | 2587 // Compute the representation of the type arguments, including access |
2592 // to the runtime type information for type variables as instructions. | 2588 // to the runtime type information for type variables as instructions. |
2593 HInstruction representations; | 2589 HInstruction representations; |
2594 if (type.element.isTypeVariable()) { | 2590 if (type.kind == TypeKind.TYPE_VARIABLE) { |
2595 return <HInstruction>[addTypeVariableReference(type)]; | 2591 return <HInstruction>[addTypeVariableReference(type)]; |
2596 } else { | 2592 } else { |
2597 assert(type.element.isClass()); | 2593 assert(type.element.isClass()); |
2598 List<HInstruction> arguments = <HInstruction>[]; | 2594 List<HInstruction> arguments = <HInstruction>[]; |
2599 InterfaceType interface = type; | 2595 InterfaceType interface = type; |
2600 for (DartType argument in interface.typeArguments) { | 2596 for (DartType argument in interface.typeArguments) { |
2601 List<HInstruction> inputs = <HInstruction>[]; | 2597 List<HInstruction> inputs = <HInstruction>[]; |
2602 String template = rti.getTypeRepresentation(argument, (variable) { | 2598 String template = rti.getTypeRepresentation(argument, (variable) { |
2603 HInstruction runtimeType = addTypeVariableReference(variable); | 2599 HInstruction runtimeType = addTypeVariableReference(variable); |
2604 inputs.add(runtimeType); | 2600 inputs.add(runtimeType); |
2605 }); | 2601 }); |
2606 HInstruction representation = createForeignArray(template, inputs); | 2602 HInstruction representation = |
2603 createForeign(template, HType.READABLE_ARRAY, inputs); | |
2607 add(representation); | 2604 add(representation); |
2608 arguments.add(representation); | 2605 arguments.add(representation); |
2609 } | 2606 } |
2610 return arguments; | 2607 return arguments; |
2611 } | 2608 } |
2612 } | 2609 } |
2613 | 2610 |
2614 visitOperatorSend(node) { | 2611 visitOperatorSend(node) { |
2615 Operator op = node.selector; | 2612 Operator op = node.selector; |
2616 if (const SourceString("[]") == op.source) { | 2613 if (const SourceString("[]") == op.source) { |
(...skipping 11 matching lines...) Expand all Loading... | |
2628 Node argument = node.arguments.head; | 2625 Node argument = node.arguments.head; |
2629 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); | 2626 TypeAnnotation typeAnnotation = argument.asTypeAnnotation(); |
2630 bool isNot = false; | 2627 bool isNot = false; |
2631 // TODO(ngeoffray): Duplicating pattern in resolver. We should | 2628 // TODO(ngeoffray): Duplicating pattern in resolver. We should |
2632 // add a new kind of node. | 2629 // add a new kind of node. |
2633 if (typeAnnotation == null) { | 2630 if (typeAnnotation == null) { |
2634 typeAnnotation = argument.asSend().receiver; | 2631 typeAnnotation = argument.asSend().receiver; |
2635 isNot = true; | 2632 isNot = true; |
2636 } | 2633 } |
2637 DartType type = elements.getType(typeAnnotation); | 2634 DartType type = elements.getType(typeAnnotation); |
2635 compiler.enqueuer.codegen.registerIsCheck(type); | |
ngeoffray
2013/02/21 10:26:18
Don't we register the is check in the SSA codegen
karlklose
2013/02/21 14:48:44
It does not for type variable tests, because they
| |
2638 if (type.isMalformed) { | 2636 if (type.isMalformed) { |
2639 String reasons = Types.fetchReasonsFromMalformedType(type); | 2637 String reasons = Types.fetchReasonsFromMalformedType(type); |
2640 if (compiler.enableTypeAssertions) { | 2638 if (compiler.enableTypeAssertions) { |
2641 generateMalformedSubtypeError(node, expression, type, reasons); | 2639 generateMalformedSubtypeError(node, expression, type, reasons); |
2642 } else { | 2640 } else { |
2643 generateRuntimeError(node, '$type is malformed: $reasons'); | 2641 generateRuntimeError(node, '$type is malformed: $reasons'); |
2644 } | 2642 } |
2645 return; | 2643 return; |
2646 } | 2644 } |
2647 if (type.element.isTypeVariable()) { | |
2648 // TODO(karlklose): remove this check when the backend can deal with | |
2649 // checks of the form [:o is T:] where [:T:] is a type variable. | |
2650 stack.add(graph.addConstantBool(true, constantSystem)); | |
2651 return; | |
2652 } | |
2653 | 2645 |
2654 HInstruction instruction; | 2646 HInstruction instruction; |
2655 if (type.element.isTypeVariable() || | 2647 if (type.kind == TypeKind.TYPE_VARIABLE) { |
2656 RuntimeTypeInformation.hasTypeArguments(type)) { | 2648 List<HInstruction> representations = |
2649 buildTypeArgumentRepresentations(type); | |
2650 assert(representations.length == 1); | |
2651 HInstruction runtimeType = addTypeVariableReference(type); | |
2652 Element helper = | |
2653 compiler.findHelper(const SourceString('objectIsSubtype')); | |
ngeoffray
2013/02/21 10:26:18
Use the method on the backend to get the helper.
karlklose
2013/02/21 14:48:44
Done.
| |
2654 HInstruction helperCall = new HStatic(helper); | |
2655 add(helperCall); | |
2656 List<HInstruction> inputs = <HInstruction>[helperCall, expression, | |
2657 runtimeType]; | |
2658 instruction = new HInvokeStatic(inputs, HType.BOOLEAN); | |
2659 add(instruction); | |
2660 ClassElement currentClass = currentElement.getEnclosingClass(); | |
ngeoffray
2013/02/21 10:26:18
Remove currentClass.
karlklose
2013/02/21 14:48:44
Done.
| |
2661 | |
2662 } else if (RuntimeTypeInformation.hasTypeArguments(type)) { | |
2657 | 2663 |
2658 void argumentsCheck() { | 2664 void argumentsCheck() { |
2659 HInstruction typeInfo = getRuntimeTypeInfo(expression); | 2665 HInstruction typeInfo = getRuntimeTypeInfo(expression); |
2660 Element helper = backend.getCheckArguments(); | 2666 Element helper = backend.getCheckArguments(); |
2661 HInstruction helperCall = new HStatic(helper); | 2667 HInstruction helperCall = new HStatic(helper); |
2662 add(helperCall); | 2668 add(helperCall); |
2663 List<HInstruction> representations = | 2669 List<HInstruction> representations = |
2664 buildTypeArgumentRepresentations(type); | 2670 buildTypeArgumentRepresentations(type); |
2665 Element element = type.element; | 2671 Element element = type.element; |
2666 String substitution = backend.namer.substitutionName(element); | 2672 String substitution = backend.namer.substitutionName(element); |
2667 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { | 2673 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { |
2668 substitution = '$substitution()'; | 2674 substitution = '$substitution()'; |
2669 } | 2675 } |
2670 HInstruction fieldGet = | 2676 HInstruction fieldGet = |
2671 createForeign('#.$substitution', HType.UNKNOWN, [expression]); | 2677 createForeign('#.$substitution', HType.UNKNOWN, [expression]); |
2672 HInstruction representationList = new HLiteralList(representations); | 2678 HInstruction representationList = new HLiteralList(representations); |
2673 add(fieldGet); | 2679 add(fieldGet); |
2674 add(representationList); | 2680 add(representationList); |
2675 List<HInstruction> inputs = <HInstruction>[helperCall, | 2681 List<HInstruction> inputs = <HInstruction>[helperCall, |
2676 fieldGet, | 2682 fieldGet, |
2677 typeInfo, | 2683 typeInfo, |
2678 representationList]; | 2684 representationList]; |
2679 push(new HInvokeStatic(inputs, HType.UNKNOWN)); | 2685 push(new HInvokeStatic(inputs, HType.UNKNOWN)); |
2680 } | 2686 } |
2681 | 2687 |
2682 void classCheck() { push(new HIs(type, <HInstruction>[expression])); } | 2688 void classCheck() { push(new HIs(type, <HInstruction>[expression])); } |
2683 | 2689 |
2684 SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, node); | 2690 SsaBranchBuilder branchBuilder = new SsaBranchBuilder(this, node); |
2685 branchBuilder.handleLogicalAndOr(classCheck, argumentsCheck, isAnd: true ); | 2691 branchBuilder.handleLogicalAndOr(classCheck, argumentsCheck, |
2692 isAnd: true); | |
2686 instruction = pop(); | 2693 instruction = pop(); |
2687 } else { | 2694 } else { |
2688 instruction = new HIs(type, <HInstruction>[expression]); | 2695 instruction = new HIs(type, <HInstruction>[expression]); |
2689 add(instruction); | 2696 add(instruction); |
2690 } | 2697 } |
2691 if (isNot) { | 2698 if (isNot) { |
2692 instruction = new HNot(instruction); | 2699 instruction = new HNot(instruction); |
2693 add(instruction); | 2700 add(instruction); |
2694 } | 2701 } |
2695 stack.add(instruction); | 2702 stack.add(instruction); |
(...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5090 new HSubGraphBlockInformation(elseBranch.graph)); | 5097 new HSubGraphBlockInformation(elseBranch.graph)); |
5091 | 5098 |
5092 HBasicBlock conditionStartBlock = conditionBranch.block; | 5099 HBasicBlock conditionStartBlock = conditionBranch.block; |
5093 conditionStartBlock.setBlockFlow(info, joinBlock); | 5100 conditionStartBlock.setBlockFlow(info, joinBlock); |
5094 SubGraph conditionGraph = conditionBranch.graph; | 5101 SubGraph conditionGraph = conditionBranch.graph; |
5095 HIf branch = conditionGraph.end.last; | 5102 HIf branch = conditionGraph.end.last; |
5096 assert(branch is HIf); | 5103 assert(branch is HIf); |
5097 branch.blockInformation = conditionStartBlock.blockFlow; | 5104 branch.blockInformation = conditionStartBlock.blockFlow; |
5098 } | 5105 } |
5099 } | 5106 } |
OLD | NEW |