| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 emitter = backend.emitter, | 146 emitter = backend.emitter, |
| 147 functionsCalledInLoop = new Set<FunctionElement>(), | 147 functionsCalledInLoop = new Set<FunctionElement>(), |
| 148 selectorsCalledInLoop = new Map<SourceString, Selector>(), | 148 selectorsCalledInLoop = new Map<SourceString, Selector>(), |
| 149 backend = backend, | 149 backend = backend, |
| 150 super(backend.compiler); | 150 super(backend.compiler); |
| 151 | 151 |
| 152 HGraph build(WorkItem work) { | 152 HGraph build(WorkItem work) { |
| 153 return measure(() { | 153 return measure(() { |
| 154 FunctionElement element = work.element; | 154 FunctionElement element = work.element; |
| 155 HInstruction.idCounter = 0; | 155 HInstruction.idCounter = 0; |
| 156 SsaBuilder builder = new SsaBuilder(this, work); | 156 FoldingOperations foldingOperations = |
| 157 compiler.constantHandler.foldingOperations; |
| 158 SsaBuilder builder = new SsaBuilder(foldingOperations, this, work); |
| 157 HGraph graph; | 159 HGraph graph; |
| 158 ElementKind kind = element.kind; | 160 ElementKind kind = element.kind; |
| 159 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { | 161 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 160 graph = compileConstructor(builder, work); | 162 graph = compileConstructor(builder, work); |
| 161 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || | 163 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || |
| 162 kind === ElementKind.FUNCTION || | 164 kind === ElementKind.FUNCTION || |
| 163 kind === ElementKind.GETTER || | 165 kind === ElementKind.GETTER || |
| 164 kind === ElementKind.SETTER) { | 166 kind === ElementKind.SETTER) { |
| 165 graph = builder.buildMethod(work.element); | 167 graph = builder.buildMethod(work.element); |
| 166 } | 168 } |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 result.add(element); | 792 result.add(element); |
| 791 } | 793 } |
| 792 return (result === null) ? const <LabelElement>[] : result; | 794 return (result === null) ? const <LabelElement>[] : result; |
| 793 } | 795 } |
| 794 } | 796 } |
| 795 | 797 |
| 796 class SsaBuilder extends ResolvedVisitor implements Visitor { | 798 class SsaBuilder extends ResolvedVisitor implements Visitor { |
| 797 final SsaBuilderTask builder; | 799 final SsaBuilderTask builder; |
| 798 final Interceptors interceptors; | 800 final Interceptors interceptors; |
| 799 final WorkItem work; | 801 final WorkItem work; |
| 802 final FoldingOperations foldingOperations; |
| 800 bool methodInterceptionEnabled; | 803 bool methodInterceptionEnabled; |
| 801 HGraph graph; | 804 HGraph graph; |
| 802 LocalsHandler localsHandler; | 805 LocalsHandler localsHandler; |
| 803 HInstruction rethrowableException; | 806 HInstruction rethrowableException; |
| 804 Map<Element, HParameterValue> parameters; | 807 Map<Element, HParameterValue> parameters; |
| 805 | 808 |
| 806 Map<TargetElement, JumpHandler> jumpTargets; | 809 Map<TargetElement, JumpHandler> jumpTargets; |
| 807 | 810 |
| 808 /** | 811 /** |
| 809 * Variables stored in the current activation. These variables are | 812 * Variables stored in the current activation. These variables are |
| (...skipping 10 matching lines...) Expand all Loading... |
| 820 HBasicBlock current; | 823 HBasicBlock current; |
| 821 // The most recently opened block. Has the same value as [current] while | 824 // The most recently opened block. Has the same value as [current] while |
| 822 // the block is open, but unlike [current], it isn't cleared when the current | 825 // the block is open, but unlike [current], it isn't cleared when the current |
| 823 // block is closed. | 826 // block is closed. |
| 824 HBasicBlock lastOpenedBlock; | 827 HBasicBlock lastOpenedBlock; |
| 825 | 828 |
| 826 LibraryElement get currentLibrary() => work.element.getLibrary(); | 829 LibraryElement get currentLibrary() => work.element.getLibrary(); |
| 827 Compiler get compiler() => builder.compiler; | 830 Compiler get compiler() => builder.compiler; |
| 828 CodeEmitterTask get emitter() => builder.emitter; | 831 CodeEmitterTask get emitter() => builder.emitter; |
| 829 | 832 |
| 830 SsaBuilder(SsaBuilderTask builder, WorkItem work) | 833 SsaBuilder(this.foldingOperations, SsaBuilderTask builder, WorkItem work) |
| 831 : this.builder = builder, | 834 : this.builder = builder, |
| 832 this.work = work, | 835 this.work = work, |
| 833 interceptors = builder.interceptors, | 836 interceptors = builder.interceptors, |
| 834 methodInterceptionEnabled = true, | 837 methodInterceptionEnabled = true, |
| 835 graph = new HGraph(), | 838 graph = new HGraph(), |
| 836 stack = new List<HInstruction>(), | 839 stack = new List<HInstruction>(), |
| 837 activationVariables = new Map<Element, HLocalValue>(), | 840 activationVariables = new Map<Element, HLocalValue>(), |
| 838 jumpTargets = new Map<TargetElement, JumpHandler>(), | 841 jumpTargets = new Map<TargetElement, JumpHandler>(), |
| 839 parameters = new Map<Element, HParameterValue>(), | 842 parameters = new Map<Element, HParameterValue>(), |
| 840 super(work.resolutionTree) { | 843 super(work.resolutionTree) { |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 switch (value) { | 1635 switch (value) { |
| 1633 case "-": result = new HNegate(target, operand); break; | 1636 case "-": result = new HNegate(target, operand); break; |
| 1634 case "~": result = new HBitNot(target, operand); break; | 1637 case "~": result = new HBitNot(target, operand); break; |
| 1635 default: | 1638 default: |
| 1636 compiler.internalError('Unexpected unary operator: $value.', node: op); | 1639 compiler.internalError('Unexpected unary operator: $value.', node: op); |
| 1637 break; | 1640 break; |
| 1638 } | 1641 } |
| 1639 // See if we can constant-fold right away. This avoids rewrites later on. | 1642 // See if we can constant-fold right away. This avoids rewrites later on. |
| 1640 if (operand is HConstant) { | 1643 if (operand is HConstant) { |
| 1641 HConstant constant = operand; | 1644 HConstant constant = operand; |
| 1642 Constant folded = result.operation.fold(constant.constant); | 1645 Constant folded = |
| 1646 result.operation(foldingOperations).fold(constant.constant); |
| 1643 if (folded !== null) { | 1647 if (folded !== null) { |
| 1644 stack.add(graph.addConstant(folded)); | 1648 stack.add(graph.addConstant(folded)); |
| 1645 return; | 1649 return; |
| 1646 } | 1650 } |
| 1647 } | 1651 } |
| 1648 pushWithPosition(result, node); | 1652 pushWithPosition(result, node); |
| 1649 } | 1653 } |
| 1650 | 1654 |
| 1651 void visitBinary(HInstruction left, Operator op, HInstruction right) { | 1655 void visitBinary(HInstruction left, Operator op, HInstruction right) { |
| 1652 Element element = interceptors.getOperatorInterceptor(op); | 1656 Element element = interceptors.getOperatorInterceptor(op); |
| (...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3606 new HSubGraphBlockInformation(elseBranch.graph)); | 3610 new HSubGraphBlockInformation(elseBranch.graph)); |
| 3607 | 3611 |
| 3608 HBasicBlock conditionStartBlock = conditionBranch.block; | 3612 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 3609 conditionStartBlock.setBlockFlow(info, joinBlock); | 3613 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 3610 SubGraph conditionGraph = conditionBranch.graph; | 3614 SubGraph conditionGraph = conditionBranch.graph; |
| 3611 HIf branch = conditionGraph.end.last; | 3615 HIf branch = conditionGraph.end.last; |
| 3612 assert(branch is HIf); | 3616 assert(branch is HIf); |
| 3613 branch.blockInformation = conditionStartBlock.blockFlow; | 3617 branch.blockInformation = conditionStartBlock.blockFlow; |
| 3614 } | 3618 } |
| 3615 } | 3619 } |
| OLD | NEW |