| 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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/generic-node-inl.h" | 6 #include "src/compiler/generic-node-inl.h" |
| 7 #include "src/compiler/graph-inl.h" | 7 #include "src/compiler/graph-inl.h" |
| 8 #include "src/compiler/js-context-specialization.h" | 8 #include "src/compiler/js-context-specialization.h" |
| 9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/compiler/node-aux-data-inl.h" | 10 #include "src/compiler/node-aux-data-inl.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { | 61 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { |
| 62 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 62 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
| 63 | 63 |
| 64 HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0)); | 64 HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0)); |
| 65 // If the context is not constant, no reduction can occur. | 65 // If the context is not constant, no reduction can occur. |
| 66 if (!m.HasValue()) { | 66 if (!m.HasValue()) { |
| 67 return Reducer::NoChange(); | 67 return Reducer::NoChange(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 ContextAccess access = OpParameter<ContextAccess>(node); | 70 const ContextAccess& access = ContextAccessOf(node->op()); |
| 71 | 71 |
| 72 // Find the right parent context. | 72 // Find the right parent context. |
| 73 Context* context = *m.Value().handle(); | 73 Context* context = *m.Value().handle(); |
| 74 for (int i = access.depth(); i > 0; --i) { | 74 for (size_t i = access.depth(); i > 0; --i) { |
| 75 context = context->previous(); | 75 context = context->previous(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // If the access itself is mutable, only fold-in the parent. | 78 // If the access itself is mutable, only fold-in the parent. |
| 79 if (!access.immutable()) { | 79 if (!access.immutable()) { |
| 80 // The access does not have to look up a parent, nothing to fold. | 80 // The access does not have to look up a parent, nothing to fold. |
| 81 if (access.depth() == 0) { | 81 if (access.depth() == 0) { |
| 82 return Reducer::NoChange(); | 82 return Reducer::NoChange(); |
| 83 } | 83 } |
| 84 const Operator* op = jsgraph_->javascript()->LoadContext( | 84 const Operator* op = jsgraph_->javascript()->LoadContext( |
| 85 0, access.index(), access.immutable()); | 85 0, access.index(), access.immutable()); |
| 86 node->set_op(op); | 86 node->set_op(op); |
| 87 Handle<Object> context_handle = Handle<Object>(context, info_->isolate()); | 87 Handle<Object> context_handle = Handle<Object>(context, info_->isolate()); |
| 88 node->ReplaceInput(0, jsgraph_->Constant(context_handle)); | 88 node->ReplaceInput(0, jsgraph_->Constant(context_handle)); |
| 89 return Reducer::Changed(node); | 89 return Reducer::Changed(node); |
| 90 } | 90 } |
| 91 Handle<Object> value = | 91 Handle<Object> value = Handle<Object>( |
| 92 Handle<Object>(context->get(access.index()), info_->isolate()); | 92 context->get(static_cast<int>(access.index())), info_->isolate()); |
| 93 | 93 |
| 94 // Even though the context slot is immutable, the context might have escaped | 94 // Even though the context slot is immutable, the context might have escaped |
| 95 // before the function to which it belongs has initialized the slot. | 95 // before the function to which it belongs has initialized the slot. |
| 96 // We must be conservative and check if the value in the slot is currently the | 96 // We must be conservative and check if the value in the slot is currently the |
| 97 // hole or undefined. If it is neither of these, then it must be initialized. | 97 // hole or undefined. If it is neither of these, then it must be initialized. |
| 98 if (value->IsUndefined() || value->IsTheHole()) { | 98 if (value->IsUndefined() || value->IsTheHole()) { |
| 99 return Reducer::NoChange(); | 99 return Reducer::NoChange(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Success. The context load can be replaced with the constant. | 102 // Success. The context load can be replaced with the constant. |
| 103 // TODO(titzer): record the specialization for sharing code across multiple | 103 // TODO(titzer): record the specialization for sharing code across multiple |
| 104 // contexts that have the same value in the corresponding context slot. | 104 // contexts that have the same value in the corresponding context slot. |
| 105 return Reducer::Replace(jsgraph_->Constant(value)); | 105 return Reducer::Replace(jsgraph_->Constant(value)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) { | 109 Reduction JSContextSpecializer::ReduceJSStoreContext(Node* node) { |
| 110 DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode()); | 110 DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode()); |
| 111 | 111 |
| 112 HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0)); | 112 HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0)); |
| 113 // If the context is not constant, no reduction can occur. | 113 // If the context is not constant, no reduction can occur. |
| 114 if (!m.HasValue()) { | 114 if (!m.HasValue()) { |
| 115 return Reducer::NoChange(); | 115 return Reducer::NoChange(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 ContextAccess access = OpParameter<ContextAccess>(node); | 118 const ContextAccess& access = ContextAccessOf(node->op()); |
| 119 | 119 |
| 120 // The access does not have to look up a parent, nothing to fold. | 120 // The access does not have to look up a parent, nothing to fold. |
| 121 if (access.depth() == 0) { | 121 if (access.depth() == 0) { |
| 122 return Reducer::NoChange(); | 122 return Reducer::NoChange(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Find the right parent context. | 125 // Find the right parent context. |
| 126 Context* context = *m.Value().handle(); | 126 Context* context = *m.Value().handle(); |
| 127 for (int i = access.depth(); i > 0; --i) { | 127 for (size_t i = access.depth(); i > 0; --i) { |
| 128 context = context->previous(); | 128 context = context->previous(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); | 131 const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); |
| 132 node->set_op(op); | 132 node->set_op(op); |
| 133 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); | 133 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); |
| 134 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); | 134 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); |
| 135 | 135 |
| 136 return Reducer::Changed(node); | 136 return Reducer::Changed(node); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace compiler | 139 } // namespace compiler |
| 140 } // namespace internal | 140 } // namespace internal |
| 141 } // namespace v8 | 141 } // namespace v8 |
| OLD | NEW |