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

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

Issue 1507683005: [Interpreter] Removes ToBoolean bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased the patch. 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 | « src/compiler/bytecode-graph-builder.cc ('k') | src/interpreter/bytecodes.h » ('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 #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
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 return *this; 586 return *this;
587 } 587 }
588 588
589 589
590 bool BytecodeArrayBuilder::NeedToBooleanCast() { 590 bool BytecodeArrayBuilder::NeedToBooleanCast() {
591 if (!LastBytecodeInSameBlock()) { 591 if (!LastBytecodeInSameBlock()) {
592 return true; 592 return true;
593 } 593 }
594 PreviousBytecodeHelper previous_bytecode(*this); 594 PreviousBytecodeHelper previous_bytecode(*this);
595 switch (previous_bytecode.GetBytecode()) { 595 switch (previous_bytecode.GetBytecode()) {
596 case Bytecode::kToBoolean:
597 UNREACHABLE();
598 // If the previous bytecode puts a boolean in the accumulator return true. 596 // If the previous bytecode puts a boolean in the accumulator return true.
599 case Bytecode::kLdaTrue: 597 case Bytecode::kLdaTrue:
600 case Bytecode::kLdaFalse: 598 case Bytecode::kLdaFalse:
601 case Bytecode::kLogicalNot: 599 case Bytecode::kLogicalNot:
602 case Bytecode::kTestEqual: 600 case Bytecode::kTestEqual:
603 case Bytecode::kTestNotEqual: 601 case Bytecode::kTestNotEqual:
604 case Bytecode::kTestEqualStrict: 602 case Bytecode::kTestEqualStrict:
605 case Bytecode::kTestNotEqualStrict: 603 case Bytecode::kTestNotEqualStrict:
606 case Bytecode::kTestLessThan: 604 case Bytecode::kTestLessThan:
607 case Bytecode::kTestLessThanOrEqual: 605 case Bytecode::kTestLessThanOrEqual:
608 case Bytecode::kTestGreaterThan: 606 case Bytecode::kTestGreaterThan:
609 case Bytecode::kTestGreaterThanOrEqual: 607 case Bytecode::kTestGreaterThanOrEqual:
610 case Bytecode::kTestInstanceOf: 608 case Bytecode::kTestInstanceOf:
611 case Bytecode::kTestIn: 609 case Bytecode::kTestIn:
612 case Bytecode::kForInDone: 610 case Bytecode::kForInDone:
613 return false; 611 return false;
614 default: 612 default:
615 return true; 613 return true;
616 } 614 }
617 } 615 }
618 616
619 617
620 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToBoolean() {
621 if (!LastBytecodeInSameBlock()) {
622 Output(Bytecode::kToBoolean);
623 return *this;
624 }
625 // If the previous bytecode puts a boolean in the accumulator
626 // there is no need to emit an instruction.
627 if (NeedToBooleanCast()) {
628 PreviousBytecodeHelper previous_bytecode(*this);
629 switch (previous_bytecode.GetBytecode()) {
630 // If the previous bytecode is a constant evaluate it and return false.
631 case Bytecode::kLdaZero: {
632 LoadFalse();
633 break;
634 }
635 case Bytecode::kLdaSmi8: {
636 LoadBooleanConstant(previous_bytecode.GetOperand(0) != 0);
637 break;
638 }
639 case Bytecode::kLdaConstant: {
640 Handle<Object> object = previous_bytecode.GetConstantForIndexOperand(0);
641 LoadBooleanConstant(object->BooleanValue());
642 break;
643 }
644 default:
645 Output(Bytecode::kToBoolean);
646 }
647 }
648 return *this;
649 }
650
651
652 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() { 618 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToJSObject() {
653 Output(Bytecode::kToObject); 619 Output(Bytecode::kToObject);
654 return *this; 620 return *this;
655 } 621 }
656 622
657 623
658 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() { 624 BytecodeArrayBuilder& BytecodeArrayBuilder::CastAccumulatorToName() {
659 if (LastBytecodeInSameBlock()) { 625 if (LastBytecodeInSameBlock()) {
660 PreviousBytecodeHelper previous_bytecode(*this); 626 PreviousBytecodeHelper previous_bytecode(*this);
661 switch (previous_bytecode.GetBytecode()) { 627 switch (previous_bytecode.GetBytecode()) {
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 DCHECK_GT(next_consecutive_count_, 0); 1406 DCHECK_GT(next_consecutive_count_, 0);
1441 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); 1407 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_);
1442 allocated_.push_back(next_consecutive_register_); 1408 allocated_.push_back(next_consecutive_register_);
1443 next_consecutive_count_--; 1409 next_consecutive_count_--;
1444 return Register(next_consecutive_register_++); 1410 return Register(next_consecutive_register_++);
1445 } 1411 }
1446 1412
1447 } // namespace interpreter 1413 } // namespace interpreter
1448 } // namespace internal 1414 } // namespace internal
1449 } // namespace v8 1415 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/bytecode-graph-builder.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698