v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
stack-check-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_STACK_CHECK_LOWERING_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_STACK_CHECK_LOWERING_REDUCER_H_
7
16
18
20
21template <class Next>
22class StackCheckLoweringReducer : public Next {
23 public:
24 TURBOSHAFT_REDUCER_BOILERPLATE(StackCheckLowering)
25
27 OptionalV<FrameState> frame_state,
28 JSStackCheckOp::Kind kind) {
29 switch (kind) {
31 // Loads of the stack limit should not be load-eliminated as it can be
32 // modified by another thread.
33 V<WordPtr> limit =
34 __ Load(__ ExternalConstant(
35 ExternalReference::address_of_jslimit(isolate())),
36 LoadOp::Kind::RawAligned().NotLoadEliminable(),
38
39 IF_NOT (LIKELY(__ StackPointerGreaterThan(
41 __ CallRuntime_StackGuardWithGap(isolate(), frame_state.value(),
42 context, __ StackCheckOffset());
43 }
44 break;
45 }
47 V<WordPtr> stack_limit = __ LoadOffHeap(
48 __ ExternalConstant(
49 ExternalReference::address_of_jslimit(isolate())),
51 IF_NOT (LIKELY(__ StackPointerGreaterThan(
53 __ CallRuntime_StackGuard(isolate(), context);
54 }
55 break;
56 }
58 V<Word32> limit = __ Load(
59 __ ExternalConstant(
60 ExternalReference::address_of_no_heap_write_interrupt_request(
61 isolate())),
62 LoadOp::Kind::RawAligned().NotLoadEliminable(),
64
65 IF_NOT (LIKELY(__ Word32Equal(limit, 0))) {
66 __ CallRuntime_HandleNoHeapWritesInterrupts(
67 isolate(), frame_state.value(), context);
68 }
69 break;
70 }
71 }
72
73 return V<None>::Invalid();
74 }
75
76#ifdef V8_ENABLE_WEBASSEMBLY
77 V<None> REDUCE(WasmStackCheck)(WasmStackCheckOp::Kind kind) {
78 if (kind == WasmStackCheckOp::Kind::kFunctionEntry && __ IsLeafFunction()) {
79 return V<None>::Invalid();
80 }
81
82 if (kind == WasmStackCheckOp::Kind::kFunctionEntry &&
83 v8_flags.experimental_wasm_growable_stacks) {
84 // WasmStackCheck should be lowered by GrowableStacksReducer
85 // in a special way.
86 return Next::ReduceWasmStackCheck(kind);
87 }
88
89 // Loads of the stack limit should not be load-eliminated as it can be
90 // modified by another thread.
91 V<WordPtr> limit = __ Load(
92 __ LoadRootRegister(), LoadOp::Kind::RawAligned().NotLoadEliminable(),
94
95 IF_NOT (LIKELY(__ StackPointerGreaterThan(limit, StackCheckKind::kWasm))) {
96 // TODO(14108): Cache descriptor.
97 const CallDescriptor* call_descriptor =
99 __ graph_zone(), // zone
100 NoContextDescriptor{}, // descriptor
101 0, // stack parameter count
103 Operator::kNoProperties, // properties
104 StubCallMode::kCallWasmRuntimeStub); // stub call mode
105 const TSCallDescriptor* ts_call_descriptor =
108 V<WordPtr> builtin =
109 __ RelocatableWasmBuiltinCallTarget(Builtin::kWasmStackGuard);
110 // Pass custom effects to the `Call` node to mark it as non-writing.
111 __ Call(
112 builtin, {}, ts_call_descriptor,
113 OpEffects().CanReadMemory().RequiredWhenUnused().CanCreateIdentity());
114 }
115
116 return V<None>::Invalid();
117 }
118#endif // V8_ENABLE_WEBASSEMBLY
119
120 private:
122 if (!isolate_) isolate_ = __ data() -> isolate();
123 return isolate_;
124 }
125
126 Isolate* isolate_ = nullptr;
127};
128
130
131} // namespace v8::internal::compiler::turboshaft
132
133#endif // V8_COMPILER_TURBOSHAFT_STACK_CHECK_LOWERING_REDUCER_H_
#define REDUCE(operation)
#define IF_NOT(...)
#define LIKELY(...)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Builtins::Kind kind
Definition builtins.cc:40
static constexpr int jslimit_offset()
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
static constexpr MemoryRepresentation UintPtr()
static constexpr MemoryRepresentation Uint8()
V< None > REDUCE JSStackCheck(V< Context > context, OptionalV< FrameState > frame_state, JSStackCheckOp::Kind kind)
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
Definition assembler.h:823
Zone * graph_zone
V8_EXPORT_PRIVATE FlagValues v8_flags
i::Address Load(i::Address address)
Definition unwinder.cc:19
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)