v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
frame-translation-builder.h
Go to the documentation of this file.
1// Copyright 2021 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_DEOPTIMIZER_FRAME_TRANSLATION_BUILDER_H_
6#define V8_DEOPTIMIZER_FRAME_TRANSLATION_BUILDER_H_
7
8#include <optional>
9
14
15#if V8_ENABLE_WEBASSEMBLY
16#include "src/wasm/value-type.h"
17#endif // V8_ENABLE_WEBASSEMBLY
18
19namespace v8 {
20namespace internal {
21
22class LocalFactory;
23
25 public:
31
33 LocalFactory* factory);
35
36 int BeginTranslation(int frame_count, int jsframe_count,
37 bool update_feedback);
38
39 void BeginInterpretedFrame(BytecodeOffset bytecode_offset, int literal_id,
40 int bytecode_array_id, unsigned height,
41 int return_value_offset, int return_value_count);
42 void BeginInlinedExtraArguments(int literal_id, unsigned height,
43 uint32_t parameter_count);
44 void BeginConstructCreateStubFrame(int literal_id, unsigned height);
45 void BeginConstructInvokeStubFrame(int literal_id);
46 void BeginBuiltinContinuationFrame(BytecodeOffset bailout_id, int literal_id,
47 unsigned height);
48#if V8_ENABLE_WEBASSEMBLY
49 void BeginJSToWasmBuiltinContinuationFrame(
50 BytecodeOffset bailout_id, int literal_id, unsigned height,
51 std::optional<wasm::ValueKind> return_kind);
52 void BeginWasmInlinedIntoJSFrame(BytecodeOffset bailout_id, int literal_id,
53 unsigned height);
54 void BeginLiftoffFrame(BytecodeOffset bailout_id, unsigned height,
55 uint32_t wasm_function_index);
56#endif // V8_ENABLE_WEBASSEMBLY
58 int literal_id, unsigned height);
60 BytecodeOffset bailout_id, int literal_id, unsigned height);
62 void ArgumentsLength();
63 void RestLength();
64 void BeginCapturedObject(int length);
65 void AddUpdateFeedback(int vector_literal, int slot);
66 void DuplicateObject(int object_index);
67 void StringConcat();
81 void StoreStackSlot(int index);
82 void StoreInt32StackSlot(int index);
83 void StoreInt64StackSlot(int index);
84 void StoreIntPtrStackSlot(int index);
85 void StoreSignedBigInt64StackSlot(int index);
86 void StoreUnsignedBigInt64StackSlot(int index);
87 void StoreUint32StackSlot(int index);
88 void StoreBoolStackSlot(int index);
89 void StoreFloatStackSlot(int index);
90 void StoreDoubleStackSlot(int index);
91 void StoreSimd128StackSlot(int index);
92 void StoreHoleyDoubleStackSlot(int index);
93 void StoreLiteral(int literal_id);
94 void StoreOptimizedOut();
96
97 private:
98 struct Instruction {
99 template <typename... T>
101 : opcode(opcode),
102 operands{operands.value()...}
103#ifdef ENABLE_SLOW_DCHECKS
104 ,
105 is_operand_signed{operands.IsSigned()...}
106#endif
107 {
108 }
110 // The operands for the instruction. Signed values were static_casted to
111 // unsigned.
113#ifdef ENABLE_SLOW_DCHECKS
114 bool is_operand_signed[kMaxTranslationOperandCount];
115#endif
116 };
117
118 // Either adds the instruction or increments matching_instructions_count_,
119 // depending on whether the instruction matches the corresponding instruction
120 // from the previous translation.
121 template <typename... T>
122 void Add(TranslationOpcode opcode, T... operands);
123
124 // Adds the instruction to contents_, without performing the other steps of
125 // Add(). Requires !v8_flags.turbo_compress_frame_translations.
126 template <typename... T>
127 void AddRawToContents(TranslationOpcode opcode, T... operands);
128
129 // Adds the instruction to contents_for_compression_, without performing the
130 // other steps of Add(). Requires v8_flags.turbo_compress_frame_translations.
131 template <typename... T>
132 void AddRawToContentsForCompression(TranslationOpcode opcode, T... operands);
133
134 // Adds a BEGIN instruction to contents_ or contents_for_compression_, but
135 // does not update other state. Used by BeginTranslation.
136 template <typename... T>
137 void AddRawBegin(bool update_feedback, T... operands);
138
139 int Size() const {
140 return V8_UNLIKELY(v8_flags.turbo_compress_frame_translations)
141 ? static_cast<int>(contents_for_compression_.size())
142 : static_cast<int>(contents_.size());
143 }
144 int SizeInBytes() const {
145 return V8_UNLIKELY(v8_flags.turbo_compress_frame_translations)
146 ? Size() * kInt32Size
147 : Size();
148 }
149
150 Zone* zone() const { return zone_; }
151
153 void ValidateBytes(DeoptTranslationIterator& iter) const;
154
157 // If match_previous_allowed_ is false, then this vector contains the
158 // instructions written so far in the current translation (since the last
159 // BEGIN). If match_previous_allowed_ is true, then this vector contains the
160 // instructions from the basis translation (the one written with
161 // !match_previous_allowed_). This allows Add() to easily check whether a
162 // newly added instruction matches the corresponding one from the basis
163 // translation.
165#ifdef ENABLE_SLOW_DCHECKS
166 std::vector<Instruction> all_instructions_;
167#endif
168 Zone* const zone_;
169 // How many consecutive instructions we've skipped writing because they match
170 // the basis translation.
173 // The current index within basis_instructions_.
175 // The byte index within the contents_ array of the BEGIN instruction for the
176 // basis translation (the most recent translation which was fully written out,
177 // not using MATCH_PREVIOUS_TRANSLATION instructions).
179 // Whether the builder can use MATCH_PREVIOUS_TRANSLATION in the current
180 // translation.
182};
183
184} // namespace internal
185} // namespace v8
186
187#endif // V8_DEOPTIMIZER_FRAME_TRANSLATION_BUILDER_H_
int16_t parameter_count
Definition builtins.cc:67
int BeginTranslation(int frame_count, int jsframe_count, bool update_feedback)
void ValidateBytes(DeoptTranslationIterator &iter) const
void BeginJavaScriptBuiltinContinuationFrame(BytecodeOffset bailout_id, int literal_id, unsigned height)
void AddRawToContentsForCompression(TranslationOpcode opcode, T... operands)
base::Vector< const uint8_t > ToFrameTranslationWasm()
void StoreRegister(TranslationOpcode opcode, Register reg)
void BeginJavaScriptBuiltinContinuationWithCatchFrame(BytecodeOffset bailout_id, int literal_id, unsigned height)
void BeginInlinedExtraArguments(int literal_id, unsigned height, uint32_t parameter_count)
void ArgumentsElements(CreateArgumentsType type)
void AddUpdateFeedback(int vector_literal, int slot)
void BeginConstructCreateStubFrame(int literal_id, unsigned height)
void BeginBuiltinContinuationFrame(BytecodeOffset bailout_id, int literal_id, unsigned height)
void BeginInterpretedFrame(BytecodeOffset bytecode_offset, int literal_id, int bytecode_array_id, unsigned height, int return_value_offset, int return_value_count)
DirectHandle< DeoptimizationFrameTranslation > ToFrameTranslation(LocalFactory *factory)
void AddRawBegin(bool update_feedback, T... operands)
void Add(TranslationOpcode opcode, T... operands)
void AddRawToContents(TranslationOpcode opcode, T... operands)
LiftoffRegister reg
constexpr int kInt32Size
Definition globals.h:401
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr int kMaxTranslationOperandCount
Instruction(TranslationOpcode opcode, T... operands)
#define V8_UNLIKELY(condition)
Definition v8config.h:660