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-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/js-operator.h" | 7 #include "src/compiler/js-operator.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/source-position.h" | 10 #include "src/compiler/source-position.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 { | 86 { |
87 // Mutable slot, constant context, depth > 0 => fold-in parent context. | 87 // Mutable slot, constant context, depth > 0 => fold-in parent context. |
88 Node* load = t.graph()->NewNode( | 88 Node* load = t.graph()->NewNode( |
89 t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false), | 89 t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false), |
90 deep_const_context, deep_const_context, start); | 90 deep_const_context, deep_const_context, start); |
91 Reduction r = t.spec()->Reduce(load); | 91 Reduction r = t.spec()->Reduce(load); |
92 CHECK(r.Changed()); | 92 CHECK(r.Changed()); |
93 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); | 93 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); |
94 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); | 94 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); |
95 HeapObjectMatcher match(new_context_input); | 95 HeapObjectMatcher match(new_context_input); |
96 CHECK_EQ(*native, *match.Value().handle()); | 96 CHECK_EQ(*native, *match.Value()); |
97 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); | 97 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); |
98 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); | 98 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); |
99 CHECK_EQ(0, static_cast<int>(access.depth())); | 99 CHECK_EQ(0, static_cast<int>(access.depth())); |
100 CHECK_EQ(false, access.immutable()); | 100 CHECK_EQ(false, access.immutable()); |
101 } | 101 } |
102 | 102 |
103 { | 103 { |
104 // Immutable slot, constant context, depth = 0 => specialize. | 104 // Immutable slot, constant context, depth = 0 => specialize. |
105 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), | 105 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), |
106 const_context, const_context, start); | 106 const_context, const_context, start); |
107 Reduction r = t.spec()->Reduce(load); | 107 Reduction r = t.spec()->Reduce(load); |
108 CHECK(r.Changed()); | 108 CHECK(r.Changed()); |
109 CHECK(r.replacement() != load); | 109 CHECK(r.replacement() != load); |
110 | 110 |
111 HeapObjectMatcher match(r.replacement()); | 111 HeapObjectMatcher match(r.replacement()); |
112 CHECK(match.HasValue()); | 112 CHECK(match.HasValue()); |
113 CHECK_EQ(*expected, *match.Value().handle()); | 113 CHECK_EQ(*expected, *match.Value()); |
114 } | 114 } |
115 | 115 |
116 // TODO(titzer): test with other kinds of contexts, e.g. a function context. | 116 // TODO(titzer): test with other kinds of contexts, e.g. a function context. |
117 // TODO(sigurds): test that loads below create context are not optimized | 117 // TODO(sigurds): test that loads below create context are not optimized |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 TEST(ReduceJSStoreContext) { | 121 TEST(ReduceJSStoreContext) { |
122 ContextSpecializationTester t; | 122 ContextSpecializationTester t; |
123 | 123 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 { | 165 { |
166 // Mutable slot, constant context, depth > 0 => fold-in parent context. | 166 // Mutable slot, constant context, depth > 0 => fold-in parent context. |
167 Node* load = t.graph()->NewNode( | 167 Node* load = t.graph()->NewNode( |
168 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), | 168 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), |
169 deep_const_context, deep_const_context, start); | 169 deep_const_context, deep_const_context, start); |
170 Reduction r = t.spec()->Reduce(load); | 170 Reduction r = t.spec()->Reduce(load); |
171 CHECK(r.Changed()); | 171 CHECK(r.Changed()); |
172 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); | 172 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); |
173 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); | 173 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); |
174 HeapObjectMatcher match(new_context_input); | 174 HeapObjectMatcher match(new_context_input); |
175 CHECK_EQ(*native, *match.Value().handle()); | 175 CHECK_EQ(*native, *match.Value()); |
176 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); | 176 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); |
177 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); | 177 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); |
178 CHECK_EQ(0, static_cast<int>(access.depth())); | 178 CHECK_EQ(0, static_cast<int>(access.depth())); |
179 CHECK_EQ(false, access.immutable()); | 179 CHECK_EQ(false, access.immutable()); |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 // TODO(titzer): factor out common code with effects checking in typed lowering. | 184 // TODO(titzer): factor out common code with effects checking in typed lowering. |
185 static void CheckEffectInput(Node* effect, Node* use) { | 185 static void CheckEffectInput(Node* effect, Node* use) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 // Effects should have been forwarded (not replaced with a value). | 243 // Effects should have been forwarded (not replaced with a value). |
244 CheckEffectInput(effect_in, effect_use); | 244 CheckEffectInput(effect_in, effect_use); |
245 | 245 |
246 // Use of {other_load} should not have been replaced. | 246 // Use of {other_load} should not have been replaced. |
247 CHECK_EQ(other_load, other_use->InputAt(0)); | 247 CHECK_EQ(other_load, other_use->InputAt(0)); |
248 | 248 |
249 Node* replacement = value_use->InputAt(0); | 249 Node* replacement = value_use->InputAt(0); |
250 HeapObjectMatcher match(replacement); | 250 HeapObjectMatcher match(replacement); |
251 CHECK(match.HasValue()); | 251 CHECK(match.HasValue()); |
252 CHECK_EQ(*expected, *match.Value().handle()); | 252 CHECK_EQ(*expected, *match.Value()); |
253 } | 253 } |
254 // TODO(titzer): clean up above test and test more complicated effects. | 254 // TODO(titzer): clean up above test and test more complicated effects. |
255 } | 255 } |
256 | 256 |
257 | 257 |
258 TEST(SpecializeJSFunction_ToConstant1) { | 258 TEST(SpecializeJSFunction_ToConstant1) { |
259 FunctionTester T( | 259 FunctionTester T( |
260 "(function() { var x = 1; function inc(a)" | 260 "(function() { var x = 1; function inc(a)" |
261 " { return a + x; } return inc; })()"); | 261 " { return a + x; } return inc; })()"); |
262 | 262 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 { | 303 { |
304 FunctionTester T( | 304 FunctionTester T( |
305 "(function() { if (false) { var x = 1; } function inc(a)" | 305 "(function() { if (false) { var x = 1; } function inc(a)" |
306 " { return a + x; } return inc; })()"); // x is undefined! | 306 " { return a + x; } return inc; })()"); // x is undefined! |
307 | 307 |
308 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 308 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
309 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 309 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
310 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 310 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
311 } | 311 } |
312 } | 312 } |
OLD | NEW |