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

Side by Side Diff: test/cctest/compiler/test-run-inlining.cc

Issue 453833003: Add initial support for inlining. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "test/cctest/compiler/function-tester.h"
8
9 using namespace v8::internal;
10 using namespace v8::internal::compiler;
11
12 // TODO(sigurds) At the moment we do not write optimization frames when
13 // inlining, thus the reported stack depth changes depending on inlining.
14 // AssertStackDepth checks the stack depth at a simple way to ensure that
15 // inlining actually occurs.
16 // Once inlining creates optimization frames, all these unit tests need to
17 // check that the optimization frame is there.
18
19 TEST(SimpleInlining) {
20 i::FLAG_turbo_inlining = true;
21 FunctionTester T(
22 "(function(){"
23 "function foo(s) { AssertStackDepth(1); return s; };"
24 "function bar(s, t) { return foo(s); };"
25 "return bar;})();");
26
27 T.CheckCall(T.Val(1), T.Val(1), T.Val(2));
28 }
29
30
31 TEST(SimpleInliningContext) {
32 i::FLAG_turbo_inlining = true;
33 FunctionTester T(
34 "(function () {"
35 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };"
36 "function bar(s, t) { return foo(s); };"
37 "return bar;"
38 "})();");
39
40 T.CheckCall(T.Val(13), T.Val(1), T.Val(2));
41 }
42
43
44 TEST(CaptureContext) {
45 i::FLAG_turbo_inlining = true;
46 FunctionTester T(
47 "var f = (function () {"
48 "var x = 42;"
49 "function bar(s) { return x + s; };"
50 "return (function (s) { return bar(s); });"
51 "})();"
52 "(function (s) { return f(s)})");
53
54 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
55 }
56
57
58 // TODO(sigurds) For now we do not inline any native functions. If we do at
59 // some point, change this test.
60 TEST(DontInlineEval) {
61 i::FLAG_turbo_inlining = true;
62 FunctionTester T(
63 "var x = 42;"
64 "(function () {"
65 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };"
66 "return bar;"
67 "})();");
68
69 T.CheckCall(T.Val(42), T.Val("x"), T.undefined());
70 }
71
72
73 TEST(InlineOmitArguments) {
74 i::FLAG_turbo_inlining = true;
75 FunctionTester T(
76 "(function () {"
77 "var x = 42;"
78 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };"
79 "return (function (s,t) { return bar(s); });"
80 "})();");
81
82 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
83 }
84
85
86 TEST(InlineSurplusArguments) {
87 i::FLAG_turbo_inlining = true;
88 FunctionTester T(
89 "(function () {"
90 "var x = 42;"
91 "function foo(s) { AssertStackDepth(1); return x + s; };"
92 "function bar(s,t) { return foo(s,t,13); };"
93 "return bar;"
94 "})();");
95
96 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined());
97 }
98
99
100 TEST(InlineTwice) {
101 i::FLAG_turbo_inlining = true;
102 FunctionTester T(
103 "(function () {"
104 "var x = 42;"
105 "function bar(s) { AssertStackDepth(1); return x + s; };"
106 "return (function (s,t) { return bar(s) + bar(t); });"
107 "})();");
108
109 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4));
110 }
111
112
113 TEST(InlineTwiceDependent) {
114 i::FLAG_turbo_inlining = true;
115 FunctionTester T(
116 "(function () {"
117 "var x = 42;"
118 "function foo(s) { AssertStackDepth(1); return x + s; };"
119 "function bar(s,t) { return foo(foo(s)); };"
120 "return bar;"
121 "})();");
122
123 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4));
124 }
125
126
127 TEST(InlineTwiceDependentDiamond) {
128 i::FLAG_turbo_inlining = true;
129 FunctionTester T(
130 "(function () {"
131 "function foo(s) { if (true) {"
132 " return 12 } else { return 13; } };"
133 "function bar(s,t) { return foo(foo(1)); };"
134 "return bar;"
135 "})();");
136
137 T.CheckCall(T.Val(12), T.undefined(), T.undefined());
138 }
139
140
141 TEST(InlineTwiceDependentDiamondReal) {
142 i::FLAG_turbo_inlining = true;
143 FunctionTester T(
144 "(function () {"
145 "var x = 41;"
146 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {"
147 " return x - s } else { return x + s; } };"
148 "function bar(s,t) { return foo(foo(s)); };"
149 "return bar;"
150 "})();");
151
152 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4));
153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698