| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.cps_ir.loop_hierarchy; | 5 library dart2js.cps_ir.loop_hierarchy; |
| 6 | 6 |
| 7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
| 8 | 8 |
| 9 /// Determines the effective nesting of loops. | 9 /// Determines the effective nesting of loops. |
| 10 /// | 10 /// |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 } else if (node is Branch) { | 121 } else if (node is Branch) { |
| 122 target = _markInnerLoop( | 122 target = _markInnerLoop( |
| 123 loopTarget[node.trueContinuation.definition], | 123 loopTarget[node.trueContinuation.definition], |
| 124 loopTarget[node.falseContinuation.definition]); | 124 loopTarget[node.falseContinuation.definition]); |
| 125 } else { | 125 } else { |
| 126 assert(node is Unreachable || node is Throw); | 126 assert(node is Unreachable || node is Throw); |
| 127 } | 127 } |
| 128 return _markInnerLoop(target, catchLoop); | 128 return _markInnerLoop(target, catchLoop); |
| 129 } | 129 } |
| 130 |
| 131 /// Returns the the innermost loop that effectively encloses both |
| 132 /// c1 and c2 (or `null` if there is no such loop). |
| 133 Continuation lowestCommonAncestor(Continuation c1, Continuation c2) { |
| 134 int d1 = getDepth(c1), d2 = getDepth(c2); |
| 135 while (c1 != c2) { |
| 136 if (d1 <= d2) { |
| 137 c2 = getEnclosingLoop(c2); |
| 138 d2 = getDepth(c2); |
| 139 } else { |
| 140 c1 = getEnclosingLoop(c1); |
| 141 d1 = getDepth(c1); |
| 142 } |
| 143 } |
| 144 return c1; |
| 145 } |
| 146 |
| 147 /// Returns the lexical nesting depth of [loop]. |
| 148 int getDepth(Continuation loop) { |
| 149 if (loop == null) return 0; |
| 150 return loopDepth[loop]; |
| 151 } |
| 130 } | 152 } |
| OLD | NEW |