Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: src/compiler/property-access-builder.cc

Issue 2936673005: [turbofan] Refactor property access building. (Closed)
Patch Set: Prune includes, add comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler/property-access-builder.h"
6
7 #include "src/compilation-dependencies.h"
8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/access-info.h"
10 #include "src/compiler/js-graph.h"
11 #include "src/compiler/node-matchers.h"
12 #include "src/compiler/simplified-operator.h"
13 #include "src/lookup.h"
14
15 #include "src/field-index-inl.h"
16 #include "src/isolate-inl.h"
17
18 namespace v8 {
19 namespace internal {
20 namespace compiler {
21
22 Graph* PropertyAccessBuilder::graph() const { return jsgraph()->graph(); }
23
24 Isolate* PropertyAccessBuilder::isolate() const { return jsgraph()->isolate(); }
25
26 CommonOperatorBuilder* PropertyAccessBuilder::common() const {
27 return jsgraph()->common();
28 }
29
30 SimplifiedOperatorBuilder* PropertyAccessBuilder::simplified() const {
31 return jsgraph()->simplified();
32 }
33
34 // static
35 bool PropertyAccessBuilder::HasOnlyNumberMaps(MapHandles const& maps) {
36 for (auto map : maps) {
37 if (map->instance_type() != HEAP_NUMBER_TYPE) return false;
38 }
39 return true;
40 }
41
42 // static
43 bool PropertyAccessBuilder::HasOnlyStringMaps(MapHandles const& maps) {
44 for (auto map : maps) {
45 if (!map->IsStringMap()) return false;
46 }
47 return true;
48 }
49
50 bool PropertyAccessBuilder::HasOnlySequentialStringMaps(
51 MapHandles const& maps) {
52 for (auto map : maps) {
53 if (!map->IsStringMap()) return false;
54 if (!StringShape(map->instance_type()).IsSequential()) {
55 return false;
56 }
57 }
58 return true;
59 }
60
61 bool PropertyAccessBuilder::TryBuildStringCheck(MapHandles const& maps,
62 Node** receiver, Node** effect,
63 Node* control) {
64 if (HasOnlyStringMaps(maps)) {
65 if (HasOnlySequentialStringMaps(maps)) {
66 *receiver = *effect = graph()->NewNode(simplified()->CheckSeqString(),
67 *receiver, *effect, control);
68 } else {
69 // Monormorphic string access (ignoring the fact that there are multiple
70 // String maps).
71 *receiver = *effect = graph()->NewNode(simplified()->CheckString(),
72 *receiver, *effect, control);
73 }
74 return true;
75 }
76 return false;
77 }
78
79 bool PropertyAccessBuilder::TryBuildNumberCheck(MapHandles const& maps,
80 Node** receiver, Node** effect,
81 Node* control) {
82 if (HasOnlyNumberMaps(maps)) {
83 // Monomorphic number access (we also deal with Smis here).
84 *receiver = *effect = graph()->NewNode(simplified()->CheckNumber(),
85 *receiver, *effect, control);
86 return true;
87 }
88 return false;
89 }
90
91 Node* PropertyAccessBuilder::BuildCheckHeapObject(Node* receiver, Node** effect,
92 Node* control) {
93 switch (receiver->opcode()) {
94 case IrOpcode::kHeapConstant:
95 case IrOpcode::kJSCreate:
96 case IrOpcode::kJSCreateArguments:
97 case IrOpcode::kJSCreateArray:
98 case IrOpcode::kJSCreateClosure:
99 case IrOpcode::kJSCreateIterResultObject:
100 case IrOpcode::kJSCreateLiteralArray:
101 case IrOpcode::kJSCreateLiteralObject:
102 case IrOpcode::kJSCreateLiteralRegExp:
103 case IrOpcode::kJSConvertReceiver:
104 case IrOpcode::kJSToName:
105 case IrOpcode::kJSToString:
106 case IrOpcode::kJSToObject:
107 case IrOpcode::kJSTypeOf: {
108 return receiver;
109 }
110 default: {
111 return *effect = graph()->NewNode(simplified()->CheckHeapObject(),
112 receiver, *effect, control);
113 }
114 }
115 UNREACHABLE();
116 return nullptr;
117 }
118
119 void PropertyAccessBuilder::BuildCheckMaps(
120 Node* receiver, Node** effect, Node* control,
121 std::vector<Handle<Map>> const& receiver_maps) {
122 HeapObjectMatcher m(receiver);
123 if (m.HasValue()) {
124 Handle<Map> receiver_map(m.Value()->map(), isolate());
125 if (receiver_map->is_stable()) {
126 for (Handle<Map> map : receiver_maps) {
127 if (map.is_identical_to(receiver_map)) {
128 dependencies()->AssumeMapStable(receiver_map);
129 return;
130 }
131 }
132 }
133 }
134 ZoneHandleSet<Map> maps;
135 CheckMapsFlags flags = CheckMapsFlag::kNone;
136 for (Handle<Map> map : receiver_maps) {
137 maps.insert(map, graph()->zone());
138 if (map->is_migration_target()) {
139 flags |= CheckMapsFlag::kTryMigrateInstance;
140 }
141 }
142 *effect = graph()->NewNode(simplified()->CheckMaps(flags, maps), receiver,
143 *effect, control);
144 }
145
146 void PropertyAccessBuilder::AssumePrototypesStable(
147 Handle<Context> native_context,
148 std::vector<Handle<Map>> const& receiver_maps, Handle<JSObject> holder) {
149 // Determine actual holder and perform prototype chain checks.
150 for (auto map : receiver_maps) {
151 // Perform the implicit ToObject for primitives here.
152 // Implemented according to ES6 section 7.3.2 GetV (V, P).
153 Handle<JSFunction> constructor;
154 if (Map::GetConstructorFunction(map, native_context)
155 .ToHandle(&constructor)) {
156 map = handle(constructor->initial_map(), holder->GetIsolate());
157 }
158 dependencies()->AssumePrototypeMapsStable(map, holder);
159 }
160 }
161
162 Node* PropertyAccessBuilder::ResolveHolder(
163 PropertyAccessInfo const& access_info, Node* receiver) {
164 Handle<JSObject> holder;
165 if (access_info.holder().ToHandle(&holder)) {
166 return jsgraph()->Constant(holder);
167 }
168 return receiver;
169 }
170
171 Node* PropertyAccessBuilder::TryBuildLoadConstantDataField(
172 Handle<Name> name, PropertyAccessInfo const& access_info, Node* receiver) {
173 // Optimize immutable property loads.
174 HeapObjectMatcher m(receiver);
175 if (m.HasValue() && m.Value()->IsJSObject()) {
176 // TODO(ishell): Use something simpler like
177 //
178 // Handle<Object> value =
179 // JSObject::FastPropertyAt(Handle<JSObject>::cast(m.Value()),
180 // Representation::Tagged(), field_index);
181 //
182 // here, once we have the immutable bit in the access_info.
183
184 // TODO(turbofan): Given that we already have the field_index here, we
185 // might be smarter in the future and not rely on the LookupIterator,
186 // but for now let's just do what Crankshaft does.
187 LookupIterator it(m.Value(), name, LookupIterator::OWN_SKIP_INTERCEPTOR);
188 if (it.state() == LookupIterator::DATA) {
189 bool is_reaonly_non_configurable =
190 it.IsReadOnly() && !it.IsConfigurable();
191 if (is_reaonly_non_configurable ||
192 (FLAG_track_constant_fields && access_info.IsDataConstantField())) {
193 Node* value = jsgraph()->Constant(JSReceiver::GetDataProperty(&it));
194 if (!is_reaonly_non_configurable) {
195 // It's necessary to add dependency on the map that introduced
196 // the field.
197 DCHECK(access_info.IsDataConstantField());
198 DCHECK(!it.is_dictionary_holder());
199 Handle<Map> field_owner_map = it.GetFieldOwnerMap();
200 dependencies()->AssumeFieldOwner(field_owner_map);
201 }
202 return value;
203 }
204 }
205 }
206 return nullptr;
207 }
208
209 Node* PropertyAccessBuilder::BuildLoadDataField(
210 Handle<Name> name, PropertyAccessInfo const& access_info, Node* receiver,
211 Node** effect, Node** control) {
212 DCHECK(access_info.IsDataField() || access_info.IsDataConstantField());
213 receiver = ResolveHolder(access_info, receiver);
214 if (Node* value =
215 TryBuildLoadConstantDataField(name, access_info, receiver)) {
216 return value;
217 }
218
219 FieldIndex const field_index = access_info.field_index();
220 Type* const field_type = access_info.field_type();
221 MachineRepresentation const field_representation =
222 access_info.field_representation();
223 Node* storage = receiver;
224 if (!field_index.is_inobject()) {
225 storage = *effect = graph()->NewNode(
226 simplified()->LoadField(AccessBuilder::ForJSObjectProperties()),
227 storage, *effect, *control);
228 }
229 FieldAccess field_access = {
230 kTaggedBase,
231 field_index.offset(),
232 name,
233 MaybeHandle<Map>(),
234 field_type,
235 MachineType::TypeForRepresentation(field_representation),
236 kFullWriteBarrier};
237 if (field_representation == MachineRepresentation::kFloat64) {
238 if (!field_index.is_inobject() || field_index.is_hidden_field() ||
239 !FLAG_unbox_double_fields) {
240 FieldAccess const storage_access = {kTaggedBase,
241 field_index.offset(),
242 name,
243 MaybeHandle<Map>(),
244 Type::OtherInternal(),
245 MachineType::TaggedPointer(),
246 kPointerWriteBarrier};
247 storage = *effect = graph()->NewNode(
248 simplified()->LoadField(storage_access), storage, *effect, *control);
249 field_access.offset = HeapNumber::kValueOffset;
250 field_access.name = MaybeHandle<Name>();
251 }
252 } else if (field_representation == MachineRepresentation::kTaggedPointer) {
253 // Remember the map of the field value, if its map is stable. This is
254 // used by the LoadElimination to eliminate map checks on the result.
255 Handle<Map> field_map;
256 if (access_info.field_map().ToHandle(&field_map)) {
257 if (field_map->is_stable()) {
258 dependencies()->AssumeMapStable(field_map);
259 field_access.map = field_map;
260 }
261 }
262 }
263 Node* value = *effect = graph()->NewNode(
264 simplified()->LoadField(field_access), storage, *effect, *control);
265 return value;
266 }
267
268 } // namespace compiler
269 } // namespace internal
270 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698