1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif // !V8_ENABLE_WEBASSEMBLY
#ifndef V8_COMPILER_WASM_GRAPH_ASSEMBLER_H_
#define V8_COMPILER_WASM_GRAPH_ASSEMBLER_H_
#include "src/compiler/graph-assembler.h"
#include "src/wasm/wasm-code-manager.h"
namespace v8 {
namespace internal {
namespace compiler {
constexpr Builtin WasmRuntimeStubIdToBuiltinName(
wasm::WasmCode::RuntimeStubId runtime_stub_id) {
switch (runtime_stub_id) {
#define DEF_CASE(name) \
case wasm::WasmCode::k##name: \
return Builtin::k##name;
#define DEF_TRAP_CASE(name) DEF_CASE(ThrowWasm##name)
WASM_RUNTIME_STUB_LIST(DEF_CASE, DEF_TRAP_CASE)
#undef DEF_CASE
#undef DEF_TRAP_CASE
default:
UNREACHABLE();
}
}
CallDescriptor* GetBuiltinCallDescriptor(
Builtin name, Zone* zone, StubCallMode stub_mode,
bool needs_frame_state = false,
Operator::Properties properties = Operator::kNoProperties);
ObjectAccess ObjectAccessForGCStores(wasm::ValueType type);
class WasmGraphAssembler : public GraphAssembler {
public:
WasmGraphAssembler(MachineGraph* mcgraph, Zone* zone)
: GraphAssembler(mcgraph, zone), simplified_(zone) {}
template <typename... Args>
Node* CallRuntimeStub(wasm::WasmCode::RuntimeStubId stub_id,
Operator::Properties properties, Args*... args) {
auto* call_descriptor = GetBuiltinCallDescriptor(
WasmRuntimeStubIdToBuiltinName(stub_id), temp_zone(),
StubCallMode::kCallWasmRuntimeStub, false, properties);
// A direct call to a wasm runtime stub defined in this module.
// Just encode the stub index. This will be patched at relocation.
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
stub_id, RelocInfo::WASM_STUB_CALL);
return Call(call_descriptor, call_target, args...);
}
Node* GetBuiltinPointerTarget(Builtin builtin) {
static_assert(std::is_same<Smi, BuiltinPtr>(), "BuiltinPtr must be Smi");
return NumberConstant(static_cast<int>(builtin));
}
template <typename... Args>
Node* CallBuiltin(Builtin name, Operator::Properties properties,
Args*... args) {
auto* call_descriptor = GetBuiltinCallDescriptor(
name, temp_zone(), StubCallMode::kCallBuiltinPointer, false,
properties);
Node* call_target = GetBuiltinPointerTarget(name);
return Call(call_descriptor, call_target, args...);
}
// Sets {true_node} and {false_node} to their corresponding Branch outputs.
// Returns the Branch node. Does not change control().
Node* Branch(Node* cond, Node** true_node, Node** false_node,
BranchHint hint);
Node* NumberConstant(double value) {
return graph()->NewNode(mcgraph()->common()->NumberConstant(value));
}
Node* SmiConstant(Tagged_t value) {
Address tagged_value = Internals::IntToSmi(static_cast<int>(value));
return kTaggedSize == kInt32Size
? Int32Constant(static_cast<int32_t>(tagged_value))
: Int64Constant(static_cast<int64_t>(tagged_value));
}
void MergeControlToEnd(Node* control) {
NodeProperties::MergeControlToEnd(graph(), common(), control);
}
// Numeric conversions
Node* BuildTruncateIntPtrToInt32(Node* value);
Node* BuildChangeInt32ToIntPtr(Node* value);
Node* BuildChangeIntPtrToInt64(Node* value);
Node* BuildChangeUint32ToUintPtr(Node* node);
Node* BuildSmiShiftBitsConstant();
Node* BuildSmiShiftBitsConstant32();
Node* BuildChangeInt32ToSmi(Node* value);
Node* BuildChangeUint31ToSmi(Node* value);
Node* BuildChangeSmiToInt32(Node* value);
Node* BuildConvertUint32ToSmiWithSaturation(Node* value, uint32_t maxval);
Node* BuildChangeSmiToIntPtr(Node* value);
// Helper functions for dealing with HeapObjects.
// Rule of thumb: if access to a given field in an object is required in
// at least two places, put a helper function here.
Node* Allocate(int size);
Node* Allocate(Node* size,
AllowLargeObjects allow_large = AllowLargeObjects::kTrue);
Node* LoadFromObject(MachineType type, Node* base, Node* offset);
Node* LoadFromObject(MachineType type, Node* base, int offset) {
return LoadFromObject(type, base, IntPtrConstant(offset));
}
Node* LoadImmutableFromObject(MachineType type, Node* base, Node* offset);
Node* LoadImmutableFromObject(MachineType type, Node* base, int offset) {
return LoadImmutableFromObject(type, base, IntPtrConstant(offset));
}
Node* LoadImmutable(LoadRepresentation rep, Node* base, Node* offset);
Node* LoadImmutable(LoadRepresentation rep, Node* base, int offset) {
return LoadImmutable(rep, base, IntPtrConstant(offset));
}
Node* StoreToObject(ObjectAccess access, Node* base, Node* offset,
Node* value);
Node* StoreToObject(ObjectAccess access, Node* base, int offset,
Node* value) {
return StoreToObject(access, base, IntPtrConstant(offset), value);
}
Node* InitializeImmutableInObject(ObjectAccess access, Node* base,
Node* offset, Node* value);
Node* InitializeImmutableInObject(ObjectAccess access, Node* base, int offset,
Node* value) {
return InitializeImmutableInObject(access, base, IntPtrConstant(offset),
value);
}
Node* IsI31(Node* object);
// Maps and their contents.
Node* LoadMap(Node* object);
void StoreMap(Node* heap_object, Node* map);
Node* LoadInstanceType(Node* map);
Node* LoadWasmTypeInfo(Node* map);
// FixedArrays.
Node* LoadFixedArrayLengthAsSmi(Node* fixed_array);
Node* LoadFixedArrayElement(Node* fixed_array, Node* index_intptr,
MachineType type = MachineType::AnyTagged());
Node* LoadImmutableFixedArrayElement(
Node* fixed_array, Node* index_intptr,
MachineType type = MachineType::AnyTagged());
Node* LoadFixedArrayElement(Node* array, int index, MachineType type);
Node* LoadFixedArrayElementSmi(Node* array, int index) {
return LoadFixedArrayElement(array, index, MachineType::TaggedSigned());
}
Node* LoadFixedArrayElementPtr(Node* array, int index) {
return LoadFixedArrayElement(array, index, MachineType::TaggedPointer());
}
Node* LoadFixedArrayElementAny(Node* array, int index) {
return LoadFixedArrayElement(array, index, MachineType::AnyTagged());
}
Node* StoreFixedArrayElement(Node* array, int index, Node* value,
ObjectAccess access);
Node* StoreFixedArrayElementSmi(Node* array, int index, Node* value) {
return StoreFixedArrayElement(
array, index, value,
ObjectAccess(MachineType::TaggedSigned(), kNoWriteBarrier));
}
Node* StoreFixedArrayElementAny(Node* array, int index, Node* value) {
return StoreFixedArrayElement(
array, index, value,
ObjectAccess(MachineType::AnyTagged(), kFullWriteBarrier));
}
// Functions, SharedFunctionInfos, FunctionData.
Node* LoadSharedFunctionInfo(Node* js_function);
Node* LoadContextFromJSFunction(Node* js_function);
Node* LoadFunctionDataFromJSFunction(Node* js_function);
Node* LoadExportedFunctionIndexAsSmi(Node* exported_function_data);
Node* LoadExportedFunctionInstance(Node* exported_function_data);
// JavaScript objects.
Node* LoadJSArrayElements(Node* js_array);
// WasmGC objects.
Node* FieldOffset(const wasm::StructType* type, uint32_t field_index);
Node* StoreStructField(Node* struct_object, const wasm::StructType* type,
uint32_t field_index, Node* value);
Node* WasmArrayElementOffset(Node* index, wasm::ValueType element_type);
Node* LoadWasmArrayLength(Node* array);
Node* IsDataRefMap(Node* map);
Node* WasmTypeCheck(Node* object, Node* rtt, WasmTypeCheckConfig config);
Node* WasmTypeCast(Node* object, Node* rtt, WasmTypeCheckConfig config);
Node* Null();
Node* IsNull(Node* object);
Node* IsNotNull(Node* object);
Node* AssertNotNull(Node* object);
Node* WasmExternInternalize(Node* object);
Node* WasmExternExternalize(Node* object);
// Generic helpers.
Node* HasInstanceType(Node* heap_object, InstanceType type);
void TrapIf(Node* condition, TrapId reason) {
AddNode(graph()->NewNode(mcgraph()->common()->TrapIf(reason), condition,
effect(), control()));
}
void TrapUnless(Node* condition, TrapId reason) {
AddNode(graph()->NewNode(mcgraph()->common()->TrapUnless(reason), condition,
effect(), control()));
}
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
private:
SimplifiedOperatorBuilder simplified_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_WASM_GRAPH_ASSEMBLER_H_
|