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:]. | |
992 * If the initial value is not a compile-time constants reports an error. | |
ngeoffray
2012/11/30 12:16:35
internal error?
kasperl
2012/11/30 12:17:59
Done.
| |
993 */ | |
994 Constant compileConstant(VariableElement element) { | |
995 return compiler.constantHandler.compileConstant(element); | |
996 } | |
997 | |
998 Constant compileVariable(VariableElement element) { | |
999 return compiler.constantHandler.compileVariable(element); | |
1000 } | |
1001 | |
1002 bool isLazilyInitialized(VariableElement element) { | |
1003 Constant initialValue = compileVariable(element); | |
1004 return initialValue == null; | |
1005 } | |
1006 | |
1007 /** | |
991 * Documentation wanted -- johnniwinther | 1008 * Documentation wanted -- johnniwinther |
992 * | 1009 * |
993 * Invariant: [functionElement] must be an implementation element. | 1010 * Invariant: [functionElement] must be an implementation element. |
994 */ | 1011 */ |
995 HGraph buildMethod(FunctionElement functionElement) { | 1012 HGraph buildMethod(FunctionElement functionElement) { |
996 assert(invariant(functionElement, functionElement.isImplementation)); | 1013 assert(invariant(functionElement, functionElement.isImplementation)); |
997 FunctionExpression function = functionElement.parseNode(compiler); | 1014 FunctionExpression function = functionElement.parseNode(compiler); |
998 assert(function != null); | 1015 assert(function != null); |
999 assert(!function.modifiers.isExternal()); | 1016 assert(!function.modifiers.isExternal()); |
1000 assert(elements[function] != null); | 1017 assert(elements[function] != null); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 // if (?a) print('parameter passed $a'); | 1534 // if (?a) print('parameter passed $a'); |
1518 // } | 1535 // } |
1519 // | 1536 // |
1520 // foo([a = 42]) { | 1537 // foo([a = 42]) { |
1521 // var t1 = identical(a, sentinel); | 1538 // var t1 = identical(a, sentinel); |
1522 // if (t1) a = 42; | 1539 // if (t1) a = 42; |
1523 // if (!t1) print('parameter passed ' + a); | 1540 // if (!t1) print('parameter passed ' + a); |
1524 // } | 1541 // } |
1525 | 1542 |
1526 // Fetch the original default value of [element]; | 1543 // Fetch the original default value of [element]; |
1527 ConstantHandler handler = compiler.constantHandler; | 1544 Constant constant = compileVariable(element); |
1528 Constant constant = handler.compileVariable(element); | |
1529 HConstant defaultValue = constant == null | 1545 HConstant defaultValue = constant == null |
1530 ? graph.addConstantNull(constantSystem) | 1546 ? graph.addConstantNull(constantSystem) |
1531 : graph.addConstant(constant); | 1547 : graph.addConstant(constant); |
1532 | 1548 |
1533 // Emit the equality check with the sentinel. | 1549 // Emit the equality check with the sentinel. |
1534 HConstant sentinel = graph.addConstant(SentinelConstant.SENTINEL); | 1550 HConstant sentinel = graph.addConstant(SentinelConstant.SENTINEL); |
1535 Element equalsHelper = interceptors.getTripleEqualsInterceptor(); | 1551 Element equalsHelper = interceptors.getTripleEqualsInterceptor(); |
1536 HInstruction target = new HStatic(equalsHelper); | 1552 HInstruction target = new HStatic(equalsHelper); |
1537 add(target); | 1553 add(target); |
1538 HInstruction operand = parameters[element]; | 1554 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); | 2467 new HInvokeDynamicGetter(selector, null, receiver, !hasGetter), send); |
2452 } | 2468 } |
2453 } | 2469 } |
2454 | 2470 |
2455 void generateGetter(Send send, Element element) { | 2471 void generateGetter(Send send, Element element) { |
2456 if (Elements.isStaticOrTopLevelField(element)) { | 2472 if (Elements.isStaticOrTopLevelField(element)) { |
2457 Constant value; | 2473 Constant value; |
2458 if (element.isField() && !element.isAssignable()) { | 2474 if (element.isField() && !element.isAssignable()) { |
2459 // A static final or const. Get its constant value and inline it if | 2475 // A static final or const. Get its constant value and inline it if |
2460 // the value can be compiled eagerly. | 2476 // the value can be compiled eagerly. |
2461 value = compiler.compileVariable(element); | 2477 value = compileVariable(element); |
2462 } | 2478 } |
2463 if (value != null) { | 2479 if (value != null) { |
2464 stack.add(graph.addConstant(value)); | 2480 stack.add(graph.addConstant(value)); |
2465 } else if (element.isField() && compiler.isLazilyInitialized(element)) { | 2481 } else if (element.isField() && isLazilyInitialized(element)) { |
2466 push(new HLazyStatic(element)); | 2482 push(new HLazyStatic(element)); |
2467 } else { | 2483 } else { |
2468 // TODO(5346): Try to avoid the need for calling [declaration] before | 2484 // TODO(5346): Try to avoid the need for calling [declaration] before |
2469 // creating an [HStatic]. | 2485 // creating an [HStatic]. |
2470 push(new HStatic(element.declaration)); | 2486 push(new HStatic(element.declaration)); |
2471 if (element.isGetter()) { | 2487 if (element.isGetter()) { |
2472 push(new HInvokeStatic(<HInstruction>[pop()])); | 2488 push(new HInvokeStatic(<HInstruction>[pop()])); |
2473 } | 2489 } |
2474 } | 2490 } |
2475 } else if (Elements.isInstanceSend(send, elements)) { | 2491 } else if (Elements.isInstanceSend(send, elements)) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2734 Link<Node> arguments, | 2750 Link<Node> arguments, |
2735 FunctionElement element, | 2751 FunctionElement element, |
2736 List<HInstruction> list) { | 2752 List<HInstruction> list) { |
2737 assert(invariant(element, element.isImplementation)); | 2753 assert(invariant(element, element.isImplementation)); |
2738 | 2754 |
2739 HInstruction compileArgument(Node argument) { | 2755 HInstruction compileArgument(Node argument) { |
2740 visit(argument); | 2756 visit(argument); |
2741 return pop(); | 2757 return pop(); |
2742 } | 2758 } |
2743 | 2759 |
2744 HInstruction compileConstant(Element parameter) { | 2760 HInstruction handleConstant(Element parameter) { |
2745 Constant constant; | 2761 Constant constant; |
2746 TreeElements calleeElements = | 2762 TreeElements calleeElements = |
2747 compiler.enqueuer.resolution.getCachedElements(element); | 2763 compiler.enqueuer.resolution.getCachedElements(element); |
2748 if (calleeElements.isParameterChecked(parameter)) { | 2764 if (calleeElements.isParameterChecked(parameter)) { |
2749 constant = SentinelConstant.SENTINEL; | 2765 constant = SentinelConstant.SENTINEL; |
2750 } else { | 2766 } else { |
2751 constant = compiler.compileConstant(parameter); | 2767 constant = compileConstant(parameter); |
2752 } | 2768 } |
2753 return graph.addConstant(constant); | 2769 return graph.addConstant(constant); |
2754 } | 2770 } |
2755 | 2771 |
2756 return selector.addArgumentsToList(arguments, | 2772 return selector.addArgumentsToList(arguments, |
2757 list, | 2773 list, |
2758 element, | 2774 element, |
2759 compileArgument, | 2775 compileArgument, |
2760 compileConstant, | 2776 handleConstant, |
2761 compiler); | 2777 compiler); |
2762 } | 2778 } |
2763 | 2779 |
2764 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) { | 2780 void addGenericSendArgumentsToList(Link<Node> link, List<HInstruction> list) { |
2765 for (; !link.isEmpty; link = link.tail) { | 2781 for (; !link.isEmpty; link = link.tail) { |
2766 visit(link.head); | 2782 visit(link.head); |
2767 list.add(pop()); | 2783 list.add(pop()); |
2768 } | 2784 } |
2769 } | 2785 } |
2770 | 2786 |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4902 new HSubGraphBlockInformation(elseBranch.graph)); | 4918 new HSubGraphBlockInformation(elseBranch.graph)); |
4903 | 4919 |
4904 HBasicBlock conditionStartBlock = conditionBranch.block; | 4920 HBasicBlock conditionStartBlock = conditionBranch.block; |
4905 conditionStartBlock.setBlockFlow(info, joinBlock); | 4921 conditionStartBlock.setBlockFlow(info, joinBlock); |
4906 SubGraph conditionGraph = conditionBranch.graph; | 4922 SubGraph conditionGraph = conditionBranch.graph; |
4907 HIf branch = conditionGraph.end.last; | 4923 HIf branch = conditionGraph.end.last; |
4908 assert(branch is HIf); | 4924 assert(branch is HIf); |
4909 branch.blockInformation = conditionStartBlock.blockFlow; | 4925 branch.blockInformation = conditionStartBlock.blockFlow; |
4910 } | 4926 } |
4911 } | 4927 } |
OLD | NEW |