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 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2137 // Install code dependency on the array protector cell. | 2137 // Install code dependency on the array protector cell. |
2138 dependencies()->AssumePropertyCell(factory()->array_protector()); | 2138 dependencies()->AssumePropertyCell(factory()->array_protector()); |
2139 return true; | 2139 return true; |
2140 } | 2140 } |
2141 | 2141 |
2142 bool JSNativeContextSpecialization::ExtractReceiverMaps( | 2142 bool JSNativeContextSpecialization::ExtractReceiverMaps( |
2143 Node* receiver, Node* effect, FeedbackNexus const& nexus, | 2143 Node* receiver, Node* effect, FeedbackNexus const& nexus, |
2144 MapHandleList* receiver_maps) { | 2144 MapHandleList* receiver_maps) { |
2145 DCHECK_EQ(0, receiver_maps->length()); | 2145 DCHECK_EQ(0, receiver_maps->length()); |
2146 // See if we can infer a concrete type for the {receiver}. | 2146 // See if we can infer a concrete type for the {receiver}. |
2147 Handle<Map> receiver_map; | 2147 if (InferReceiverMaps(receiver, effect, receiver_maps)) { |
2148 if (InferReceiverMap(receiver, effect).ToHandle(&receiver_map)) { | 2148 // We can assume that the {receiver} still has the infered {receiver_maps}. |
2149 // We can assume that the {receiver} still has the infered {receiver_map}. | |
2150 receiver_maps->Add(receiver_map); | |
2151 return true; | 2149 return true; |
2152 } | 2150 } |
2153 // Try to extract some maps from the {nexus}. | 2151 // Try to extract some maps from the {nexus}. |
2154 if (nexus.ExtractMaps(receiver_maps) != 0) { | 2152 if (nexus.ExtractMaps(receiver_maps) != 0) { |
2155 // Try to filter impossible candidates based on infered root map. | 2153 // Try to filter impossible candidates based on infered root map. |
| 2154 Handle<Map> receiver_map; |
2156 if (InferReceiverRootMap(receiver).ToHandle(&receiver_map)) { | 2155 if (InferReceiverRootMap(receiver).ToHandle(&receiver_map)) { |
2157 for (int i = receiver_maps->length(); --i >= 0;) { | 2156 for (int i = receiver_maps->length(); --i >= 0;) { |
2158 if (receiver_maps->at(i)->FindRootMap() != *receiver_map) { | 2157 if (receiver_maps->at(i)->FindRootMap() != *receiver_map) { |
2159 receiver_maps->Remove(i); | 2158 receiver_maps->Remove(i); |
2160 } | 2159 } |
2161 } | 2160 } |
2162 } | 2161 } |
2163 return true; | 2162 return true; |
2164 } | 2163 } |
2165 return false; | 2164 return false; |
2166 } | 2165 } |
2167 | 2166 |
2168 MaybeHandle<Map> JSNativeContextSpecialization::InferReceiverMap(Node* receiver, | 2167 bool JSNativeContextSpecialization::InferReceiverMaps( |
2169 Node* effect) { | 2168 Node* receiver, Node* effect, MapHandleList* receiver_maps) { |
2170 HeapObjectMatcher m(receiver); | 2169 ZoneHandleSet<Map> maps; |
2171 if (m.HasValue()) { | 2170 if (NodeProperties::InferReceiverMaps(receiver, effect, &maps)) { |
2172 Handle<Map> receiver_map(m.Value()->map(), isolate()); | 2171 for (size_t i = 0; i < maps.size(); ++i) { |
2173 if (receiver_map->is_stable()) return receiver_map; | 2172 receiver_maps->Add(maps[i]); |
2174 } else if (m.IsJSCreate()) { | |
2175 HeapObjectMatcher mtarget(m.InputAt(0)); | |
2176 HeapObjectMatcher mnewtarget(m.InputAt(1)); | |
2177 if (mtarget.HasValue() && mnewtarget.HasValue()) { | |
2178 Handle<JSFunction> original_constructor = | |
2179 Handle<JSFunction>::cast(mnewtarget.Value()); | |
2180 if (original_constructor->has_initial_map()) { | |
2181 Handle<Map> initial_map(original_constructor->initial_map(), isolate()); | |
2182 if (initial_map->constructor_or_backpointer() == *mtarget.Value()) { | |
2183 // Walk up the {effect} chain to see if the {receiver} is the | |
2184 // dominating effect and there's no other observable write in | |
2185 // between. | |
2186 while (true) { | |
2187 if (receiver == effect) return initial_map; | |
2188 if (!effect->op()->HasProperty(Operator::kNoWrite) || | |
2189 effect->op()->EffectInputCount() != 1) { | |
2190 break; | |
2191 } | |
2192 effect = NodeProperties::GetEffectInput(effect); | |
2193 } | |
2194 } | |
2195 } | |
2196 } | 2173 } |
| 2174 return true; |
2197 } | 2175 } |
2198 // Go hunting for a matching CheckMaps(receiver) or StoreField[Map](receiver) | 2176 return false; |
2199 // in the {effect} chain. | |
2200 // TODO(turbofan): Propagate the information along the control/effect chains | |
2201 // instead at some point to avoid this potentially inefficient hunting. | |
2202 while (true) { | |
2203 if (effect->opcode() == IrOpcode::kCheckMaps) { | |
2204 ZoneHandleSet<Map> maps = CheckMapsParametersOf(effect->op()).maps(); | |
2205 if (maps.size() == 1u) { | |
2206 Node* object = NodeProperties::GetValueInput(effect, 0); | |
2207 if (NodeProperties::IsSame(receiver, object)) return maps[0]; | |
2208 } | |
2209 } else if (effect->opcode() == IrOpcode::kStoreField) { | |
2210 FieldAccess const access = FieldAccessOf(effect->op()); | |
2211 if (access.offset == HeapObject::kMapOffset) { | |
2212 Node* object = NodeProperties::GetValueInput(effect, 0); | |
2213 Node* value = NodeProperties::GetValueInput(effect, 1); | |
2214 if (object == receiver) { | |
2215 HeapObjectMatcher m(value); | |
2216 if (m.HasValue()) return Handle<Map>::cast(m.Value()); | |
2217 } | |
2218 break; | |
2219 } | |
2220 } else if (!effect->op()->HasProperty(Operator::kNoWrite) || | |
2221 effect->op()->EffectInputCount() != 1) { | |
2222 break; | |
2223 } | |
2224 effect = NodeProperties::GetEffectInput(effect); | |
2225 } | |
2226 return MaybeHandle<Map>(); | |
2227 } | 2177 } |
2228 | 2178 |
2229 MaybeHandle<Map> JSNativeContextSpecialization::InferReceiverRootMap( | 2179 MaybeHandle<Map> JSNativeContextSpecialization::InferReceiverRootMap( |
2230 Node* receiver) { | 2180 Node* receiver) { |
2231 HeapObjectMatcher m(receiver); | 2181 HeapObjectMatcher m(receiver); |
2232 if (m.HasValue()) { | 2182 if (m.HasValue()) { |
2233 return handle(m.Value()->map()->FindRootMap(), isolate()); | 2183 return handle(m.Value()->map()->FindRootMap(), isolate()); |
2234 } else if (m.IsJSCreate()) { | 2184 } else if (m.IsJSCreate()) { |
2235 HeapObjectMatcher mtarget(m.InputAt(0)); | 2185 HeapObjectMatcher mtarget(m.InputAt(0)); |
2236 HeapObjectMatcher mnewtarget(m.InputAt(1)); | 2186 HeapObjectMatcher mnewtarget(m.InputAt(1)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 return jsgraph()->javascript(); | 2241 return jsgraph()->javascript(); |
2292 } | 2242 } |
2293 | 2243 |
2294 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { | 2244 SimplifiedOperatorBuilder* JSNativeContextSpecialization::simplified() const { |
2295 return jsgraph()->simplified(); | 2245 return jsgraph()->simplified(); |
2296 } | 2246 } |
2297 | 2247 |
2298 } // namespace compiler | 2248 } // namespace compiler |
2299 } // namespace internal | 2249 } // namespace internal |
2300 } // namespace v8 | 2250 } // namespace v8 |
OLD | NEW |