v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
maglev-code-gen-state.h
Go to the documentation of this file.
1// Copyright 2022 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_MAGLEV_MAGLEV_CODE_GEN_STATE_H_
6#define V8_MAGLEV_MAGLEV_CODE_GEN_STATE_H_
7
9#include "src/codegen/label.h"
12#include "src/common/globals.h"
18
19namespace v8 {
20namespace internal {
21namespace maglev {
22
23class InterpreterFrameState;
24class MaglevAssembler;
25class Graph;
26
28 public:
29 virtual void Generate(MaglevAssembler* masm) = 0;
31};
32
34 public:
41
42 void set_tagged_slots(int slots) { tagged_slots_ = slots; }
44
48 const std::vector<DeferredCodeInfo*>& deferred_code() const {
49 return deferred_code_;
50 }
51 std::vector<DeferredCodeInfo*> TakeDeferredCode() {
52 return std::exchange(deferred_code_, std::vector<DeferredCodeInfo*>());
53 }
54 void PushEagerDeopt(EagerDeoptInfo* info) { eager_deopts_.push_back(info); }
55 void PushLazyDeopt(LazyDeoptInfo* info) { lazy_deopts_.push_back(info); }
56 const std::vector<EagerDeoptInfo*>& eager_deopts() const {
57 return eager_deopts_;
58 }
59 const std::vector<LazyDeoptInfo*>& lazy_deopts() const {
60 return lazy_deopts_;
61 }
62
63 void PushHandlerInfo(NodeBase* node) { handlers_.push_back(node); }
64 const std::vector<NodeBase*>& handlers() const { return handlers_; }
65
73 int stack_slots() const { return untagged_slots_ + tagged_slots_; }
74 int tagged_slots() const { return tagged_slots_; }
75
79
84
86
87 void set_max_deopted_stack_size(uint32_t max_deopted_stack_size) {
88 max_deopted_stack_size_ = max_deopted_stack_size;
89 }
90
91 void set_max_call_stack_args_(uint32_t max_call_stack_args) {
92 max_call_stack_args_ = max_call_stack_args;
93 }
94
95 uint32_t stack_check_offset() {
96 int32_t parameter_slots =
99 DCHECK(is_int32(stack_slots));
100 int32_t optimized_frame_height = parameter_slots * kSystemPointerSize +
104 int32_t signed_max_unoptimized_frame_height =
105 static_cast<int32_t>(max_deopted_stack_size_);
106
107 // The offset is either the delta between the optimized frames and the
108 // interpreted frame, or the maximal number of bytes pushed to the stack
109 // while preparing for function calls, whichever is bigger.
110 uint32_t frame_height_delta = static_cast<uint32_t>(std::max(
111 signed_max_unoptimized_frame_height - optimized_frame_height, 0));
112 uint32_t max_pushed_argument_bytes =
113 static_cast<uint32_t>(max_call_stack_args_ * kSystemPointerSize);
114 return std::max(frame_height_delta, max_pushed_argument_bytes);
115 }
116
117 Label* osr_entry() { return &osr_entry_; }
118
119 inline BasicBlock* RealJumpTarget(BasicBlock* block);
120
121 private:
124
125 std::vector<DeferredCodeInfo*> deferred_code_;
126 std::vector<EagerDeoptInfo*> eager_deopts_;
127 std::vector<LazyDeoptInfo*> lazy_deopts_;
128 std::vector<NodeBase*> handlers_;
129
134
135 // Entry point label for recursive calls.
138
139 // Cached jump targets skipping empty blocks.
140 std::vector<BasicBlock*> real_jump_target_;
141};
142
143// Some helpers for codegen.
144// TODO(leszeks): consider moving this to a separate header.
145
147 // Safepoint tables also contain slots for all fixed frame slots (both
148 // above and below the fp).
150}
151
155
160
161template <typename RegisterT>
162inline auto ToRegisterT(const compiler::InstructionOperand& operand) {
163 if constexpr (std::is_same_v<RegisterT, Register>) {
164 return ToRegister(operand);
165 } else {
166 return ToDoubleRegister(operand);
167 }
168}
169
170inline Register ToRegister(const ValueLocation& location) {
171 return ToRegister(location.operand());
172}
173
175 return ToDoubleRegister(location.operand());
176}
177
178} // namespace maglev
179} // namespace internal
180} // namespace v8
181
182#endif // V8_MAGLEV_MAGLEV_CODE_GEN_STATE_H_
NativeContextRef target_native_context() const
static LocationOperand * cast(InstructionOperand *op)
DoubleRegister GetDoubleRegister() const
virtual void Generate(MaglevAssembler *masm)=0
MaglevGraphLabeller * graph_labeller() const
const std::vector< EagerDeoptInfo * > & eager_deopts() const
std::vector< LazyDeoptInfo * > lazy_deopts_
void PushDeferredCode(DeferredCodeInfo *deferred_code)
const std::vector< DeferredCodeInfo * > & deferred_code() const
MaglevSafepointTableBuilder *const safepoint_table_builder_
std::vector< DeferredCodeInfo * > TakeDeferredCode()
const std::vector< NodeBase * > & handlers() const
compiler::JSHeapBroker * broker() const
void set_max_call_stack_args_(uint32_t max_call_stack_args)
const std::vector< LazyDeoptInfo * > & lazy_deopts() const
MaglevCompilationInfo * compilation_info() const
std::vector< DeferredCodeInfo * > deferred_code_
void set_max_deopted_stack_size(uint32_t max_deopted_stack_size)
MaglevCodeGenState(MaglevCompilationInfo *compilation_info, MaglevSafepointTableBuilder *safepoint_table_builder, uint32_t max_block_id)
MaglevSafepointTableBuilder * safepoint_table_builder() const
compiler::NativeContextRef native_context() const
std::vector< EagerDeoptInfo * > eager_deopts_
MaglevCompilationUnit * toplevel_compilation_unit() const
const compiler::InstructionOperand & operand() const
Definition maglev-ir.h:1280
ZoneVector< int > slots
DoubleRegister ToDoubleRegister(const compiler::InstructionOperand &operand)
Register ToRegister(const compiler::InstructionOperand &operand)
auto ToRegisterT(const compiler::InstructionOperand &operand)
constexpr int kSystemPointerSize
Definition globals.h:410
constexpr uint32_t kMaxUInt32
Definition globals.h:387
#define DCHECK(condition)
Definition logging.h:482