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 <ostream> | 5 #include <ostream> |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/compilation-dependencies.h" | 8 #include "src/compilation-dependencies.h" |
9 #include "src/compiler/access-info.h" | 9 #include "src/compiler/access-info.h" |
10 #include "src/field-index-inl.h" | 10 #include "src/field-index-inl.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 Type* receiver_type, FieldIndex field_index, Type* field_type, | 74 Type* receiver_type, FieldIndex field_index, Type* field_type, |
75 MaybeHandle<JSObject> holder, MaybeHandle<Map> transition_map) { | 75 MaybeHandle<JSObject> holder, MaybeHandle<Map> transition_map) { |
76 return PropertyAccessInfo(holder, transition_map, field_index, field_type, | 76 return PropertyAccessInfo(holder, transition_map, field_index, field_type, |
77 receiver_type); | 77 receiver_type); |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 ElementAccessInfo::ElementAccessInfo() : receiver_type_(Type::None()) {} | 81 ElementAccessInfo::ElementAccessInfo() : receiver_type_(Type::None()) {} |
82 | 82 |
83 | 83 |
| 84 ElementAccessInfo::ElementAccessInfo(Type* receiver_type, |
| 85 ElementsKind elements_kind, |
| 86 MaybeHandle<JSObject> holder) |
| 87 : elements_kind_(elements_kind), |
| 88 holder_(holder), |
| 89 receiver_type_(receiver_type) {} |
| 90 |
| 91 |
84 PropertyAccessInfo::PropertyAccessInfo() | 92 PropertyAccessInfo::PropertyAccessInfo() |
85 : kind_(kInvalid), receiver_type_(Type::None()), field_type_(Type::Any()) {} | 93 : kind_(kInvalid), receiver_type_(Type::None()), field_type_(Type::Any()) {} |
86 | 94 |
87 | 95 |
88 PropertyAccessInfo::PropertyAccessInfo(MaybeHandle<JSObject> holder, | 96 PropertyAccessInfo::PropertyAccessInfo(MaybeHandle<JSObject> holder, |
89 Type* receiver_type) | 97 Type* receiver_type) |
90 : kind_(kNotFound), | 98 : kind_(kNotFound), |
91 receiver_type_(receiver_type), | 99 receiver_type_(receiver_type), |
92 holder_(holder), | 100 holder_(holder), |
93 field_type_(Type::Any()) {} | 101 field_type_(Type::Any()) {} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 154 |
147 *access_info = | 155 *access_info = |
148 ElementAccessInfo(Type::Class(map, zone()), elements_kind, holder); | 156 ElementAccessInfo(Type::Class(map, zone()), elements_kind, holder); |
149 return true; | 157 return true; |
150 } | 158 } |
151 | 159 |
152 | 160 |
153 bool AccessInfoFactory::ComputeElementAccessInfos( | 161 bool AccessInfoFactory::ComputeElementAccessInfos( |
154 MapHandleList const& maps, AccessMode access_mode, | 162 MapHandleList const& maps, AccessMode access_mode, |
155 ZoneVector<ElementAccessInfo>* access_infos) { | 163 ZoneVector<ElementAccessInfo>* access_infos) { |
| 164 // Collect possible transition targets. |
| 165 MapHandleList possible_transition_targets(maps.length()); |
156 for (Handle<Map> map : maps) { | 166 for (Handle<Map> map : maps) { |
157 if (Map::TryUpdate(map).ToHandle(&map)) { | 167 if (Map::TryUpdate(map).ToHandle(&map)) { |
158 ElementAccessInfo access_info; | 168 if (CanInlineElementAccess(map) && |
159 if (!ComputeElementAccessInfo(map, access_mode, &access_info)) { | 169 IsFastElementsKind(map->elements_kind()) && |
160 return false; | 170 GetInitialFastElementsKind() != map->elements_kind()) { |
| 171 possible_transition_targets.Add(map); |
161 } | 172 } |
162 access_infos->push_back(access_info); | |
163 } | 173 } |
164 } | 174 } |
| 175 |
| 176 // Separate the actual receiver maps and the possible transition sources. |
| 177 MapHandleList receiver_maps(maps.length()); |
| 178 MapTransitionList transitions(maps.length()); |
| 179 for (Handle<Map> map : maps) { |
| 180 if (Map::TryUpdate(map).ToHandle(&map)) { |
| 181 Handle<Map> transition_target = |
| 182 Map::FindTransitionedMap(map, &possible_transition_targets); |
| 183 if (transition_target.is_null()) { |
| 184 receiver_maps.Add(map); |
| 185 } else { |
| 186 transitions.push_back(std::make_pair(map, transition_target)); |
| 187 } |
| 188 } |
| 189 } |
| 190 |
| 191 for (Handle<Map> receiver_map : receiver_maps) { |
| 192 // Compute the element access information. |
| 193 ElementAccessInfo access_info; |
| 194 if (!ComputeElementAccessInfo(receiver_map, access_mode, &access_info)) { |
| 195 return false; |
| 196 } |
| 197 |
| 198 // Collect the possible transitions for the {receiver_map}. |
| 199 for (auto transition : transitions) { |
| 200 if (transition.second.is_identical_to(receiver_map)) { |
| 201 access_info.transitions().push_back(transition); |
| 202 } |
| 203 } |
| 204 |
| 205 // Schedule the access information. |
| 206 access_infos->push_back(access_info); |
| 207 } |
165 return true; | 208 return true; |
166 } | 209 } |
167 | 210 |
168 | 211 |
169 bool AccessInfoFactory::ComputePropertyAccessInfo( | 212 bool AccessInfoFactory::ComputePropertyAccessInfo( |
170 Handle<Map> map, Handle<Name> name, AccessMode access_mode, | 213 Handle<Map> map, Handle<Name> name, AccessMode access_mode, |
171 PropertyAccessInfo* access_info) { | 214 PropertyAccessInfo* access_info) { |
172 // Check if it is safe to inline property access for the {map}. | 215 // Check if it is safe to inline property access for the {map}. |
173 if (!CanInlinePropertyAccess(map)) return false; | 216 if (!CanInlinePropertyAccess(map)) return false; |
174 | 217 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 444 } |
402 return false; | 445 return false; |
403 } | 446 } |
404 | 447 |
405 | 448 |
406 Factory* AccessInfoFactory::factory() const { return isolate()->factory(); } | 449 Factory* AccessInfoFactory::factory() const { return isolate()->factory(); } |
407 | 450 |
408 } // namespace compiler | 451 } // namespace compiler |
409 } // namespace internal | 452 } // namespace internal |
410 } // namespace v8 | 453 } // namespace v8 |
OLD | NEW |