v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-js-lowering-reducer.h
Go to the documentation of this file.
1// Copyright 2023 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_TURBOSHAFT_WASM_JS_LOWERING_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_WASM_JS_LOWERING_REDUCER_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
16
18
20
21// This reducer is part of the JavaScript pipeline and contains lowering of
22// wasm nodes (from inlined wasm functions).
23//
24// The reducer replaces all TrapIf nodes with a conditional goto to deferred
25// code containing a call to the trap builtin.
26template <class Next>
27class WasmJSLoweringReducer : public Next {
28 public:
29 TURBOSHAFT_REDUCER_BOILERPLATE(WasmJSLowering)
30
32 bool negated, TrapId trap_id) {
33 // All TrapIf nodes in JS need to have a FrameState.
34 DCHECK(frame_state.valid());
35 Builtin trap = static_cast<Builtin>(trap_id);
36 // The call is not marked as Operator::kNoDeopt. While it cannot actually
37 // deopt, deopt info based on the provided FrameState is required for stack
38 // trace creation of the wasm trap.
39 const bool needs_frame_state = true;
40 const CallDescriptor* tf_descriptor = GetBuiltinCallDescriptor(
42 needs_frame_state, Operator::kNoProperties);
43 const TSCallDescriptor* ts_descriptor =
46
47 V<FrameState> new_frame_state =
48 CreateFrameStateWithUpdatedBailoutId(frame_state.value());
49 V<Word32> should_trap = negated ? __ Word32Equal(condition, 0) : condition;
50 IF (UNLIKELY(should_trap)) {
51 OpIndex call_target = __ NumberConstant(static_cast<int>(trap));
52 __ Call(call_target, new_frame_state, {}, ts_descriptor);
53 __ Unreachable(); // The trap builtin never returns.
54 }
55
56 return V<None>::Invalid();
57 }
58
59 private:
61 // Create new FrameState with the correct source position (the position of
62 // the trap location).
63 const FrameStateOp& frame_state_op =
64 Asm().output_graph().Get(frame_state).template Cast<FrameStateOp>();
65 const FrameStateData* data = frame_state_op.data;
66 const FrameStateInfo& info = data->frame_state_info;
67
68 V<AnyOrNone> origin = Asm().current_operation_origin();
69 DCHECK(origin.valid());
70 int offset = __ input_graph().source_positions()[origin].ScriptOffset();
71
72 const FrameStateInfo* new_info =
73 Asm().graph_zone()->template New<FrameStateInfo>(
74 BytecodeOffset(offset), info.state_combine(), info.function_info());
75 FrameStateData* new_data = Asm().graph_zone()->template New<FrameStateData>(
76 FrameStateData{*new_info, data->instructions, data->machine_types,
77 data->int_operands});
78 return __ FrameState(frame_state_op.inputs(), frame_state_op.inlined,
79 new_data);
80 }
81
84};
85
87
88} // namespace v8::internal::compiler::turboshaft
89
90#endif // V8_COMPILER_TURBOSHAFT_WASM_JS_LOWERING_REDUCER_H_
#define REDUCE(operation)
#define UNLIKELY(...)
#define IF(...)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
OpIndex CreateFrameStateWithUpdatedBailoutId(V< FrameState > frame_state)
V< None > REDUCE TrapIf(V< Word32 > condition, OptionalV< FrameState > frame_state, bool negated, TrapId trap_id)
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
Definition assembler.h:823
Isolate * isolate
Zone * graph_zone
SourcePositionTable * source_positions
int32_t offset
std::optional< OolTrapLabel > trap
NumberConstant(std::numeric_limits< double >::quiet_NaN())) DEFINE_GETTER(EmptyStateValues
CallDescriptor * GetBuiltinCallDescriptor(Builtin name, Zone *zone, StubCallMode stub_mode, bool needs_frame_state, Operator::Properties properties)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK(condition)
Definition logging.h:482
static const TSCallDescriptor * Create(const CallDescriptor *descriptor, CanThrow can_throw, LazyDeoptOnThrow lazy_deopt_on_throw, Zone *graph_zone, const JSWasmCallParameters *js_wasm_call_parameters=nullptr)