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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1399773002: [Interpreter] Adds logical and, logical or and comma operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a new bytecode to jump by casting the value to boolean. This reduces code size for logical op… Created 5 years, 2 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/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/interpreter/control-flow-builders.h" 10 #include "src/interpreter/control-flow-builders.h"
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 833
834 834
835 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { 835 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
836 UNIMPLEMENTED(); 836 UNIMPLEMENTED();
837 } 837 }
838 838
839 839
840 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) { 840 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) {
841 switch (binop->op()) { 841 switch (binop->op()) {
842 case Token::COMMA: 842 case Token::COMMA:
843 VisitCommaExpression(binop);
844 break;
843 case Token::OR: 845 case Token::OR:
846 VisitLogicalOrExpression(binop);
847 break;
844 case Token::AND: 848 case Token::AND:
845 UNIMPLEMENTED(); 849 VisitLogicalAndExpression(binop);
846 break; 850 break;
847 default: 851 default:
848 VisitArithmeticExpression(binop); 852 VisitArithmeticExpression(binop);
849 break; 853 break;
850 } 854 }
851 } 855 }
852 856
853 857
854 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { 858 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) {
855 Token::Value op = expr->op(); 859 Token::Value op = expr->op();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 TemporaryRegisterScope temporary_register_scope(builder()); 937 TemporaryRegisterScope temporary_register_scope(builder());
934 Register temporary = temporary_register_scope.NewRegister(); 938 Register temporary = temporary_register_scope.NewRegister();
935 939
936 Visit(left); 940 Visit(left);
937 builder()->StoreAccumulatorInRegister(temporary); 941 builder()->StoreAccumulatorInRegister(temporary);
938 Visit(right); 942 Visit(right);
939 builder()->BinaryOperation(op, temporary, language_mode_strength()); 943 builder()->BinaryOperation(op, temporary, language_mode_strength());
940 } 944 }
941 945
942 946
947 void BytecodeGenerator::VisitCommaExpression(BinaryOperation* binop) {
948 Expression* left = binop->left();
949 Expression* right = binop->right();
950
951 Visit(left);
952 Visit(right);
953 }
954
955
956 void BytecodeGenerator::VisitLogicalOrExpression(BinaryOperation* binop) {
957 Expression* left = binop->left();
958 Expression* right = binop->right();
959
960 // Short-circuit evaluation- If it is known that left is always true,
961 // no need to visit right
962 if (left->ToBooleanIsTrue()) {
963 Visit(left);
964 } else {
965 BytecodeLabel end_label;
966
967 Visit(left);
968 builder()->JumpIfToBooleanTrue(&end_label);
969 Visit(right);
970 builder()->Bind(&end_label);
971 }
972 }
973
974
975 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) {
976 Expression* left = binop->left();
977 Expression* right = binop->right();
978
979 // Short-circuit evaluation- If it is known that left is always false,
980 // no need to visit right
981 if (left->ToBooleanIsFalse()) {
982 Visit(left);
983 } else {
984 BytecodeLabel end_label;
985
986 Visit(left);
987 builder()->JumpIfToBooleanFalse(&end_label);
988 Visit(right);
989 builder()->Bind(&end_label);
990 }
991 }
992
993
943 LanguageMode BytecodeGenerator::language_mode() const { 994 LanguageMode BytecodeGenerator::language_mode() const {
944 return info()->language_mode(); 995 return info()->language_mode();
945 } 996 }
946 997
947 998
948 Strength BytecodeGenerator::language_mode_strength() const { 999 Strength BytecodeGenerator::language_mode_strength() const {
949 return strength(language_mode()); 1000 return strength(language_mode());
950 } 1001 }
951 1002
952 1003
953 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 1004 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
954 return info()->feedback_vector()->GetIndex(slot); 1005 return info()->feedback_vector()->GetIndex(slot);
955 } 1006 }
956 1007
957 } // namespace interpreter 1008 } // namespace interpreter
958 } // namespace internal 1009 } // namespace internal
959 } // namespace v8 1010 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698