v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
growable-stacks-reducer.h
Go to the documentation of this file.
1// Copyright 2024 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_GROWABLE_STACKS_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_GROWABLE_STACKS_REDUCER_H_
7
16
18
20
21template <class Next>
22class GrowableStacksReducer : public Next {
23 public:
24 TURBOSHAFT_REDUCER_BOILERPLATE(GrowableStacks)
25
27 if (!__ data()->wasm_module_sig() ||
28 !v8_flags.experimental_wasm_growable_stacks) {
29 // We are not compiling a wasm function if there is no signature.
30 skip_reducer_ = true;
31 return;
32 }
34 __ graph_zone(), __ data()->wasm_module_sig());
35#if V8_TARGET_ARCH_32_BIT
37 compiler::GetI32WasmCallDescriptor(__ graph_zone(), call_descriptor_);
38#endif
39 }
40
41 V<None> REDUCE(WasmStackCheck)(WasmStackCheckOp::Kind kind) {
42 CHECK_EQ(kind, WasmStackCheckOp::Kind::kFunctionEntry);
43 if (skip_reducer_) {
44 return Next::ReduceWasmStackCheck(kind);
45 }
46 // Loads of the stack limit should not be load-eliminated as it can be
47 // modified by another thread.
48 V<WordPtr> limit = __ Load(
49 __ LoadRootRegister(), LoadOp::Kind::RawAligned().NotLoadEliminable(),
51
52 IF_NOT (LIKELY(__ StackPointerGreaterThan(limit, StackCheckKind::kWasm))) {
53 const int stack_parameter_count = 0;
54 const CallDescriptor* stub_call_descriptor =
56 __ graph_zone(), WasmGrowableStackGuardDescriptor{},
57 stack_parameter_count, CallDescriptor::kNoFlags,
58 Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
59 const TSCallDescriptor* ts_stub_call_descriptor =
60 TSCallDescriptor::Create(stub_call_descriptor,
63 V<WordPtr> builtin =
64 __ RelocatableWasmBuiltinCallTarget(Builtin::kWasmGrowableStackGuard);
65 auto param_slots_size = __ IntPtrConstant(
67 __ Call(
68 builtin, {param_slots_size}, ts_stub_call_descriptor,
70 }
71
72 return V<None>::Invalid();
73 }
74
76 base::Vector<const OpIndex> return_values,
77 bool spill_caller_frame_slots) {
78 if (skip_reducer_ || !spill_caller_frame_slots ||
80 return Next::ReduceReturn(pop_count, return_values,
81 spill_caller_frame_slots);
82 }
83 V<Word32> frame_marker = __ Load(
84 __ FramePointer(), LoadOp::Kind::RawAligned(),
85 MemoryRepresentation::Uint32(), WasmFrameConstants::kFrameTypeOffset);
86
87 Label<WordPtr> done(this);
88 IF (UNLIKELY(__ Word32Equal(
89 frame_marker,
90 StackFrame::TypeToMarker(StackFrame::WASM_SEGMENT_START)))) {
91 auto sig =
93 .Params(MachineType::Pointer());
94 const CallDescriptor* ccall_descriptor =
96 const TSCallDescriptor* ts_ccall_descriptor = TSCallDescriptor::Create(
97 ccall_descriptor, compiler::CanThrow::kNo,
99 GOTO(done, __ template Call<WordPtr>(
100 __ ExternalConstant(ExternalReference::wasm_load_old_fp()),
102 base::VectorOf({__ ExternalConstant(
104 ts_ccall_descriptor));
105 } ELSE {
106 GOTO(done, __ FramePointer());
107 }
108 BIND(done, old_fp);
109
110 base::SmallVector<OpIndex, 8> register_return_values;
111 for (size_t i = 0; i < call_descriptor_->ReturnCount(); i++) {
113 if (!loc.IsCallerFrameSlot()) {
114 register_return_values.push_back(return_values[i]);
115 continue;
116 }
117 MemoryRepresentation mem_rep =
119 OpIndex ret_value = return_values[i];
120 // Pointers are stored uncompressed on the stacks.
121 // Also, we don't need to mark the stack slot as a reference, because
122 // we are about to return from this frame, so it is the caller's
123 // responsibility to track the tagged return values using the signature.
124 if (mem_rep == MemoryRepresentation::AnyTagged()) {
126 ret_value = __ BitcastTaggedToWordPtr(ret_value);
127 }
128 __ StoreOffHeap(old_fp, ret_value, mem_rep,
130 }
131 return Next::ReduceReturn(pop_count, base::VectorOf(register_return_values),
132 spill_caller_frame_slots);
133 }
134
135 private:
136 bool skip_reducer_ = false;
138};
139
141
142} // namespace v8::internal::compiler::turboshaft
143
144#endif // V8_COMPILER_TURBOSHAFT_GROWABLE_STACKS_REDUCER_H_
#define BIND(label)
#define REDUCE(operation)
#define ELSE
#define GOTO(label,...)
#define IF_NOT(...)
#define UNLIKELY(...)
#define LIKELY(...)
#define IF(...)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Builtins::Kind kind
Definition builtins.cc:40
static V8_EXPORT_PRIVATE ExternalReference isolate_address()
auto Returns(ReturnTypes... return_types) const
Definition signature.h:166
static constexpr int jslimit_offset()
static constexpr MachineType Pointer()
static constexpr int32_t TypeToMarker(Type type)
Definition frames.h:196
LinkageLocation GetReturnLocation(size_t index) const
Definition linkage.h:270
static CallDescriptor * GetSimplifiedCDescriptor(Zone *zone, const MachineSignature *sig, CallDescriptor::Flags flags=CallDescriptor::kNoFlags, Operator::Properties properties=Operator::kNoThrow)
Definition c-linkage.cc:269
static CallDescriptor * GetStubCallDescriptor(Zone *zone, const CallInterfaceDescriptor &descriptor, int stack_parameter_count, CallDescriptor::Flags flags, Operator::Properties properties=Operator::kNoProperties, StubCallMode stub_mode=StubCallMode::kCallCodeObject)
Definition linkage.cc:587
V< None > REDUCE WasmStackCheck(WasmStackCheckOp::Kind kind)
OpIndex REDUCE Return(V< Word32 > pop_count, base::Vector< const OpIndex > return_values, bool spill_caller_frame_slots)
static MemoryRepresentation FromMachineType(MachineType type)
static constexpr MemoryRepresentation AnyTagged()
static constexpr MemoryRepresentation Uint32()
static constexpr MemoryRepresentation UintPtr()
static constexpr OpIndex Invalid()
Definition index.h:88
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
Definition assembler.h:823
Zone * graph_zone
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
CallDescriptor * GetWasmCallDescriptor(Zone *zone, const Signature< T > *fsig, WasmCallKind call_kind, bool need_frame_state)
static const Operator * IntPtrConstant(CommonOperatorBuilder *common, intptr_t value)
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
constexpr int kSystemPointerSize
Definition globals.h:410
V8_EXPORT_PRIVATE FlagValues v8_flags
static int FrameSlotToFPOffset(int slot)
i::Address Load(i::Address address)
Definition unwinder.cc:19
#define CHECK_EQ(lhs, rhs)
constexpr OpEffects CanCreateIdentity() const
Definition operations.h:790
constexpr OpEffects RequiredWhenUnused() const
Definition operations.h:804
constexpr OpEffects CanReadMemory() const
Definition operations.h:745
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)