| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
| 8 | 8 |
| 9 #if V8_TURBOFAN_TARGET | 9 #if V8_TURBOFAN_TARGET |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 static void InstallAssertStackDepthHelper(v8::Isolate* isolate) { | 30 static void InstallAssertStackDepthHelper(v8::Isolate* isolate) { |
| 31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 31 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 32 v8::Local<v8::FunctionTemplate> t = | 32 v8::Local<v8::FunctionTemplate> t = |
| 33 v8::FunctionTemplate::New(isolate, AssertStackDepth); | 33 v8::FunctionTemplate::New(isolate, AssertStackDepth); |
| 34 context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction()); | 34 context->Global()->Set(v8_str("AssertStackDepth"), t->GetFunction()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 TEST(SimpleInlining) { | 38 TEST(SimpleInlining) { |
| 39 FLAG_context_specialization = true; | |
| 40 FLAG_turbo_inlining = true; | |
| 41 FunctionTester T( | 39 FunctionTester T( |
| 42 "(function(){" | 40 "(function(){" |
| 43 "function foo(s) { AssertStackDepth(1); return s; };" | 41 "function foo(s) { AssertStackDepth(1); return s; };" |
| 44 "function bar(s, t) { return foo(s); };" | 42 "function bar(s, t) { return foo(s); };" |
| 45 "return bar;})();"); | 43 "return bar;})();", |
| 44 CompilationInfo::kInliningEnabled | |
| 45 CompilationInfo::kContextSpecializing); |
| 46 | 46 |
| 47 InstallAssertStackDepthHelper(CcTest::isolate()); | 47 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 48 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); | 48 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 TEST(SimpleInliningContext) { | 52 TEST(SimpleInliningContext) { |
| 53 FLAG_context_specialization = true; | |
| 54 FLAG_turbo_inlining = true; | |
| 55 FunctionTester T( | 53 FunctionTester T( |
| 56 "(function () {" | 54 "(function () {" |
| 57 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" | 55 "function foo(s) { AssertStackDepth(1); var x = 12; return s + x; };" |
| 58 "function bar(s, t) { return foo(s); };" | 56 "function bar(s, t) { return foo(s); };" |
| 59 "return bar;" | 57 "return bar;" |
| 60 "})();"); | 58 "})();", |
| 59 CompilationInfo::kInliningEnabled | |
| 60 CompilationInfo::kContextSpecializing); |
| 61 | 61 |
| 62 InstallAssertStackDepthHelper(CcTest::isolate()); | 62 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 63 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); | 63 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 TEST(CaptureContext) { | 67 TEST(CaptureContext) { |
| 68 FLAG_context_specialization = true; | |
| 69 FLAG_turbo_inlining = true; | |
| 70 FunctionTester T( | 68 FunctionTester T( |
| 71 "var f = (function () {" | 69 "var f = (function () {" |
| 72 "var x = 42;" | 70 "var x = 42;" |
| 73 "function bar(s) { return x + s; };" | 71 "function bar(s) { return x + s; };" |
| 74 "return (function (s) { return bar(s); });" | 72 "return (function (s) { return bar(s); });" |
| 75 "})();" | 73 "})();" |
| 76 "(function (s) { return f(s)})"); | 74 "(function (s) { return f(s)})", |
| 75 CompilationInfo::kInliningEnabled | |
| 76 CompilationInfo::kContextSpecializing); |
| 77 | 77 |
| 78 InstallAssertStackDepthHelper(CcTest::isolate()); | 78 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 79 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 79 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 // TODO(sigurds) For now we do not inline any native functions. If we do at | 83 // TODO(sigurds) For now we do not inline any native functions. If we do at |
| 84 // some point, change this test. | 84 // some point, change this test. |
| 85 TEST(DontInlineEval) { | 85 TEST(DontInlineEval) { |
| 86 FLAG_context_specialization = true; | |
| 87 FLAG_turbo_inlining = true; | |
| 88 FunctionTester T( | 86 FunctionTester T( |
| 89 "var x = 42;" | 87 "var x = 42;" |
| 90 "(function () {" | 88 "(function () {" |
| 91 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" | 89 "function bar(s, t) { return eval(\"AssertStackDepth(2); x\") };" |
| 92 "return bar;" | 90 "return bar;" |
| 93 "})();"); | 91 "})();", |
| 92 CompilationInfo::kInliningEnabled | |
| 93 CompilationInfo::kContextSpecializing); |
| 94 | 94 |
| 95 InstallAssertStackDepthHelper(CcTest::isolate()); | 95 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 96 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); | 96 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 | 99 |
| 100 TEST(InlineOmitArguments) { | 100 TEST(InlineOmitArguments) { |
| 101 FLAG_context_specialization = true; | |
| 102 FLAG_turbo_inlining = true; | |
| 103 FunctionTester T( | 101 FunctionTester T( |
| 104 "(function () {" | 102 "(function () {" |
| 105 "var x = 42;" | 103 "var x = 42;" |
| 106 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" | 104 "function bar(s, t, u, v) { AssertStackDepth(1); return x + s; };" |
| 107 "return (function (s,t) { return bar(s); });" | 105 "return (function (s,t) { return bar(s); });" |
| 108 "})();"); | 106 "})();", |
| 107 CompilationInfo::kInliningEnabled | |
| 108 CompilationInfo::kContextSpecializing); |
| 109 | 109 |
| 110 InstallAssertStackDepthHelper(CcTest::isolate()); | 110 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 111 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 111 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 TEST(InlineSurplusArguments) { | 115 TEST(InlineSurplusArguments) { |
| 116 FLAG_context_specialization = true; | |
| 117 FLAG_turbo_inlining = true; | |
| 118 FunctionTester T( | 116 FunctionTester T( |
| 119 "(function () {" | 117 "(function () {" |
| 120 "var x = 42;" | 118 "var x = 42;" |
| 121 "function foo(s) { AssertStackDepth(1); return x + s; };" | 119 "function foo(s) { AssertStackDepth(1); return x + s; };" |
| 122 "function bar(s,t) { return foo(s,t,13); };" | 120 "function bar(s,t) { return foo(s,t,13); };" |
| 123 "return bar;" | 121 "return bar;" |
| 124 "})();"); | 122 "})();", |
| 123 CompilationInfo::kInliningEnabled | |
| 124 CompilationInfo::kContextSpecializing); |
| 125 | 125 |
| 126 InstallAssertStackDepthHelper(CcTest::isolate()); | 126 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 127 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 127 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 TEST(InlineTwice) { | 131 TEST(InlineTwice) { |
| 132 FLAG_context_specialization = true; | |
| 133 FLAG_turbo_inlining = true; | |
| 134 FunctionTester T( | 132 FunctionTester T( |
| 135 "(function () {" | 133 "(function () {" |
| 136 "var x = 42;" | 134 "var x = 42;" |
| 137 "function bar(s) { AssertStackDepth(1); return x + s; };" | 135 "function bar(s) { AssertStackDepth(1); return x + s; };" |
| 138 "return (function (s,t) { return bar(s) + bar(t); });" | 136 "return (function (s,t) { return bar(s) + bar(t); });" |
| 139 "})();"); | 137 "})();", |
| 138 CompilationInfo::kInliningEnabled | |
| 139 CompilationInfo::kContextSpecializing); |
| 140 | 140 |
| 141 InstallAssertStackDepthHelper(CcTest::isolate()); | 141 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 142 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); | 142 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 TEST(InlineTwiceDependent) { | 146 TEST(InlineTwiceDependent) { |
| 147 FLAG_context_specialization = true; | |
| 148 FLAG_turbo_inlining = true; | |
| 149 FunctionTester T( | 147 FunctionTester T( |
| 150 "(function () {" | 148 "(function () {" |
| 151 "var x = 42;" | 149 "var x = 42;" |
| 152 "function foo(s) { AssertStackDepth(1); return x + s; };" | 150 "function foo(s) { AssertStackDepth(1); return x + s; };" |
| 153 "function bar(s,t) { return foo(foo(s)); };" | 151 "function bar(s,t) { return foo(foo(s)); };" |
| 154 "return bar;" | 152 "return bar;" |
| 155 "})();"); | 153 "})();", |
| 154 CompilationInfo::kInliningEnabled | |
| 155 CompilationInfo::kContextSpecializing); |
| 156 | 156 |
| 157 InstallAssertStackDepthHelper(CcTest::isolate()); | 157 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 158 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); | 158 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 TEST(InlineTwiceDependentDiamond) { | 162 TEST(InlineTwiceDependentDiamond) { |
| 163 FLAG_context_specialization = true; | |
| 164 FLAG_turbo_inlining = true; | |
| 165 FunctionTester T( | 163 FunctionTester T( |
| 166 "(function () {" | 164 "(function () {" |
| 167 "function foo(s) { if (true) {" | 165 "function foo(s) { if (true) {" |
| 168 " return 12 } else { return 13; } };" | 166 " return 12 } else { return 13; } };" |
| 169 "function bar(s,t) { return foo(foo(1)); };" | 167 "function bar(s,t) { return foo(foo(1)); };" |
| 170 "return bar;" | 168 "return bar;" |
| 171 "})();"); | 169 "})();", |
| 170 CompilationInfo::kInliningEnabled | |
| 171 CompilationInfo::kContextSpecializing); |
| 172 | 172 |
| 173 InstallAssertStackDepthHelper(CcTest::isolate()); | 173 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 174 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); | 174 T.CheckCall(T.Val(12), T.undefined(), T.undefined()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 TEST(InlineTwiceDependentDiamondReal) { | 178 TEST(InlineTwiceDependentDiamondReal) { |
| 179 FLAG_context_specialization = true; | |
| 180 FLAG_turbo_inlining = true; | |
| 181 FunctionTester T( | 179 FunctionTester T( |
| 182 "(function () {" | 180 "(function () {" |
| 183 "var x = 41;" | 181 "var x = 41;" |
| 184 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" | 182 "function foo(s) { AssertStackDepth(1); if (s % 2 == 0) {" |
| 185 " return x - s } else { return x + s; } };" | 183 " return x - s } else { return x + s; } };" |
| 186 "function bar(s,t) { return foo(foo(s)); };" | 184 "function bar(s,t) { return foo(foo(s)); };" |
| 187 "return bar;" | 185 "return bar;" |
| 188 "})();"); | 186 "})();", |
| 187 CompilationInfo::kInliningEnabled | |
| 188 CompilationInfo::kContextSpecializing); |
| 189 | 189 |
| 190 InstallAssertStackDepthHelper(CcTest::isolate()); | 190 InstallAssertStackDepthHelper(CcTest::isolate()); |
| 191 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); | 191 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 #endif // V8_TURBOFAN_TARGET | 194 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |