| 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 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
| 9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 11 #include "src/compiler/node-properties.h" | 11 #include "src/compiler/node-properties.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 namespace compiler { | 15 namespace compiler { |
| 16 | 16 |
| 17 Reduction JSContextSpecializer::Reduce(Node* node) { | 17 Reduction JSContextSpecializer::Reduce(Node* node) { |
| 18 if (node == context_) { | 18 if (node == context_) { |
| 19 Node* constant = jsgraph_->Constant(info_->context()); | 19 Node* constant = jsgraph_->Constant(ctx_); |
| 20 NodeProperties::ReplaceWithValue(node, constant); | 20 NodeProperties::ReplaceWithValue(node, constant); |
| 21 return Replace(constant); | 21 return Replace(constant); |
| 22 } | 22 } |
| 23 if (node->opcode() == IrOpcode::kJSLoadContext) { | 23 if (node->opcode() == IrOpcode::kJSLoadContext) { |
| 24 return ReduceJSLoadContext(node); | 24 return ReduceJSLoadContext(node); |
| 25 } | 25 } |
| 26 if (node->opcode() == IrOpcode::kJSStoreContext) { | 26 if (node->opcode() == IrOpcode::kJSStoreContext) { |
| 27 return ReduceJSStoreContext(node); | 27 return ReduceJSStoreContext(node); |
| 28 } | 28 } |
| 29 return NoChange(); | 29 return NoChange(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 | 49 |
| 50 // If the access itself is mutable, only fold-in the parent. | 50 // If the access itself is mutable, only fold-in the parent. |
| 51 if (!access.immutable()) { | 51 if (!access.immutable()) { |
| 52 // The access does not have to look up a parent, nothing to fold. | 52 // The access does not have to look up a parent, nothing to fold. |
| 53 if (access.depth() == 0) { | 53 if (access.depth() == 0) { |
| 54 return NoChange(); | 54 return NoChange(); |
| 55 } | 55 } |
| 56 const Operator* op = jsgraph_->javascript()->LoadContext( | 56 const Operator* op = jsgraph_->javascript()->LoadContext( |
| 57 0, access.index(), access.immutable()); | 57 0, access.index(), access.immutable()); |
| 58 node->set_op(op); | 58 node->set_op(op); |
| 59 Handle<Object> context_handle = Handle<Object>(context, info_->isolate()); | 59 Handle<Object> context_handle = |
| 60 Handle<Object>(context, jsgraph_->isolate()); |
| 60 node->ReplaceInput(0, jsgraph_->Constant(context_handle)); | 61 node->ReplaceInput(0, jsgraph_->Constant(context_handle)); |
| 61 return Changed(node); | 62 return Changed(node); |
| 62 } | 63 } |
| 63 Handle<Object> value = Handle<Object>( | 64 Handle<Object> value = Handle<Object>( |
| 64 context->get(static_cast<int>(access.index())), info_->isolate()); | 65 context->get(static_cast<int>(access.index())), jsgraph_->isolate()); |
| 65 | 66 |
| 66 // Even though the context slot is immutable, the context might have escaped | 67 // Even though the context slot is immutable, the context might have escaped |
| 67 // before the function to which it belongs has initialized the slot. | 68 // before the function to which it belongs has initialized the slot. |
| 68 // We must be conservative and check if the value in the slot is currently the | 69 // We must be conservative and check if the value in the slot is currently the |
| 69 // hole or undefined. If it is neither of these, then it must be initialized. | 70 // hole or undefined. If it is neither of these, then it must be initialized. |
| 70 if (value->IsUndefined() || value->IsTheHole()) { | 71 if (value->IsUndefined() || value->IsTheHole()) { |
| 71 return NoChange(); | 72 return NoChange(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Success. The context load can be replaced with the constant. | 75 // Success. The context load can be replaced with the constant. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Find the right parent context. | 100 // Find the right parent context. |
| 100 Context* context = *m.Value().handle(); | 101 Context* context = *m.Value().handle(); |
| 101 for (size_t i = access.depth(); i > 0; --i) { | 102 for (size_t i = access.depth(); i > 0; --i) { |
| 102 context = context->previous(); | 103 context = context->previous(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); | 106 const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); |
| 106 node->set_op(op); | 107 node->set_op(op); |
| 107 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); | 108 Handle<Object> new_context_handle = |
| 109 Handle<Object>(context, jsgraph_->isolate()); |
| 108 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); | 110 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); |
| 109 | 111 |
| 110 return Changed(node); | 112 return Changed(node); |
| 111 } | 113 } |
| 112 | 114 |
| 113 } // namespace compiler | 115 } // namespace compiler |
| 114 } // namespace internal | 116 } // namespace internal |
| 115 } // namespace v8 | 117 } // namespace v8 |
| OLD | NEW |