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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // TODO(karlklose,ngeoffray): add a check to make sure that element is | 195 // TODO(karlklose,ngeoffray): add a check to make sure that element is |
196 // of type FunctionElement. | 196 // of type FunctionElement. |
197 FunctionElement function = element; | 197 FunctionElement function = element; |
198 OptionalParameterTypes defaultValueTypes = null; | 198 OptionalParameterTypes defaultValueTypes = null; |
199 FunctionSignature signature = function.computeSignature(compiler); | 199 FunctionSignature signature = function.computeSignature(compiler); |
200 if (signature.optionalParameterCount > 0) { | 200 if (signature.optionalParameterCount > 0) { |
201 defaultValueTypes = | 201 defaultValueTypes = |
202 new OptionalParameterTypes(signature.optionalParameterCount); | 202 new OptionalParameterTypes(signature.optionalParameterCount); |
203 int index = 0; | 203 int index = 0; |
204 signature.forEachOptionalParameter((Element parameter) { | 204 signature.forEachOptionalParameter((Element parameter) { |
205 Constant defaultValue = compiler.compileVariable(parameter); | 205 Constant defaultValue = builder.compileVariable(parameter); |
206 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); | 206 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); |
207 defaultValueTypes.update(index, parameter.name, type); | 207 defaultValueTypes.update(index, parameter.name, type); |
208 index++; | 208 index++; |
209 }); | 209 }); |
210 } else { | 210 } else { |
211 // TODO(ahe): I have disabled type optimizations for | 211 // TODO(ahe): I have disabled type optimizations for |
212 // optional arguments as the types are stored in the wrong | 212 // optional arguments as the types are stored in the wrong |
213 // order. | 213 // order. |
214 HTypeList parameterTypes = | 214 HTypeList parameterTypes = |
215 backend.optimisticParameterTypes(element.declaration, | 215 backend.optimisticParameterTypes(element.declaration, |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 assert(methodInterceptionEnabled); | 981 assert(methodInterceptionEnabled); |
982 methodInterceptionEnabled = false; | 982 methodInterceptionEnabled = false; |
983 } | 983 } |
984 | 984 |
985 void enableMethodInterception() { | 985 void enableMethodInterception() { |
986 assert(!methodInterceptionEnabled); | 986 assert(!methodInterceptionEnabled); |
987 methodInterceptionEnabled = true; | 987 methodInterceptionEnabled = true; |
988 } | 988 } |
989 | 989 |
990 /** | 990 /** |
| 991 * Compiles compile-time constants. Never returns [:null:]. If the |
| 992 * initial value is not a compile-time constants, it reports an |
| 993 * internal error. |
| 994 */ |
| 995 Constant compileConstant(VariableElement element) { |
| 996 return compiler.constantHandler.compileConstant(element); |
| 997 } |
| 998 |
| 999 Constant compileVariable(VariableElement element) { |
| 1000 return compiler.constantHandler.compileVariable(element); |
| 1001 } |
| 1002 |
| 1003 bool isLazilyInitialized(VariableElement element) { |
| 1004 Constant initialValue = compileVariable(element); |
| 1005 return initialValue == null; |
| 1006 } |
| 1007 |
| 1008 /** |
991 * Documentation wanted -- johnniwinther | 1009 * Documentation wanted -- johnniwinther |
992 * | 1010 * |
993 * Invariant: [functionElement] must be an implementation element. | 1011 * Invariant: [functionElement] must be an implementation element. |
994 */ | 1012 */ |
995 HGraph buildMethod(FunctionElement functionElement) { | 1013 HGraph buildMethod(FunctionElement functionElement) { |
996 assert(invariant(functionElement, functionElement.isImplementation)); | 1014 assert(invariant(functionElement, functionElement.isImplementation)); |
997 FunctionExpression function = functionElement.parseNode(compiler); | 1015 FunctionExpression function = functionElement.parseNode(compiler); |
998 assert(function != null); | 1016 assert(function != null); |
999 assert(!function.modifiers.isExternal()); | 1017 assert(!function.modifiers.isExternal()); |
1000 assert(elements[function] != null); | 1018 assert(elements[function] != null); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 // if (?a) print('parameter passed $a'); | 1535 // if (?a) print('parameter passed $a'); |
1518 // } | 1536 // } |
1519 // | 1537 // |
1520 // foo([a = 42]) { | 1538 // foo([a = 42]) { |
1521 // var t1 = identical(a, sentinel); | 1539 // var t1 = identical(a, sentinel); |
1522 // if (t1) a = 42; | 1540 // if (t1) a = 42; |
1523 // if (!t1) print('parameter passed ' + a); | 1541 // if (!t1) print('parameter passed ' + a); |
1524 // } | 1542 // } |
1525 | 1543 |
1526 // Fetch the original default value of [element]; | 1544 // Fetch the original default value of [element]; |
1527 ConstantHandler handler = compiler.constantHandler; | 1545 Constant constant = compileVariable(element); |
1528 Constant constant = handler.compileVariable(element); | |
1529 HConstant defaultValue = constant == null | 1546 HConstant defaultValue = constant == null |
1530 ? graph.addConstantNull(constantSystem) | 1547 ? graph.addConstantNull(constantSystem) |
1531 : graph.addConstant(constant); | 1548 : graph.addConstant(constant); |
1532 | 1549 |
1533 // Emit the equality check with the sentinel. | 1550 // Emit the equality check with the sentinel. |
1534 HConstant sentinel = graph.addConstant(SentinelConstant.SENTINEL); | 1551 HConstant sentinel = graph.addConstant(SentinelConstant.SENTINEL); |
1535 Element equalsHelper = interceptors.getTripleEqualsInterceptor(); | 1552 Element equalsHelper = interceptors.getTripleEqualsInterceptor(); |
1536 HInstruction target = new HStatic(equalsHelper); | 1553 HInstruction target = new HStatic(equalsHelper); |
1537 add(target); | 1554 add(target); |
1538 HInstruction operand = parameters[element]; | 1555 HInstruction operand = parameters[element]; |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send); | 2468 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send); |
2452 } | 2469 } |
2453 } | 2470 } |
2454 | 2471 |
2455 void generateGetter(Send send, Element element) { | 2472 void generateGetter(Send send, Element element) { |
2456 if (Elements.isStaticOrTopLevelField(element)) { | 2473 if (Elements.isStaticOrTopLevelField(element)) { |
2457 Constant value; | 2474 Constant value; |
2458 if (element.isField() && !element.isAssignable()) { | 2475 if (element.isField() && !element.isAssignable()) { |
2459 // A static final or const. Get its constant value and inline it if | 2476 // A static final or const. Get its constant value and inline it if |
2460 // the value can be compiled eagerly. | 2477 // the value can be compiled eagerly. |
2461 value = compiler.compileVariable(element); | 2478 value = compileVariable(element); |
2462 } | 2479 } |
2463 if (value != null) { | 2480 if (value != null) { |
2464 stack.add(graph.addConstant(value)); | 2481 stack.add(graph.addConstant(value)); |
2465 } else if (element.isField() && compiler.isLazilyInitialized(element)) { | 2482 } else if (element.isField() && isLazilyInitialized(element)) { |
2466 push(new HLazyStatic(element)); | 2483 push(new HLazyStatic(element)); |
2467 } else { | 2484 } else { |
2468 // TODO(5346): Try to avoid the need for calling [declaration] before | 2485 // TODO(5346): Try to avoid the need for calling [declaration] before |
2469 // creating an [HStatic]. | 2486 // creating an [HStatic]. |
2470 push(new HStatic(element.declaration)); | 2487 push(new HStatic(element.declaration)); |
2471 if (element.isGetter()) { | 2488 if (element.isGetter()) { |
2472 push(new HInvokeStatic(<HInstruction>[pop()])); | 2489 push(new HInvokeStatic(<HInstruction>[pop()])); |
2473 } | 2490 } |
2474 } | 2491 } |
2475 } else if (Elements.isInstanceSend(send, elements)) { | 2492 } else if (Elements.isInstanceSend(send, elements)) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 Link<Node> arguments, | 2751 Link<Node> arguments, |
2735 FunctionElement element, | 2752 FunctionElement element, |
2736 List<HInstruction> list) { | 2753 List<HInstruction> list) { |
2737 assert(invariant(element, element.isImplementation)); | 2754 assert(invariant(element, element.isImplementation)); |
2738 | 2755 |
2739 HInstruction compileArgument(Node argument) { | 2756 HInstruction compileArgument(Node argument) { |
2740 visit(argument); | 2757 visit(argument); |
2741 return pop(); | 2758 return pop(); |
2742 } | 2759 } |
2743 | 2760 |
2744 HInstruction compileConstant(Element parameter) { | 2761 HInstruction handleConstant(Element parameter) { |
2745 Constant constant; | 2762 Constant constant; |
2746 TreeElements calleeElements = | 2763 TreeElements calleeElements = |
2747 compiler.enqueuer.resolution.getCachedElements(element); | 2764 compiler.enqueuer.resolution.getCachedElements(element); |
2748 if (calleeElements.isParameterChecked(parameter)) { | 2765 if (calleeElements.isParameterChecked(parameter)) { |
2749 constant = SentinelConstant.SENTINEL; | 2766 constant = SentinelConstant.SENTINEL; |
2750 } else { | 2767 } else { |
2751 constant = compiler.compileConstant(parameter); | 2768 constant = compileConstant(parameter); |
2752 } | 2769 } |
2753 return graph.addConstant(constant); | 2770 return graph.addConstant(constant); |
2754 } | 2771 } |
2755 | 2772 |
2756 return selector.addArgumentsToList(arguments, | 2773 return selector.addArgumentsToList(arguments, |
2757 list, | 2774 list, |
2758 element, | 2775 element, |
2759 compileArgument, | 2776 compileArgument, |
2760 compileConstant, | 2777 handleConstant, |
2761 compiler); | 2778 compiler); |
2762 } | 2779 } |
2763 | 2780 |
2764 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) { | 2781 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) { |
2765 for (; !link.isEmpty; link = link.tail) { | 2782 for (; !link.isEmpty; link = link.tail) { |
2766 visit(link.head); | 2783 visit(link.head); |
2767 list.add(pop()); | 2784 list.add(pop()); |
2768 } | 2785 } |
2769 } | 2786 } |
2770 | 2787 |
(...skipping 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4904 new HSubGraphBlockInformation(elseBranch.graph)); | 4921 new HSubGraphBlockInformation(elseBranch.graph)); |
4905 | 4922 |
4906 HBasicBlock conditionStartBlock = conditionBranch.block; | 4923 HBasicBlock conditionStartBlock = conditionBranch.block; |
4907 conditionStartBlock.setBlockFlow(info, joinBlock); | 4924 conditionStartBlock.setBlockFlow(info, joinBlock); |
4908 SubGraph conditionGraph = conditionBranch.graph; | 4925 SubGraph conditionGraph = conditionBranch.graph; |
4909 HIf branch = conditionGraph.end.last; | 4926 HIf branch = conditionGraph.end.last; |
4910 assert(branch is HIf); | 4927 assert(branch is HIf); |
4911 branch.blockInformation = conditionStartBlock.blockFlow; | 4928 branch.blockInformation = conditionStartBlock.blockFlow; |
4912 } | 4929 } |
4913 } | 4930 } |
OLD | NEW |