v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-graph-assembler.h
Go to the documentation of this file.
1// Copyright 2022 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_WASM_GRAPH_ASSEMBLER_H_
6#define V8_COMPILER_WASM_GRAPH_ASSEMBLER_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
14
15namespace v8 {
16namespace internal {
17namespace compiler {
18
19CallDescriptor* GetBuiltinCallDescriptor(
20 Builtin name, Zone* zone, StubCallMode stub_mode,
21 bool needs_frame_state = false,
23
24ObjectAccess ObjectAccessForGCStores(wasm::ValueType type);
25
27 public:
31
32 // While CallBuiltin() translates to a direct call to the address of the
33 // builtin, CallBuiltinThroughJumptable instead jumps to a slot in a jump
34 // table that then calls the builtin. As the jump table is "close" to the
35 // generated code, this is encoded as a near call resulting in the instruction
36 // being shorter than a direct call to the builtin.
37 template <typename... Args>
39 Operator::Properties properties,
40 Args... args) {
41 auto* call_descriptor = GetBuiltinCallDescriptor(
42 builtin, temp_zone(), StubCallMode::kCallWasmRuntimeStub, false,
43 properties);
44 // A direct call to a wasm runtime stub defined in this module.
45 // Just encode the stub index. This will be patched at relocation.
46 Node* call_target = mcgraph()->RelocatableWasmBuiltinCallTarget(builtin);
47 return Call(call_descriptor, call_target, args...);
48 }
49
51 static_assert(std::is_same<Smi, BuiltinPtr>(), "BuiltinPtr must be Smi");
52 return NumberConstant(static_cast<int>(builtin));
53 }
54
55 template <typename... Args>
57 Args... args) {
58 return CallBuiltinImpl(name, false, properties, args...);
59 }
60
61 template <typename... Args>
63 Node* frame_state, Args... args) {
64 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState);
65 return CallBuiltinImpl(name, true, properties, frame_state, args...);
66 }
67
68 // Sets {true_node} and {false_node} to their corresponding Branch outputs.
69 // Returns the Branch node. Does not change control().
70 Node* Branch(Node* cond, Node** true_node, Node** false_node,
71 BranchHint hint);
72
73 Node* NumberConstant(double value) {
74 return graph()->NewNode(mcgraph()->common()->NumberConstant(value));
75 }
76
78 Address tagged_value = Internals::IntegralToSmi(static_cast<int>(value));
79 return kTaggedSize == kInt32Size
80 ? Int32Constant(static_cast<int32_t>(tagged_value))
81 : Int64Constant(static_cast<int64_t>(tagged_value));
82 }
83
87
88 // Numeric conversions
90
92
94
96
98
100
102
104
106
107 Node* BuildConvertUint32ToSmiWithSaturation(Node* value, uint32_t maxval);
108
110
111 // Helper functions for dealing with HeapObjects.
112 // Rule of thumb: if access to a given field in an object is required in
113 // at least two places, put a helper function here.
114
115 Node* Allocate(int size);
116
117 Node* Allocate(Node* size);
118
120
123 }
124
129
135
137
141
143
147
148 Node* LoadWasmCodePointer(Node* code_pointer);
149
151 Node* value);
152
154 Node* value) {
155 return StoreToObject(access, base, IntPtrConstant(offset), value);
156 }
157
159 Node* offset, Node* value);
160
162 Node* value) {
164 value);
165 }
166
168 ExternalPointerTagRange tag_range,
169 Node* isolate_root);
171 ExternalPointerTagRange tag_range,
172 Node* isolate_root);
173
175 Node* index,
176 ExternalPointerTagRange tag_range,
177 Node* isolate_root);
178
183 // Returns the load node (where the source position for the trap needs to be
184 // set by the caller) and the result.
185 std::pair<Node*, Node*> LoadTrustedPointerFromObjectTrapOnNull(
186 Node* object, int offset, IndirectPointerTag tag);
188
189 Node* IsSmi(Node* object);
190
191 // Maps and their contents.
192
193 Node* LoadMap(Node* object);
194
195 void StoreMap(Node* heap_object, Node* map);
196
198
200
201 // FixedArrays.
202
203 Node* LoadFixedArrayLengthAsSmi(Node* fixed_array);
204
205 Node* LoadFixedArrayElement(Node* fixed_array, Node* index_intptr,
207
209 Node* fixed_array, Node* index_intptr,
211
212 Node* LoadFixedArrayElement(Node* array, int index, MachineType type);
213
214 Node* LoadFixedArrayElementSmi(Node* array, int index) {
215 return LoadFixedArrayElement(array, index, MachineType::TaggedSigned());
216 }
217
218 Node* LoadFixedArrayElementPtr(Node* array, int index) {
220 }
221
222 Node* LoadFixedArrayElementAny(Node* array, int index) {
223 return LoadFixedArrayElement(array, index, MachineType::AnyTagged());
224 }
225
226 Node* LoadProtectedFixedArrayElement(Node* array, int index);
227 Node* LoadProtectedFixedArrayElement(Node* array, Node* index_intptr);
228
229 Node* LoadByteArrayElement(Node* byte_array, Node* index_intptr,
230 MachineType type);
231
232 Node* StoreFixedArrayElement(Node* array, int index, Node* value,
233 ObjectAccess access);
234
235 Node* StoreFixedArrayElementSmi(Node* array, int index, Node* value) {
237 array, index, value,
239 }
240
241 Node* StoreFixedArrayElementAny(Node* array, int index, Node* value) {
243 array, index, value,
245 }
246
247 Node* LoadWeakFixedArrayElement(Node* fixed_array, Node* index_intptr);
248
249 // Functions, SharedFunctionInfos, FunctionData.
250
251 Node* LoadSharedFunctionInfo(Node* js_function);
252
253 Node* LoadContextFromJSFunction(Node* js_function);
254
256
257 Node* LoadExportedFunctionIndexAsSmi(Node* exported_function_data);
258
259 Node* LoadExportedFunctionInstanceData(Node* exported_function_data);
260
261 // JavaScript objects.
262
263 Node* LoadJSArrayElements(Node* js_array);
264
265 // WasmGC objects.
266
267 Node* FieldOffset(const wasm::StructType* type, uint32_t field_index);
268
269 Node* WasmArrayElementOffset(Node* index, wasm::ValueType element_type);
270
271 Node* IsDataRefMap(Node* map);
272
273 Node* WasmTypeCheck(Node* object, Node* rtt, WasmTypeCheckConfig config);
275
276 Node* WasmTypeCast(Node* object, Node* rtt, WasmTypeCheckConfig config);
278
280
281 Node* IsNull(Node* object, wasm::ValueType type);
282
283 Node* IsNotNull(Node* object, wasm::ValueType type);
284
285 Node* AssertNotNull(Node* object, wasm::ValueType type, TrapId trap_id);
286
288
290
291 Node* StructGet(Node* object, const wasm::StructType* type, int field_index,
292 bool is_signed, CheckForNull null_check);
293
294 void StructSet(Node* object, Node* value, const wasm::StructType* type,
295 int field_index, CheckForNull null_check);
296
297 Node* ArrayGet(Node* array, Node* index, const wasm::ArrayType* type,
298 bool is_signed);
299
300 void ArraySet(Node* array, Node* index, Node* value,
301 const wasm::ArrayType* type);
302
303 Node* ArrayLength(Node* array, CheckForNull null_check);
304
305 void ArrayInitializeLength(Node* array, Node* length);
306
307 Node* LoadStringLength(Node* string);
308
309 Node* StringAsWtf16(Node* string);
310
312
313 // Generic helpers.
314
315 Node* HasInstanceType(Node* heap_object, InstanceType type);
316
317 void TrapIf(Node* condition, TrapId reason) {
318 // Initially wasm traps don't have a FrameState.
319 const bool has_frame_state = false;
320 AddNode(
321 graph()->NewNode(mcgraph()->common()->TrapIf(reason, has_frame_state),
322 condition, effect(), control()));
323 }
324
325 void TrapUnless(Node* condition, TrapId reason) {
326 // Initially wasm traps don't have a FrameState.
327 const bool has_frame_state = false;
328 AddNode(graph()->NewNode(
329 mcgraph()->common()->TrapUnless(reason, has_frame_state), condition,
330 effect(), control()));
331 }
332
334
336
337 private:
338 template <typename... Args>
339 Node* CallBuiltinImpl(Builtin name, bool needs_frame_state,
340 Operator::Properties properties, Args... args) {
341 auto* call_descriptor = GetBuiltinCallDescriptor(
342 name, temp_zone(), StubCallMode::kCallBuiltinPointer, needs_frame_state,
343 properties);
344 Node* call_target = GetBuiltinPointerTarget(name);
345 return Call(call_descriptor, call_target, args...);
346 }
347
349};
350
351} // namespace compiler
352} // namespace internal
353} // namespace v8
354
355#endif // V8_COMPILER_WASM_GRAPH_ASSEMBLER_H_
friend Zone
Definition asm-types.cc:195
static V8_INLINE constexpr Address IntegralToSmi(T value)
static constexpr MachineType AnyTagged()
static constexpr MachineType TaggedSigned()
static constexpr MachineType TaggedPointer()
TNode< Object > Call(const CallDescriptor *call_descriptor, int inputs_size, Node **inputs)
CommonOperatorBuilder * common() const
Node * RelocatableWasmBuiltinCallTarget(Builtin builtin)
static void MergeControlToEnd(TFGraph *graph, CommonOperatorBuilder *common, Node *node)
constexpr IrOpcode::Value opcode() const
Definition node.h:52
base::Flags< Property, uint8_t > Properties
Definition operator.h:60
Node * NewNode(const Operator *op, int input_count, Node *const *inputs, bool incomplete=false)
Node * ArrayLength(Node *array, CheckForNull null_check)
Node * WasmTypeCast(Node *object, Node *rtt, WasmTypeCheckConfig config)
Node * LoadImmutableFromObject(MachineType type, Node *base, Node *offset)
Node * StoreFixedArrayElementAny(Node *array, int index, Node *value)
Node * WasmTypeCheck(Node *object, Node *rtt, WasmTypeCheckConfig config)
Node * LoadProtectedPointerFromObject(Node *object, int offset)
Node * LoadExportedFunctionIndexAsSmi(Node *exported_function_data)
WasmGraphAssembler(MachineGraph *mcgraph, Zone *zone)
Node * FieldOffset(const wasm::StructType *type, uint32_t field_index)
Node * BuildLoadExternalPointerFromObject(Node *object, int offset, ExternalPointerTagRange tag_range, Node *isolate_root)
Node * CallBuiltin(Builtin name, Operator::Properties properties, Args... args)
Node * LoadProtectedFixedArrayElement(Node *array, int index)
Node * LoadFromObject(MachineType type, Node *base, int offset)
void TrapIf(Node *condition, TrapId reason)
void ArraySet(Node *array, Node *index, Node *value, const wasm::ArrayType *type)
void TrapUnless(Node *condition, TrapId reason)
Node * BuildConvertUint32ToSmiWithSaturation(Node *value, uint32_t maxval)
Node * Branch(Node *cond, Node **true_node, Node **false_node, BranchHint hint)
Node * LoadImmutableFixedArrayElement(Node *fixed_array, Node *index_intptr, MachineType type=MachineType::AnyTagged())
Node * CallBuiltinWithFrameState(Builtin name, Operator::Properties properties, Node *frame_state, Args... args)
Node * LoadExportedFunctionInstanceData(Node *exported_function_data)
Node * LoadFromObject(MachineType type, Node *base, Node *offset)
Node * StoreToObject(ObjectAccess access, Node *base, Node *offset, Node *value)
Node * LoadFixedArrayElementAny(Node *array, int index)
Node * LoadTrustedDataFromInstanceObject(Node *instance_object)
Node * StoreFixedArrayElementSmi(Node *array, int index, Node *value)
Node * LoadImmutable(LoadRepresentation rep, Node *base, Node *offset)
Node * LoadWeakFixedArrayElement(Node *fixed_array, Node *index_intptr)
Node * WasmTypeCastAbstract(Node *object, WasmTypeCheckConfig config)
SimplifiedOperatorBuilder * simplified() override
Node * BuildDecodeTrustedPointer(Node *handle, IndirectPointerTag tag)
Node * LoadProtectedPointerFromObject(Node *object, Node *offset)
Node * CallBuiltinImpl(Builtin name, bool needs_frame_state, Operator::Properties properties, Args... args)
Node * LoadFixedArrayElementPtr(Node *array, int index)
Node * InitializeImmutableInObject(ObjectAccess access, Node *base, int offset, Node *value)
Node * BuildDecodeSandboxedExternalPointer(Node *handle, ExternalPointerTagRange tag_range, Node *isolate_root)
Node * LoadImmutableTrustedPointerFromObject(Node *object, int offset, IndirectPointerTag tag)
Node * IsNull(Node *object, wasm::ValueType type)
Node * CallBuiltinThroughJumptable(Builtin builtin, Operator::Properties properties, Args... args)
Node * StoreToObject(ObjectAccess access, Node *base, int offset, Node *value)
Node * ArrayGet(Node *array, Node *index, const wasm::ArrayType *type, bool is_signed)
Node * WasmTypeCheckAbstract(Node *object, WasmTypeCheckConfig config)
void StoreMap(Node *heap_object, Node *map)
Node * LoadByteArrayElement(Node *byte_array, Node *index_intptr, MachineType type)
void StructSet(Node *object, Node *value, const wasm::StructType *type, int field_index, CheckForNull null_check)
Node * InitializeImmutableInObject(ObjectAccess access, Node *base, Node *offset, Node *value)
Node * LoadImmutableProtectedPointerFromObject(Node *object, Node *offset)
Node * LoadImmutable(LoadRepresentation rep, Node *base, int offset)
Node * LoadFixedArrayElementSmi(Node *array, int index)
Node * LoadTrustedPointerFromObject(Node *object, int offset, IndirectPointerTag tag)
Node * LoadFixedArrayElement(Node *fixed_array, Node *index_intptr, MachineType type=MachineType::AnyTagged())
std::pair< Node *, Node * > LoadTrustedPointerFromObjectTrapOnNull(Node *object, int offset, IndirectPointerTag tag)
void ArrayInitializeLength(Node *array, Node *length)
Node * StructGet(Node *object, const wasm::StructType *type, int field_index, bool is_signed, CheckForNull null_check)
Node * HasInstanceType(Node *heap_object, InstanceType type)
Node * WasmArrayElementOffset(Node *index, wasm::ValueType element_type)
Node * LoadImmutableFromObject(MachineType type, Node *base, int offset)
Node * IsNotNull(Node *object, wasm::ValueType type)
Node * StoreFixedArrayElement(Node *array, int index, Node *value, ObjectAccess access)
Node * BuildLoadExternalPointerFromObject(Node *object, int offset, Node *index, ExternalPointerTagRange tag_range, Node *isolate_root)
Node * AssertNotNull(Node *object, wasm::ValueType type, TrapId trap_id)
Node * LoadImmutableProtectedPointerFromObject(Node *object, int offset)
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
int32_t offset
ObjectAccess ObjectAccessForGCStores(wasm::ValueType type)
CallDescriptor * GetBuiltinCallDescriptor(Builtin name, Zone *zone, StubCallMode stub_mode, bool needs_frame_state, Operator::Properties properties)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
constexpr int kTaggedSize
Definition globals.h:542
Address Tagged_t
Definition globals.h:547
constexpr int kInt32Size
Definition globals.h:401
kMemory0SizeOffset Address kNewAllocationLimitAddressOffset Address kOldAllocationLimitAddressOffset uint8_t kGlobalsStartOffset kJumpTableStartOffset std::atomic< uint32_t > kTieringBudgetArrayOffset kDataSegmentStartsOffset kElementSegmentsOffset instance_object
bool is_signed(Condition cond)
#define DCHECK_EQ(v1, v2)
Definition logging.h:485