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