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/compiler/js-context-specialization.h" | 5 #include "src/compiler/js-context-specialization.h" |
6 #include "src/compiler/js-operator.h" | 6 #include "src/compiler/js-operator.h" |
7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
9 #include "src/compiler/source-position.h" | 9 #include "src/compiler/source-position.h" |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 Handle<Context> subcontext2 = t.factory()->NewNativeContext(); | 53 Handle<Context> subcontext2 = t.factory()->NewNativeContext(); |
54 subcontext2->set_previous(*subcontext1); | 54 subcontext2->set_previous(*subcontext1); |
55 subcontext1->set_previous(*native); | 55 subcontext1->set_previous(*native); |
56 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); | 56 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); |
57 const int slot = Context::GLOBAL_OBJECT_INDEX; | 57 const int slot = Context::GLOBAL_OBJECT_INDEX; |
58 native->set(slot, *expected); | 58 native->set(slot, *expected); |
59 | 59 |
60 Node* const_context = t.jsgraph()->Constant(native); | 60 Node* const_context = t.jsgraph()->Constant(native); |
61 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); | 61 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); |
62 Node* param_context = t.NewNode(t.common()->Parameter(0), start); | 62 Node* param_context = t.NewNode(t.common()->Parameter(0), start); |
63 JSContextSpecializer spec(Handle<Context>(), t.jsgraph(), const_context); | 63 JSContextSpecializer spec(t.jsgraph()); |
64 | 64 |
65 { | 65 { |
66 // Mutable slot, constant context, depth = 0 => do nothing. | 66 // Mutable slot, constant context, depth = 0 => do nothing. |
67 Node* load = t.NewNode(t.javascript()->LoadContext(0, 0, false), | 67 Node* load = t.NewNode(t.javascript()->LoadContext(0, 0, false), |
68 const_context, const_context, start); | 68 const_context, const_context, start); |
69 Reduction r = spec.ReduceJSLoadContext(load); | 69 Reduction r = spec.ReduceJSLoadContext(load); |
70 CHECK(!r.Changed()); | 70 CHECK(!r.Changed()); |
71 } | 71 } |
72 | 72 |
73 { | 73 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 Handle<Context> subcontext2 = t.factory()->NewNativeContext(); | 125 Handle<Context> subcontext2 = t.factory()->NewNativeContext(); |
126 subcontext2->set_previous(*subcontext1); | 126 subcontext2->set_previous(*subcontext1); |
127 subcontext1->set_previous(*native); | 127 subcontext1->set_previous(*native); |
128 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); | 128 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); |
129 const int slot = Context::GLOBAL_OBJECT_INDEX; | 129 const int slot = Context::GLOBAL_OBJECT_INDEX; |
130 native->set(slot, *expected); | 130 native->set(slot, *expected); |
131 | 131 |
132 Node* const_context = t.jsgraph()->Constant(native); | 132 Node* const_context = t.jsgraph()->Constant(native); |
133 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); | 133 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); |
134 Node* param_context = t.NewNode(t.common()->Parameter(0), start); | 134 Node* param_context = t.NewNode(t.common()->Parameter(0), start); |
135 JSContextSpecializer spec(Handle<Context>(), t.jsgraph(), const_context); | 135 JSContextSpecializer spec(t.jsgraph()); |
136 | 136 |
137 { | 137 { |
138 // Mutable slot, constant context, depth = 0 => do nothing. | 138 // Mutable slot, constant context, depth = 0 => do nothing. |
139 Node* load = t.NewNode(t.javascript()->StoreContext(0, 0), const_context, | 139 Node* load = t.NewNode(t.javascript()->StoreContext(0, 0), const_context, |
140 const_context, start); | 140 const_context, start); |
141 Reduction r = spec.ReduceJSStoreContext(load); | 141 Reduction r = spec.ReduceJSStoreContext(load); |
142 CHECK(!r.Changed()); | 142 CHECK(!r.Changed()); |
143 } | 143 } |
144 | 144 |
145 { | 145 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 t.graph()->SetStart(start); | 190 t.graph()->SetStart(start); |
191 | 191 |
192 // Make a context and initialize it a bit for this test. | 192 // Make a context and initialize it a bit for this test. |
193 Handle<Context> native = t.factory()->NewNativeContext(); | 193 Handle<Context> native = t.factory()->NewNativeContext(); |
194 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); | 194 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); |
195 const int slot = Context::GLOBAL_OBJECT_INDEX; | 195 const int slot = Context::GLOBAL_OBJECT_INDEX; |
196 native->set(slot, *expected); | 196 native->set(slot, *expected); |
197 | 197 |
198 Node* const_context = t.jsgraph()->Constant(native); | 198 Node* const_context = t.jsgraph()->Constant(native); |
199 Node* param_context = t.NewNode(t.common()->Parameter(0), start); | 199 Node* param_context = t.NewNode(t.common()->Parameter(0), start); |
200 JSContextSpecializer spec(native, t.jsgraph(), const_context); | 200 JSContextSpecializer spec(t.jsgraph()); |
201 | 201 |
202 { | 202 { |
203 // Check that specialization replaces values and forwards effects | 203 // Check that specialization replaces values and forwards effects |
204 // correctly, and folds values from constant and non-constant contexts | 204 // correctly, and folds values from constant and non-constant contexts |
205 Node* effect_in = start; | 205 Node* effect_in = start; |
206 Node* load = t.NewNode(t.javascript()->LoadContext(0, slot, true), | 206 Node* load = t.NewNode(t.javascript()->LoadContext(0, slot, true), |
207 const_context, const_context, effect_in); | 207 const_context, const_context, effect_in); |
208 | 208 |
209 | 209 |
210 Node* value_use = t.NewNode(t.simplified()->ChangeTaggedToInt32(), load); | 210 Node* value_use = t.NewNode(t.simplified()->ChangeTaggedToInt32(), load); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 { | 294 { |
295 FunctionTester T( | 295 FunctionTester T( |
296 "(function() { if (false) { var x = 1; } function inc(a)" | 296 "(function() { if (false) { var x = 1; } function inc(a)" |
297 " { return a + x; } return inc; })()"); // x is undefined! | 297 " { return a + x; } return inc; })()"); // x is undefined! |
298 | 298 |
299 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 299 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
300 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 300 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
301 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 301 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
302 } | 302 } |
303 } | 303 } |
OLD | NEW |