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

Side by Side Diff: src/interpreter/interpreter.cc

Issue 2372113004: [turbofan] JSGenericLowering mostly uses builtins instead of code stubs now (Closed)
Patch Set: Ross' comments Created 4 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
« no previous file with comments | « src/interpreter/interpreter.h ('k') | 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/interpreter.h" 5 #include "src/interpreter/interpreter.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 // PopContext <context> 897 // PopContext <context>
898 // 898 //
899 // Pops the current context and sets <context> as the new context. 899 // Pops the current context and sets <context> as the new context.
900 void Interpreter::DoPopContext(InterpreterAssembler* assembler) { 900 void Interpreter::DoPopContext(InterpreterAssembler* assembler) {
901 Node* reg_index = __ BytecodeOperandReg(0); 901 Node* reg_index = __ BytecodeOperandReg(0);
902 Node* context = __ LoadRegister(reg_index); 902 Node* context = __ LoadRegister(reg_index);
903 __ SetContext(context); 903 __ SetContext(context);
904 __ Dispatch(); 904 __ Dispatch();
905 } 905 }
906 906
907 // TODO(mythria): Remove this function once all BinaryOps record type feedback. 907 // TODO(mythria): Remove this function once all CompareOps record type feedback.
908 template <class Generator> 908 void Interpreter::DoCompareOp(Token::Value compare_op,
909 void Interpreter::DoBinaryOp(InterpreterAssembler* assembler) { 909 InterpreterAssembler* assembler) {
910 Node* reg_index = __ BytecodeOperandReg(0); 910 Node* reg_index = __ BytecodeOperandReg(0);
911 Node* lhs = __ LoadRegister(reg_index); 911 Node* lhs = __ LoadRegister(reg_index);
912 Node* rhs = __ GetAccumulator(); 912 Node* rhs = __ GetAccumulator();
913 Node* context = __ GetContext(); 913 Node* context = __ GetContext();
914 Node* result = Generator::Generate(assembler, lhs, rhs, context); 914 Node* result;
915 switch (compare_op) {
916 case Token::IN:
917 result = assembler->HasProperty(rhs, lhs, context);
918 break;
919 case Token::INSTANCEOF:
920 result = assembler->InstanceOf(lhs, rhs, context);
921 break;
922 default:
923 UNREACHABLE();
924 }
915 __ SetAccumulator(result); 925 __ SetAccumulator(result);
916 __ Dispatch(); 926 __ Dispatch();
917 } 927 }
918 928
919 template <class Generator> 929 template <class Generator>
920 void Interpreter::DoBinaryOpWithFeedback(InterpreterAssembler* assembler) { 930 void Interpreter::DoBinaryOpWithFeedback(InterpreterAssembler* assembler) {
921 Node* reg_index = __ BytecodeOperandReg(0); 931 Node* reg_index = __ BytecodeOperandReg(0);
922 Node* lhs = __ LoadRegister(reg_index); 932 Node* lhs = __ LoadRegister(reg_index);
923 Node* rhs = __ GetAccumulator(); 933 Node* rhs = __ GetAccumulator();
924 Node* context = __ GetContext(); 934 Node* context = __ GetContext();
925 Node* slot_index = __ BytecodeOperandIdx(1); 935 Node* slot_index = __ BytecodeOperandIdx(1);
926 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); 936 Node* type_feedback_vector = __ LoadTypeFeedbackVector();
927 Node* result = Generator::Generate(assembler, lhs, rhs, slot_index, 937 Node* result = Generator::Generate(assembler, lhs, rhs, slot_index,
928 type_feedback_vector, context); 938 type_feedback_vector, context);
929 __ SetAccumulator(result); 939 __ SetAccumulator(result);
930 __ Dispatch(); 940 __ Dispatch();
931 } 941 }
932 942
933 template <class Generator> 943 void Interpreter::DoCompareOpWithFeedback(Token::Value compare_op,
934 void Interpreter::DoCompareOpWithFeedback(InterpreterAssembler* assembler) { 944 InterpreterAssembler* assembler) {
935 Node* reg_index = __ BytecodeOperandReg(0); 945 Node* reg_index = __ BytecodeOperandReg(0);
936 Node* lhs = __ LoadRegister(reg_index); 946 Node* lhs = __ LoadRegister(reg_index);
937 Node* rhs = __ GetAccumulator(); 947 Node* rhs = __ GetAccumulator();
938 Node* context = __ GetContext(); 948 Node* context = __ GetContext();
939 Node* slot_index = __ BytecodeOperandIdx(1); 949 Node* slot_index = __ BytecodeOperandIdx(1);
940 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); 950 Node* type_feedback_vector = __ LoadTypeFeedbackVector();
941 951
942 // TODO(interpreter): the only reason this check is here is because we 952 // TODO(interpreter): the only reason this check is here is because we
943 // sometimes emit comparisons that shouldn't collect feedback (e.g. 953 // sometimes emit comparisons that shouldn't collect feedback (e.g.
944 // try-finally blocks and generators), and we could get rid of this by 954 // try-finally blocks and generators), and we could get rid of this by
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 __ Int32Constant(CompareOperationFeedback::kSignedSmall))); 1002 __ Int32Constant(CompareOperationFeedback::kSignedSmall)));
993 __ Goto(&do_compare); 1003 __ Goto(&do_compare);
994 } 1004 }
995 1005
996 __ Bind(&do_compare); 1006 __ Bind(&do_compare);
997 __ UpdateFeedback(var_type_feedback.value(), type_feedback_vector, 1007 __ UpdateFeedback(var_type_feedback.value(), type_feedback_vector,
998 slot_index); 1008 slot_index);
999 __ Goto(&skip_feedback_update); 1009 __ Goto(&skip_feedback_update);
1000 1010
1001 __ Bind(&skip_feedback_update); 1011 __ Bind(&skip_feedback_update);
1002 Node* result = Generator::Generate(assembler, lhs, rhs, context); 1012 Node* result;
1013 switch (compare_op) {
1014 case Token::EQ:
1015 result = assembler->Equal(CodeStubAssembler::kDontNegateResult, lhs, rhs,
1016 context);
1017 break;
1018 case Token::NE:
1019 result =
1020 assembler->Equal(CodeStubAssembler::kNegateResult, lhs, rhs, context);
1021 break;
1022 case Token::EQ_STRICT:
1023 result = assembler->StrictEqual(CodeStubAssembler::kDontNegateResult, lhs,
1024 rhs, context);
1025 break;
1026 case Token::LT:
1027 result = assembler->RelationalComparison(CodeStubAssembler::kLessThan,
1028 lhs, rhs, context);
1029 break;
1030 case Token::GT:
1031 result = assembler->RelationalComparison(CodeStubAssembler::kGreaterThan,
1032 lhs, rhs, context);
1033 break;
1034 case Token::LTE:
1035 result = assembler->RelationalComparison(
1036 CodeStubAssembler::kLessThanOrEqual, lhs, rhs, context);
1037 break;
1038 case Token::GTE:
1039 result = assembler->RelationalComparison(
1040 CodeStubAssembler::kGreaterThanOrEqual, lhs, rhs, context);
1041 break;
1042 default:
1043 UNREACHABLE();
1044 }
1003 __ SetAccumulator(result); 1045 __ SetAccumulator(result);
1004 __ Dispatch(); 1046 __ Dispatch();
1005 } 1047 }
1006 1048
1007 // Add <src> 1049 // Add <src>
1008 // 1050 //
1009 // Add register <src> to accumulator. 1051 // Add register <src> to accumulator.
1010 void Interpreter::DoAdd(InterpreterAssembler* assembler) { 1052 void Interpreter::DoAdd(InterpreterAssembler* assembler) {
1011 DoBinaryOpWithFeedback<AddWithFeedbackStub>(assembler); 1053 DoBinaryOpWithFeedback<AddWithFeedbackStub>(assembler);
1012 } 1054 }
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 1428
1387 Node* Interpreter::BuildUnaryOp(Callable callable, 1429 Node* Interpreter::BuildUnaryOp(Callable callable,
1388 InterpreterAssembler* assembler) { 1430 InterpreterAssembler* assembler) {
1389 Node* target = __ HeapConstant(callable.code()); 1431 Node* target = __ HeapConstant(callable.code());
1390 Node* accumulator = __ GetAccumulator(); 1432 Node* accumulator = __ GetAccumulator();
1391 Node* context = __ GetContext(); 1433 Node* context = __ GetContext();
1392 return __ CallStub(callable.descriptor(), target, context, accumulator); 1434 return __ CallStub(callable.descriptor(), target, context, accumulator);
1393 } 1435 }
1394 1436
1395 template <class Generator> 1437 template <class Generator>
1396 void Interpreter::DoUnaryOp(InterpreterAssembler* assembler) {
1397 Node* value = __ GetAccumulator();
1398 Node* context = __ GetContext();
1399 Node* result = Generator::Generate(assembler, value, context);
1400 __ SetAccumulator(result);
1401 __ Dispatch();
1402 }
1403
1404 template <class Generator>
1405 void Interpreter::DoUnaryOpWithFeedback(InterpreterAssembler* assembler) { 1438 void Interpreter::DoUnaryOpWithFeedback(InterpreterAssembler* assembler) {
1406 Node* value = __ GetAccumulator(); 1439 Node* value = __ GetAccumulator();
1407 Node* context = __ GetContext(); 1440 Node* context = __ GetContext();
1408 Node* slot_index = __ BytecodeOperandIdx(0); 1441 Node* slot_index = __ BytecodeOperandIdx(0);
1409 Node* type_feedback_vector = __ LoadTypeFeedbackVector(); 1442 Node* type_feedback_vector = __ LoadTypeFeedbackVector();
1410 Node* result = Generator::Generate(assembler, value, context, 1443 Node* result = Generator::Generate(assembler, value, context,
1411 type_feedback_vector, slot_index); 1444 type_feedback_vector, slot_index);
1412 __ SetAccumulator(result); 1445 __ SetAccumulator(result);
1413 __ Dispatch(); 1446 __ Dispatch();
1414 } 1447 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 __ Bind(&end); 1546 __ Bind(&end);
1514 __ SetAccumulator(result.value()); 1547 __ SetAccumulator(result.value());
1515 __ Dispatch(); 1548 __ Dispatch();
1516 } 1549 }
1517 1550
1518 // TypeOf 1551 // TypeOf
1519 // 1552 //
1520 // Load the accumulator with the string representating type of the 1553 // Load the accumulator with the string representating type of the
1521 // object in the accumulator. 1554 // object in the accumulator.
1522 void Interpreter::DoTypeOf(InterpreterAssembler* assembler) { 1555 void Interpreter::DoTypeOf(InterpreterAssembler* assembler) {
1523 DoUnaryOp<TypeofStub>(assembler); 1556 Node* value = __ GetAccumulator();
1557 Node* context = __ GetContext();
1558 Node* result = assembler->Typeof(value, context);
1559 __ SetAccumulator(result);
1560 __ Dispatch();
1524 } 1561 }
1525 1562
1526 void Interpreter::DoDelete(Runtime::FunctionId function_id, 1563 void Interpreter::DoDelete(Runtime::FunctionId function_id,
1527 InterpreterAssembler* assembler) { 1564 InterpreterAssembler* assembler) {
1528 Node* reg_index = __ BytecodeOperandReg(0); 1565 Node* reg_index = __ BytecodeOperandReg(0);
1529 Node* object = __ LoadRegister(reg_index); 1566 Node* object = __ LoadRegister(reg_index);
1530 Node* key = __ GetAccumulator(); 1567 Node* key = __ GetAccumulator();
1531 Node* context = __ GetContext(); 1568 Node* context = __ GetContext();
1532 Node* result = __ CallRuntime(function_id, context, object, key); 1569 Node* result = __ CallRuntime(function_id, context, object, key);
1533 __ SetAccumulator(result); 1570 __ SetAccumulator(result);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 Node* result = __ CallConstruct(constructor, context, new_target, first_arg, 1728 Node* result = __ CallConstruct(constructor, context, new_target, first_arg,
1692 args_count, slot_id, type_feedback_vector); 1729 args_count, slot_id, type_feedback_vector);
1693 __ SetAccumulator(result); 1730 __ SetAccumulator(result);
1694 __ Dispatch(); 1731 __ Dispatch();
1695 } 1732 }
1696 1733
1697 // TestEqual <src> 1734 // TestEqual <src>
1698 // 1735 //
1699 // Test if the value in the <src> register equals the accumulator. 1736 // Test if the value in the <src> register equals the accumulator.
1700 void Interpreter::DoTestEqual(InterpreterAssembler* assembler) { 1737 void Interpreter::DoTestEqual(InterpreterAssembler* assembler) {
1701 DoCompareOpWithFeedback<EqualStub>(assembler); 1738 DoCompareOpWithFeedback(Token::Value::EQ, assembler);
1702 } 1739 }
1703 1740
1704 // TestNotEqual <src> 1741 // TestNotEqual <src>
1705 // 1742 //
1706 // Test if the value in the <src> register is not equal to the accumulator. 1743 // Test if the value in the <src> register is not equal to the accumulator.
1707 void Interpreter::DoTestNotEqual(InterpreterAssembler* assembler) { 1744 void Interpreter::DoTestNotEqual(InterpreterAssembler* assembler) {
1708 DoCompareOpWithFeedback<NotEqualStub>(assembler); 1745 DoCompareOpWithFeedback(Token::Value::NE, assembler);
1709 } 1746 }
1710 1747
1711 // TestEqualStrict <src> 1748 // TestEqualStrict <src>
1712 // 1749 //
1713 // Test if the value in the <src> register is strictly equal to the accumulator. 1750 // Test if the value in the <src> register is strictly equal to the accumulator.
1714 void Interpreter::DoTestEqualStrict(InterpreterAssembler* assembler) { 1751 void Interpreter::DoTestEqualStrict(InterpreterAssembler* assembler) {
1715 DoCompareOpWithFeedback<StrictEqualStub>(assembler); 1752 DoCompareOpWithFeedback(Token::Value::EQ_STRICT, assembler);
1716 } 1753 }
1717 1754
1718 // TestLessThan <src> 1755 // TestLessThan <src>
1719 // 1756 //
1720 // Test if the value in the <src> register is less than the accumulator. 1757 // Test if the value in the <src> register is less than the accumulator.
1721 void Interpreter::DoTestLessThan(InterpreterAssembler* assembler) { 1758 void Interpreter::DoTestLessThan(InterpreterAssembler* assembler) {
1722 DoCompareOpWithFeedback<LessThanStub>(assembler); 1759 DoCompareOpWithFeedback(Token::Value::LT, assembler);
1723 } 1760 }
1724 1761
1725 // TestGreaterThan <src> 1762 // TestGreaterThan <src>
1726 // 1763 //
1727 // Test if the value in the <src> register is greater than the accumulator. 1764 // Test if the value in the <src> register is greater than the accumulator.
1728 void Interpreter::DoTestGreaterThan(InterpreterAssembler* assembler) { 1765 void Interpreter::DoTestGreaterThan(InterpreterAssembler* assembler) {
1729 DoCompareOpWithFeedback<GreaterThanStub>(assembler); 1766 DoCompareOpWithFeedback(Token::Value::GT, assembler);
1730 } 1767 }
1731 1768
1732 // TestLessThanOrEqual <src> 1769 // TestLessThanOrEqual <src>
1733 // 1770 //
1734 // Test if the value in the <src> register is less than or equal to the 1771 // Test if the value in the <src> register is less than or equal to the
1735 // accumulator. 1772 // accumulator.
1736 void Interpreter::DoTestLessThanOrEqual(InterpreterAssembler* assembler) { 1773 void Interpreter::DoTestLessThanOrEqual(InterpreterAssembler* assembler) {
1737 DoCompareOpWithFeedback<LessThanOrEqualStub>(assembler); 1774 DoCompareOpWithFeedback(Token::Value::LTE, assembler);
1738 } 1775 }
1739 1776
1740 // TestGreaterThanOrEqual <src> 1777 // TestGreaterThanOrEqual <src>
1741 // 1778 //
1742 // Test if the value in the <src> register is greater than or equal to the 1779 // Test if the value in the <src> register is greater than or equal to the
1743 // accumulator. 1780 // accumulator.
1744 void Interpreter::DoTestGreaterThanOrEqual(InterpreterAssembler* assembler) { 1781 void Interpreter::DoTestGreaterThanOrEqual(InterpreterAssembler* assembler) {
1745 DoCompareOpWithFeedback<GreaterThanOrEqualStub>(assembler); 1782 DoCompareOpWithFeedback(Token::Value::GTE, assembler);
1746 } 1783 }
1747 1784
1748 // TestIn <src> 1785 // TestIn <src>
1749 // 1786 //
1750 // Test if the object referenced by the register operand is a property of the 1787 // Test if the object referenced by the register operand is a property of the
1751 // object referenced by the accumulator. 1788 // object referenced by the accumulator.
1752 void Interpreter::DoTestIn(InterpreterAssembler* assembler) { 1789 void Interpreter::DoTestIn(InterpreterAssembler* assembler) {
1753 DoBinaryOp<HasPropertyStub>(assembler); 1790 DoCompareOp(Token::IN, assembler);
1754 } 1791 }
1755 1792
1756 // TestInstanceOf <src> 1793 // TestInstanceOf <src>
1757 // 1794 //
1758 // Test if the object referenced by the <src> register is an an instance of type 1795 // Test if the object referenced by the <src> register is an an instance of type
1759 // referenced by the accumulator. 1796 // referenced by the accumulator.
1760 void Interpreter::DoTestInstanceOf(InterpreterAssembler* assembler) { 1797 void Interpreter::DoTestInstanceOf(InterpreterAssembler* assembler) {
1761 DoBinaryOp<InstanceOfStub>(assembler); 1798 DoCompareOp(Token::INSTANCEOF, assembler);
1762 } 1799 }
1763 1800
1764 // Jump <imm> 1801 // Jump <imm>
1765 // 1802 //
1766 // Jump by number of bytes represented by the immediate operand |imm|. 1803 // Jump by number of bytes represented by the immediate operand |imm|.
1767 void Interpreter::DoJump(InterpreterAssembler* assembler) { 1804 void Interpreter::DoJump(InterpreterAssembler* assembler) {
1768 Node* relative_jump = __ BytecodeOperandImm(0); 1805 Node* relative_jump = __ BytecodeOperandImm(0);
1769 __ Jump(relative_jump); 1806 __ Jump(relative_jump);
1770 } 1807 }
1771 1808
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, 2635 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset,
2599 __ SmiTag(new_state)); 2636 __ SmiTag(new_state));
2600 __ SetAccumulator(old_state); 2637 __ SetAccumulator(old_state);
2601 2638
2602 __ Dispatch(); 2639 __ Dispatch();
2603 } 2640 }
2604 2641
2605 } // namespace interpreter 2642 } // namespace interpreter
2606 } // namespace internal 2643 } // namespace internal
2607 } // namespace v8 2644 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698