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

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

Issue 2393683004: [Interpreter] Optimize the Register Optimizer. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 | « no previous file | src/interpreter/bytecode-array-builder.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_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/base/compiler-specific.h" 9 #include "src/base/compiler-specific.h"
10 #include "src/globals.h" 10 #include "src/globals.h"
11 #include "src/interpreter/bytecode-array-writer.h" 11 #include "src/interpreter/bytecode-array-writer.h"
12 #include "src/interpreter/bytecode-register-allocator.h" 12 #include "src/interpreter/bytecode-register-allocator.h"
13 #include "src/interpreter/bytecode-register.h" 13 #include "src/interpreter/bytecode-register.h"
14 #include "src/interpreter/bytecodes.h" 14 #include "src/interpreter/bytecodes.h"
15 #include "src/interpreter/constant-array-builder.h" 15 #include "src/interpreter/constant-array-builder.h"
16 #include "src/interpreter/handler-table-builder.h" 16 #include "src/interpreter/handler-table-builder.h"
17 #include "src/zone/zone-containers.h" 17 #include "src/zone/zone-containers.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 class Isolate; 22 class Isolate;
23 23
24 namespace interpreter { 24 namespace interpreter {
25 25
26 class BytecodeLabel; 26 class BytecodeLabel;
27 class BytecodeNode; 27 class BytecodeNode;
28 class BytecodePipelineStage; 28 class BytecodePipelineStage;
29 class BytecodeRegisterOptimizer;
29 class Register; 30 class Register;
30 31
31 class V8_EXPORT_PRIVATE BytecodeArrayBuilder final 32 class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
32 : public NON_EXPORTED_BASE(ZoneObject) { 33 : public NON_EXPORTED_BASE(ZoneObject) {
33 public: 34 public:
34 BytecodeArrayBuilder( 35 BytecodeArrayBuilder(
35 Isolate* isolate, Zone* zone, int parameter_count, int context_count, 36 Isolate* isolate, Zone* zone, int parameter_count, int context_count,
36 int locals_count, FunctionLiteral* literal = nullptr, 37 int locals_count, FunctionLiteral* literal = nullptr,
37 SourcePositionTableBuilder::RecordingMode source_position_mode = 38 SourcePositionTableBuilder::RecordingMode source_position_mode =
38 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS); 39 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 314 }
314 } 315 }
315 316
316 void SetExpressionAsStatementPosition(Expression* expr) { 317 void SetExpressionAsStatementPosition(Expression* expr) {
317 if (expr->position() == kNoSourcePosition) return; 318 if (expr->position() == kNoSourcePosition) return;
318 latest_source_info_.MakeStatementPosition(expr->position()); 319 latest_source_info_.MakeStatementPosition(expr->position());
319 } 320 }
320 321
321 bool RequiresImplicitReturn() const { return !return_seen_in_block_; } 322 bool RequiresImplicitReturn() const { return !return_seen_in_block_; }
322 323
324 // Returns the raw operand value for the given register or register list.
325 uint32_t GetInputRegisterOperand(Register reg);
326 uint32_t GetOutputRegisterOperand(Register reg);
327 uint32_t GetInputRegisterListOperand(RegisterList reg_list);
328 uint32_t GetOutputRegisterListOperand(RegisterList reg_list);
329
323 // Accessors 330 // Accessors
324 BytecodeRegisterAllocator* register_allocator() { 331 BytecodeRegisterAllocator* register_allocator() {
325 return &register_allocator_; 332 return &register_allocator_;
326 } 333 }
327 const BytecodeRegisterAllocator* register_allocator() const { 334 const BytecodeRegisterAllocator* register_allocator() const {
328 return &register_allocator_; 335 return &register_allocator_;
329 } 336 }
330 Zone* zone() const { return zone_; } 337 Zone* zone() const { return zone_; }
331 338
332 private: 339 private:
333 friend class BytecodeRegisterAllocator; 340 friend class BytecodeRegisterAllocator;
341 template <OperandType... operand_types>
342 friend class BytecodeNodeBuilder;
334 343
335 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, 344 // Returns the current source position for the given |bytecode|.
336 uint32_t operand2, uint32_t operand3)); 345 INLINE(BytecodeSourceInfo CurrentSourcePosition(Bytecode bytecode));
337 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1,
338 uint32_t operand2));
339 INLINE(void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1));
340 INLINE(void Output(Bytecode bytecode, uint32_t operand0));
341 INLINE(void Output(Bytecode bytecode));
342 346
343 INLINE(void OutputJump(Bytecode bytecode, BytecodeLabel* label)); 347 #define DECLARE_BYTECODE_OUTPUT(Name, ...) \
344 INLINE(void OutputJump(Bytecode bytecode, uint32_t operand0, 348 template <typename... Operands> \
345 BytecodeLabel* label)); 349 INLINE(void Output##Name(Operands... operands)); \
350 template <typename... Operands> \
351 INLINE(void Output##Name(BytecodeLabel* label, Operands... operands));
352 BYTECODE_LIST(DECLARE_BYTECODE_OUTPUT)
353 #undef DECLARE_OPERAND_TYPE_INFO
346 354
347 bool RegisterIsValid(Register reg) const; 355 bool RegisterIsValid(Register reg) const;
348 bool OperandsAreValid(Bytecode bytecode, int operand_count, 356 bool RegisterListIsValid(RegisterList reg_list) const;
349 uint32_t operand0 = 0, uint32_t operand1 = 0,
350 uint32_t operand2 = 0, uint32_t operand3 = 0) const;
351
352 static uint32_t RegisterOperand(Register reg) {
353 return static_cast<uint32_t>(reg.ToOperand());
354 }
355
356 static uint32_t SignedOperand(int value) {
357 return static_cast<uint32_t>(value);
358 }
359
360 static uint32_t UnsignedOperand(int value) {
361 DCHECK_GE(value, 0);
362 return static_cast<uint32_t>(value);
363 }
364
365 static uint32_t UnsignedOperand(size_t value) {
366 DCHECK_LE(value, kMaxUInt32);
367 return static_cast<uint32_t>(value);
368 }
369 357
370 // Set position for return. 358 // Set position for return.
371 void SetReturnPosition(); 359 void SetReturnPosition();
372 360
373 // Gets a constant pool entry for the |object|. 361 // Gets a constant pool entry for the |object|.
374 size_t GetConstantPoolEntry(Handle<Object> object); 362 size_t GetConstantPoolEntry(Handle<Object> object);
375 363
376 // Not implemented as the illegal bytecode is used inside internally 364 // Not implemented as the illegal bytecode is used inside internally
377 // to indicate a bytecode field is not valid or an error has occured 365 // to indicate a bytecode field is not valid or an error has occured
378 // during bytecode generation. 366 // during bytecode generation.
379 BytecodeArrayBuilder& Illegal(); 367 BytecodeArrayBuilder& Illegal();
380 368
369 void PrepareToOutputBytecode(Bytecode bytecode);
370
381 void LeaveBasicBlock() { return_seen_in_block_ = false; } 371 void LeaveBasicBlock() { return_seen_in_block_ = false; }
382 372
383 BytecodeArrayWriter* bytecode_array_writer() { 373 BytecodeArrayWriter* bytecode_array_writer() {
384 return &bytecode_array_writer_; 374 return &bytecode_array_writer_;
385 } 375 }
386 BytecodePipelineStage* pipeline() { return pipeline_; } 376 BytecodePipelineStage* pipeline() { return pipeline_; }
387 ConstantArrayBuilder* constant_array_builder() { 377 ConstantArrayBuilder* constant_array_builder() {
388 return &constant_array_builder_; 378 return &constant_array_builder_;
389 } 379 }
390 const ConstantArrayBuilder* constant_array_builder() const { 380 const ConstantArrayBuilder* constant_array_builder() const {
391 return &constant_array_builder_; 381 return &constant_array_builder_;
392 } 382 }
393 HandlerTableBuilder* handler_table_builder() { 383 HandlerTableBuilder* handler_table_builder() {
394 return &handler_table_builder_; 384 return &handler_table_builder_;
395 } 385 }
396 386
397 Zone* zone_; 387 Zone* zone_;
398 bool bytecode_generated_; 388 bool bytecode_generated_;
399 ConstantArrayBuilder constant_array_builder_; 389 ConstantArrayBuilder constant_array_builder_;
400 HandlerTableBuilder handler_table_builder_; 390 HandlerTableBuilder handler_table_builder_;
401 bool return_seen_in_block_; 391 bool return_seen_in_block_;
402 int parameter_count_; 392 int parameter_count_;
403 int local_register_count_; 393 int local_register_count_;
404 int context_register_count_; 394 int context_register_count_;
405 int return_position_; 395 int return_position_;
406 BytecodeRegisterAllocator register_allocator_; 396 BytecodeRegisterAllocator register_allocator_;
407 BytecodeArrayWriter bytecode_array_writer_; 397 BytecodeArrayWriter bytecode_array_writer_;
408 BytecodePipelineStage* pipeline_; 398 BytecodePipelineStage* pipeline_;
399 BytecodeRegisterOptimizer* register_optimizer_;
409 BytecodeSourceInfo latest_source_info_; 400 BytecodeSourceInfo latest_source_info_;
410 401
411 static int const kNoFeedbackSlot = 0; 402 static int const kNoFeedbackSlot = 0;
412 403
413 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); 404 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder);
414 }; 405 };
415 406
416 } // namespace interpreter 407 } // namespace interpreter
417 } // namespace internal 408 } // namespace internal
418 } // namespace v8 409 } // namespace v8
419 410
420 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 411 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
OLDNEW
« no previous file with comments | « no previous file | src/interpreter/bytecode-array-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698