5 #ifndef V8_COMPILER_WASM_COMPILER_H_ 6 #define V8_COMPILER_WASM_COMPILER_H_ 12 #include "src/runtime/runtime.h" 13 #include "src/wasm/function-body-decoder.h" 14 #include "src/wasm/function-compiler.h" 15 #include "src/wasm/wasm-module.h" 16 #include "src/wasm/wasm-opcodes.h" 17 #include "src/wasm/wasm-result.h" 18 #include "src/zone/zone.h" 22 struct AssemblerOptions;
30 class NodeOriginTable;
32 class SourcePositionTable;
40 typedef compiler::Node TFNode;
41 typedef compiler::MachineGraph TFGraph;
72 enum class WasmImportCallKind : uint8_t {
76 kJSFunctionArityMatch,
77 kJSFunctionArityMatchSloppy,
78 kJSFunctionArityMismatch,
79 kJSFunctionArityMismatchSloppy,
82 kF64Acos = kFirstMathIntrinsic,
105 kLastMathIntrinsic = kF32ConvertF64,
117 bool source_positions);
131 enum CWasmEntryParameters {
142 MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig);
158 enum EnforceBoundsCheck :
bool {
159 kNeedsBoundsCheck =
true,
160 kCanOmitBoundsCheck =
false 162 enum UseRetpoline :
bool {
166 enum ExtraCallableParam :
bool {
167 kExtraCallableParam =
true,
168 kNoExtraCallableParam =
false 175 Node** Buffer(
size_t count) {
176 if (count > cur_bufsize_) {
177 size_t new_size = count + cur_bufsize_ + 5;
179 reinterpret_cast<Node**
>(zone_->New(new_size *
sizeof(
Node*)));
180 cur_bufsize_ = new_size;
189 Node* Start(
unsigned params);
190 Node* Param(
unsigned index);
194 Node* Merge(
unsigned count,
Node** controls);
195 Node* Phi(wasm::ValueType
type,
unsigned count,
Node** vals,
Node* control);
196 Node* CreateOrMergeIntoPhi(MachineRepresentation rep,
Node* merge,
199 Node* EffectPhi(
unsigned count,
Node** effects,
Node* control);
202 Node* Int32Constant(int32_t value);
204 Node* IntPtrConstant(intptr_t value);
205 Node* Float32Constant(
float value);
206 Node* Float64Constant(
double value);
207 Node* Binop(wasm::WasmOpcode opcode,
Node* left,
Node* right,
209 Node* Unop(wasm::WasmOpcode opcode,
Node* input,
215 Node* ExceptionTagEqual(
Node* caught_tag,
Node* expected_tag);
216 Node* LoadExceptionTagFromTable(
uint32_t exception_index);
217 Node* GetExceptionTag(
Node* except_obj);
218 Node** GetExceptionValues(
Node* except_obj,
220 bool IsPhiWithMerge(
Node* phi,
Node* merge);
221 bool ThrowsException(
Node* node,
Node** if_success,
Node** if_exception);
222 void AppendToMerge(
Node* merge,
Node* from);
223 void AppendToPhi(
Node* phi,
Node* from);
226 Node** control =
nullptr);
228 void PatchInStackCheckIfNeeded();
237 Node* TrapIfTrue(wasm::TrapReason reason,
Node* cond,
239 Node* TrapIfFalse(wasm::TrapReason reason,
Node* cond,
241 Node* TrapIfEq32(wasm::TrapReason reason,
Node* node, int32_t val,
243 Node* ZeroCheck32(wasm::TrapReason reason,
Node* node,
247 Node* ZeroCheck64(wasm::TrapReason reason,
Node* node,
250 Node* Switch(
unsigned count,
Node* key);
251 Node* IfValue(int32_t value,
Node* sw);
253 Node* Return(
unsigned count,
Node** nodes);
254 template <
typename... Nodes>
255 Node* Return(
Node* fst, Nodes*... more) {
256 Node* arr[] = {fst, more...};
257 return Return(arraysize(arr), arr);
272 Node* CurrentMemoryPages();
275 Node* TraceMemoryOperation(
bool is_store, MachineRepresentation,
Node* index,
282 wasm::ValueType
type);
283 static void PrintDebugName(
Node* node);
285 void set_instance_node(
Node* instance_node) {
286 this->instance_node_ = instance_node;
290 DCHECK_NOT_NULL(*control_);
294 DCHECK_NOT_NULL(*effect_);
306 void set_control_ptr(
Node** control) { this->control_ = control; }
308 void set_effect_ptr(
Node** effect) { this->effect_ = effect; }
311 Node** base_node,
Node** offset_node);
323 this->instance_cache_ = instance_cache;
330 void SimdScalarLoweringForTesting();
339 Node* SimdOp(wasm::WasmOpcode opcode,
Node*
const* inputs);
341 Node* SimdLaneOp(wasm::WasmOpcode opcode, uint8_t lane,
Node*
const* inputs);
343 Node* SimdShiftOp(wasm::WasmOpcode opcode, uint8_t shift,
344 Node*
const* inputs);
346 Node* Simd8x16ShuffleOp(
const uint8_t shuffle[16],
Node*
const* inputs);
348 Node* AtomicOp(wasm::WasmOpcode opcode,
Node*
const* inputs,
352 bool has_simd()
const {
return has_simd_; }
356 wasm::UseTrapHandler use_trap_handler()
const {
357 return env_ ? env_->use_trap_handler : wasm::kNoTrapHandler;
366 void RemoveBytecodePositionDecorator();
369 static const int kDefaultBufferSize = 16;
375 Node** control_ =
nullptr;
376 Node** effect_ =
nullptr;
387 Node* def_buffer_[kDefaultBufferSize];
388 bool has_simd_ =
false;
389 bool needs_stack_check_ =
false;
390 const bool untrusted_code_mitigations_ =
true;
398 Node* NoContextConstant();
404 Node* CheckBoundsAndAlignment(uint8_t access_size,
Node* index,
407 const Operator* GetSafeLoadOperator(
int offset, wasm::ValueType
type);
408 const Operator* GetSafeStoreOperator(
int offset, wasm::ValueType
type);
409 Node* BuildChangeEndiannessStore(
Node* node, MachineRepresentation rep,
410 wasm::ValueType wasmtype = wasm::kWasmStmt);
412 wasm::ValueType wasmtype = wasm::kWasmStmt);
417 template <
typename... Args>
421 UseRetpoline use_retpoline);
437 MachineRepresentation input_type);
440 Node* input0,
Node* input1 =
nullptr);
444 Node* BuildF32NearestInt(
Node* input);
448 Node* BuildF64NearestInt(
Node* input);
457 Node* BuildIntToFloatConversionInstruction(
459 MachineRepresentation parameter_representation,
461 Node* BuildF32SConvertI64(
Node* input);
462 Node* BuildF32UConvertI64(
Node* input);
463 Node* BuildF64SConvertI64(
Node* input);
464 Node* BuildF64UConvertI64(
Node* input);
467 wasm::WasmOpcode opcode);
479 MachineType result_type, wasm::TrapReason trap_zero,
482 Node* BuildChangeInt32ToIntPtr(
Node* value);
483 Node* BuildChangeInt32ToSmi(
Node* value);
484 Node* BuildChangeUint31ToSmi(
Node* value);
485 Node* BuildSmiShiftBitsConstant();
486 Node* BuildChangeSmiToInt32(
Node* value);
489 Node* BuildI32AsmjsSConvertF32(
Node* input);
490 Node* BuildI32AsmjsSConvertF64(
Node* input);
491 Node* BuildI32AsmjsUConvertF32(
Node* input);
492 Node* BuildI32AsmjsUConvertF64(
Node* input);
501 void BuildEncodeException32BitValue(
Node* values_array,
uint32_t* index,
506 Node** Realloc(
Node*
const* buffer,
size_t old_count,
size_t new_count) {
507 Node** buf = Buffer(new_count);
508 if (buf != buffer) memcpy(buf, buffer, old_count *
sizeof(
Node*));
512 Node* BuildLoadBuiltinFromInstance(
int builtin_index);
518 Node* BuildCallToRuntime(Runtime::FunctionId f,
Node** parameters,
519 int parameter_count);
521 Node* BuildCallToRuntimeWithContext(Runtime::FunctionId f,
Node* js_context,
522 Node** parameters,
int parameter_count);
523 TrapId GetTrapIdForTrap(wasm::TrapReason reason);
528 WasmGraphBuilder::UseRetpoline use_retpoline =
529 WasmGraphBuilder::kNoRetpoline,
530 WasmGraphBuilder::ExtraCallableParam callable_param =
531 WasmGraphBuilder::kNoExtraCallableParam);
536 V8_EXPORT_PRIVATE
CallDescriptor* GetI32WasmCallDescriptorForSimd(
545 #endif // V8_COMPILER_WASM_COMPILER_H_