| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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-native-context-specialization.h" | 5 #include "src/compiler/js-native-context-specialization.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 : AdvancedReducer(editor), | 62 : AdvancedReducer(editor), |
| 63 jsgraph_(jsgraph), | 63 jsgraph_(jsgraph), |
| 64 flags_(flags), | 64 flags_(flags), |
| 65 native_context_(native_context), | 65 native_context_(native_context), |
| 66 dependencies_(dependencies), | 66 dependencies_(dependencies), |
| 67 zone_(zone), | 67 zone_(zone), |
| 68 type_cache_(TypeCache::Get()) {} | 68 type_cache_(TypeCache::Get()) {} |
| 69 | 69 |
| 70 Reduction JSNativeContextSpecialization::Reduce(Node* node) { | 70 Reduction JSNativeContextSpecialization::Reduce(Node* node) { |
| 71 switch (node->opcode()) { | 71 switch (node->opcode()) { |
| 72 case IrOpcode::kJSInstanceOf: |
| 73 return ReduceJSInstanceOf(node); |
| 72 case IrOpcode::kJSLoadContext: | 74 case IrOpcode::kJSLoadContext: |
| 73 return ReduceJSLoadContext(node); | 75 return ReduceJSLoadContext(node); |
| 74 case IrOpcode::kJSLoadNamed: | 76 case IrOpcode::kJSLoadNamed: |
| 75 return ReduceJSLoadNamed(node); | 77 return ReduceJSLoadNamed(node); |
| 76 case IrOpcode::kJSStoreNamed: | 78 case IrOpcode::kJSStoreNamed: |
| 77 return ReduceJSStoreNamed(node); | 79 return ReduceJSStoreNamed(node); |
| 78 case IrOpcode::kJSLoadProperty: | 80 case IrOpcode::kJSLoadProperty: |
| 79 return ReduceJSLoadProperty(node); | 81 return ReduceJSLoadProperty(node); |
| 80 case IrOpcode::kJSStoreProperty: | 82 case IrOpcode::kJSStoreProperty: |
| 81 return ReduceJSStoreProperty(node); | 83 return ReduceJSStoreProperty(node); |
| 82 default: | 84 default: |
| 83 break; | 85 break; |
| 84 } | 86 } |
| 85 return NoChange(); | 87 return NoChange(); |
| 86 } | 88 } |
| 87 | 89 |
| 90 Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) { |
| 91 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode()); |
| 92 Node* object = NodeProperties::GetValueInput(node, 0); |
| 93 Node* constructor = NodeProperties::GetValueInput(node, 1); |
| 94 Node* context = NodeProperties::GetContextInput(node); |
| 95 Node* effect = NodeProperties::GetEffectInput(node); |
| 96 Node* control = NodeProperties::GetControlInput(node); |
| 97 |
| 98 // If deoptimization is disabled, we cannot optimize. |
| 99 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); |
| 100 |
| 101 // Check if the right hand side is a known {receiver}. |
| 102 HeapObjectMatcher m(constructor); |
| 103 if (!m.HasValue() || !m.Value()->IsJSObject()) return NoChange(); |
| 104 Handle<JSObject> receiver = Handle<JSObject>::cast(m.Value()); |
| 105 Handle<Map> receiver_map(receiver->map(), isolate()); |
| 106 |
| 107 // Compute property access info for @@hasInstance on {receiver}. |
| 108 PropertyAccessInfo access_info; |
| 109 AccessInfoFactory access_info_factory(dependencies(), native_context(), |
| 110 graph()->zone()); |
| 111 if (!access_info_factory.ComputePropertyAccessInfo( |
| 112 receiver_map, factory()->has_instance_symbol(), AccessMode::kLoad, |
| 113 &access_info)) { |
| 114 return NoChange(); |
| 115 } |
| 116 |
| 117 if (access_info.IsNotFound()) { |
| 118 // If there's no @@hasInstance handler, the OrdinaryHasInstance operation |
| 119 // takes over, but that requires the {receiver} to be callable. |
| 120 if (receiver->IsCallable()) { |
| 121 // Determine actual holder and perform prototype chain checks. |
| 122 Handle<JSObject> holder; |
| 123 if (access_info.holder().ToHandle(&holder)) { |
| 124 AssumePrototypesStable(access_info.receiver_maps(), holder); |
| 125 } |
| 126 |
| 127 // Monomorphic property access. |
| 128 effect = |
| 129 BuildCheckMaps(constructor, effect, control, MapList{receiver_map}); |
| 130 |
| 131 // Lower to OrdinaryHasInstance(C, O). |
| 132 NodeProperties::ReplaceValueInput(node, constructor, 0); |
| 133 NodeProperties::ReplaceValueInput(node, object, 1); |
| 134 NodeProperties::ReplaceEffectInput(node, effect); |
| 135 NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance()); |
| 136 return Changed(node); |
| 137 } |
| 138 } else if (access_info.IsDataConstant()) { |
| 139 DCHECK(access_info.constant()->IsCallable()); |
| 140 |
| 141 // Determine actual holder and perform prototype chain checks. |
| 142 Handle<JSObject> holder; |
| 143 if (access_info.holder().ToHandle(&holder)) { |
| 144 AssumePrototypesStable(access_info.receiver_maps(), holder); |
| 145 } |
| 146 |
| 147 // Monomorphic property access. |
| 148 effect = |
| 149 BuildCheckMaps(constructor, effect, control, MapList{receiver_map}); |
| 150 |
| 151 // Call the @@hasInstance handler. |
| 152 Node* target = jsgraph()->Constant(access_info.constant()); |
| 153 node->InsertInput(graph()->zone(), 0, target); |
| 154 node->ReplaceInput(1, constructor); |
| 155 node->ReplaceInput(2, object); |
| 156 node->ReplaceInput(5, effect); |
| 157 NodeProperties::ChangeOp( |
| 158 node, |
| 159 javascript()->CallFunction(3, 0.0f, VectorSlotPair(), |
| 160 ConvertReceiverMode::kNotNullOrUndefined)); |
| 161 |
| 162 // Rewire the value uses of {node} to ToBoolean conversion of the result. |
| 163 Node* value = graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), |
| 164 node, context); |
| 165 for (Edge edge : node->use_edges()) { |
| 166 if (NodeProperties::IsValueEdge(edge) && edge.from() != value) { |
| 167 edge.UpdateTo(value); |
| 168 Revisit(edge.from()); |
| 169 } |
| 170 } |
| 171 return Changed(node); |
| 172 } |
| 173 |
| 174 return NoChange(); |
| 175 } |
| 176 |
| 88 Reduction JSNativeContextSpecialization::ReduceJSLoadContext(Node* node) { | 177 Reduction JSNativeContextSpecialization::ReduceJSLoadContext(Node* node) { |
| 89 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 178 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
| 90 ContextAccess const& access = ContextAccessOf(node->op()); | 179 ContextAccess const& access = ContextAccessOf(node->op()); |
| 91 // Specialize JSLoadContext(NATIVE_CONTEXT_INDEX) to the known native | 180 // Specialize JSLoadContext(NATIVE_CONTEXT_INDEX) to the known native |
| 92 // context (if any), so we can constant-fold those fields, which is | 181 // context (if any), so we can constant-fold those fields, which is |
| 93 // safe, since the NATIVE_CONTEXT_INDEX slot is always immutable. | 182 // safe, since the NATIVE_CONTEXT_INDEX slot is always immutable. |
| 94 if (access.index() == Context::NATIVE_CONTEXT_INDEX) { | 183 if (access.index() == Context::NATIVE_CONTEXT_INDEX) { |
| 95 Node* value = jsgraph()->HeapConstant(native_context()); | 184 Node* value = jsgraph()->HeapConstant(native_context()); |
| 96 ReplaceWithValue(node, value); | 185 ReplaceWithValue(node, value); |
| 97 return Replace(value); | 186 return Replace(value); |
| (...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 return jsgraph()->javascript(); | 1742 return jsgraph()->javascript(); |
| 1654 } | 1743 } |
| 1655 | 1744 |
| 1656 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 1745 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
| 1657 return jsgraph()->simplified(); | 1746 return jsgraph()->simplified(); |
| 1658 } | 1747 } |
| 1659 | 1748 |
| 1660 } // namespace compiler | 1749 } // namespace compiler |
| 1661 } // namespace internal | 1750 } // namespace internal |
| 1662 } // namespace v8 | 1751 } // namespace v8 |
| OLD | NEW |