| 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/compiler-source-position-table.h" | 5 #include "src/compiler/compiler-source-position-table.h" |
| 6 #include "src/compiler/js-context-specialization.h" | 6 #include "src/compiler/js-context-specialization.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const int slot = Context::NATIVE_CONTEXT_INDEX; | 65 const int slot = Context::NATIVE_CONTEXT_INDEX; |
| 66 native->set(slot, *expected); | 66 native->set(slot, *expected); |
| 67 | 67 |
| 68 Node* const_context = t.jsgraph()->Constant(native); | 68 Node* const_context = t.jsgraph()->Constant(native); |
| 69 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); | 69 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); |
| 70 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); | 70 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); |
| 71 | 71 |
| 72 { | 72 { |
| 73 // Mutable slot, constant context, depth = 0 => do nothing. | 73 // Mutable slot, constant context, depth = 0 => do nothing. |
| 74 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), | 74 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), |
| 75 const_context, const_context, start); | 75 const_context, start); |
| 76 Reduction r = t.spec()->Reduce(load); | 76 Reduction r = t.spec()->Reduce(load); |
| 77 CHECK(!r.Changed()); | 77 CHECK(!r.Changed()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 { | 80 { |
| 81 // Mutable slot, non-constant context, depth = 0 => do nothing. | 81 // Mutable slot, non-constant context, depth = 0 => do nothing. |
| 82 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), | 82 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), |
| 83 param_context, param_context, start); | 83 param_context, start); |
| 84 Reduction r = t.spec()->Reduce(load); | 84 Reduction r = t.spec()->Reduce(load); |
| 85 CHECK(!r.Changed()); | 85 CHECK(!r.Changed()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 { | 88 { |
| 89 // Mutable slot, constant context, depth > 0 => fold-in parent context. | 89 // Mutable slot, constant context, depth > 0 => fold-in parent context. |
| 90 Node* load = t.graph()->NewNode( | 90 Node* load = t.graph()->NewNode( |
| 91 t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false), | 91 t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false), |
| 92 deep_const_context, deep_const_context, start); | 92 deep_const_context, start); |
| 93 Reduction r = t.spec()->Reduce(load); | 93 Reduction r = t.spec()->Reduce(load); |
| 94 CHECK(r.Changed()); | 94 CHECK(r.Changed()); |
| 95 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); | 95 Node* new_context_input = NodeProperties::GetContextInput(r.replacement()); |
| 96 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); | 96 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); |
| 97 HeapObjectMatcher match(new_context_input); | 97 HeapObjectMatcher match(new_context_input); |
| 98 CHECK_EQ(*native, *match.Value()); | 98 CHECK_EQ(*native, *match.Value()); |
| 99 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); | 99 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); |
| 100 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); | 100 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); |
| 101 CHECK_EQ(0, static_cast<int>(access.depth())); | 101 CHECK_EQ(0, static_cast<int>(access.depth())); |
| 102 CHECK_EQ(false, access.immutable()); | 102 CHECK_EQ(false, access.immutable()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 { | 105 { |
| 106 // Immutable slot, constant context, depth = 0 => specialize. | 106 // Immutable slot, constant context, depth = 0 => specialize. |
| 107 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), | 107 Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), |
| 108 const_context, const_context, start); | 108 const_context, start); |
| 109 Reduction r = t.spec()->Reduce(load); | 109 Reduction r = t.spec()->Reduce(load); |
| 110 CHECK(r.Changed()); | 110 CHECK(r.Changed()); |
| 111 CHECK(r.replacement() != load); | 111 CHECK(r.replacement() != load); |
| 112 | 112 |
| 113 HeapObjectMatcher match(r.replacement()); | 113 HeapObjectMatcher match(r.replacement()); |
| 114 CHECK(match.HasValue()); | 114 CHECK(match.HasValue()); |
| 115 CHECK_EQ(*expected, *match.Value()); | 115 CHECK_EQ(*expected, *match.Value()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // TODO(titzer): test with other kinds of contexts, e.g. a function context. | 118 // TODO(titzer): test with other kinds of contexts, e.g. a function context. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); | 135 Handle<Object> expected = t.factory()->InternalizeUtf8String("gboy!"); |
| 136 const int slot = Context::NATIVE_CONTEXT_INDEX; | 136 const int slot = Context::NATIVE_CONTEXT_INDEX; |
| 137 native->set(slot, *expected); | 137 native->set(slot, *expected); |
| 138 | 138 |
| 139 Node* const_context = t.jsgraph()->Constant(native); | 139 Node* const_context = t.jsgraph()->Constant(native); |
| 140 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); | 140 Node* deep_const_context = t.jsgraph()->Constant(subcontext2); |
| 141 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); | 141 Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start); |
| 142 | 142 |
| 143 { | 143 { |
| 144 // Mutable slot, constant context, depth = 0 => do nothing. | 144 // Mutable slot, constant context, depth = 0 => do nothing. |
| 145 Node* load = | 145 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0), |
| 146 t.graph()->NewNode(t.javascript()->StoreContext(0, 0), const_context, | 146 const_context, const_context, start, start); |
| 147 const_context, const_context, start, start); | |
| 148 Reduction r = t.spec()->Reduce(load); | 147 Reduction r = t.spec()->Reduce(load); |
| 149 CHECK(!r.Changed()); | 148 CHECK(!r.Changed()); |
| 150 } | 149 } |
| 151 | 150 |
| 152 { | 151 { |
| 153 // Mutable slot, non-constant context, depth = 0 => do nothing. | 152 // Mutable slot, non-constant context, depth = 0 => do nothing. |
| 154 Node* load = | 153 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0), |
| 155 t.graph()->NewNode(t.javascript()->StoreContext(0, 0), param_context, | 154 param_context, param_context, start, start); |
| 156 param_context, const_context, start, start); | |
| 157 Reduction r = t.spec()->Reduce(load); | 155 Reduction r = t.spec()->Reduce(load); |
| 158 CHECK(!r.Changed()); | 156 CHECK(!r.Changed()); |
| 159 } | 157 } |
| 160 | 158 |
| 161 { | 159 { |
| 162 // Immutable slot, constant context, depth = 0 => do nothing. | 160 // Immutable slot, constant context, depth = 0 => do nothing. |
| 163 Node* load = | 161 Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, slot), |
| 164 t.graph()->NewNode(t.javascript()->StoreContext(0, slot), const_context, | 162 const_context, const_context, start, start); |
| 165 const_context, const_context, start, start); | |
| 166 Reduction r = t.spec()->Reduce(load); | 163 Reduction r = t.spec()->Reduce(load); |
| 167 CHECK(!r.Changed()); | 164 CHECK(!r.Changed()); |
| 168 } | 165 } |
| 169 | 166 |
| 170 { | 167 { |
| 171 // Mutable slot, constant context, depth > 0 => fold-in parent context. | 168 // Mutable slot, constant context, depth > 0 => fold-in parent context. |
| 172 Node* load = t.graph()->NewNode( | 169 Node* load = t.graph()->NewNode( |
| 173 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), | 170 t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), |
| 174 deep_const_context, deep_const_context, const_context, start, start); | 171 deep_const_context, deep_const_context, start, start); |
| 175 Reduction r = t.spec()->Reduce(load); | 172 Reduction r = t.spec()->Reduce(load); |
| 176 CHECK(r.Changed()); | 173 CHECK(r.Changed()); |
| 177 Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); | 174 Node* new_context_input = NodeProperties::GetContextInput(r.replacement()); |
| 178 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); | 175 CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); |
| 179 HeapObjectMatcher match(new_context_input); | 176 HeapObjectMatcher match(new_context_input); |
| 180 CHECK_EQ(*native, *match.Value()); | 177 CHECK_EQ(*native, *match.Value()); |
| 181 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); | 178 ContextAccess access = OpParameter<ContextAccess>(r.replacement()); |
| 182 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); | 179 CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, static_cast<int>(access.index())); |
| 183 CHECK_EQ(0, static_cast<int>(access.depth())); | 180 CHECK_EQ(0, static_cast<int>(access.depth())); |
| 184 CHECK_EQ(false, access.immutable()); | 181 CHECK_EQ(false, access.immutable()); |
| 185 } | 182 } |
| 186 } | 183 } |
| 187 | 184 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 239 |
| 243 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 240 CHECK(T.Call(T.Val(0.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
| 244 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 241 CHECK(T.Call(T.Val(2.0), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
| 245 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); | 242 CHECK(T.Call(T.Val(-2.1), T.Val(0.0)).ToHandleChecked()->IsNaN()); |
| 246 } | 243 } |
| 247 } | 244 } |
| 248 | 245 |
| 249 } // namespace compiler | 246 } // namespace compiler |
| 250 } // namespace internal | 247 } // namespace internal |
| 251 } // namespace v8 | 248 } // namespace v8 |
| OLD | NEW |