| 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 import 'compiler_helper.dart'; | 5 import 'compiler_helper.dart'; |
| 6 | 6 |
| 7 const String TEST_ONE = r""" | 7 const String TEST_ONE = r""" |
| 8 void foo(bar) { | 8 void foo(bar) { |
| 9 for (int i = 0; i < 1; i++) { | 9 for (int i = 0; i < 1; i++) { |
| 10 print(1 + bar); | 10 print(1 + bar); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // Check that instructions that don't have a builtin equivalent can | 35 // Check that instructions that don't have a builtin equivalent can |
| 36 // still be GVN'ed. | 36 // still be GVN'ed. |
| 37 const String TEST_FOUR = r""" | 37 const String TEST_FOUR = r""" |
| 38 void foo(a) { | 38 void foo(a) { |
| 39 print(1 >> a); | 39 print(1 >> a); |
| 40 print(1 >> a); | 40 print(1 >> a); |
| 41 } | 41 } |
| 42 """; | 42 """; |
| 43 | 43 |
| 44 // Check that [HCheck] instructions do not prevent GVN. |
| 45 const String TEST_FIVE = r""" |
| 46 class A { |
| 47 var foo = 21; |
| 48 } |
| 49 |
| 50 class B {} |
| 51 |
| 52 main() { |
| 53 var a = [new B(), new A()][0]; |
| 54 var b = a.foo; |
| 55 var c = a.foo; |
| 56 if (a is B) { |
| 57 c = a.foo; |
| 58 } |
| 59 return b + c; |
| 60 } |
| 61 """; |
| 62 |
| 44 main() { | 63 main() { |
| 45 String generated = compile(TEST_ONE, entry: 'foo'); | 64 String generated = compile(TEST_ONE, entry: 'foo'); |
| 46 RegExp regexp = new RegExp(r"1 \+ [a-z]+"); | 65 RegExp regexp = new RegExp(r"1 \+ [a-z]+"); |
| 47 checkNumberOfMatches(regexp.allMatches(generated).iterator, 1); | 66 checkNumberOfMatches(regexp.allMatches(generated).iterator, 1); |
| 48 | 67 |
| 49 generated = compile(TEST_TWO, entry: 'foo'); | 68 generated = compile(TEST_TWO, entry: 'foo'); |
| 50 checkNumberOfMatches(new RegExp("length").allMatches(generated).iterator, 1); | 69 checkNumberOfMatches(new RegExp("length").allMatches(generated).iterator, 1); |
| 51 | 70 |
| 52 generated = compile(TEST_THREE, entry: 'foo'); | 71 generated = compile(TEST_THREE, entry: 'foo'); |
| 53 checkNumberOfMatches(new RegExp("number").allMatches(generated).iterator, 1); | 72 checkNumberOfMatches(new RegExp("number").allMatches(generated).iterator, 1); |
| 54 | 73 |
| 55 generated = compile(TEST_FOUR, entry: 'foo'); | 74 generated = compile(TEST_FOUR, entry: 'foo'); |
| 56 checkNumberOfMatches(new RegExp("shr").allMatches(generated).iterator, 1); | 75 checkNumberOfMatches(new RegExp("shr").allMatches(generated).iterator, 1); |
| 76 |
| 77 generated = compileAll(TEST_FIVE); |
| 78 checkNumberOfMatches( |
| 79 new RegExp("get\\\$foo").allMatches(generated).iterator, 1); |
| 57 } | 80 } |
| OLD | NEW |