| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 SsaBuilderTask extends CompilerTask { | 5 class SsaBuilderTask extends CompilerTask { |
| 6 SsaBuilderTask(Compiler compiler) : super(compiler); | 6 SsaBuilderTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA builder'; | 7 String get name() => 'SSA builder'; |
| 8 | 8 |
| 9 HGraph build(FunctionElement element, TreeElements elements) { | 9 HGraph build(FunctionElement element, TreeElements elements) { |
| 10 return measure(() { | 10 return measure(() { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 List superInputs = <HInstruction>[]; | 122 List superInputs = <HInstruction>[]; |
| 123 superInputs.add(new HThis()); | 123 superInputs.add(new HThis()); |
| 124 Link link = superInvocation.arguments.head; | 124 Link link = superInvocation.arguments.head; |
| 125 for (; !link.isEmpty(); link = link.tail) { | 125 for (; !link.isEmpty(); link = link.tail) { |
| 126 visit(link.head); | 126 visit(link.head); |
| 127 superInputs.add(pop()); | 127 superInputs.add(pop()); |
| 128 } | 128 } |
| 129 add(new HInvokeDynamic(methodName, superInputs)); | 129 add(new HInvokeDynamic(methodName, superInputs)); |
| 130 } | 130 } |
| 131 body.accept(this); | 131 body.accept(this); |
| 132 return closeFunction(); | 132 return closeFunction(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void openFunction(NodeList parameters) { | 135 void openFunction(NodeList parameters) { |
| 136 stack = new List<HInstruction>(); | 136 stack = new List<HInstruction>(); |
| 137 definitions = new Map<Element, HInstruction>(); | 137 definitions = new Map<Element, HInstruction>(); |
| 138 | 138 |
| 139 graph = new HGraph(); | 139 graph = new HGraph(); |
| 140 HBasicBlock block = graph.addNewBlock(); | 140 HBasicBlock block = graph.addNewBlock(); |
| 141 | 141 |
| 142 open(graph.entry); | 142 open(graph.entry); |
| 143 visitParameterValues(parameters); | 143 visitParameterValues(parameters); |
| 144 close(new HGoto()).addSuccessor(block); | 144 close(new HGoto()).addSuccessor(block); |
| 145 | 145 |
| 146 open(block); | 146 open(block); |
| 147 } | 147 } |
| 148 | 148 |
| 149 HGraph closeFunction() { | 149 HGraph closeFunction() { |
| 150 // TODO(kasperl): Make this goto an implicit return. | 150 // TODO(kasperl): Make this goto an implicit return. |
| 151 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); | 151 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); |
| 152 graph.finalize(); | 152 graph.finalize(); |
| 153 return graph; | 153 return graph; |
| 154 } | 154 } |
| 155 | 155 |
| 156 HBasicBlock addNewBlock() { | 156 HBasicBlock addNewBlock() { |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 visit(node.receiver); | 627 visit(node.receiver); |
| 628 visit(node.argumentsNode); | 628 visit(node.argumentsNode); |
| 629 var right = pop(); | 629 var right = pop(); |
| 630 var left = pop(); | 630 var left = pop(); |
| 631 visitBinary(left, op, right, element); | 631 visitBinary(left, op, right, element); |
| 632 } | 632 } |
| 633 } else if (node.isPropertyAccess) { | 633 } else if (node.isPropertyAccess) { |
| 634 if (node.receiver !== null) { | 634 if (node.receiver !== null) { |
| 635 compiler.unimplemented("SsaBuilder.visitSend with receiver"); | 635 compiler.unimplemented("SsaBuilder.visitSend with receiver"); |
| 636 } | 636 } |
| 637 HInstruction instruction = definitions[element]; | 637 if (element != null |
| 638 assert(instruction !== null); | 638 && !element.isInstanceMember() |
| 639 stack.add(instruction); | 639 && element.kind === ElementKind.FIELD) { |
| 640 compiler.unimplemented("SsaBuilder.visitSend with static field"); |
| 641 push(new HStatic(element)); |
| 642 } else { |
| 643 HInstruction instruction = definitions[element]; |
| 644 assert(instruction !== null); |
| 645 stack.add(instruction); |
| 646 } |
| 640 } else { | 647 } else { |
| 641 if (element === null) { | 648 if (element === null) { |
| 642 compiler.unimplemented("SsaBuilder.visitSend with receiver"); | 649 compiler.unimplemented("SsaBuilder.visitSend with receiver"); |
| 643 } | 650 } |
| 644 Link<Node> link = node.arguments; | 651 Link<Node> link = node.arguments; |
| 645 if (element.kind === ElementKind.FOREIGN) { | 652 if (element.kind === ElementKind.FOREIGN) { |
| 646 // If the invoke is on foreign code, don't visit the first | 653 // If the invoke is on foreign code, don't visit the first |
| 647 // argument, which is the foreign code. | 654 // argument, which is the foreign code. |
| 648 link = link.tail; | 655 link = link.tail; |
| 649 } | 656 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 thenBlock.addSuccessor(joinBlock); | 876 thenBlock.addSuccessor(joinBlock); |
| 870 elseBlock.addSuccessor(joinBlock); | 877 elseBlock.addSuccessor(joinBlock); |
| 871 open(joinBlock); | 878 open(joinBlock); |
| 872 | 879 |
| 873 definitions = joinDefinitions(joinBlock, thenDefinitions, definitions); | 880 definitions = joinDefinitions(joinBlock, thenDefinitions, definitions); |
| 874 HPhi phi = new HPhi.manyInputs(null, [thenInstruction, elseInstruction]); | 881 HPhi phi = new HPhi.manyInputs(null, [thenInstruction, elseInstruction]); |
| 875 joinBlock.addPhi(phi); | 882 joinBlock.addPhi(phi); |
| 876 stack.add(phi); | 883 stack.add(phi); |
| 877 } | 884 } |
| 878 } | 885 } |
| OLD | NEW |