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/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 break; | 26 break; |
27 } | 27 } |
28 return NoChange(); | 28 return NoChange(); |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext( | 32 MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext( |
33 Node* node) { | 33 Node* node) { |
34 DCHECK(node->opcode() == IrOpcode::kJSLoadContext || | 34 DCHECK(node->opcode() == IrOpcode::kJSLoadContext || |
35 node->opcode() == IrOpcode::kJSStoreContext); | 35 node->opcode() == IrOpcode::kJSStoreContext); |
36 Node* const object = NodeProperties::GetValueInput(node, 0); | 36 Node* const object = NodeProperties::GetContextInput(node); |
37 return NodeProperties::GetSpecializationContext(object, context()); | 37 return NodeProperties::GetSpecializationContext(object, context()); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { | 41 Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { |
42 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 42 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
43 | 43 |
44 // Get the specialization context from the node. | 44 // Get the specialization context from the node. |
45 Handle<Context> context; | 45 Handle<Context> context; |
46 if (!GetSpecializationContext(node).ToHandle(&context)) return NoChange(); | 46 if (!GetSpecializationContext(node).ToHandle(&context)) return NoChange(); |
47 | 47 |
48 // Find the right parent context. | 48 // Find the right parent context. |
49 const ContextAccess& access = ContextAccessOf(node->op()); | 49 const ContextAccess& access = ContextAccessOf(node->op()); |
50 for (size_t i = access.depth(); i > 0; --i) { | 50 for (size_t i = access.depth(); i > 0; --i) { |
51 context = handle(context->previous(), isolate()); | 51 context = handle(context->previous(), isolate()); |
52 } | 52 } |
53 | 53 |
54 // If the access itself is mutable, only fold-in the parent. | 54 // If the access itself is mutable, only fold-in the parent. |
55 if (!access.immutable()) { | 55 if (!access.immutable()) { |
56 // The access does not have to look up a parent, nothing to fold. | 56 // The access does not have to look up a parent, nothing to fold. |
57 if (access.depth() == 0) { | 57 if (access.depth() == 0) { |
58 return NoChange(); | 58 return NoChange(); |
59 } | 59 } |
60 const Operator* op = jsgraph_->javascript()->LoadContext( | 60 const Operator* op = jsgraph_->javascript()->LoadContext( |
61 0, access.index(), access.immutable()); | 61 0, access.index(), access.immutable()); |
62 node->ReplaceInput(0, jsgraph_->Constant(context)); | 62 NodeProperties::ReplaceContextInput(node, jsgraph_->Constant(context)); |
63 NodeProperties::ChangeOp(node, op); | 63 NodeProperties::ChangeOp(node, op); |
64 return Changed(node); | 64 return Changed(node); |
65 } | 65 } |
66 Handle<Object> value = | 66 Handle<Object> value = |
67 handle(context->get(static_cast<int>(access.index())), isolate()); | 67 handle(context->get(static_cast<int>(access.index())), isolate()); |
68 | 68 |
69 // Even though the context slot is immutable, the context might have escaped | 69 // Even though the context slot is immutable, the context might have escaped |
70 // before the function to which it belongs has initialized the slot. | 70 // before the function to which it belongs has initialized the slot. |
71 // We must be conservative and check if the value in the slot is currently the | 71 // We must be conservative and check if the value in the slot is currently the |
72 // hole or undefined. If it is neither of these, then it must be initialized. | 72 // hole or undefined. If it is neither of these, then it must be initialized. |
(...skipping 21 matching lines...) Expand all Loading... |
94 const ContextAccess& access = ContextAccessOf(node->op()); | 94 const ContextAccess& access = ContextAccessOf(node->op()); |
95 if (access.depth() == 0) { | 95 if (access.depth() == 0) { |
96 return NoChange(); | 96 return NoChange(); |
97 } | 97 } |
98 | 98 |
99 // Find the right parent context. | 99 // Find the right parent context. |
100 for (size_t i = access.depth(); i > 0; --i) { | 100 for (size_t i = access.depth(); i > 0; --i) { |
101 context = handle(context->previous(), isolate()); | 101 context = handle(context->previous(), isolate()); |
102 } | 102 } |
103 | 103 |
104 node->ReplaceInput(0, jsgraph_->Constant(context)); | 104 NodeProperties::ReplaceContextInput(node, jsgraph_->Constant(context)); |
105 NodeProperties::ChangeOp(node, javascript()->StoreContext(0, access.index())); | 105 NodeProperties::ChangeOp(node, javascript()->StoreContext(0, access.index())); |
106 return Changed(node); | 106 return Changed(node); |
107 } | 107 } |
108 | 108 |
109 | 109 |
110 Isolate* JSContextSpecialization::isolate() const { | 110 Isolate* JSContextSpecialization::isolate() const { |
111 return jsgraph()->isolate(); | 111 return jsgraph()->isolate(); |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 JSOperatorBuilder* JSContextSpecialization::javascript() const { | 115 JSOperatorBuilder* JSContextSpecialization::javascript() const { |
116 return jsgraph()->javascript(); | 116 return jsgraph()->javascript(); |
117 } | 117 } |
118 | 118 |
119 } // namespace compiler | 119 } // namespace compiler |
120 } // namespace internal | 120 } // namespace internal |
121 } // namespace v8 | 121 } // namespace v8 |
OLD | NEW |