| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); | 133 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); |
| 134 const int slot = Context::GLOBAL_OBJECT_INDEX; | 134 const int slot = Context::GLOBAL_OBJECT_INDEX; |
| 135 native->set(slot, *expected); | 135 native->set(slot, *expected); |
| 136 | 136 |
| 137 Node* const_context = t.jsgraph()->Constant(native); | 137 Node* const_context = t.jsgraph()->Constant(native); |
| 138 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); | 138 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); |
| 139 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); | 139 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); |
| 140 | 140 |
| 141 { | 141 { |
| 142 // Mutable slot, constant context, depth = 0 => do nothing. | 142 // Mutable slot, constant context, depth = 0 => do nothing. |
| 143 Node* load = | 143 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0), |
| 144 t.graph()->NewNode(t.javascript()->StoreContext(0, 0), const_context, | 144 const_context, const_context, start); |
| 145 const_context, const_context, start, start); | |
| 146 Reduction r = t.spec()->Reduce(load); | 145 Reduction r = t.spec()->Reduce(load); |
| 147 CHECK(!r.Changed()); | 146 CHECK(!r.Changed()); |
| 148 } | 147 } |
| 149 | 148 |
| 150 { | 149 { |
| 151 // Mutable slot, non-constant context, depth = 0 => do nothing. | 150 // Mutable slot, non-constant context, depth = 0 => do nothing. |
| 152 Node* load = | 151 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0), |
| 153 t.graph()->NewNode(t.javascript()->StoreContext(0, 0), param_context, | 152 param_context, param_context, start); |
| 154 param_context, const_context, start, start); | |
| 155 Reduction r = t.spec()->Reduce(load); | 153 Reduction r = t.spec()->Reduce(load); |
| 156 CHECK(!r.Changed()); | 154 CHECK(!r.Changed()); |
| 157 } | 155 } |
| 158 | 156 |
| 159 { | 157 { |
| 160 // Immutable slot, constant context, depth = 0 => do nothing. | 158 // Immutable slot, constant context, depth = 0 => do nothing. |
| 161 Node* load = | 159 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, slot), |
| 162 t.graph()->NewNode(t.javascript()->StoreContext(0, slot), const_context, | 160 const_context, const_context, start); |
| 163 const_context, const_context, start, start); | |
| 164 Reduction r = t.spec()->Reduce(load); | 161 Reduction r = t.spec()->Reduce(load); |
| 165 CHECK(!r.Changed()); | 162 CHECK(!r.Changed()); |
| 166 } | 163 } |
| 167 | 164 |
| 168 { | 165 { |
| 169 // Mutable slot, constant context, depth > 0 => fold-in parent context. | 166 // Mutable slot, constant context, depth > 0 => fold-in parent context. |
| 170 Node* load = t.graph()->NewNode( | 167 Node* load = t.graph()->NewNode( |
| 171 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), | 168 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), |
| 172 deep_const_context, deep_const_context, const_context, start, start); | 169 deep_const_context, deep_const_context, start); |
| 173 Reduction r = t.spec()->Reduce(load); | 170 Reduction r = t.spec()->Reduce(load); |
| 174 CHECK(r.Changed()); | 171 CHECK(r.Changed()); |
| 175 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); | 172 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); |
| 176 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); | 173 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); |
| 177 HeapObjectMatcher match(new_context_input); | 174 HeapObjectMatcher match(new_context_input); |
| 178 CHECK_EQ(*native, *match.Value()); | 175 CHECK_EQ(*native, *match.Value()); |
| 179 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); | 176 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); |
| 180 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())); |
| 181 CHECK_EQ(0, static_cast<int>(access.depth())); | 178 CHECK_EQ(0, static_cast<int>(access.depth())); |
| 182 CHECK_EQ(false, access.immutable()); | 179 CHECK_EQ(false, access.immutable()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 212 |
| 216 Node* value_use = | 213 Node* value_use = |
| 217 t.graph()->NewNode(t.simplified()->ChangeTaggedToInt32(), load); | 214 t.graph()->NewNode(t.simplified()->ChangeTaggedToInt32(), load); |
| 218 Node* other_load = | 215 Node* other_load = |
| 219 t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), | 216 t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), |
| 220 param_context, param_context, load); | 217 param_context, param_context, load); |
| 221 Node* effect_use = other_load; | 218 Node* effect_use = other_load; |
| 222 Node* other_use = | 219 Node* other_use = |
| 223 t.graph()->NewNode(t.simplified()->ChangeTaggedToInt32(), other_load); | 220 t.graph()->NewNode(t.simplified()->ChangeTaggedToInt32(), other_load); |
| 224 | 221 |
| 225 Node* add = t.graph()->NewNode( | 222 Node* add = |
| 226 t.javascript()->Add(LanguageMode::SLOPPY), value_use, other_use, | 223 t.graph()->NewNode(t.javascript()->Add(LanguageMode::SLOPPY), value_use, |
| 227 param_context, t.jsgraph()->EmptyFrameState(), | 224 other_use, param_context, other_load, start); |
| 228 t.jsgraph()->EmptyFrameState(), other_load, start); | |
| 229 | 225 |
| 230 Node* ret = | 226 Node* ret = |
| 231 t.graph()->NewNode(t.common()->Return(), add, effect_use, start); | 227 t.graph()->NewNode(t.common()->Return(), add, effect_use, start); |
| 232 Node* end = t.graph()->NewNode(t.common()->End(1), ret); | 228 Node* end = t.graph()->NewNode(t.common()->End(1), ret); |
| 233 USE(end); | 229 USE(end); |
| 234 t.graph()->SetEnd(end); | 230 t.graph()->SetEnd(end); |
| 235 | 231 |
| 236 // Double check the above graph is what we expect, or the test is broken. | 232 // Double check the above graph is what we expect, or the test is broken. |
| 237 CheckEffectInput(effect_in, load); | 233 CheckEffectInput(effect_in, load); |
| 238 CheckEffectInput(load, effect_use); | 234 CheckEffectInput(load, effect_use); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 { | 303 { |
| 308 FunctionTester T( | 304 FunctionTester T( |
| 309 "(function() { if (false) { var x = 1; } function inc(a)" | 305 "(function() { if (false) { var x = 1; } function inc(a)" |
| 310 " { return a + x; } return inc; })()"); // x is undefined! | 306 " { return a + x; } return inc; })()"); // x is undefined! |
| 311 | 307 |
| 312 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()); |
| 313 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()); |
| 314 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()); |
| 315 } | 311 } |
| 316 } | 312 } |
| OLD | NEW |