v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
deopt-data.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_COMPILER_TURBOSHAFT_DEOPT_DATA_H_
6#define V8_COMPILER_TURBOSHAFT_DEOPT_DATA_H_
7
13
15
17 // The data is encoded as a pre-traversal of a tree.
18 enum class Instr : uint8_t {
19 kInput, // 1 Operand: input machine type
21 kDematerializedObject, // 2 Operands: id, field_count
22 kDematerializedObjectReference, // 1 Operand: id
23 kArgumentsElements, // 1 Operand: type
26 kDematerializedStringConcat, // 1 Operand: id
27 // TODO(dmercadier): do escape analysis for objects and string-concat in a
28 // single pass, and always use kDematerializedObjectReference rather than
29 // kDematerializedStringConcatReference (and thus remove
30 // kDematerializedStringConcatReference).
32 };
33
34 class Builder {
35 public:
37 DCHECK(inputs_.empty());
38 inlined_ = true;
39 inputs_.push_back(parent);
40 }
41 void AddInput(MachineType type, OpIndex input) {
42 instructions_.push_back(Instr::kInput);
43 machine_types_.push_back(type);
44 inputs_.push_back(input);
45 }
46
48 instructions_.push_back(Instr::kUnusedRegister);
49 }
50
52 instructions_.push_back(Instr::kDematerializedObjectReference);
54 }
55
56 void AddDematerializedObject(uint32_t id, uint32_t field_count) {
57 instructions_.push_back(Instr::kDematerializedObject);
59 int_operands_.push_back(field_count);
60 }
61
63 instructions_.push_back(Instr::kDematerializedStringConcat);
65 }
66
68 instructions_.push_back(Instr::kDematerializedStringConcatReference);
70 }
71
73 instructions_.push_back(Instr::kArgumentsElements);
74 int_operands_.push_back(static_cast<int>(type));
75 }
76
78 instructions_.push_back(Instr::kArgumentsLength);
79 }
80
81 void AddRestLength() { instructions_.push_back(Instr::kRestLength); }
82
90
92 bool inlined() const { return inlined_; }
93
94 private:
99
100 bool inlined_ = false;
101 };
102
103 struct Iterator {
108
109 bool has_more() const {
110 DCHECK_IMPLIES(instructions.empty(), machine_types.empty());
111 DCHECK_IMPLIES(instructions.empty(), int_operands.empty());
112 DCHECK_IMPLIES(instructions.empty(), inputs.empty());
113 return !instructions.empty();
114 }
115
116 Instr current_instr() { return instructions[0]; }
117
118 void ConsumeInput(MachineType* machine_type, OpIndex* input) {
119 DCHECK_EQ(instructions[0], Instr::kInput);
120 instructions += 1;
121 *machine_type = machine_types[0];
122 machine_types += 1;
123 *input = inputs[0];
124 inputs += 1;
125 }
127 DCHECK_EQ(instructions[0], Instr::kUnusedRegister);
128 instructions += 1;
129 }
130 void ConsumeDematerializedObject(uint32_t* id, uint32_t* field_count) {
131 DCHECK_EQ(instructions[0], Instr::kDematerializedObject);
132 instructions += 1;
133 *id = int_operands[0];
134 *field_count = int_operands[1];
135 int_operands += 2;
136 }
138 DCHECK_EQ(instructions[0], Instr::kDematerializedObjectReference);
139 instructions += 1;
140 *id = int_operands[0];
141 int_operands += 1;
142 }
144 DCHECK_EQ(instructions[0], Instr::kDematerializedStringConcat);
145 instructions += 1;
146 *id = int_operands[0];
147 int_operands += 1;
148 }
150 DCHECK_EQ(instructions[0], Instr::kDematerializedStringConcatReference);
151 instructions += 1;
152 *id = int_operands[0];
153 int_operands += 1;
154 }
156 DCHECK_EQ(instructions[0], Instr::kArgumentsElements);
157 instructions += 1;
158 *type = static_cast<CreateArgumentsType>(int_operands[0]);
159 int_operands += 1;
160 }
162 DCHECK_EQ(instructions[0], Instr::kArgumentsLength);
163 instructions += 1;
164 }
166 DCHECK_EQ(instructions[0], Instr::kRestLength);
167 instructions += 1;
168 }
169 };
170
172 return Iterator{instructions, machine_types, int_operands, state_values};
173 }
174
179};
180
181inline bool operator==(const FrameStateData& lhs, const FrameStateData& rhs) {
182 return lhs.frame_state_info == rhs.frame_state_info &&
183 lhs.instructions == rhs.instructions &&
184 lhs.machine_types == rhs.machine_types &&
185 lhs.int_operands == rhs.int_operands;
186}
187
188} // namespace v8::internal::compiler::turboshaft
189
190#endif // V8_COMPILER_TURBOSHAFT_DEOPT_DATA_H_
constexpr bool empty() const
Definition vector.h:73
base::Vector< std::remove_const_t< T > > CloneVector(base::Vector< T > v)
Definition zone.h:159
T * New(Args &&... args)
Definition zone.h:114
const FrameStateData * AllocateFrameStateData(const FrameStateInfo &info, Zone *zone)
Definition deopt-data.h:83
void AddDematerializedObject(uint32_t id, uint32_t field_count)
Definition deopt-data.h:56
base::SmallVector< MachineType, 32 > machine_types_
Definition deopt-data.h:96
void AddInput(MachineType type, OpIndex input)
Definition deopt-data.h:41
Handle< SharedFunctionInfo > info
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
bool operator==(const ControlState &lhs, const ControlState &rhs)
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
void ConsumeDematerializedObject(uint32_t *id, uint32_t *field_count)
Definition deopt-data.h:130
void ConsumeInput(MachineType *machine_type, OpIndex *input)
Definition deopt-data.h:118
Iterator iterator(base::Vector< const OpIndex > state_values) const
Definition deopt-data.h:171