1 // Copyright 2014 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 #ifndef V8_COMPILER_ACCESS_BUILDER_H_
6 #define V8_COMPILER_ACCESS_BUILDER_H_
7 
8 #include "src/base/compiler-specific.h"
9 #include "src/compiler/simplified-operator.h"
10 #include "src/elements-kind.h"
11 #include "src/globals.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16 
17 // This access builder provides a set of static methods constructing commonly
18 // used FieldAccess and ElementAccess descriptors. These descriptors serve as
19 // parameters to simplified load/store operators.
20 class V8_EXPORT_PRIVATE AccessBuilder final
NON_EXPORTED_BASE(AllStatic)21     : public NON_EXPORTED_BASE(AllStatic) {
22  public:
23   // ===========================================================================
24   // Access to external values (based on external references).
25 
26   // Provides access to a tagged field identified by an external reference.
27   static FieldAccess ForExternalTaggedValue();
28 
29   // Provides access to an uint8 field identified by an external reference.
30   static FieldAccess ForExternalUint8Value();
31 
32   // ===========================================================================
33   // Access to heap object fields and elements (based on tagged pointer).
34 
35   // Provides access to HeapObject::map() field.
36   static FieldAccess ForMap();
37 
38   // Provides access to HeapNumber::value() field.
39   static FieldAccess ForHeapNumberValue();
40 
41   // Provides access to BigInt's bit field.
42   static FieldAccess ForBigIntBitfield();
43 
44   // Provides access to JSObject::properties() field.
45   static FieldAccess ForJSObjectPropertiesOrHash();
46 
47   // Provides access to JSObject::elements() field.
48   static FieldAccess ForJSObjectElements();
49 
50   // Provides access to JSObject inobject property fields.
51   static FieldAccess ForJSObjectInObjectProperty(const MapRef& map, int index);
52   static FieldAccess ForJSObjectOffset(
53       int offset, WriteBarrierKind write_barrier_kind = kFullWriteBarrier);
54 
55   // Provides access to JSCollecton::table() field.
56   static FieldAccess ForJSCollectionTable();
57 
58   // Provides access to JSCollectionIterator::table() field.
59   static FieldAccess ForJSCollectionIteratorTable();
60 
61   // Provides access to JSCollectionIterator::index() field.
62   static FieldAccess ForJSCollectionIteratorIndex();
63 
64   // Provides access to JSFunction::prototype_or_initial_map() field.
65   static FieldAccess ForJSFunctionPrototypeOrInitialMap();
66 
67   // Provides access to JSFunction::context() field.
68   static FieldAccess ForJSFunctionContext();
69 
70   // Provides access to JSFunction::shared() field.
71   static FieldAccess ForJSFunctionSharedFunctionInfo();
72 
73   // Provides access to JSFunction::feedback_cell() field.
74   static FieldAccess ForJSFunctionFeedbackCell();
75 
76   // Provides access to JSFunction::code() field.
77   static FieldAccess ForJSFunctionCode();
78 
79   // Provides access to JSBoundFunction::bound_target_function() field.
80   static FieldAccess ForJSBoundFunctionBoundTargetFunction();
81 
82   // Provides access to JSBoundFunction::bound_this() field.
83   static FieldAccess ForJSBoundFunctionBoundThis();
84 
85   // Provides access to JSBoundFunction::bound_arguments() field.
86   static FieldAccess ForJSBoundFunctionBoundArguments();
87 
88   // Provides access to JSGeneratorObject::context() field.
89   static FieldAccess ForJSGeneratorObjectContext();
90 
91   // Provides access to JSGeneratorObject::continuation() field.
92   static FieldAccess ForJSGeneratorObjectContinuation();
93 
94   // Provides access to JSGeneratorObject::input_or_debug_pos() field.
95   static FieldAccess ForJSGeneratorObjectInputOrDebugPos();
96 
97   // Provides access to JSGeneratorObject::parameters_and_registers() field.
98   static FieldAccess ForJSGeneratorObjectParametersAndRegisters();
99 
100   // Provides access to JSGeneratorObject::function() field.
101   static FieldAccess ForJSGeneratorObjectFunction();
102 
103   // Provides access to JSGeneratorObject::receiver() field.
104   static FieldAccess ForJSGeneratorObjectReceiver();
105 
106   // Provides access to JSGeneratorObject::resume_mode() field.
107   static FieldAccess ForJSGeneratorObjectResumeMode();
108 
109   // Provides access to JSAsyncGeneratorObject::queue() field.
110   static FieldAccess ForJSAsyncGeneratorObjectQueue();
111 
112   // Provides access to JSAsyncGeneratorObject::is_awaiting() field.
113   static FieldAccess ForJSAsyncGeneratorObjectIsAwaiting();
114 
115   // Provides access to JSArray::length() field.
116   static FieldAccess ForJSArrayLength(ElementsKind elements_kind);
117 
118   // Provides access to JSArrayBuffer::backing_store() field.
119   static FieldAccess ForJSArrayBufferBackingStore();
120 
121   // Provides access to JSArrayBuffer::bit_field() field.
122   static FieldAccess ForJSArrayBufferBitField();
123 
124   // Provides access to JSArrayBufferView::buffer() field.
125   static FieldAccess ForJSArrayBufferViewBuffer();
126 
127   // Provides access to JSArrayBufferView::byteLength() field.
128   static FieldAccess ForJSArrayBufferViewByteLength();
129 
130   // Provides access to JSArrayBufferView::byteOffset() field.
131   static FieldAccess ForJSArrayBufferViewByteOffset();
132 
133   // Provides access to JSTypedArray::length() field.
134   static FieldAccess ForJSTypedArrayLength();
135 
136   // Provides access to JSDate::value() field.
137   static FieldAccess ForJSDateValue();
138 
139   // Provides access to JSDate fields.
140   static FieldAccess ForJSDateField(JSDate::FieldIndex index);
141 
142   // Provides access to JSIteratorResult::done() field.
143   static FieldAccess ForJSIteratorResultDone();
144 
145   // Provides access to JSIteratorResult::value() field.
146   static FieldAccess ForJSIteratorResultValue();
147 
148   // Provides access to JSRegExp::data() field.
149   static FieldAccess ForJSRegExpData();
150 
151   // Provides access to JSRegExp::flags() field.
152   static FieldAccess ForJSRegExpFlags();
153 
154   // Provides access to JSRegExp::last_index() field.
155   static FieldAccess ForJSRegExpLastIndex();
156 
157   // Provides access to JSRegExp::source() field.
158   static FieldAccess ForJSRegExpSource();
159 
160   // Provides access to FixedArray::length() field.
161   static FieldAccess ForFixedArrayLength();
162 
163   // Provides access to PropertyArray::length() field.
164   static FieldAccess ForPropertyArrayLengthAndHash();
165 
166   // Provides access to FixedTypedArrayBase::base_pointer() field.
167   static FieldAccess ForFixedTypedArrayBaseBasePointer();
168 
169   // Provides access to FixedTypedArrayBase::external_pointer() field.
170   static FieldAccess ForFixedTypedArrayBaseExternalPointer();
171 
172   // Provides access to DescriptorArray::enum_cache() field.
173   static FieldAccess ForDescriptorArrayEnumCache();
174 
175   // Provides access to Map::bit_field() byte.
176   static FieldAccess ForMapBitField();
177 
178   // Provides access to Map::bit_field2() byte.
179   static FieldAccess ForMapBitField2();
180 
181   // Provides access to Map::bit_field3() field.
182   static FieldAccess ForMapBitField3();
183 
184   // Provides access to Map::descriptors() field.
185   static FieldAccess ForMapDescriptors();
186 
187   // Provides access to Map::instance_type() field.
188   static FieldAccess ForMapInstanceType();
189 
190   // Provides access to Map::prototype() field.
191   static FieldAccess ForMapPrototype();
192 
193   // Provides access to Module::regular_exports() field.
194   static FieldAccess ForModuleRegularExports();
195 
196   // Provides access to Module::regular_imports() field.
197   static FieldAccess ForModuleRegularImports();
198 
199   // Provides access to Name::hash_field() field.
200   static FieldAccess ForNameHashField();
201 
202   // Provides access to String::length() field.
203   static FieldAccess ForStringLength();
204 
205   // Provides access to ConsString::first() field.
206   static FieldAccess ForConsStringFirst();
207 
208   // Provides access to ConsString::second() field.
209   static FieldAccess ForConsStringSecond();
210 
211   // Provides access to ThinString::actual() field.
212   static FieldAccess ForThinStringActual();
213 
214   // Provides access to SlicedString::offset() field.
215   static FieldAccess ForSlicedStringOffset();
216 
217   // Provides access to SlicedString::parent() field.
218   static FieldAccess ForSlicedStringParent();
219 
220   // Provides access to ExternalString::resource_data() field.
221   static FieldAccess ForExternalStringResourceData();
222 
223   // Provides access to ExternalOneByteString characters.
224   static ElementAccess ForExternalOneByteStringCharacter();
225 
226   // Provides access to ExternalTwoByteString characters.
227   static ElementAccess ForExternalTwoByteStringCharacter();
228 
229   // Provides access to SeqOneByteString characters.
230   static ElementAccess ForSeqOneByteStringCharacter();
231 
232   // Provides access to SeqTwoByteString characters.
233   static ElementAccess ForSeqTwoByteStringCharacter();
234 
235   // Provides access to JSGlobalObject::global_proxy() field.
236   static FieldAccess ForJSGlobalObjectGlobalProxy();
237 
238   // Provides access to JSGlobalObject::native_context() field.
239   static FieldAccess ForJSGlobalObjectNativeContext();
240 
241   // Provides access to JSGlobalProxy::native_context() field.
242   static FieldAccess ForJSGlobalProxyNativeContext();
243 
244   // Provides access to JSArrayIterator::iterated_object() field.
245   static FieldAccess ForJSArrayIteratorIteratedObject();
246 
247   // Provides access to JSArrayIterator::next_index() field.
248   static FieldAccess ForJSArrayIteratorNextIndex();
249 
250   // Provides access to JSArrayIterator::kind() field.
251   static FieldAccess ForJSArrayIteratorKind();
252 
253   // Provides access to JSStringIterator::string() field.
254   static FieldAccess ForJSStringIteratorString();
255 
256   // Provides access to JSStringIterator::index() field.
257   static FieldAccess ForJSStringIteratorIndex();
258 
259   // Provides access to JSValue::value() field.
260   static FieldAccess ForValue();
261 
262   // Provides access to Cell::value() field.
263   static FieldAccess ForCellValue();
264 
265   // Provides access to arguments object fields.
266   static FieldAccess ForArgumentsLength();
267   static FieldAccess ForArgumentsCallee();
268 
269   // Provides access to FixedArray slots.
270   static FieldAccess ForFixedArraySlot(
271       size_t index, WriteBarrierKind write_barrier_kind = kFullWriteBarrier);
272 
273   // Provides access to Context slots.
274   static FieldAccess ForContextSlot(size_t index);
275 
276   // Provides access to FixedArray elements.
277   static ElementAccess ForFixedArrayElement();
278   static ElementAccess ForFixedArrayElement(
279       ElementsKind kind,
280       LoadSensitivity load_sensitivity = LoadSensitivity::kUnsafe);
281 
282   // Provides access to FixedDoubleArray elements.
283   static ElementAccess ForFixedDoubleArrayElement();
284 
285   // Provides access to EnumCache::keys() field.
286   static FieldAccess ForEnumCacheKeys();
287 
288   // Provides access to EnumCache::indices() field.
289   static FieldAccess ForEnumCacheIndices();
290 
291   // Provides access to Fixed{type}TypedArray and External{type}Array elements.
292   static ElementAccess ForTypedArrayElement(
293       ExternalArrayType type, bool is_external,
294       LoadSensitivity load_sensitivity = LoadSensitivity::kUnsafe);
295 
296   // Provides access to HashTable fields.
297   static FieldAccess ForHashTableBaseNumberOfElements();
298   static FieldAccess ForHashTableBaseNumberOfDeletedElement();
299   static FieldAccess ForHashTableBaseCapacity();
300 
301   // Provides access to OrderedHashTableBase fields.
302   static FieldAccess ForOrderedHashTableBaseNextTable();
303   static FieldAccess ForOrderedHashTableBaseNumberOfBuckets();
304   static FieldAccess ForOrderedHashTableBaseNumberOfElements();
305   static FieldAccess ForOrderedHashTableBaseNumberOfDeletedElements();
306 
307   // Provides access to OrderedHashMap elements.
308   static ElementAccess ForOrderedHashMapEntryValue();
309 
310   // Provides access to Dictionary fields.
311   static FieldAccess ForDictionaryMaxNumberKey();
312   static FieldAccess ForDictionaryNextEnumerationIndex();
313   static FieldAccess ForDictionaryObjectHashIndex();
314 
315  private:
316   DISALLOW_IMPLICIT_CONSTRUCTORS(AccessBuilder);
317 };
318 
319 }  // namespace compiler
320 }  // namespace internal
321 }  // namespace v8
322 
323 #endif  // V8_COMPILER_ACCESS_BUILDER_H_
324