Chromium Code Reviews| 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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 List<HInstruction> stack; | 838 List<HInstruction> stack; |
| 839 | 839 |
| 840 // The current block to add instructions to. Might be null, if we are | 840 // The current block to add instructions to. Might be null, if we are |
| 841 // visiting dead code. | 841 // visiting dead code. |
| 842 HBasicBlock current; | 842 HBasicBlock current; |
| 843 // The most recently opened block. Has the same value as [current] while | 843 // The most recently opened block. Has the same value as [current] while |
| 844 // the block is open, but unlike [current], it isn't cleared when the current | 844 // the block is open, but unlike [current], it isn't cleared when the current |
| 845 // block is closed. | 845 // block is closed. |
| 846 HBasicBlock lastOpenedBlock; | 846 HBasicBlock lastOpenedBlock; |
| 847 | 847 |
| 848 List<Element> sourceElementStack; | |
| 849 | |
| 848 LibraryElement get currentLibrary => work.element.getLibrary(); | 850 LibraryElement get currentLibrary => work.element.getLibrary(); |
| 849 Element get currentElement => work.element; | 851 Element get currentElement => work.element; |
| 850 Compiler get compiler => builder.compiler; | 852 Compiler get compiler => builder.compiler; |
| 851 CodeEmitterTask get emitter => builder.emitter; | 853 CodeEmitterTask get emitter => builder.emitter; |
| 852 | 854 |
| 853 SsaBuilder(this.constantSystem, SsaBuilderTask builder, WorkItem work) | 855 SsaBuilder(this.constantSystem, SsaBuilderTask builder, WorkItem work) |
| 854 : this.builder = builder, | 856 : this.builder = builder, |
| 855 this.work = work, | 857 this.work = work, |
| 856 interceptors = builder.interceptors, | 858 interceptors = builder.interceptors, |
| 857 methodInterceptionEnabled = true, | 859 methodInterceptionEnabled = true, |
| 858 graph = new HGraph(), | 860 graph = new HGraph(), |
| 859 stack = new List<HInstruction>(), | 861 stack = new List<HInstruction>(), |
| 860 activationVariables = new Map<Element, HLocalValue>(), | 862 activationVariables = new Map<Element, HLocalValue>(), |
| 861 jumpTargets = new Map<TargetElement, JumpHandler>(), | 863 jumpTargets = new Map<TargetElement, JumpHandler>(), |
| 862 parameters = new Map<Element, HParameterValue>(), | 864 parameters = new Map<Element, HParameterValue>(), |
| 865 sourceElementStack = <Element>[work.element], | |
| 863 inliningStack = <InliningState>[], | 866 inliningStack = <InliningState>[], |
| 864 super(work.resolutionTree) { | 867 super(work.resolutionTree) { |
| 865 localsHandler = new LocalsHandler(this); | 868 localsHandler = new LocalsHandler(this); |
| 866 } | 869 } |
| 867 | 870 |
| 868 static const MAX_INLINING_DEPTH = 3; | 871 static const MAX_INLINING_DEPTH = 3; |
| 869 static const MAX_INLINING_SOURCE_SIZE = 100; | 872 static const MAX_INLINING_SOURCE_SIZE = 100; |
| 870 List<InliningState> inliningStack; | 873 List<InliningState> inliningStack; |
| 871 Element returnElement = null; | 874 Element returnElement = null; |
| 872 | 875 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 List<HInstruction> compiledArguments = new List<HInstruction>(); | 954 List<HInstruction> compiledArguments = new List<HInstruction>(); |
| 952 bool succeeded = addStaticSendArgumentsToList(selector, | 955 bool succeeded = addStaticSendArgumentsToList(selector, |
| 953 arguments, | 956 arguments, |
| 954 function, | 957 function, |
| 955 compiledArguments); | 958 compiledArguments); |
| 956 assert(succeeded); | 959 assert(succeeded); |
| 957 | 960 |
| 958 InliningState state = | 961 InliningState state = |
| 959 new InliningState(function, returnElement, elements, stack); | 962 new InliningState(function, returnElement, elements, stack); |
| 960 inliningStack.add(state); | 963 inliningStack.add(state); |
| 964 sourceElementStack.add(function); | |
| 961 stack = <HInstruction>[]; | 965 stack = <HInstruction>[]; |
| 962 returnElement = new Element(const SourceString("result"), | 966 returnElement = new Element(const SourceString("result"), |
| 963 ElementKind.VARIABLE, | 967 ElementKind.VARIABLE, |
| 964 function); | 968 function); |
| 965 localsHandler.updateLocal(returnElement, | 969 localsHandler.updateLocal(returnElement, |
| 966 graph.addConstantNull(constantSystem)); | 970 graph.addConstantNull(constantSystem)); |
| 967 elements = compiler.enqueuer.resolution.getCachedElements(function); | 971 elements = compiler.enqueuer.resolution.getCachedElements(function); |
| 968 FunctionSignature signature = function.computeSignature(compiler); | 972 FunctionSignature signature = function.computeSignature(compiler); |
| 969 int index = 0; | 973 int index = 0; |
| 970 signature.forEachParameter((Element parameter) { | 974 signature.forEachParameter((Element parameter) { |
| 971 HInstruction argument = compiledArguments[index++]; | 975 HInstruction argument = compiledArguments[index++]; |
| 972 localsHandler.updateLocal(parameter, argument); | 976 localsHandler.updateLocal(parameter, argument); |
| 973 potentiallyCheckType(argument, parameter); | 977 potentiallyCheckType(argument, parameter); |
| 974 }); | 978 }); |
| 975 return state; | 979 return state; |
| 976 } | 980 } |
| 977 | 981 |
| 978 void leaveInlinedMethod(InliningState state) { | 982 void leaveInlinedMethod(InliningState state) { |
| 979 InliningState poppedState = inliningStack.removeLast(); | 983 InliningState poppedState = inliningStack.removeLast(); |
| 980 assert(state == poppedState); | 984 assert(state == poppedState); |
| 985 FunctionElement poppedElement = sourceElementStack.removeLast(); | |
| 986 assert(poppedElement == poppedState.function); | |
| 981 elements = state.oldElements; | 987 elements = state.oldElements; |
| 982 stack.add(localsHandler.readLocal(returnElement)); | 988 stack.add(localsHandler.readLocal(returnElement)); |
| 983 returnElement = state.oldReturnElement; | 989 returnElement = state.oldReturnElement; |
| 984 assert(stack.length == 1); | 990 assert(stack.length == 1); |
| 985 state.oldStack.add(stack[0]); | 991 state.oldStack.add(stack[0]); |
| 986 stack = state.oldStack; | 992 stack = state.oldStack; |
| 987 } | 993 } |
| 988 | 994 |
| 989 bool tryInlineMethod(Element element, | 995 bool tryInlineMethod(Element element, |
| 990 Selector selector, | 996 Selector selector, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 Selector selector = elements.getSelector(call); | 1104 Selector selector = elements.getSelector(call); |
| 1099 Link<Node> arguments = call.arguments; | 1105 Link<Node> arguments = call.arguments; |
| 1100 inlineSuperOrRedirect(target, selector, arguments, constructors, | 1106 inlineSuperOrRedirect(target, selector, arguments, constructors, |
| 1101 fieldValues); | 1107 fieldValues); |
| 1102 foundSuperOrRedirect = true; | 1108 foundSuperOrRedirect = true; |
| 1103 } else { | 1109 } else { |
| 1104 // A field initializer. | 1110 // A field initializer. |
| 1105 SendSet init = link.head; | 1111 SendSet init = link.head; |
| 1106 Link<Node> arguments = init.arguments; | 1112 Link<Node> arguments = init.arguments; |
| 1107 assert(!arguments.isEmpty() && arguments.tail.isEmpty()); | 1113 assert(!arguments.isEmpty() && arguments.tail.isEmpty()); |
| 1114 sourceElementStack.add(constructor); | |
| 1108 visit(arguments.head); | 1115 visit(arguments.head); |
| 1116 sourceElementStack.removeLast(); | |
| 1109 fieldValues[elements[init]] = pop(); | 1117 fieldValues[elements[init]] = pop(); |
| 1110 } | 1118 } |
| 1111 } | 1119 } |
| 1112 } | 1120 } |
| 1113 | 1121 |
| 1114 if (!foundSuperOrRedirect) { | 1122 if (!foundSuperOrRedirect) { |
| 1115 // No super initializer found. Try to find the default constructor if | 1123 // No super initializer found. Try to find the default constructor if |
| 1116 // the class is not Object. | 1124 // the class is not Object. |
| 1117 ClassElement enclosingClass = constructor.getEnclosingClass(); | 1125 ClassElement enclosingClass = constructor.getEnclosingClass(); |
| 1118 ClassElement superClass = enclosingClass.superclass; | 1126 ClassElement superClass = enclosingClass.superclass; |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1454 stack.add(stack.last()); | 1462 stack.add(stack.last()); |
| 1455 } | 1463 } |
| 1456 | 1464 |
| 1457 HBoolify popBoolified() { | 1465 HBoolify popBoolified() { |
| 1458 HBoolify boolified = new HBoolify(pop()); | 1466 HBoolify boolified = new HBoolify(pop()); |
| 1459 add(boolified); | 1467 add(boolified); |
| 1460 return boolified; | 1468 return boolified; |
| 1461 } | 1469 } |
| 1462 | 1470 |
| 1463 HInstruction attachPosition(HInstruction target, Node node) { | 1471 HInstruction attachPosition(HInstruction target, Node node) { |
| 1464 target.sourcePosition = node.getBeginToken(); | 1472 target.sourcePosition = sourceFileLocationForToken(node.getBeginToken()); |
| 1465 return target; | 1473 return target; |
| 1466 } | 1474 } |
| 1467 | 1475 |
| 1476 SourceFileLocation sourceFileLocationForToken(Token token) { | |
| 1477 Element element = sourceElementStack.last(); | |
| 1478 if (element is FunctionElement && element.dynamic.patch != null) { | |
|
floitsch
2012/09/06 16:44:55
don't use 'dynamic'.
Either use "as", or create a
ahe
2012/09/08 08:55:50
Yes. Please don't use "as".
podivilov
2012/09/10 11:13:23
Done.
| |
| 1479 element = element.dynamic.patch; | |
|
ahe
2012/09/08 08:55:50
This is a hack and you should add a TODO for Johnn
podivilov
2012/09/10 11:13:23
Done.
| |
| 1480 } | |
| 1481 SourceFile sourceFile = element.getCompilationUnit().script.file; | |
| 1482 return new SourceFileLocation(sourceFile, token); | |
| 1483 } | |
| 1484 | |
| 1468 void visit(Node node) { | 1485 void visit(Node node) { |
| 1469 if (node !== null) node.accept(this); | 1486 if (node !== null) node.accept(this); |
| 1470 } | 1487 } |
| 1471 | 1488 |
| 1472 visitBlock(Block node) { | 1489 visitBlock(Block node) { |
| 1473 for (Link<Node> link = node.statements.nodes; | 1490 for (Link<Node> link = node.statements.nodes; |
| 1474 !link.isEmpty(); | 1491 !link.isEmpty(); |
| 1475 link = link.tail) { | 1492 link = link.tail) { |
| 1476 visit(link.head); | 1493 visit(link.head); |
| 1477 if (isAborted()) { | 1494 if (isAborted()) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 endLoop(conditionBlock, conditionExitBlock, jumpHandler, savedLocals); | 1673 endLoop(conditionBlock, conditionExitBlock, jumpHandler, savedLocals); |
| 1657 HLoopBlockInformation info = | 1674 HLoopBlockInformation info = |
| 1658 new HLoopBlockInformation( | 1675 new HLoopBlockInformation( |
| 1659 HLoopBlockInformation.loopType(loop), | 1676 HLoopBlockInformation.loopType(loop), |
| 1660 wrapExpressionGraph(initializerGraph), | 1677 wrapExpressionGraph(initializerGraph), |
| 1661 wrapExpressionGraph(conditionExpression), | 1678 wrapExpressionGraph(conditionExpression), |
| 1662 wrapStatementGraph(bodyGraph), | 1679 wrapStatementGraph(bodyGraph), |
| 1663 wrapExpressionGraph(updateGraph), | 1680 wrapExpressionGraph(updateGraph), |
| 1664 conditionBlock.loopInformation.target, | 1681 conditionBlock.loopInformation.target, |
| 1665 conditionBlock.loopInformation.labels, | 1682 conditionBlock.loopInformation.labels, |
| 1666 loop); | 1683 sourceFileLocationForToken(loop.getBeginToken()), |
| 1684 sourceFileLocationForToken(loop.getEndToken())); | |
| 1667 | 1685 |
| 1668 startBlock.setBlockFlow(info, current); | 1686 startBlock.setBlockFlow(info, current); |
| 1669 loopInfo.loopBlockInformation = info; | 1687 loopInfo.loopBlockInformation = info; |
| 1670 } | 1688 } |
| 1671 | 1689 |
| 1672 visitFor(For node) { | 1690 visitFor(For node) { |
| 1673 assert(node.body !== null); | 1691 assert(node.body !== null); |
| 1674 void buildInitializer() { | 1692 void buildInitializer() { |
| 1675 if (node.initializer === null) return; | 1693 if (node.initializer === null) return; |
| 1676 Node initializer = node.initializer; | 1694 Node initializer = node.initializer; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1784 | 1802 |
| 1785 HLoopBlockInformation loopBlockInfo = | 1803 HLoopBlockInformation loopBlockInfo = |
| 1786 new HLoopBlockInformation( | 1804 new HLoopBlockInformation( |
| 1787 HLoopBlockInformation.DO_WHILE_LOOP, | 1805 HLoopBlockInformation.DO_WHILE_LOOP, |
| 1788 null, | 1806 null, |
| 1789 wrapExpressionGraph(conditionExpression), | 1807 wrapExpressionGraph(conditionExpression), |
| 1790 wrapStatementGraph(bodyGraph), | 1808 wrapStatementGraph(bodyGraph), |
| 1791 null, | 1809 null, |
| 1792 loopEntryBlock.loopInformation.target, | 1810 loopEntryBlock.loopInformation.target, |
| 1793 loopEntryBlock.loopInformation.labels, | 1811 loopEntryBlock.loopInformation.labels, |
| 1794 node); | 1812 sourceFileLocationForToken(node.getBeginToken()), |
| 1813 sourceFileLocationForToken(node.getEndToken())); | |
| 1795 loopEntryBlock.setBlockFlow(loopBlockInfo, current); | 1814 loopEntryBlock.setBlockFlow(loopBlockInfo, current); |
| 1796 loopInfo.loopBlockInformation = loopBlockInfo; | 1815 loopInfo.loopBlockInformation = loopBlockInfo; |
| 1797 } | 1816 } |
| 1798 | 1817 |
| 1799 visitFunctionExpression(FunctionExpression node) { | 1818 visitFunctionExpression(FunctionExpression node) { |
| 1800 ClosureClassMap nestedClosureData = | 1819 ClosureClassMap nestedClosureData = |
| 1801 compiler.closureToClassMapper.getMappingForNestedFunction(node); | 1820 compiler.closureToClassMapper.getMappingForNestedFunction(node); |
| 1802 assert(nestedClosureData !== null); | 1821 assert(nestedClosureData !== null); |
| 1803 assert(nestedClosureData.closureClassElement !== null); | 1822 assert(nestedClosureData.closureClassElement !== null); |
| 1804 ClassElement closureClassElement = | 1823 ClassElement closureClassElement = |
| (...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4051 new HSubGraphBlockInformation(elseBranch.graph)); | 4070 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4052 | 4071 |
| 4053 HBasicBlock conditionStartBlock = conditionBranch.block; | 4072 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4054 conditionStartBlock.setBlockFlow(info, joinBlock); | 4073 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4055 SubGraph conditionGraph = conditionBranch.graph; | 4074 SubGraph conditionGraph = conditionBranch.graph; |
| 4056 HIf branch = conditionGraph.end.last; | 4075 HIf branch = conditionGraph.end.last; |
| 4057 assert(branch is HIf); | 4076 assert(branch is HIf); |
| 4058 branch.blockInformation = conditionStartBlock.blockFlow; | 4077 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4059 } | 4078 } |
| 4060 } | 4079 } |
| OLD | NEW |