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.octagon; | 5 library dart2js.cps_ir.octagon; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 /// For every variable in the constraint system, two [SignedVariable]s exist, | 9 /// For every variable in the constraint system, two [SignedVariable]s exist, |
10 /// representing the positive and negative uses of the variable. | 10 /// representing the positive and negative uses of the variable. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 /// (both inclusive). | 65 /// (both inclusive). |
66 /// | 66 /// |
67 /// The constraints generated for [min] and [max] are also expressible using | 67 /// The constraints generated for [min] and [max] are also expressible using |
68 /// [Constraint] objects, but the constraints added in [makeVariable] live | 68 /// [Constraint] objects, but the constraints added in [makeVariable] live |
69 /// outside the stack discipline (i.e. the bounds are never popped), which is | 69 /// outside the stack discipline (i.e. the bounds are never popped), which is |
70 /// useful when generating variables on-the-fly. | 70 /// useful when generating variables on-the-fly. |
71 SignedVariable makeVariable([int min, int max]) { | 71 SignedVariable makeVariable([int min, int max]) { |
72 SignedVariable v1 = new SignedVariable._make(); | 72 SignedVariable v1 = new SignedVariable._make(); |
73 if (min != null) { | 73 if (min != null) { |
74 // v1 >= min <==> -v1 - v1 <= -2 * min | 74 // v1 >= min <==> -v1 - v1 <= -2 * min |
75 v1.negated._constraints.add( | 75 v1.negated._constraints |
76 new Constraint(v1.negated, v1.negated, -2 * min)); | 76 .add(new Constraint(v1.negated, v1.negated, -2 * min)); |
77 } | 77 } |
78 if (max != null) { | 78 if (max != null) { |
79 // v1 <= max <==> v1 + v1 <= 2 * max | 79 // v1 <= max <==> v1 + v1 <= 2 * max |
80 v1._constraints.add(new Constraint(v1, v1, 2 * max)); | 80 v1._constraints.add(new Constraint(v1, v1, 2 * max)); |
81 } | 81 } |
82 return v1; | 82 return v1; |
83 } | 83 } |
84 | 84 |
85 /// Add the constraint `v1 + v2 <= k`. | 85 /// Add the constraint `v1 + v2 <= k`. |
86 /// | 86 /// |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 updateDistance(constraint.v1.negated, distanceToV2 + constraint.bound); | 188 updateDistance(constraint.v1.negated, distanceToV2 + constraint.bound); |
189 iterateWorklist(); | 189 iterateWorklist(); |
190 } | 190 } |
191 } | 191 } |
192 // Get the distance to (v1) and check if the A edge would complete a cycle. | 192 // Get the distance to (v1) and check if the A edge would complete a cycle. |
193 int distanceToV1 = distance[constraint.v1]; | 193 int distanceToV1 = distance[constraint.v1]; |
194 if (distanceToV1 == null) return null; | 194 if (distanceToV1 == null) return null; |
195 return distanceToV1 + constraint.bound; | 195 return distanceToV1 + constraint.bound; |
196 } | 196 } |
197 } | 197 } |
OLD | NEW |