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

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

Issue 2793923002: [Interpreter] Optimize code of the form 'if (x === undefined)'. (Closed)
Patch Set: Rebase Created 3 years, 8 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
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-peephole-optimizer.cc » ('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-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/compile-time-value.h" 7 #include "src/ast/compile-time-value.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/builtins/builtins-constructor.h" 9 #include "src/builtins/builtins-constructor.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after
3033 break; 3033 break;
3034 case Token::AND: 3034 case Token::AND:
3035 VisitLogicalAndExpression(binop); 3035 VisitLogicalAndExpression(binop);
3036 break; 3036 break;
3037 default: 3037 default:
3038 VisitArithmeticExpression(binop); 3038 VisitArithmeticExpression(binop);
3039 break; 3039 break;
3040 } 3040 }
3041 } 3041 }
3042 3042
3043 void BytecodeGenerator::BuildLiteralCompareNil(Token::Value op, NilValue nil) {
3044 if (execution_result()->IsTest()) {
3045 TestResultScope* test_result = execution_result()->AsTest();
3046 switch (test_result->fallthrough()) {
3047 case TestFallthrough::kThen:
3048 builder()->JumpIfNotNil(test_result->NewElseLabel(), op, nil);
3049 break;
3050 case TestFallthrough::kElse:
3051 builder()->JumpIfNil(test_result->NewThenLabel(), op, nil);
3052 break;
3053 case TestFallthrough::kNone:
3054 builder()
3055 ->JumpIfNil(test_result->NewThenLabel(), op, nil)
3056 .Jump(test_result->NewElseLabel());
3057 }
3058 test_result->SetResultConsumedByTest();
3059 } else {
3060 builder()->CompareNil(op, nil);
3061 }
3062 }
3063
3043 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { 3064 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) {
3044 // Emit a fast literal comparion for expressions of the form: 3065 Expression* sub_expr;
3045 // typeof(x) === 'string'.
3046 Expression* typeof_sub_expr;
3047 Literal* literal; 3066 Literal* literal;
3048 if (expr->IsLiteralCompareTypeof(&typeof_sub_expr, &literal)) { 3067 if (expr->IsLiteralCompareTypeof(&sub_expr, &literal)) {
3049 VisitForTypeOfValue(typeof_sub_expr); 3068 // Emit a fast literal comparion for expressions of the form:
3069 // typeof(x) === 'string'.
3070 VisitForTypeOfValue(sub_expr);
3050 builder()->SetExpressionPosition(expr); 3071 builder()->SetExpressionPosition(expr);
3051 TestTypeOfFlags::LiteralFlag literal_flag = 3072 TestTypeOfFlags::LiteralFlag literal_flag =
3052 TestTypeOfFlags::GetFlagForLiteral(ast_string_constants(), literal); 3073 TestTypeOfFlags::GetFlagForLiteral(ast_string_constants(), literal);
3053 if (literal_flag == TestTypeOfFlags::LiteralFlag::kOther) { 3074 if (literal_flag == TestTypeOfFlags::LiteralFlag::kOther) {
3054 builder()->LoadFalse(); 3075 builder()->LoadFalse();
3055 } else { 3076 } else {
3056 builder()->CompareTypeOf(literal_flag); 3077 builder()->CompareTypeOf(literal_flag);
3057 } 3078 }
3079 } else if (expr->IsLiteralCompareUndefined(&sub_expr)) {
3080 VisitForAccumulatorValue(sub_expr);
3081 builder()->SetExpressionPosition(expr);
3082 BuildLiteralCompareNil(expr->op(), kUndefinedValue);
3083 } else if (expr->IsLiteralCompareNull(&sub_expr)) {
3084 VisitForAccumulatorValue(sub_expr);
3085 builder()->SetExpressionPosition(expr);
3086 BuildLiteralCompareNil(expr->op(), kNullValue);
3058 } else { 3087 } else {
3059 Register lhs = VisitForRegisterValue(expr->left()); 3088 Register lhs = VisitForRegisterValue(expr->left());
3060 VisitForAccumulatorValue(expr->right()); 3089 VisitForAccumulatorValue(expr->right());
3061 builder()->SetExpressionPosition(expr); 3090 builder()->SetExpressionPosition(expr);
3062 FeedbackSlot slot = expr->CompareOperationFeedbackSlot(); 3091 FeedbackSlot slot = expr->CompareOperationFeedbackSlot();
3063 if (slot.IsInvalid()) { 3092 if (slot.IsInvalid()) {
3064 builder()->CompareOperation(expr->op(), lhs); 3093 builder()->CompareOperation(expr->op(), lhs);
3065 } else { 3094 } else {
3066 builder()->CompareOperation(expr->op(), lhs, feedback_index(slot)); 3095 builder()->CompareOperation(expr->op(), lhs, feedback_index(slot));
3067 } 3096 }
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
3566 } 3595 }
3567 3596
3568 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { 3597 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() {
3569 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict 3598 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
3570 : Runtime::kStoreKeyedToSuper_Sloppy; 3599 : Runtime::kStoreKeyedToSuper_Sloppy;
3571 } 3600 }
3572 3601
3573 } // namespace interpreter 3602 } // namespace interpreter
3574 } // namespace internal 3603 } // namespace internal
3575 } // namespace v8 3604 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-peephole-optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698