| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test allocation sinking optimization. | 4 // Test allocation sinking optimization. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 6 | 6 |
| 7 import 'dart:typed_data'; |
| 7 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 8 | 9 |
| 9 class Point { | 10 class Point { |
| 10 var x, y; | 11 var x, y; |
| 11 | 12 |
| 12 Point(this.x, this.y); | 13 Point(this.x, this.y); |
| 13 | 14 |
| 14 operator * (other) { | 15 operator * (other) { |
| 15 return x * other.x + y * other.y; | 16 return x * other.x + y * other.y; |
| 16 } | 17 } |
| 17 } | 18 } |
| 18 | 19 |
| 19 class C { | 20 class C { |
| 20 var p; | 21 var p; |
| 21 C(this.p); | 22 C(this.p); |
| 22 } | 23 } |
| 23 | 24 |
| 25 |
| 26 class Pointx4 { |
| 27 var x, y; |
| 28 |
| 29 Pointx4(this.x, this.y); |
| 30 |
| 31 operator * (other) { |
| 32 return x * other.x + y * other.y; |
| 33 } |
| 34 } |
| 35 |
| 36 class Cx4 { |
| 37 var p; |
| 38 Cx4(this.p); |
| 39 } |
| 40 |
| 24 class D { | 41 class D { |
| 25 var p; | 42 var p; |
| 26 D(this.p); | 43 D(this.p); |
| 27 } | 44 } |
| 28 | 45 |
| 29 // Class that is used to capture materialized Point object with * operator. | 46 // Class that is used to capture materialized Point object with * operator. |
| 30 class F { | 47 class F { |
| 31 var p; | 48 var p; |
| 32 var val; | 49 var val; |
| 33 | 50 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 } | 65 } |
| 49 } | 66 } |
| 50 | 67 |
| 51 test1(c, x, y) { | 68 test1(c, x, y) { |
| 52 var a = new Point(x - 0.5, y + 0.5); | 69 var a = new Point(x - 0.5, y + 0.5); |
| 53 var b = new Point(x + 0.5, y + 0.8); | 70 var b = new Point(x + 0.5, y + 0.8); |
| 54 var d = new Point(c.p * a, c.p * b); | 71 var d = new Point(c.p * a, c.p * b); |
| 55 return d * d; | 72 return d * d; |
| 56 } | 73 } |
| 57 | 74 |
| 75 test1x4(c, x, y, z, w) { |
| 76 var a = new Pointx4(x - z, y + w); |
| 77 var b = new Pointx4(x + w, y + z); |
| 78 var d = new Pointx4(c.p * a, c.p * b); |
| 79 return d * d; |
| 80 } |
| 81 |
| 58 effects() { | 82 effects() { |
| 59 // This function should not be inlinable. | 83 // This function should not be inlinable. |
| 60 try { } catch (e) { } | 84 try { } catch (e) { } |
| 61 } | 85 } |
| 62 | 86 |
| 63 testForwardingThroughEffects(c, x, y) { | 87 testForwardingThroughEffects(c, x, y) { |
| 64 var a = new Point(x - 0.5, y + 0.5); | 88 var a = new Point(x - 0.5, y + 0.5); |
| 65 var b = new Point(x - 0.5, y - 0.8); | 89 var b = new Point(x - 0.5, y - 0.8); |
| 66 var d = new Point(c.p * a, c.p * b); | 90 var d = new Point(c.p * a, c.p * b); |
| 67 // Effects can't affect neither a, b, nor d because they do not escape. | 91 // Effects can't affect neither a, b, nor d because they do not escape. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 Expect.equals(84, test_vm_field()); | 161 Expect.equals(84, test_vm_field()); |
| 138 for (var i = 0; i < 100; i++) test_vm_field(); | 162 for (var i = 0; i < 100; i++) test_vm_field(); |
| 139 Expect.equals(84, test_vm_field()); | 163 Expect.equals(84, test_vm_field()); |
| 140 } | 164 } |
| 141 | 165 |
| 142 main() { | 166 main() { |
| 143 var c = new C(new Point(0.1, 0.2)); | 167 var c = new C(new Point(0.1, 0.2)); |
| 144 | 168 |
| 145 // Compute initial values. | 169 // Compute initial values. |
| 146 final x0 = test1(c, 11.11, 22.22); | 170 final x0 = test1(c, 11.11, 22.22); |
| 171 var fc = new Cx4(new Pointx4(new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 172 new Float32x4(1.0, 1.0, 1.0, 1.0))); |
| 173 final fx0 = test1x4(fc, new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 174 new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 175 new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 176 new Float32x4(1.0, 1.0, 1.0, 1.0)); |
| 147 final y0 = testForwardingThroughEffects(c, 11.11, 22.22); | 177 final y0 = testForwardingThroughEffects(c, 11.11, 22.22); |
| 148 final z0 = testIdentity(c.p); | 178 final z0 = testIdentity(c.p); |
| 149 | 179 |
| 150 // Force optimization. | 180 // Force optimization. |
| 151 for (var i = 0; i < 100; i++) { | 181 for (var i = 0; i < 100; i++) { |
| 152 test1(c, i.toDouble(), i.toDouble()); | 182 test1(c, i.toDouble(), i.toDouble()); |
| 183 test1x4(fc, new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 184 new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 185 new Float32x4(1.0, 1.0, 1.0, 1.0), |
| 186 new Float32x4(1.0, 1.0, 1.0, 1.0)); |
| 153 testForwardingThroughEffects(c, i.toDouble(), i.toDouble()); | 187 testForwardingThroughEffects(c, i.toDouble(), i.toDouble()); |
| 154 testIdentity(c.p); | 188 testIdentity(c.p); |
| 155 foo2(); | 189 foo2(); |
| 156 Expect.equals(10, foo3(5)); | 190 Expect.equals(10, foo3(5)); |
| 157 } | 191 } |
| 158 Expect.equals(0.0, foo3(0.5)); | 192 Expect.equals(0.0, foo3(0.5)); |
| 159 | 193 |
| 160 // Test returned value after optimization. | 194 // Test returned value after optimization. |
| 161 final x1 = test1(c, 11.11, 22.22); | 195 final x1 = test1(c, 11.11, 22.22); |
| 162 final y1 = testForwardingThroughEffects(c, 11.11, 22.22); | 196 final y1 = testForwardingThroughEffects(c, 11.11, 22.22); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 180 // Test that identity of materialized objects is preserved correctly and | 214 // Test that identity of materialized objects is preserved correctly and |
| 181 // no copies are materialized. | 215 // no copies are materialized. |
| 182 final z1 = testIdentity(c.p); | 216 final z1 = testIdentity(c.p); |
| 183 final z2 = testIdentity(new F(c.p)); | 217 final z2 = testIdentity(new F(c.p)); |
| 184 Expect.equals(z0, z1); | 218 Expect.equals(z0, z1); |
| 185 Expect.equals(z0, z2); | 219 Expect.equals(z0, z2); |
| 186 | 220 |
| 187 testFinalField(); | 221 testFinalField(); |
| 188 testVMField(); | 222 testVMField(); |
| 189 } | 223 } |
| OLD | NEW |