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

Side by Side Diff: src/interpreter/interpreter-assembler.cc

Issue 2142273003: [interpreter] Inline Star on dispatch for some bytecodes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: restrict InterpreterAssemblerTest.Jump to jumps Created 4 years, 5 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 #include "src/interpreter/interpreter-assembler.h" 5 #include "src/interpreter/interpreter-assembler.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <ostream> 8 #include <ostream>
9 9
10 #include "src/code-factory.h" 10 #include "src/code-factory.h"
(...skipping 13 matching lines...) Expand all
24 24
25 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, 25 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone,
26 Bytecode bytecode, 26 Bytecode bytecode,
27 OperandScale operand_scale) 27 OperandScale operand_scale)
28 : CodeStubAssembler(isolate, zone, InterpreterDispatchDescriptor(isolate), 28 : CodeStubAssembler(isolate, zone, InterpreterDispatchDescriptor(isolate),
29 Code::ComputeFlags(Code::BYTECODE_HANDLER), 29 Code::ComputeFlags(Code::BYTECODE_HANDLER),
30 Bytecodes::ToString(bytecode), 30 Bytecodes::ToString(bytecode),
31 Bytecodes::ReturnCount(bytecode)), 31 Bytecodes::ReturnCount(bytecode)),
32 bytecode_(bytecode), 32 bytecode_(bytecode),
33 operand_scale_(operand_scale), 33 operand_scale_(operand_scale),
34 bytecode_offset_(this, MachineType::PointerRepresentation()),
34 interpreted_frame_pointer_(this, MachineType::PointerRepresentation()), 35 interpreted_frame_pointer_(this, MachineType::PointerRepresentation()),
35 accumulator_(this, MachineRepresentation::kTagged), 36 accumulator_(this, MachineRepresentation::kTagged),
36 accumulator_use_(AccumulatorUse::kNone), 37 accumulator_use_(AccumulatorUse::kNone),
37 made_call_(false), 38 made_call_(false),
38 disable_stack_check_across_call_(false), 39 disable_stack_check_across_call_(false),
39 stack_pointer_before_call_(nullptr) { 40 stack_pointer_before_call_(nullptr) {
40 accumulator_.Bind( 41 accumulator_.Bind(
41 Parameter(InterpreterDispatchDescriptor::kAccumulatorParameter)); 42 Parameter(InterpreterDispatchDescriptor::kAccumulatorParameter));
43 bytecode_offset_.Bind(
44 Parameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter));
42 if (FLAG_trace_ignition) { 45 if (FLAG_trace_ignition) {
43 TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry); 46 TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry);
44 } 47 }
45 } 48 }
46 49
47 InterpreterAssembler::~InterpreterAssembler() { 50 InterpreterAssembler::~InterpreterAssembler() {
48 // If the following check fails the handler does not use the 51 // If the following check fails the handler does not use the
49 // accumulator in the way described in the bytecode definitions in 52 // accumulator in the way described in the bytecode definitions in
50 // bytecodes.h. 53 // bytecodes.h.
51 DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_)); 54 DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
(...skipping 24 matching lines...) Expand all
76 79
77 Node* InterpreterAssembler::GetContext() { 80 Node* InterpreterAssembler::GetContext() {
78 return LoadRegister(Register::current_context()); 81 return LoadRegister(Register::current_context());
79 } 82 }
80 83
81 void InterpreterAssembler::SetContext(Node* value) { 84 void InterpreterAssembler::SetContext(Node* value) {
82 StoreRegister(value, Register::current_context()); 85 StoreRegister(value, Register::current_context());
83 } 86 }
84 87
85 Node* InterpreterAssembler::BytecodeOffset() { 88 Node* InterpreterAssembler::BytecodeOffset() {
86 return Parameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter); 89 return bytecode_offset_.value();
87 } 90 }
88 91
89 Node* InterpreterAssembler::BytecodeArrayTaggedPointer() { 92 Node* InterpreterAssembler::BytecodeArrayTaggedPointer() {
90 if (made_call_) { 93 if (made_call_) {
91 // If we have made a call, restore bytecode array from stack frame in case 94 // If we have made a call, restore bytecode array from stack frame in case
92 // the debugger has swapped us to the patched debugger bytecode array. 95 // the debugger has swapped us to the patched debugger bytecode array.
93 return LoadRegister(Register::bytecode_array()); 96 return LoadRegister(Register::bytecode_array());
94 } else { 97 } else {
95 return Parameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter); 98 return Parameter(InterpreterDispatchDescriptor::kBytecodeArrayParameter);
96 } 99 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 Goto(&ok); 502 Goto(&ok);
500 } 503 }
501 504
502 // Update budget. 505 // Update budget.
503 Bind(&ok); 506 Bind(&ok);
504 StoreNoWriteBarrier(MachineRepresentation::kWord32, 507 StoreNoWriteBarrier(MachineRepresentation::kWord32,
505 BytecodeArrayTaggedPointer(), budget_offset, 508 BytecodeArrayTaggedPointer(), budget_offset,
506 new_budget.value()); 509 new_budget.value());
507 } 510 }
508 511
512 Node* InterpreterAssembler::Advance() {
513 return Advance(Bytecodes::Size(bytecode_, operand_scale_));
514 }
515
509 Node* InterpreterAssembler::Advance(int delta) { 516 Node* InterpreterAssembler::Advance(int delta) {
510 return IntPtrAdd(BytecodeOffset(), IntPtrConstant(delta)); 517 return Advance(IntPtrConstant(delta));
511 } 518 }
512 519
513 Node* InterpreterAssembler::Advance(Node* delta) { 520 Node* InterpreterAssembler::Advance(Node* delta) {
514 return IntPtrAdd(BytecodeOffset(), delta); 521 if (FLAG_trace_ignition) {
522 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
523 }
524 Node* next_offset = IntPtrAdd(BytecodeOffset(), delta);
525 bytecode_offset_.Bind(next_offset);
526 return next_offset;
515 } 527 }
516 528
517 Node* InterpreterAssembler::Jump(Node* delta) { 529 Node* InterpreterAssembler::Jump(Node* delta) {
530 DCHECK(!Bytecodes::IsStarLookahead(bytecode_, operand_scale_));
531
518 UpdateInterruptBudget(delta); 532 UpdateInterruptBudget(delta);
519 return DispatchTo(Advance(delta)); 533 Node* new_bytecode_offset = Advance(delta);
534 Node* target_bytecode = LoadBytecode(new_bytecode_offset);
535 return DispatchToBytecode(target_bytecode, new_bytecode_offset);
520 } 536 }
521 537
522 void InterpreterAssembler::JumpConditional(Node* condition, Node* delta) { 538 void InterpreterAssembler::JumpConditional(Node* condition, Node* delta) {
523 Label match(this), no_match(this); 539 Label match(this), no_match(this);
524 540
525 BranchIf(condition, &match, &no_match); 541 BranchIf(condition, &match, &no_match);
526 Bind(&match); 542 Bind(&match);
527 Jump(delta); 543 Jump(delta);
528 Bind(&no_match); 544 Bind(&no_match);
529 Dispatch(); 545 Dispatch();
530 } 546 }
531 547
532 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) { 548 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) {
533 JumpConditional(WordEqual(lhs, rhs), delta); 549 JumpConditional(WordEqual(lhs, rhs), delta);
534 } 550 }
535 551
536 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs, 552 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs,
537 Node* delta) { 553 Node* delta) {
538 JumpConditional(WordNotEqual(lhs, rhs), delta); 554 JumpConditional(WordNotEqual(lhs, rhs), delta);
539 } 555 }
540 556
541 Node* InterpreterAssembler::Dispatch() { 557 Node* InterpreterAssembler::LoadBytecode(compiler::Node* bytecode_offset) {
542 return DispatchTo(Advance(Bytecodes::Size(bytecode_, operand_scale_))); 558 Node* bytecode =
559 Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(), bytecode_offset);
560 if (kPointerSize == 8) {
561 bytecode = ChangeUint32ToUint64(bytecode);
562 }
563 return bytecode;
543 } 564 }
544 565
545 Node* InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) { 566 Node* InterpreterAssembler::StarDispatchLookahead(Node* target_bytecode) {
546 Node* target_bytecode = Load( 567 Label do_inline_star(this), done(this);
547 MachineType::Uint8(), BytecodeArrayTaggedPointer(), new_bytecode_offset); 568
548 if (kPointerSize == 8) { 569 Variable var_bytecode(this, MachineRepresentation::kWord8);
549 target_bytecode = ChangeUint32ToUint64(target_bytecode); 570 var_bytecode.Bind(target_bytecode);
571
572 Node* star_bytecode = IntPtrConstant(static_cast<int>(Bytecode::kStar));
573 Node* is_star = WordEqual(target_bytecode, star_bytecode);
574 BranchIf(is_star, &do_inline_star, &done);
575
576 Bind(&do_inline_star);
577 {
578 InlineStar();
579 var_bytecode.Bind(LoadBytecode(BytecodeOffset()));
580 Goto(&done);
550 } 581 }
582 Bind(&done);
583 return var_bytecode.value();
584 }
551 585
586 void InterpreterAssembler::InlineStar() {
587 Bytecode previous_bytecode = bytecode_;
588 AccumulatorUse previous_acc_use = accumulator_use_;
589
590 bytecode_ = Bytecode::kStar;
591 accumulator_use_ = AccumulatorUse::kNone;
592
593 if (FLAG_trace_ignition) {
594 TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry);
595 }
596 StoreRegister(GetAccumulator(), BytecodeOperandReg(0));
597
598 DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
599
600 Advance();
601 bytecode_ = previous_bytecode;
602 accumulator_use_ = previous_acc_use;
603 }
604
605 Node* InterpreterAssembler::Dispatch() {
606 Node* target_offset = Advance();
607 Node* target_bytecode = LoadBytecode(target_offset);
608
609 if (Bytecodes::IsStarLookahead(bytecode_, operand_scale_)) {
610 target_bytecode = StarDispatchLookahead(target_bytecode);
611 }
612 return DispatchToBytecode(target_bytecode, BytecodeOffset());
613 }
614
615 Node* InterpreterAssembler::DispatchToBytecode(Node* target_bytecode,
616 Node* new_bytecode_offset) {
552 if (FLAG_trace_ignition_dispatches) { 617 if (FLAG_trace_ignition_dispatches) {
553 TraceBytecodeDispatch(target_bytecode); 618 TraceBytecodeDispatch(target_bytecode);
554 } 619 }
555 620
556 Node* target_code_entry = 621 Node* target_code_entry =
557 Load(MachineType::Pointer(), DispatchTableRawPointer(), 622 Load(MachineType::Pointer(), DispatchTableRawPointer(),
558 WordShl(target_bytecode, IntPtrConstant(kPointerSizeLog2))); 623 WordShl(target_bytecode, IntPtrConstant(kPointerSizeLog2)));
559 624
560 return DispatchToBytecodeHandlerEntry(target_code_entry, new_bytecode_offset); 625 return DispatchToBytecodeHandlerEntry(target_code_entry, new_bytecode_offset);
561 } 626 }
562 627
563 Node* InterpreterAssembler::DispatchToBytecodeHandler(Node* handler, 628 Node* InterpreterAssembler::DispatchToBytecodeHandler(Node* handler,
564 Node* bytecode_offset) { 629 Node* bytecode_offset) {
565 Node* handler_entry = 630 Node* handler_entry =
566 IntPtrAdd(handler, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag)); 631 IntPtrAdd(handler, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag));
567 return DispatchToBytecodeHandlerEntry(handler_entry, bytecode_offset); 632 return DispatchToBytecodeHandlerEntry(handler_entry, bytecode_offset);
568 } 633 }
569 634
570 Node* InterpreterAssembler::DispatchToBytecodeHandlerEntry( 635 Node* InterpreterAssembler::DispatchToBytecodeHandlerEntry(
571 Node* handler_entry, Node* bytecode_offset) { 636 Node* handler_entry, Node* bytecode_offset) {
572 if (FLAG_trace_ignition) {
573 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
574 }
575
576 InterpreterDispatchDescriptor descriptor(isolate()); 637 InterpreterDispatchDescriptor descriptor(isolate());
577 Node* args[] = {GetAccumulatorUnchecked(), bytecode_offset, 638 Node* args[] = {GetAccumulatorUnchecked(), bytecode_offset,
578 BytecodeArrayTaggedPointer(), DispatchTableRawPointer()}; 639 BytecodeArrayTaggedPointer(), DispatchTableRawPointer()};
579 return TailCallBytecodeDispatch(descriptor, handler_entry, args); 640 return TailCallBytecodeDispatch(descriptor, handler_entry, args);
580 } 641 }
581 642
582 void InterpreterAssembler::DispatchWide(OperandScale operand_scale) { 643 void InterpreterAssembler::DispatchWide(OperandScale operand_scale) {
583 // Dispatching a wide bytecode requires treating the prefix 644 // Dispatching a wide bytecode requires treating the prefix
584 // bytecode a base pointer into the dispatch table and dispatching 645 // bytecode a base pointer into the dispatch table and dispatching
585 // the bytecode that follows relative to this base. 646 // the bytecode that follows relative to this base.
586 // 647 //
587 // Indices 0-255 correspond to bytecodes with operand_scale == 0 648 // Indices 0-255 correspond to bytecodes with operand_scale == 0
588 // Indices 256-511 correspond to bytecodes with operand_scale == 1 649 // Indices 256-511 correspond to bytecodes with operand_scale == 1
589 // Indices 512-767 correspond to bytecodes with operand_scale == 2 650 // Indices 512-767 correspond to bytecodes with operand_scale == 2
590 Node* next_bytecode_offset = Advance(1); 651 Node* next_bytecode_offset = Advance(1);
591 Node* next_bytecode = Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(), 652 Node* next_bytecode = LoadBytecode(next_bytecode_offset);
592 next_bytecode_offset);
593 if (kPointerSize == 8) {
594 next_bytecode = ChangeUint32ToUint64(next_bytecode);
595 }
596 653
597 if (FLAG_trace_ignition_dispatches) { 654 if (FLAG_trace_ignition_dispatches) {
598 TraceBytecodeDispatch(next_bytecode); 655 TraceBytecodeDispatch(next_bytecode);
599 } 656 }
600 657
601 Node* base_index; 658 Node* base_index;
602 switch (operand_scale) { 659 switch (operand_scale) {
603 case OperandScale::kDouble: 660 case OperandScale::kDouble:
604 base_index = IntPtrConstant(1 << kBitsPerByte); 661 base_index = IntPtrConstant(1 << kBitsPerByte);
605 break; 662 break;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 Goto(&loop); 836 Goto(&loop);
780 } 837 }
781 Bind(&done_loop); 838 Bind(&done_loop);
782 839
783 return array; 840 return array;
784 } 841 }
785 842
786 } // namespace interpreter 843 } // namespace interpreter
787 } // namespace internal 844 } // namespace internal
788 } // namespace v8 845 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter-assembler.h ('k') | test/unittests/interpreter/interpreter-assembler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698