Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: src/interpreter/bytecode-pipeline.h

Issue 2358423002: Version 5.5.251.1 (cherry-pick) (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/bytecode-peephole-optimizer.cc ('k') | src/interpreter/bytecode-pipeline.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_PIPELINE_H_
6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_ 6 #define V8_INTERPRETER_BYTECODE_PIPELINE_H_
7 7
8 #include "src/interpreter/bytecode-register-allocator.h" 8 #include "src/interpreter/bytecode-register-allocator.h"
9 #include "src/interpreter/bytecode-register.h" 9 #include "src/interpreter/bytecode-register.h"
10 #include "src/interpreter/bytecodes.h" 10 #include "src/interpreter/bytecodes.h"
(...skipping 29 matching lines...) Expand all
40 // written to the next stage. 40 // written to the next stage.
41 virtual void BindLabel(BytecodeLabel* label) = 0; 41 virtual void BindLabel(BytecodeLabel* label) = 0;
42 42
43 // Binds |label| to the location of |target|. This call implicitly 43 // Binds |label| to the location of |target|. This call implicitly
44 // ends the current basic block and so any deferred bytecodes should be 44 // ends the current basic block and so any deferred bytecodes should be
45 // written to the next stage. 45 // written to the next stage.
46 virtual void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) = 0; 46 virtual void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) = 0;
47 47
48 // Flush the pipeline and generate a bytecode array. 48 // Flush the pipeline and generate a bytecode array.
49 virtual Handle<BytecodeArray> ToBytecodeArray( 49 virtual Handle<BytecodeArray> ToBytecodeArray(
50 Isolate* isolate, int register_count, int parameter_count, 50 Isolate* isolate, int fixed_register_count, int parameter_count,
51 Handle<FixedArray> handler_table) = 0; 51 Handle<FixedArray> handler_table) = 0;
52 }; 52 };
53 53
54 // Source code position information. 54 // Source code position information.
55 class BytecodeSourceInfo final { 55 class BytecodeSourceInfo final {
56 public: 56 public:
57 static const int kUninitializedPosition = -1; 57 static const int kUninitializedPosition = -1;
58 58
59 BytecodeSourceInfo() 59 BytecodeSourceInfo()
60 : position_type_(PositionType::kNone), 60 : position_type_(PositionType::kNone),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 bool operator!=(const BytecodeSourceInfo& other) const { 127 bool operator!=(const BytecodeSourceInfo& other) const {
128 return position_type_ != other.position_type_ || 128 return position_type_ != other.position_type_ ||
129 source_position_ != other.source_position_; 129 source_position_ != other.source_position_;
130 } 130 }
131 131
132 private: 132 private:
133 enum class PositionType : uint8_t { kNone, kExpression, kStatement }; 133 enum class PositionType : uint8_t { kNone, kExpression, kStatement };
134 134
135 PositionType position_type_; 135 PositionType position_type_;
136 int source_position_; 136 int source_position_;
137
138 DISALLOW_COPY_AND_ASSIGN(BytecodeSourceInfo);
137 }; 139 };
138 140
139 // A container for a generated bytecode, it's operands, and source information. 141 // A container for a generated bytecode, it's operands, and source information.
140 // These must be allocated by a BytecodeNodeAllocator instance. 142 // These must be allocated by a BytecodeNodeAllocator instance.
141 class BytecodeNode final : ZoneObject { 143 class BytecodeNode final : ZoneObject {
142 public: 144 public:
143 INLINE(BytecodeNode(const Bytecode bytecode, 145 explicit BytecodeNode(Bytecode bytecode = Bytecode::kIllegal);
144 BytecodeSourceInfo* source_info = nullptr)) 146 BytecodeNode(Bytecode bytecode, uint32_t operand0);
145 : bytecode_(bytecode), 147 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1);
146 operand_count_(0), 148 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
147 operand_scale_(OperandScale::kSingle) { 149 uint32_t operand2);
148 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count()); 150 BytecodeNode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
149 AttachSourceInfo(source_info); 151 uint32_t operand2, uint32_t operand3);
150 }
151
152 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
153 BytecodeSourceInfo* source_info = nullptr))
154 : bytecode_(bytecode),
155 operand_count_(1),
156 operand_scale_(OperandScale::kSingle) {
157 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
158 SetOperand(0, operand0);
159 AttachSourceInfo(source_info);
160 }
161
162 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
163 uint32_t operand1,
164 BytecodeSourceInfo* source_info = nullptr))
165 : bytecode_(bytecode),
166 operand_count_(2),
167 operand_scale_(OperandScale::kSingle) {
168 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
169 SetOperand(0, operand0);
170 SetOperand(1, operand1);
171 AttachSourceInfo(source_info);
172 }
173
174 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
175 uint32_t operand1, uint32_t operand2,
176 BytecodeSourceInfo* source_info = nullptr))
177 : bytecode_(bytecode),
178 operand_count_(3),
179 operand_scale_(OperandScale::kSingle) {
180 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
181 SetOperand(0, operand0);
182 SetOperand(1, operand1);
183 SetOperand(2, operand2);
184 AttachSourceInfo(source_info);
185 }
186
187 INLINE(BytecodeNode(const Bytecode bytecode, uint32_t operand0,
188 uint32_t operand1, uint32_t operand2, uint32_t operand3,
189 BytecodeSourceInfo* source_info = nullptr))
190 : bytecode_(bytecode),
191 operand_count_(4),
192 operand_scale_(OperandScale::kSingle) {
193 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count());
194 SetOperand(0, operand0);
195 SetOperand(1, operand1);
196 SetOperand(2, operand2);
197 SetOperand(3, operand3);
198 AttachSourceInfo(source_info);
199 }
200 152
201 BytecodeNode(const BytecodeNode& other); 153 BytecodeNode(const BytecodeNode& other);
202 BytecodeNode& operator=(const BytecodeNode& other); 154 BytecodeNode& operator=(const BytecodeNode& other);
203 155
204 // Replace the bytecode of this node with |bytecode| and keep the operands. 156 // Replace the bytecode of this node with |bytecode| and keep the operands.
205 void replace_bytecode(Bytecode bytecode) { 157 void replace_bytecode(Bytecode bytecode) {
206 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_), 158 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode_),
207 Bytecodes::NumberOfOperands(bytecode)); 159 Bytecodes::NumberOfOperands(bytecode));
208 bytecode_ = bytecode; 160 bytecode_ = bytecode;
209 } 161 }
210 void set_bytecode(Bytecode bytecode) { 162 void set_bytecode(Bytecode bytecode) {
211 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); 163 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
212 bytecode_ = bytecode; 164 bytecode_ = bytecode;
213 operand_count_ = 0;
214 operand_scale_ = OperandScale::kSingle;
215 } 165 }
216 void set_bytecode(Bytecode bytecode, uint32_t operand0) { 166 void set_bytecode(Bytecode bytecode, uint32_t operand0) {
217 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); 167 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1);
218 bytecode_ = bytecode; 168 bytecode_ = bytecode;
219 operand_count_ = 1; 169 operands_[0] = operand0;
220 operand_scale_ = OperandScale::kSingle;
221 SetOperand(0, operand0);
222 } 170 }
223 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) { 171 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1) {
224 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); 172 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2);
225 bytecode_ = bytecode; 173 bytecode_ = bytecode;
226 operand_count_ = 2; 174 operands_[0] = operand0;
227 operand_scale_ = OperandScale::kSingle; 175 operands_[1] = operand1;
228 SetOperand(0, operand0);
229 SetOperand(1, operand1);
230 } 176 }
231 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 177 void set_bytecode(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
232 uint32_t operand2) { 178 uint32_t operand2) {
233 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); 179 DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3);
234 bytecode_ = bytecode; 180 bytecode_ = bytecode;
235 operand_count_ = 3; 181 operands_[0] = operand0;
236 operand_scale_ = OperandScale::kSingle; 182 operands_[1] = operand1;
237 SetOperand(0, operand0); 183 operands_[2] = operand2;
238 SetOperand(1, operand1);
239 SetOperand(2, operand2);
240 } 184 }
241 185
242 // Clone |other|. 186 // Clone |other|.
243 void Clone(const BytecodeNode* const other); 187 void Clone(const BytecodeNode* const other);
244 188
245 // Print to stream |os|. 189 // Print to stream |os|.
246 void Print(std::ostream& os) const; 190 void Print(std::ostream& os) const;
247 191
248 // Transform to a node representing |new_bytecode| which has one 192 // Transform to a node representing |new_bytecode| which has one
249 // operand more than the current bytecode. 193 // operand more than the current bytecode.
250 void Transform(Bytecode new_bytecode, uint32_t extra_operand) { 194 void Transform(Bytecode new_bytecode, uint32_t extra_operand);
251 DCHECK_EQ(Bytecodes::NumberOfOperands(new_bytecode),
252 Bytecodes::NumberOfOperands(bytecode()) + 1);
253 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 1 ||
254 Bytecodes::GetOperandType(new_bytecode, 0) ==
255 Bytecodes::GetOperandType(bytecode(), 0));
256 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 2 ||
257 Bytecodes::GetOperandType(new_bytecode, 1) ==
258 Bytecodes::GetOperandType(bytecode(), 1));
259 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 3 ||
260 Bytecodes::GetOperandType(new_bytecode, 2) ==
261 Bytecodes::GetOperandType(bytecode(), 2));
262 DCHECK(Bytecodes::NumberOfOperands(bytecode()) < 4);
263
264 bytecode_ = new_bytecode;
265 operand_count_++;
266 SetOperand(operand_count() - 1, extra_operand);
267 }
268
269 // Updates the operand at |operand_index| to |operand|.
270 void UpdateOperand(int operand_index, uint32_t operand) {
271 DCHECK_LE(operand_index, Bytecodes::NumberOfOperands(bytecode()));
272 operands_[operand_index] = operand;
273 if ((Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index) &&
274 Bytecodes::ScaleForSignedOperand(operand) != operand_scale_) ||
275 (Bytecodes::OperandIsScalableUnsignedByte(bytecode(), operand_index) &&
276 Bytecodes::ScaleForUnsignedOperand(operand) != operand_scale_)) {
277 UpdateScale();
278 }
279 }
280 195
281 Bytecode bytecode() const { return bytecode_; } 196 Bytecode bytecode() const { return bytecode_; }
282 197
283 uint32_t operand(int i) const { 198 uint32_t operand(int i) const {
284 DCHECK_LT(i, operand_count()); 199 DCHECK_LT(i, operand_count());
285 return operands_[i]; 200 return operands_[i];
286 } 201 }
202 uint32_t* operands() { return operands_; }
287 const uint32_t* operands() const { return operands_; } 203 const uint32_t* operands() const { return operands_; }
288 204
289 int operand_count() const { return operand_count_; } 205 int operand_count() const { return Bytecodes::NumberOfOperands(bytecode_); }
290 OperandScale operand_scale() const { return operand_scale_; }
291 206
292 const BytecodeSourceInfo& source_info() const { return source_info_; } 207 const BytecodeSourceInfo& source_info() const { return source_info_; }
293 BytecodeSourceInfo* source_info_ptr() { return &source_info_; } 208 BytecodeSourceInfo& source_info() { return source_info_; }
294 209
295 bool operator==(const BytecodeNode& other) const; 210 bool operator==(const BytecodeNode& other) const;
296 bool operator!=(const BytecodeNode& other) const { return !(*this == other); } 211 bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
297 212
298 private: 213 private:
299 INLINE(void AttachSourceInfo(BytecodeSourceInfo* source_info)) { 214 static const int kInvalidPosition = kMinInt;
300 if (source_info && source_info->is_valid()) {
301 // Statement positions need to be emitted immediately. Expression
302 // positions can be pushed back until a bytecode is found that can
303 // throw (if expression position filtering is turned on). We only
304 // invalidate the existing source position information if it is used.
305 if (source_info->is_statement() ||
306 !FLAG_ignition_filter_expression_positions ||
307 !Bytecodes::IsWithoutExternalSideEffects(bytecode())) {
308 source_info_.Clone(*source_info);
309 source_info->set_invalid();
310 }
311 }
312 }
313
314 INLINE(void UpdateScaleForOperand(int operand_index, uint32_t operand)) {
315 if (Bytecodes::OperandIsScalableSignedByte(bytecode(), operand_index)) {
316 operand_scale_ =
317 std::max(operand_scale_, Bytecodes::ScaleForSignedOperand(operand));
318 } else if (Bytecodes::OperandIsScalableUnsignedByte(bytecode(),
319 operand_index)) {
320 operand_scale_ =
321 std::max(operand_scale_, Bytecodes::ScaleForUnsignedOperand(operand));
322 }
323 }
324
325 INLINE(void SetOperand(int operand_index, uint32_t operand)) {
326 operands_[operand_index] = operand;
327 UpdateScaleForOperand(operand_index, operand);
328 }
329
330 void UpdateScale() {
331 operand_scale_ = OperandScale::kSingle;
332 for (int i = 0; i < operand_count(); i++) {
333 UpdateScaleForOperand(i, operands_[i]);
334 }
335 }
336 215
337 Bytecode bytecode_; 216 Bytecode bytecode_;
338 uint32_t operands_[Bytecodes::kMaxOperands]; 217 uint32_t operands_[Bytecodes::kMaxOperands];
339 int operand_count_;
340 OperandScale operand_scale_;
341 BytecodeSourceInfo source_info_; 218 BytecodeSourceInfo source_info_;
342 }; 219 };
343 220
344 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info); 221 std::ostream& operator<<(std::ostream& os, const BytecodeSourceInfo& info);
345 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node); 222 std::ostream& operator<<(std::ostream& os, const BytecodeNode& node);
346 223
347 } // namespace interpreter 224 } // namespace interpreter
348 } // namespace internal 225 } // namespace internal
349 } // namespace v8 226 } // namespace v8
350 227
351 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_ 228 #endif // V8_INTERPRETER_BYTECODE_PIPELINE_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-peephole-optimizer.cc ('k') | src/interpreter/bytecode-pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698