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

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: remove 100% dispatching bytecodes again 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 12 matching lines...) Expand all
23 using compiler::Node; 23 using compiler::Node;
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 bytecode_offset_(this, MachineType::PointerRepresentation()),
33 operand_scale_(operand_scale), 34 operand_scale_(operand_scale),
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 return IntPtrAdd(BytecodeOffset(), delta);
515 } 522 }
516 523
517 Node* InterpreterAssembler::Jump(Node* delta) { 524 Node* InterpreterAssembler::Jump(Node* delta) {
518 UpdateInterruptBudget(delta); 525 UpdateInterruptBudget(delta);
526 if (FLAG_trace_ignition) {
527 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
528 }
519 return DispatchTo(Advance(delta)); 529 return DispatchTo(Advance(delta));
520 } 530 }
521 531
522 void InterpreterAssembler::JumpConditional(Node* condition, Node* delta) { 532 void InterpreterAssembler::JumpConditional(Node* condition, Node* delta) {
523 Label match(this), no_match(this); 533 Label match(this), no_match(this);
524 534
525 BranchIf(condition, &match, &no_match); 535 BranchIf(condition, &match, &no_match);
526 Bind(&match); 536 Bind(&match);
527 Jump(delta); 537 Jump(delta);
528 Bind(&no_match); 538 Bind(&no_match);
529 Dispatch(); 539 Dispatch();
530 } 540 }
531 541
532 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) { 542 void InterpreterAssembler::JumpIfWordEqual(Node* lhs, Node* rhs, Node* delta) {
533 JumpConditional(WordEqual(lhs, rhs), delta); 543 JumpConditional(WordEqual(lhs, rhs), delta);
534 } 544 }
535 545
536 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs, 546 void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs,
537 Node* delta) { 547 Node* delta) {
538 JumpConditional(WordNotEqual(lhs, rhs), delta); 548 JumpConditional(WordNotEqual(lhs, rhs), delta);
539 } 549 }
540 550
551 Node* InterpreterAssembler::LoadBytecode(compiler::Node* bytecode_offset) {
552 return Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(),
553 bytecode_offset);
554 }
555
541 Node* InterpreterAssembler::Dispatch() { 556 Node* InterpreterAssembler::Dispatch() {
542 return DispatchTo(Advance(Bytecodes::Size(bytecode_, operand_scale_))); 557 Node* target_offset = Advance();
558 Node* target_bytecode = LoadBytecode(target_offset);
559 Variable var_offset(this, MachineType::PointerRepresentation());
560 Variable var_bytecode(this, MachineRepresentation::kWord8);
561 var_offset.Bind(target_offset);
562 var_bytecode.Bind(target_bytecode);
563
564 if (FLAG_trace_ignition) {
565 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
rmcilroy 2016/07/19 10:03:56 I think the TraceBytecode can still stay in Dispat
klaasb 2016/07/19 14:24:13 I had it that way before, but probably the offset
rmcilroy 2016/07/19 15:26:04 As discussed offline, this is probably because you
klaasb 2016/07/19 15:39:00 Yes, that's what I did now.
566 }
567
568 if (Bytecodes::IsStarLookahead(bytecode_, operand_scale_)) {
569 StarDispatchLookahead(var_bytecode, var_offset);
570 }
571 return DispatchToBytecode(var_bytecode.value(), var_offset.value());
572 }
573
574 void InterpreterAssembler::StarDispatchLookahead(Variable& target_bytecode,
575 Variable& target_offset) {
576 Label store(this), done(this);
577
578 Node* star_bytecode = Int32Constant(static_cast<int>(Bytecode::kStar));
rmcilroy 2016/07/19 10:03:56 IntPtrConstant
klaasb 2016/07/19 14:24:13 Done.
579 Node* is_star = WordEqual(target_bytecode.value(), star_bytecode);
580 BranchIf(is_star, &store, &done);
581 Bind(&store);
rmcilroy 2016/07/19 10:03:56 nit - do_inline_star
klaasb 2016/07/19 14:24:13 Done.
582 {
583 InlineStar(target_offset);
584 target_bytecode.Bind(LoadBytecode(target_offset.value()));
585 Goto(&done);
586 }
587 Bind(&done);
588 }
589
590 void InterpreterAssembler::InlineStar(Variable& target_offset) {
591 Bytecode previous_bytecode = bytecode_;
592 Variable previous_offset = bytecode_offset_;
593 AccumulatorUse previous_acc_use = accumulator_use_;
594 bytecode_ = Bytecode::kStar;
rmcilroy 2016/07/19 10:03:56 nit - newline
klaasb 2016/07/19 14:24:13 Done.
595 bytecode_offset_ = target_offset;
596 accumulator_use_ = AccumulatorUse::kNone;
597 if (FLAG_trace_ignition) {
598 TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry);
599 }
600
601 StoreRegister(GetAccumulator(), BytecodeOperandReg(0));
602
603 DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
604 if (FLAG_trace_ignition) {
605 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
606 }
607 Node* next_bytecode_offset = Advance();
608 target_offset.Bind(next_bytecode_offset);
609
610 bytecode_ = previous_bytecode;
611 bytecode_offset_ = previous_offset;
612 accumulator_use_ = previous_acc_use;
543 } 613 }
544 614
545 Node* InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) { 615 Node* InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) {
546 Node* target_bytecode = Load( 616 Node* target_bytecode = LoadBytecode(new_bytecode_offset);
547 MachineType::Uint8(), BytecodeArrayTaggedPointer(), new_bytecode_offset); 617 return DispatchToBytecode(target_bytecode, new_bytecode_offset);
618 }
619
620 Node* InterpreterAssembler::DispatchToBytecode(Node* target_bytecode,
621 Node* new_bytecode_offset) {
548 if (kPointerSize == 8) { 622 if (kPointerSize == 8) {
549 target_bytecode = ChangeUint32ToUint64(target_bytecode); 623 target_bytecode = ChangeUint32ToUint64(target_bytecode);
550 } 624 }
rmcilroy 2016/07/19 10:03:56 This should also be in LoadBytecode (hopefully we
klaasb 2016/07/19 14:24:13 Done.
551
552 if (FLAG_trace_ignition_dispatches) { 625 if (FLAG_trace_ignition_dispatches) {
553 TraceBytecodeDispatch(target_bytecode); 626 TraceBytecodeDispatch(target_bytecode);
rmcilroy 2016/07/19 10:03:56 Just to point out, we will no longer count these i
klaasb 2016/07/19 14:24:13 Acknowledged.
554 } 627 }
555 628
556 Node* target_code_entry = 629 Node* target_code_entry =
557 Load(MachineType::Pointer(), DispatchTableRawPointer(), 630 Load(MachineType::Pointer(), DispatchTableRawPointer(),
558 WordShl(target_bytecode, IntPtrConstant(kPointerSizeLog2))); 631 WordShl(target_bytecode, IntPtrConstant(kPointerSizeLog2)));
559 632
560 return DispatchToBytecodeHandlerEntry(target_code_entry, new_bytecode_offset); 633 return DispatchToBytecodeHandlerEntry(target_code_entry, new_bytecode_offset);
561 } 634 }
562 635
563 Node* InterpreterAssembler::DispatchToBytecodeHandler(Node* handler, 636 Node* InterpreterAssembler::DispatchToBytecodeHandler(Node* handler,
564 Node* bytecode_offset) { 637 Node* bytecode_offset) {
565 Node* handler_entry = 638 Node* handler_entry =
566 IntPtrAdd(handler, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag)); 639 IntPtrAdd(handler, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag));
640 if (FLAG_trace_ignition) {
641 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
642 }
567 return DispatchToBytecodeHandlerEntry(handler_entry, bytecode_offset); 643 return DispatchToBytecodeHandlerEntry(handler_entry, bytecode_offset);
568 } 644 }
569 645
570 Node* InterpreterAssembler::DispatchToBytecodeHandlerEntry( 646 Node* InterpreterAssembler::DispatchToBytecodeHandlerEntry(
571 Node* handler_entry, Node* bytecode_offset) { 647 Node* handler_entry, Node* bytecode_offset) {
572 if (FLAG_trace_ignition) {
573 TraceBytecode(Runtime::kInterpreterTraceBytecodeExit);
574 }
575
576 InterpreterDispatchDescriptor descriptor(isolate()); 648 InterpreterDispatchDescriptor descriptor(isolate());
577 Node* args[] = {GetAccumulatorUnchecked(), bytecode_offset, 649 Node* args[] = {GetAccumulatorUnchecked(), bytecode_offset,
578 BytecodeArrayTaggedPointer(), DispatchTableRawPointer()}; 650 BytecodeArrayTaggedPointer(), DispatchTableRawPointer()};
579 return TailCallBytecodeDispatch(descriptor, handler_entry, args); 651 return TailCallBytecodeDispatch(descriptor, handler_entry, args);
580 } 652 }
581 653
582 void InterpreterAssembler::DispatchWide(OperandScale operand_scale) { 654 void InterpreterAssembler::DispatchWide(OperandScale operand_scale) {
583 // Dispatching a wide bytecode requires treating the prefix 655 // Dispatching a wide bytecode requires treating the prefix
584 // bytecode a base pointer into the dispatch table and dispatching 656 // bytecode a base pointer into the dispatch table and dispatching
585 // the bytecode that follows relative to this base. 657 // the bytecode that follows relative to this base.
586 // 658 //
587 // Indices 0-255 correspond to bytecodes with operand_scale == 0 659 // Indices 0-255 correspond to bytecodes with operand_scale == 0
588 // Indices 256-511 correspond to bytecodes with operand_scale == 1 660 // Indices 256-511 correspond to bytecodes with operand_scale == 1
589 // Indices 512-767 correspond to bytecodes with operand_scale == 2 661 // Indices 512-767 correspond to bytecodes with operand_scale == 2
590 Node* next_bytecode_offset = Advance(1); 662 Node* next_bytecode_offset = Advance(1);
591 Node* next_bytecode = Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(), 663 Node* next_bytecode = LoadBytecode(next_bytecode_offset);
592 next_bytecode_offset);
593 if (kPointerSize == 8) { 664 if (kPointerSize == 8) {
594 next_bytecode = ChangeUint32ToUint64(next_bytecode); 665 next_bytecode = ChangeUint32ToUint64(next_bytecode);
595 } 666 }
596 667
597 if (FLAG_trace_ignition_dispatches) { 668 if (FLAG_trace_ignition_dispatches) {
598 TraceBytecodeDispatch(next_bytecode); 669 TraceBytecodeDispatch(next_bytecode);
599 } 670 }
600 671
601 Node* base_index; 672 Node* base_index;
602 switch (operand_scale) { 673 switch (operand_scale) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 Goto(&loop); 850 Goto(&loop);
780 } 851 }
781 Bind(&done_loop); 852 Bind(&done_loop);
782 853
783 return array; 854 return array;
784 } 855 }
785 856
786 } // namespace interpreter 857 } // namespace interpreter
787 } // namespace internal 858 } // namespace internal
788 } // namespace v8 859 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698