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

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

Issue 1426913002: [Interpreter] Merges ToBoolean and JumpIfTrue/False bytecodes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Last patch was not complete. Forgot few changes. Created 5 years, 1 month 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 "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/control-flow-builders.h" 8 #include "src/interpreter/control-flow-builders.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 489
490 490
491 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { 491 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) {
492 // TODO(oth): Spot easy cases where there code would not need to 492 // TODO(oth): Spot easy cases where there code would not need to
493 // emit the then block or the else block, e.g. condition is 493 // emit the then block or the else block, e.g. condition is
494 // obviously true/1/false/0. 494 // obviously true/1/false/0.
495 495
496 BytecodeLabel else_label, end_label; 496 BytecodeLabel else_label, end_label;
497 497
498 VisitForAccumulatorValue(stmt->condition()); 498 VisitForAccumulatorValue(stmt->condition());
499 builder()->CastAccumulatorToBoolean();
500 builder()->JumpIfFalse(&else_label); 499 builder()->JumpIfFalse(&else_label);
501 Visit(stmt->then_statement()); 500 Visit(stmt->then_statement());
502 if (stmt->HasElseStatement()) { 501 if (stmt->HasElseStatement()) {
503 builder()->Jump(&end_label); 502 builder()->Jump(&end_label);
504 builder()->Bind(&else_label); 503 builder()->Bind(&else_label);
505 Visit(stmt->else_statement()); 504 Visit(stmt->else_statement());
506 } else { 505 } else {
507 builder()->Bind(&else_label); 506 builder()->Bind(&else_label);
508 } 507 }
509 builder()->Bind(&end_label); 508 builder()->Bind(&end_label);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 676
678 677
679 void BytecodeGenerator::VisitConditional(Conditional* expr) { 678 void BytecodeGenerator::VisitConditional(Conditional* expr) {
680 // TODO(rmcilroy): Spot easy cases where there code would not need to 679 // TODO(rmcilroy): Spot easy cases where there code would not need to
681 // emit the then block or the else block, e.g. condition is 680 // emit the then block or the else block, e.g. condition is
682 // obviously true/1/false/0. 681 // obviously true/1/false/0.
683 682
684 BytecodeLabel else_label, end_label; 683 BytecodeLabel else_label, end_label;
685 684
686 VisitForAccumulatorValue(expr->condition()); 685 VisitForAccumulatorValue(expr->condition());
687 builder()->CastAccumulatorToBoolean();
688 builder()->JumpIfFalse(&else_label); 686 builder()->JumpIfFalse(&else_label);
689 687
690 VisitForAccumulatorValue(expr->then_expression()); 688 VisitForAccumulatorValue(expr->then_expression());
691 builder()->Jump(&end_label); 689 builder()->Jump(&end_label);
692 690
693 builder()->Bind(&else_label); 691 builder()->Bind(&else_label);
694 VisitForAccumulatorValue(expr->else_expression()); 692 VisitForAccumulatorValue(expr->else_expression());
695 builder()->Bind(&end_label); 693 builder()->Bind(&end_label);
696 694
697 execution_result()->SetResultInAccumulator(); 695 execution_result()->SetResultInAccumulator();
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 Expression* left = binop->left(); 1676 Expression* left = binop->left();
1679 Expression* right = binop->right(); 1677 Expression* right = binop->right();
1680 1678
1681 // Short-circuit evaluation- If it is known that left is always true, 1679 // Short-circuit evaluation- If it is known that left is always true,
1682 // no need to visit right 1680 // no need to visit right
1683 if (left->ToBooleanIsTrue()) { 1681 if (left->ToBooleanIsTrue()) {
1684 VisitForAccumulatorValue(left); 1682 VisitForAccumulatorValue(left);
1685 } else { 1683 } else {
1686 BytecodeLabel end_label; 1684 BytecodeLabel end_label;
1687 VisitForAccumulatorValue(left); 1685 VisitForAccumulatorValue(left);
1688 builder()->JumpIfToBooleanTrue(&end_label); 1686 builder()->JumpIfTrue(&end_label);
1689 VisitForAccumulatorValue(right); 1687 VisitForAccumulatorValue(right);
1690 builder()->Bind(&end_label); 1688 builder()->Bind(&end_label);
1691 } 1689 }
1692 execution_result()->SetResultInAccumulator(); 1690 execution_result()->SetResultInAccumulator();
1693 } 1691 }
1694 1692
1695 1693
1696 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) { 1694 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) {
1697 Expression* left = binop->left(); 1695 Expression* left = binop->left();
1698 Expression* right = binop->right(); 1696 Expression* right = binop->right();
1699 1697
1700 // Short-circuit evaluation- If it is known that left is always false, 1698 // Short-circuit evaluation- If it is known that left is always false,
1701 // no need to visit right 1699 // no need to visit right
1702 if (left->ToBooleanIsFalse()) { 1700 if (left->ToBooleanIsFalse()) {
1703 VisitForAccumulatorValue(left); 1701 VisitForAccumulatorValue(left);
1704 } else { 1702 } else {
1705 BytecodeLabel end_label; 1703 BytecodeLabel end_label;
1706 VisitForAccumulatorValue(left); 1704 VisitForAccumulatorValue(left);
1707 builder()->JumpIfToBooleanFalse(&end_label); 1705 builder()->JumpIfFalse(&end_label);
1708 VisitForAccumulatorValue(right); 1706 VisitForAccumulatorValue(right);
1709 builder()->Bind(&end_label); 1707 builder()->Bind(&end_label);
1710 } 1708 }
1711 execution_result()->SetResultInAccumulator(); 1709 execution_result()->SetResultInAccumulator();
1712 } 1710 }
1713 1711
1714 1712
1715 void BytecodeGenerator::VisitNewLocalFunctionContext() { 1713 void BytecodeGenerator::VisitNewLocalFunctionContext() {
1716 AccumulatorResultScope accumulator_execution_result(this); 1714 AccumulatorResultScope accumulator_execution_result(this);
1717 Scope* scope = this->scope(); 1715 Scope* scope = this->scope();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 } 1945 }
1948 1946
1949 1947
1950 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 1948 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
1951 return info()->feedback_vector()->GetIndex(slot); 1949 return info()->feedback_vector()->GetIndex(slot);
1952 } 1950 }
1953 1951
1954 } // namespace interpreter 1952 } // namespace interpreter
1955 } // namespace internal 1953 } // namespace internal
1956 } // namespace v8 1954 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698