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 #ifndef V8_COMPILER_ACCESS_INFO_H_ | 5 #ifndef V8_COMPILER_ACCESS_INFO_H_ |
6 #define V8_COMPILER_ACCESS_INFO_H_ | 6 #define V8_COMPILER_ACCESS_INFO_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/field-index.h" | 10 #include "src/field-index.h" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 #include "src/zone-containers.h" | 12 #include "src/zone-containers.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 // Forward declarations. | 17 // Forward declarations. |
18 class CompilationDependencies; | 18 class CompilationDependencies; |
19 class Factory; | 19 class Factory; |
20 class TypeCache; | 20 class TypeCache; |
21 | 21 |
22 | |
23 namespace compiler { | 22 namespace compiler { |
24 | 23 |
25 // Whether we are loading a property or storing to a property. | 24 // Whether we are loading a property or storing to a property. |
26 enum class AccessMode { kLoad, kStore }; | 25 enum class AccessMode { kLoad, kStore }; |
27 | 26 |
28 std::ostream& operator<<(std::ostream&, AccessMode); | 27 std::ostream& operator<<(std::ostream&, AccessMode); |
29 | 28 |
| 29 typedef std::vector<Handle<Map>> MapList; |
30 | 30 |
31 // Mapping of transition source to transition target. | 31 // Mapping of transition source to transition target. |
32 typedef std::vector<std::pair<Handle<Map>, Handle<Map>>> MapTransitionList; | 32 typedef std::vector<std::pair<Handle<Map>, Handle<Map>>> MapTransitionList; |
33 | 33 |
34 | |
35 // This class encapsulates all information required to access a certain element. | 34 // This class encapsulates all information required to access a certain element. |
36 class ElementAccessInfo final { | 35 class ElementAccessInfo final { |
37 public: | 36 public: |
38 ElementAccessInfo(); | 37 ElementAccessInfo(); |
39 ElementAccessInfo(Type* receiver_type, ElementsKind elements_kind, | 38 ElementAccessInfo(MapList const& receiver_maps, ElementsKind elements_kind, |
40 MaybeHandle<JSObject> holder); | 39 MaybeHandle<JSObject> holder); |
41 | 40 |
42 MaybeHandle<JSObject> holder() const { return holder_; } | 41 MaybeHandle<JSObject> holder() const { return holder_; } |
43 ElementsKind elements_kind() const { return elements_kind_; } | 42 ElementsKind elements_kind() const { return elements_kind_; } |
44 Type* receiver_type() const { return receiver_type_; } | 43 MapList const& receiver_maps() const { return receiver_maps_; } |
45 MapTransitionList& transitions() { return transitions_; } | 44 MapTransitionList& transitions() { return transitions_; } |
46 MapTransitionList const& transitions() const { return transitions_; } | 45 MapTransitionList const& transitions() const { return transitions_; } |
47 | 46 |
48 private: | 47 private: |
49 ElementsKind elements_kind_; | 48 ElementsKind elements_kind_; |
50 MaybeHandle<JSObject> holder_; | 49 MaybeHandle<JSObject> holder_; |
51 Type* receiver_type_; | 50 MapList receiver_maps_; |
52 MapTransitionList transitions_; | 51 MapTransitionList transitions_; |
53 }; | 52 }; |
54 | 53 |
55 | |
56 // This class encapsulates all information required to access a certain | 54 // This class encapsulates all information required to access a certain |
57 // object property, either on the object itself or on the prototype chain. | 55 // object property, either on the object itself or on the prototype chain. |
58 class PropertyAccessInfo final { | 56 class PropertyAccessInfo final { |
59 public: | 57 public: |
60 enum Kind { kInvalid, kNotFound, kDataConstant, kDataField }; | 58 enum Kind { kInvalid, kNotFound, kDataConstant, kDataField }; |
61 | 59 |
62 static PropertyAccessInfo NotFound(Type* receiver_type, | 60 static PropertyAccessInfo NotFound(MapList const& receiver_maps, |
63 MaybeHandle<JSObject> holder); | 61 MaybeHandle<JSObject> holder); |
64 static PropertyAccessInfo DataConstant(Type* receiver_type, | 62 static PropertyAccessInfo DataConstant(MapList const& receiver_maps, |
65 Handle<Object> constant, | 63 Handle<Object> constant, |
66 MaybeHandle<JSObject> holder); | 64 MaybeHandle<JSObject> holder); |
67 static PropertyAccessInfo DataField( | 65 static PropertyAccessInfo DataField( |
68 Type* receiver_type, FieldIndex field_index, Type* field_type, | 66 MapList const& receiver_maps, FieldIndex field_index, Type* field_type, |
69 MaybeHandle<JSObject> holder = MaybeHandle<JSObject>(), | 67 MaybeHandle<JSObject> holder = MaybeHandle<JSObject>(), |
70 MaybeHandle<Map> transition_map = MaybeHandle<Map>()); | 68 MaybeHandle<Map> transition_map = MaybeHandle<Map>()); |
71 | 69 |
72 PropertyAccessInfo(); | 70 PropertyAccessInfo(); |
73 | 71 |
| 72 bool Merge(PropertyAccessInfo const* that) WARN_UNUSED_RESULT; |
| 73 |
74 bool IsNotFound() const { return kind() == kNotFound; } | 74 bool IsNotFound() const { return kind() == kNotFound; } |
75 bool IsDataConstant() const { return kind() == kDataConstant; } | 75 bool IsDataConstant() const { return kind() == kDataConstant; } |
76 bool IsDataField() const { return kind() == kDataField; } | 76 bool IsDataField() const { return kind() == kDataField; } |
77 | 77 |
78 bool HasTransitionMap() const { return !transition_map().is_null(); } | 78 bool HasTransitionMap() const { return !transition_map().is_null(); } |
79 | 79 |
80 Kind kind() const { return kind_; } | 80 Kind kind() const { return kind_; } |
81 MaybeHandle<JSObject> holder() const { return holder_; } | 81 MaybeHandle<JSObject> holder() const { return holder_; } |
82 MaybeHandle<Map> transition_map() const { return transition_map_; } | 82 MaybeHandle<Map> transition_map() const { return transition_map_; } |
83 Handle<Object> constant() const { return constant_; } | 83 Handle<Object> constant() const { return constant_; } |
84 FieldIndex field_index() const { return field_index_; } | 84 FieldIndex field_index() const { return field_index_; } |
85 Type* field_type() const { return field_type_; } | 85 Type* field_type() const { return field_type_; } |
86 Type* receiver_type() const { return receiver_type_; } | 86 MapList const& receiver_maps() const { return receiver_maps_; } |
87 | 87 |
88 private: | 88 private: |
89 PropertyAccessInfo(MaybeHandle<JSObject> holder, Type* receiver_type); | 89 PropertyAccessInfo(MaybeHandle<JSObject> holder, |
| 90 MapList const& receiver_maps); |
90 PropertyAccessInfo(MaybeHandle<JSObject> holder, Handle<Object> constant, | 91 PropertyAccessInfo(MaybeHandle<JSObject> holder, Handle<Object> constant, |
91 Type* receiver_type); | 92 MapList const& receiver_maps); |
92 PropertyAccessInfo(MaybeHandle<JSObject> holder, | 93 PropertyAccessInfo(MaybeHandle<JSObject> holder, |
93 MaybeHandle<Map> transition_map, FieldIndex field_index, | 94 MaybeHandle<Map> transition_map, FieldIndex field_index, |
94 Type* field_type, Type* receiver_type); | 95 Type* field_type, MapList const& receiver_maps); |
95 | 96 |
96 Kind kind_; | 97 Kind kind_; |
97 Type* receiver_type_; | 98 MapList receiver_maps_; |
98 Handle<Object> constant_; | 99 Handle<Object> constant_; |
99 MaybeHandle<Map> transition_map_; | 100 MaybeHandle<Map> transition_map_; |
100 MaybeHandle<JSObject> holder_; | 101 MaybeHandle<JSObject> holder_; |
101 FieldIndex field_index_; | 102 FieldIndex field_index_; |
102 Type* field_type_; | 103 Type* field_type_; |
103 }; | 104 }; |
104 | 105 |
105 | 106 |
106 // Factory class for {ElementAccessInfo}s and {PropertyAccessInfo}s. | 107 // Factory class for {ElementAccessInfo}s and {PropertyAccessInfo}s. |
107 class AccessInfoFactory final { | 108 class AccessInfoFactory final { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Zone* const zone_; | 142 Zone* const zone_; |
142 | 143 |
143 DISALLOW_COPY_AND_ASSIGN(AccessInfoFactory); | 144 DISALLOW_COPY_AND_ASSIGN(AccessInfoFactory); |
144 }; | 145 }; |
145 | 146 |
146 } // namespace compiler | 147 } // namespace compiler |
147 } // namespace internal | 148 } // namespace internal |
148 } // namespace v8 | 149 } // namespace v8 |
149 | 150 |
150 #endif // V8_COMPILER_ACCESS_INFO_H_ | 151 #endif // V8_COMPILER_ACCESS_INFO_H_ |
OLD | NEW |