OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import '../compiler.dart'; |
5 import '../elements/elements.dart'; | 6 import '../elements/elements.dart'; |
| 7 import '../resolution/tree_elements.dart'; |
6 import '../types/types.dart'; | 8 import '../types/types.dart'; |
7 | 9 |
| 10 import 'jump_handler.dart'; |
8 import 'locals_handler.dart'; | 11 import 'locals_handler.dart'; |
9 import 'nodes.dart'; | 12 import 'nodes.dart'; |
10 | 13 |
11 /// Base class for objects that build up an SSA graph. | 14 /// Base class for objects that build up an SSA graph. |
12 /// | 15 /// |
13 /// This contains helpers for building the graph and tracking information about | 16 /// This contains helpers for building the graph and tracking information about |
14 /// the current state of the graph being built. | 17 /// the current state of the graph being built. |
15 abstract class GraphBuilder { | 18 abstract class GraphBuilder { |
16 /// Holds the resulting SSA graph. | 19 /// Holds the resulting SSA graph. |
17 final HGraph graph = new HGraph(); | 20 final HGraph graph = new HGraph(); |
18 | 21 |
| 22 // TODO(het): remove this |
| 23 /// A reference to the compiler. |
| 24 Compiler compiler; |
| 25 |
| 26 /// The tree elements for the element being built into an SSA graph. |
| 27 TreeElements get elements; |
| 28 |
19 /// Used to track the locals while building the graph. | 29 /// Used to track the locals while building the graph. |
20 LocalsHandler localsHandler; | 30 LocalsHandler localsHandler; |
21 | 31 |
22 /// A stack of instructions. | 32 /// A stack of instructions. |
23 /// | 33 /// |
24 /// We build the SSA graph by simulating a stack machine. | 34 /// We build the SSA graph by simulating a stack machine. |
25 List<HInstruction> stack = <HInstruction>[]; | 35 List<HInstruction> stack = <HInstruction>[]; |
26 | 36 |
| 37 /// The count of nested loops we are currently building. |
| 38 /// |
| 39 /// The loop nesting is consulted when inlining a function invocation. The |
| 40 /// inlining heuristics take this information into account. |
| 41 int loopDepth = 0; |
| 42 |
| 43 /// A mapping from jump targets to their handlers. |
| 44 Map<JumpTarget, JumpHandler> jumpTargets = <JumpTarget, JumpHandler>{}; |
| 45 |
27 void push(HInstruction instruction) { | 46 void push(HInstruction instruction) { |
28 add(instruction); | 47 add(instruction); |
29 stack.add(instruction); | 48 stack.add(instruction); |
30 } | 49 } |
31 | 50 |
32 HInstruction pop() { | 51 HInstruction pop() { |
33 return stack.removeLast(); | 52 return stack.removeLast(); |
34 } | 53 } |
35 | 54 |
36 /// Pops the most recent instruction from the stack and 'boolifies' it. | 55 /// Pops the most recent instruction from the stack and 'boolifies' it. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 HParameterValue addParameter(Entity parameter, TypeMask type) { | 145 HParameterValue addParameter(Entity parameter, TypeMask type) { |
127 HParameterValue result = new HParameterValue(parameter, type); | 146 HParameterValue result = new HParameterValue(parameter, type); |
128 if (lastAddedParameter == null) { | 147 if (lastAddedParameter == null) { |
129 graph.entry.addBefore(graph.entry.first, result); | 148 graph.entry.addBefore(graph.entry.first, result); |
130 } else { | 149 } else { |
131 graph.entry.addAfter(lastAddedParameter, result); | 150 graph.entry.addAfter(lastAddedParameter, result); |
132 } | 151 } |
133 lastAddedParameter = result; | 152 lastAddedParameter = result; |
134 return result; | 153 return result; |
135 } | 154 } |
| 155 |
| 156 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { |
| 157 if (statements == null) return null; |
| 158 return new HSubGraphBlockInformation(statements); |
| 159 } |
| 160 |
| 161 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { |
| 162 if (expression == null) return null; |
| 163 return new HSubExpressionBlockInformation(expression); |
| 164 } |
136 } | 165 } |
OLD | NEW |