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

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

Issue 1510553002: [Interpreter] Fixes PreviousBytecodeHelper to check if previous bytecode is in the same basic block. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 | no next file » | 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 #include "src/interpreter/bytecode-array-builder.h" 5 #include "src/interpreter/bytecode-array-builder.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace interpreter { 9 namespace interpreter {
10 10
11 class BytecodeArrayBuilder::PreviousBytecodeHelper { 11 class BytecodeArrayBuilder::PreviousBytecodeHelper {
12 public: 12 public:
13 explicit PreviousBytecodeHelper(const BytecodeArrayBuilder& array_builder) 13 explicit PreviousBytecodeHelper(const BytecodeArrayBuilder& array_builder)
14 : array_builder_(array_builder) {} 14 : array_builder_(array_builder) {}
oth 2015/12/08 09:54:14 It would be better to have: CHECK(array_builder-
mythria 2015/12/08 11:24:42 Done.
15 15
16 Bytecode GetBytecode() const { 16 bool GetBytecode(Bytecode* bytecode) const {
oth 2015/12/08 09:54:15 Propose leaving this as Bytecode, adding MUST_USE_
mythria 2015/12/08 11:24:42 Done.
17 // Returns the previous bytecode in the same basicblock. If there is none it 17 // Returns the previous bytecode in the same basicblock. If there is none it
18 // returns Bytecode::kLast. 18 // returns false and does not change bytecode.
19 if (!array_builder_.LastBytecodeInSameBlock()) { 19 if (!array_builder_.LastBytecodeInSameBlock()) {
20 return Bytecode::kLast; 20 return false;
21 } 21 }
22 return Bytecodes::FromByte( 22 *bytecode = Bytecodes::FromByte(
23 array_builder_.bytecodes()->at(array_builder_.last_bytecode_start_)); 23 array_builder_.bytecodes()->at(array_builder_.last_bytecode_start_));
24 return true;
24 } 25 }
25 26
26 uint32_t GetOperand(int operand_index) const { 27 uint32_t GetOperand(int operand_index) const {
oth 2015/12/08 09:54:14 Propse adding MUST_USE_RESULT and DCHECK'ing in th
mythria 2015/12/08 11:24:42 The DCHECK is done when we call GetBytecode() from
27 Bytecode bytecode = GetBytecode(); 28 Bytecode bytecode = Bytecode::kLast;
29 CHECK(GetBytecode(&bytecode));
28 DCHECK_GE(operand_index, 0); 30 DCHECK_GE(operand_index, 0);
29 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode)); 31 DCHECK_LT(operand_index, Bytecodes::NumberOfOperands(bytecode));
30 size_t operand_offset = 32 size_t operand_offset =
31 array_builder_.last_bytecode_start_ + 33 array_builder_.last_bytecode_start_ +
32 Bytecodes::GetOperandOffset(bytecode, operand_index); 34 Bytecodes::GetOperandOffset(bytecode, operand_index);
33 OperandSize size = Bytecodes::GetOperandSize(bytecode, operand_index); 35 OperandSize size = Bytecodes::GetOperandSize(bytecode, operand_index);
34 switch (size) { 36 switch (size) {
35 default: 37 default:
36 case OperandSize::kNone: 38 case OperandSize::kNone:
37 UNREACHABLE(); 39 UNREACHABLE();
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 576
575 577
576 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) { 578 BytecodeArrayBuilder& BytecodeArrayBuilder::PopContext(Register context) {
577 Output(Bytecode::kPopContext, context.ToOperand()); 579 Output(Bytecode::kPopContext, context.ToOperand());
578 return *this; 580 return *this;
579 } 581 }
580 582
581 583
582 bool BytecodeArrayBuilder::NeedToBooleanCast() { 584 bool BytecodeArrayBuilder::NeedToBooleanCast() {
583 PreviousBytecodeHelper previous_bytecode(*this); 585 PreviousBytecodeHelper previous_bytecode(*this);
584 switch (previous_bytecode.GetBytecode()) { 586 Bytecode bytecode = Bytecode::kLast;
587 if (!previous_bytecode.GetBytecode(&bytecode)) {
588 return true;
589 }
590 switch (bytecode) {
585 case Bytecode::kToBoolean: 591 case Bytecode::kToBoolean:
586 UNREACHABLE(); 592 UNREACHABLE();
587 // If the previous bytecode puts a boolean in the accumulator return true. 593 // If the previous bytecode puts a boolean in the accumulator return true.
588 case Bytecode::kLdaTrue: 594 case Bytecode::kLdaTrue:
589 case Bytecode::kLdaFalse: 595 case Bytecode::kLdaFalse:
590 case Bytecode::kLogicalNot: 596 case Bytecode::kLogicalNot:
591 case Bytecode::kTestEqual: 597 case Bytecode::kTestEqual:
592 case Bytecode::kTestNotEqual: 598 case Bytecode::kTestNotEqual:
593 case Bytecode::kTestEqualStrict: 599 case Bytecode::kTestEqualStrict:
594 case Bytecode::kTestNotEqualStrict: 600 case Bytecode::kTestNotEqualStrict:
595 case Bytecode::kTestLessThan: 601 case Bytecode::kTestLessThan:
596 case Bytecode::kTestLessThanOrEqual: 602 case Bytecode::kTestLessThanOrEqual:
597 case Bytecode::kTestGreaterThan: 603 case Bytecode::kTestGreaterThan:
598 case Bytecode::kTestGreaterThanOrEqual: 604 case Bytecode::kTestGreaterThanOrEqual:
599 case Bytecode::kTestInstanceOf: 605 case Bytecode::kTestInstanceOf:
600 case Bytecode::kTestIn: 606 case Bytecode::kTestIn:
601 case Bytecode::kForInDone: 607 case Bytecode::kForInDone:
602 return false; 608 return false;
603 // Also handles the case where the previous bytecode was in a different
604 // block.
605 default: 609 default:
606 return true; 610 return true;
607 } 611 }
608 } 612 }
609 613
610 614
611 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() { 615 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() {
612 PreviousBytecodeHelper previous_bytecode(*this); 616 PreviousBytecodeHelper previous_bytecode(*this);
613 // If the previous bytecode puts a boolean in the accumulator 617 // If the previous bytecode puts a boolean in the accumulator
614 // there is no need to emit an instruction. 618 // there is no need to emit an instruction.
615 if (NeedToBooleanCast()) { 619 if (NeedToBooleanCast()) {
616 switch (previous_bytecode.GetBytecode()) { 620 Bytecode bytecode = Bytecode::kLast;
621 if (!previous_bytecode.GetBytecode(&bytecode)) {
622 Output(Bytecode::kToBoolean);
623 return *this;
624 }
625 switch (bytecode) {
617 // If the previous bytecode is a constant evaluate it and return false. 626 // If the previous bytecode is a constant evaluate it and return false.
618 case Bytecode::kLdaZero: { 627 case Bytecode::kLdaZero: {
619 LoadFalse(); 628 LoadFalse();
620 break; 629 break;
621 } 630 }
622 case Bytecode::kLdaSmi8: { 631 case Bytecode::kLdaSmi8: {
623 LoadBooleanConstant(previous_bytecode.GetOperand(0) != 0); 632 LoadBooleanConstant(previous_bytecode.GetOperand(0) != 0);
624 break; 633 break;
625 } 634 }
626 case Bytecode::kLdaConstant: { 635 case Bytecode::kLdaConstant: {
(...skipping 10 matching lines...) Expand all
637 646
638 647
639 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { 648 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() {
640 Output(Bytecode::kToObject); 649 Output(Bytecode::kToObject);
641 return *this; 650 return *this;
642 } 651 }
643 652
644 653
645 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { 654 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() {
646 PreviousBytecodeHelper previous_bytecode(*this); 655 PreviousBytecodeHelper previous_bytecode(*this);
647 switch (previous_bytecode.GetBytecode()) { 656 Bytecode bytecode = Bytecode::kLast;
657 if (!previous_bytecode.GetBytecode(&bytecode)) {
658 Output(Bytecode::kToName);
659 return *this;
660 }
661 switch (bytecode) {
662 case Bytecode::kToName:
663 case Bytecode::kTypeOf:
664 return *this;
648 case Bytecode::kLdaConstantWide: 665 case Bytecode::kLdaConstantWide:
649 case Bytecode::kLdaConstant: { 666 case Bytecode::kLdaConstant: {
650 Handle<Object> object = previous_bytecode.GetConstantForIndexOperand(0); 667 Handle<Object> object = previous_bytecode.GetConstantForIndexOperand(0);
651 if (object->IsName()) return *this; 668 if (object->IsName()) return *this;
652 break; 669 break;
653 } 670 }
654 case Bytecode::kToName:
655 case Bytecode::kTypeOf:
656 return *this;
657 default: 671 default:
658 break; 672 break;
659 } 673 }
660 Output(Bytecode::kToName); 674 Output(Bytecode::kToName);
661 return *this; 675 return *this;
662 } 676 }
663 677
664 678
665 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() { 679 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToNumber() {
666 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns 680 // TODO(rmcilroy): consider omitting if the preceeding bytecode always returns
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 1097
1084 1098
1085 bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const { 1099 bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const {
1086 return last_bytecode_start_ < bytecodes()->size() && 1100 return last_bytecode_start_ < bytecodes()->size() &&
1087 last_bytecode_start_ >= last_block_end_; 1101 last_bytecode_start_ >= last_block_end_;
1088 } 1102 }
1089 1103
1090 1104
1091 bool BytecodeArrayBuilder::IsRegisterInAccumulator(Register reg) { 1105 bool BytecodeArrayBuilder::IsRegisterInAccumulator(Register reg) {
1092 PreviousBytecodeHelper previous_bytecode(*this); 1106 PreviousBytecodeHelper previous_bytecode(*this);
1093 if (previous_bytecode.GetBytecode() == Bytecode::kLdar || 1107 Bytecode bytecode = Bytecode::kLast;
1094 previous_bytecode.GetBytecode() == Bytecode::kStar) { 1108 if (!previous_bytecode.GetBytecode(&bytecode)) {
1095 if (reg == Register::FromOperand(previous_bytecode.GetOperand(0))) { 1109 return false;
1096 return true; 1110 }
1097 } 1111 if ((bytecode == Bytecode::kLdar || bytecode == Bytecode::kStar) &&
1112 (reg == Register::FromOperand(previous_bytecode.GetOperand(0)))) {
1113 return true;
1098 } 1114 }
1099 return false; 1115 return false;
1100 } 1116 }
1101 1117
1102 1118
1103 // static 1119 // static
1104 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) { 1120 Bytecode BytecodeArrayBuilder::BytecodeForBinaryOperation(Token::Value op) {
1105 switch (op) { 1121 switch (op) {
1106 case Token::Value::ADD: 1122 case Token::Value::ADD:
1107 return Bytecode::kAdd; 1123 return Bytecode::kAdd;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 DCHECK_GT(next_consecutive_count_, 0); 1440 DCHECK_GT(next_consecutive_count_, 0);
1425 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); 1441 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_);
1426 allocated_.push_back(next_consecutive_register_); 1442 allocated_.push_back(next_consecutive_register_);
1427 next_consecutive_count_--; 1443 next_consecutive_count_--;
1428 return Register(next_consecutive_register_++); 1444 return Register(next_consecutive_register_++);
1429 } 1445 }
1430 1446
1431 } // namespace interpreter 1447 } // namespace interpreter
1432 } // namespace internal 1448 } // namespace internal
1433 } // namespace v8 1449 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698