Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: test/mjsunit/compiler/osr-block-scope.js

Issue 934293002: [turbofan] Simply context specialization and fix for OSR. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --allow-natives-syntax --use-osr --turbo-osr 5 // Flags: --allow-natives-syntax --use-osr --turbo-osr
6 6
7 "use strict"; 7 "use strict";
8 8
9 function nest(body, name, depth) {
10 var header = "";
11 for (var i = 0; i < depth; i++) {
12 var x = "x" + (i + 1);
13 header += " for(var " + x + " = 0; " + x + " < 2; " + x + " = " + x + " + 1 | 0) {\n";
14 body = body + "}"
15 }
16
17 return body.replace(new RegExp("function " + name + "\\(\\) {"),
18 "function " + name + "_" + x + "() {\n" + header);
19 }
20
21 function test(expected, func, depth) {
22 assertEquals(expected, func());
23 assertEquals(expected, func());
24 assertEquals(expected, func());
25
26 var orig = func.toString();
27 var name = func.name;
28 for (var depth = 1; depth < 4; depth++) {
29 var body = nest(orig, name, depth);
30 func = eval("(" + body + ")");
31
32 assertEquals(expected, func());
33 assertEquals(expected, func());
34 assertEquals(expected, func());
35 }
36 }
37
9 function foo() { 38 function foo() {
10 var result; 39 var result;
11 { 40 {
12 let sum = 0; 41 let sum = 0;
13 for (var i = 0; i < 100; i++) { 42 for (var i = 0; i < 10; i++) {
14 if (i == 50) %OptimizeOsr(); 43 %OptimizeOsr();
15 sum += i; 44 sum += i;
16 } 45 }
17 result = sum; 46 result = sum;
18 } 47 }
19 return result; 48 return result;
20 } 49 }
21 50
22 assertEquals(4950, foo()); 51 test(45, foo);
23 assertEquals(4950, foo());
24 assertEquals(4950, foo());
25 52
26 function bar() { 53 function bar() {
27 var result; 54 let sum = 0;
55 for (var i = 0; i < 10; i++) {
56 %OptimizeOsr();
57 sum += i;
58 }
59 return sum;
60 }
61
62 test(45, bar);
63
64 function bon() {
28 { 65 {
29 let sum = 0; 66 let sum = 0;
30 for (let i = 0; i < 90; i++) { 67 for (var i = 0; i < 10; i++) {
68 if (i == 5) %OptimizeOsr();
31 sum += i; 69 sum += i;
32 if (i == 45) %OptimizeOsr();
33 } 70 }
34 result = sum; 71 return sum;
72 }
73 }
74
75 test(45, bon);
76
77 function row() {
78 var i = 0;
79 {
80 let sum = 0;
81 while (true) {
82 if (i == 8) return sum;
83 %OptimizeOsr();
84 sum = i;
85 i = i + 1 | 0;
86 }
87 }
88 return 11;
89 }
90
91 test(7, row);
92
93 function nub() {
94 let i = 0;
95 while (i < 2) {
96 %OptimizeOsr();
97 i++;
98 }
99 return i;
100 }
101
102 test(2, nub);
103
104 function kub() {
105 var result = 0;
106 let i = 0;
107 while (i < 2) {
108 let x = i;
109 %OptimizeOsr();
110 i++;
111 result = x;
35 } 112 }
36 return result; 113 return result;
37 } 114 }
38 115
39 assertEquals(4005, bar()); 116 test(1, kub);
40 assertEquals(4005, bar());
41 assertEquals(4005, bar());
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-js-context-specialization.cc ('k') | test/mjsunit/compiler/osr-block-scope-func.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698