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

Side by Side Diff: src/interpreter/bytecode-array-builder.h

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments. Created 4 years, 7 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
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_ARRAY_BUILDER_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/interpreter/bytecode-array-writer.h"
9 #include "src/interpreter/bytecode-register-allocator.h" 10 #include "src/interpreter/bytecode-register-allocator.h"
10 #include "src/interpreter/bytecodes.h" 11 #include "src/interpreter/bytecodes.h"
11 #include "src/interpreter/constant-array-builder.h" 12 #include "src/interpreter/constant-array-builder.h"
12 #include "src/interpreter/handler-table-builder.h" 13 #include "src/interpreter/handler-table-builder.h"
13 #include "src/interpreter/source-position-table.h" 14 #include "src/interpreter/source-position-table.h"
14 #include "src/zone-containers.h" 15 #include "src/zone-containers.h"
15 16
16 namespace v8 { 17 namespace v8 {
17 namespace internal { 18 namespace internal {
18 19
19 class Isolate; 20 class Isolate;
20 21
21 namespace interpreter { 22 namespace interpreter {
22 23
23 class BytecodeLabel; 24 class BytecodeLabel;
25 class BytecodePipelineStage;
24 class Register; 26 class Register;
25 27
26 class BytecodeArrayBuilder final : public ZoneObject { 28 class BytecodeArrayBuilder final : public ZoneObject {
27 public: 29 public:
28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count, 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count,
29 int context_count, int locals_count, 31 int context_count, int locals_count,
30 FunctionLiteral* literal = nullptr); 32 FunctionLiteral* literal = nullptr);
31 33
32 Handle<BytecodeArray> ToBytecodeArray(); 34 Handle<BytecodeArray> ToBytecodeArray();
33 35
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // entry, so that it can be referenced by above exception handling support. 257 // entry, so that it can be referenced by above exception handling support.
256 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } 258 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); }
257 259
258 void InitializeReturnPosition(FunctionLiteral* literal); 260 void InitializeReturnPosition(FunctionLiteral* literal);
259 261
260 void SetStatementPosition(Statement* stmt); 262 void SetStatementPosition(Statement* stmt);
261 void SetExpressionPosition(Expression* expr); 263 void SetExpressionPosition(Expression* expr);
262 void SetExpressionAsStatementPosition(Expression* expr); 264 void SetExpressionAsStatementPosition(Expression* expr);
263 265
264 // Accessors 266 // Accessors
265 Zone* zone() const { return zone_; }
266 TemporaryRegisterAllocator* temporary_register_allocator() { 267 TemporaryRegisterAllocator* temporary_register_allocator() {
267 return &temporary_allocator_; 268 return &temporary_allocator_;
268 } 269 }
269 const TemporaryRegisterAllocator* temporary_register_allocator() const { 270 const TemporaryRegisterAllocator* temporary_register_allocator() const {
270 return &temporary_allocator_; 271 return &temporary_allocator_;
271 } 272 }
273 Zone* zone() const { return zone_; }
272 274
273 void EnsureReturn(); 275 void EnsureReturn();
274 276
275 static OperandScale OperandSizesToScale(
276 OperandSize size0, OperandSize size1 = OperandSize::kByte,
277 OperandSize size2 = OperandSize::kByte,
278 OperandSize size3 = OperandSize::kByte);
279
280 static OperandSize SizeForRegisterOperand(Register reg);
281 static OperandSize SizeForSignedOperand(int value);
282 static OperandSize SizeForUnsignedOperand(int value);
283 static OperandSize SizeForUnsignedOperand(size_t value);
284
285 static uint32_t RegisterOperand(Register reg); 277 static uint32_t RegisterOperand(Register reg);
286 static Register RegisterFromOperand(uint32_t operand); 278 static Register RegisterFromOperand(uint32_t operand);
287 static uint32_t SignedOperand(int value, OperandSize size); 279 static uint32_t SignedOperand(int value, OperandSize size);
288 static uint32_t UnsignedOperand(int value); 280 static uint32_t UnsignedOperand(int value);
289 static uint32_t UnsignedOperand(size_t value); 281 static uint32_t UnsignedOperand(size_t value);
290 282
291 private: 283 private:
292 class PreviousBytecodeHelper;
293 friend class BytecodeRegisterAllocator; 284 friend class BytecodeRegisterAllocator;
294 285
295 static Bytecode BytecodeForBinaryOperation(Token::Value op); 286 static Bytecode BytecodeForBinaryOperation(Token::Value op);
296 static Bytecode BytecodeForCountOperation(Token::Value op); 287 static Bytecode BytecodeForCountOperation(Token::Value op);
297 static Bytecode BytecodeForCompareOperation(Token::Value op); 288 static Bytecode BytecodeForCompareOperation(Token::Value op);
298 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); 289 static Bytecode BytecodeForStoreIC(LanguageMode language_mode);
299 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); 290 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode);
300 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode); 291 static Bytecode BytecodeForLoadGlobal(TypeofMode typeof_mode);
301 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); 292 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode);
302 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); 293 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode);
303 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); 294 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type);
304 static Bytecode BytecodeForDelete(LanguageMode language_mode); 295 static Bytecode BytecodeForDelete(LanguageMode language_mode);
305 static Bytecode BytecodeForCall(TailCallMode tail_call_mode); 296 static Bytecode BytecodeForCall(TailCallMode tail_call_mode);
306 297
307 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); 298 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand);
308 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); 299 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand);
309 300
310 template <size_t N>
311 INLINE(void Output(Bytecode bytecode, uint32_t (&operands)[N],
312 OperandScale operand_scale = OperandScale::kSingle));
313 void Output(Bytecode bytecode); 301 void Output(Bytecode bytecode);
314 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, 302 void OutputScaled(Bytecode bytecode, OperandScale operand_scale,
315 uint32_t operand0, uint32_t operand1, uint32_t operand2, 303 uint32_t operand0, uint32_t operand1, uint32_t operand2,
316 uint32_t operand3); 304 uint32_t operand3);
317 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, 305 void OutputScaled(Bytecode bytecode, OperandScale operand_scale,
318 uint32_t operand0, uint32_t operand1, uint32_t operand2); 306 uint32_t operand0, uint32_t operand1, uint32_t operand2);
319 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, 307 void OutputScaled(Bytecode bytecode, OperandScale operand_scale,
320 uint32_t operand0, uint32_t operand1); 308 uint32_t operand0, uint32_t operand1);
321 void OutputScaled(Bytecode bytecode, OperandScale operand_scale, 309 void OutputScaled(Bytecode bytecode, OperandScale operand_scale,
322 uint32_t operand0); 310 uint32_t operand0);
323 311
324 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, 312 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode,
325 BytecodeLabel* label); 313 BytecodeLabel* label);
326 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, 314 void PatchJump(ZoneVector<uint8_t>* bytecodes, size_t jump_target,
327 const ZoneVector<uint8_t>::iterator& jump_location); 315 size_t jump_location);
328 void PatchIndirectJumpWith8BitOperand( 316 void PatchJumpWith8BitOperand(ZoneVector<uint8_t>* bytecodes,
329 const ZoneVector<uint8_t>::iterator& jump_location, int delta); 317 size_t jump_location, int delta);
330 void PatchIndirectJumpWith16BitOperand( 318 void PatchJumpWith16BitOperand(ZoneVector<uint8_t>* bytecodes,
331 const ZoneVector<uint8_t>::iterator& jump_location, int delta); 319 size_t jump_location, int delta);
332 void PatchIndirectJumpWith32BitOperand( 320 void PatchJumpWith32BitOperand(ZoneVector<uint8_t>* bytecodes,
333 const ZoneVector<uint8_t>::iterator& jump_location, int delta); 321 size_t jump_location, int delta);
334 322
335 void LeaveBasicBlock(); 323 void LeaveBasicBlock();
336 324
337 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale, 325 bool OperandIsValid(Bytecode bytecode, OperandScale operand_scale,
338 int operand_index, uint32_t operand_value) const; 326 int operand_index, uint32_t operand_value) const;
339 bool RegisterIsValid(Register reg, OperandSize reg_size) const; 327 bool RegisterIsValid(Register reg, OperandSize reg_size) const;
340 328
341 bool LastBytecodeInSameBlock() const;
342 bool NeedToBooleanCast();
343 bool IsRegisterInAccumulator(Register reg);
344
345 // Set position for return. 329 // Set position for return.
346 void SetReturnPosition(); 330 void SetReturnPosition();
347 331
348 // Gets a constant pool entry for the |object|. 332 // Gets a constant pool entry for the |object|.
349 size_t GetConstantPoolEntry(Handle<Object> object); 333 size_t GetConstantPoolEntry(Handle<Object> object);
350 334
351 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; }
352 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; }
353 Isolate* isolate() const { return isolate_; } 335 Isolate* isolate() const { return isolate_; }
336 BytecodeArrayWriter* bytecode_array_writer() {
337 return &bytecode_array_writer_;
338 }
339 BytecodePipelineStage* pipeline() { return pipeline_; }
340 BytecodeNode* current_node() { return current_node_; }
354 ConstantArrayBuilder* constant_array_builder() { 341 ConstantArrayBuilder* constant_array_builder() {
355 return &constant_array_builder_; 342 return &constant_array_builder_;
356 } 343 }
357 const ConstantArrayBuilder* constant_array_builder() const { 344 const ConstantArrayBuilder* constant_array_builder() const {
358 return &constant_array_builder_; 345 return &constant_array_builder_;
359 } 346 }
360 HandlerTableBuilder* handler_table_builder() { 347 HandlerTableBuilder* handler_table_builder() {
361 return &handler_table_builder_; 348 return &handler_table_builder_;
362 } 349 }
363 SourcePositionTableBuilder* source_position_table_builder() { 350 SourcePositionTableBuilder* source_position_table_builder() {
364 return &source_position_table_builder_; 351 return &source_position_table_builder_;
365 } 352 }
353 BytecodeNodeAllocator* bytecode_node_allocator() {
354 return &bytecode_node_allocator_;
355 }
366 356
367 Isolate* isolate_; 357 Isolate* isolate_;
368 Zone* zone_; 358 Zone* zone_;
369 ZoneVector<uint8_t> bytecodes_;
370 bool bytecode_generated_; 359 bool bytecode_generated_;
371 ConstantArrayBuilder constant_array_builder_; 360 ConstantArrayBuilder constant_array_builder_;
372 HandlerTableBuilder handler_table_builder_; 361 HandlerTableBuilder handler_table_builder_;
373 SourcePositionTableBuilder source_position_table_builder_; 362 SourcePositionTableBuilder source_position_table_builder_;
374 size_t last_block_end_;
375 size_t last_bytecode_start_;
376 bool exit_seen_in_block_; 363 bool exit_seen_in_block_;
377 int unbound_jumps_; 364 int unbound_jumps_;
378 int parameter_count_; 365 int parameter_count_;
379 int local_register_count_; 366 int local_register_count_;
380 int context_register_count_; 367 int context_register_count_;
381 int return_position_; 368 int return_position_;
382 TemporaryRegisterAllocator temporary_allocator_; 369 TemporaryRegisterAllocator temporary_allocator_;
370 BytecodeNodeAllocator bytecode_node_allocator_;
371 BytecodeArrayWriter bytecode_array_writer_;
372 BytecodePipelineStage* pipeline_;
373 BytecodeNode* current_node_;
383 374
384 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); 375 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder);
385 }; 376 };
386 377
387 378
388 // A label representing a branch target in a bytecode array. When a 379 // A label representing a branch target in a bytecode array. When a
389 // label is bound, it represents a known position in the bytecode 380 // label is bound, it represents a known position in the bytecode
390 // array. For labels that are forward references there can be at most 381 // array. For labels that are forward references there can be at most
391 // one reference whilst it is unbound. 382 // one reference whilst it is unbound.
392 class BytecodeLabel final { 383 class BytecodeLabel final {
(...skipping 30 matching lines...) Expand all
423 size_t offset_; 414 size_t offset_;
424 415
425 friend class BytecodeArrayBuilder; 416 friend class BytecodeArrayBuilder;
426 }; 417 };
427 418
428 } // namespace interpreter 419 } // namespace interpreter
429 } // namespace internal 420 } // namespace internal
430 } // namespace v8 421 } // namespace v8
431 422
432 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 423 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698