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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return GenericGraphVisit::CONTINUE; | 62 return GenericGraphVisit::CONTINUE; |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 JSContextSpecializer* spec_; | 66 JSContextSpecializer* spec_; |
67 }; | 67 }; |
68 | 68 |
69 | 69 |
70 void JSContextSpecializer::SpecializeToContext() { | 70 void JSContextSpecializer::SpecializeToContext() { |
71 ReplaceEffectfulWithValue(context_, jsgraph_->Constant(info_->context())); | 71 ReplaceEffectfulWithValue(context_, jsgraph_->Constant(info_->context())); |
| 72 specialized_ = true; |
72 | 73 |
73 ContextSpecializationVisitor visitor(this); | 74 ContextSpecializationVisitor visitor(this); |
74 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); | 75 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { | 79 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { |
79 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 80 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
80 | 81 |
81 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); | 82 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 context = context->previous(); | 146 context = context->previous(); |
146 } | 147 } |
147 | 148 |
148 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); | 149 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); |
149 node->set_op(op); | 150 node->set_op(op); |
150 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); | 151 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); |
151 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); | 152 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); |
152 | 153 |
153 return Reducer::Changed(node); | 154 return Reducer::Changed(node); |
154 } | 155 } |
| 156 |
| 157 |
| 158 Node* JSContextSpecializer::InsertBuiltinLoadBefore(Node* before, |
| 159 Builtins::JavaScript id) { |
| 160 if (specialized_) { |
| 161 Handle<JSFunction> function( |
| 162 JSFunction::cast(info_->context()->builtins()->javascript_builtin(id))); |
| 163 return jsgraph_->HeapConstant(function); |
| 164 } |
| 165 Node* context = NodeProperties::GetContextInput(before); |
| 166 Node* global = jsgraph_->LoadObjectField( |
| 167 context, |
| 168 Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX) + kHeapObjectTag, |
| 169 context, NodeProperties::GetEffectInput(before)); |
| 170 Node* builtins = jsgraph_->LoadObjectField( |
| 171 global, JSGlobalObject::kBuiltinsOffset, context, global); |
| 172 Node* function_node = jsgraph_->LoadObjectField( |
| 173 builtins, JSBuiltinsObject::OffsetOfFunctionWithId(id), context, |
| 174 builtins); |
| 175 NodeProperties::ReplaceEffectInput(before, function_node); |
| 176 return function_node; |
| 177 } |
155 } | 178 } |
156 } | 179 } |
157 } // namespace v8::internal::compiler | 180 } // namespace v8::internal::compiler |
OLD | NEW |