OLD | NEW |
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 #include "src/compiler.h" | 6 #include "src/compiler.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace interpreter { | 10 namespace interpreter { |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 } | 1052 } |
1053 | 1053 |
1054 void BytecodeArrayBuilder::EnsureReturn(FunctionLiteral* literal) { | 1054 void BytecodeArrayBuilder::EnsureReturn(FunctionLiteral* literal) { |
1055 if (!exit_seen_in_block_) { | 1055 if (!exit_seen_in_block_) { |
1056 LoadUndefined(); | 1056 LoadUndefined(); |
1057 SetReturnPosition(literal); | 1057 SetReturnPosition(literal); |
1058 Return(); | 1058 Return(); |
1059 } | 1059 } |
1060 } | 1060 } |
1061 | 1061 |
1062 BytecodeArrayBuilder& BytecodeArrayBuilder::CallIC( | 1062 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, |
1063 Register callable, Register receiver_args, size_t receiver_args_count, | 1063 Register receiver_args, |
1064 int feedback_slot, TailCallMode tail_call_mode) { | 1064 size_t receiver_args_count, |
1065 Bytecode bytecode = BytecodeForCallIC(tail_call_mode); | 1065 int feedback_slot, |
| 1066 TailCallMode tail_call_mode) { |
| 1067 Bytecode bytecode = BytecodeForCall(tail_call_mode); |
1066 if (FitsInReg8Operand(callable) && FitsInReg8Operand(receiver_args) && | 1068 if (FitsInReg8Operand(callable) && FitsInReg8Operand(receiver_args) && |
1067 FitsInIdx8Operand(receiver_args_count) && | 1069 FitsInIdx8Operand(receiver_args_count) && |
1068 FitsInIdx8Operand(feedback_slot)) { | 1070 FitsInIdx8Operand(feedback_slot)) { |
1069 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), | 1071 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), |
1070 static_cast<uint8_t>(receiver_args_count), | 1072 static_cast<uint8_t>(receiver_args_count), |
1071 static_cast<uint8_t>(feedback_slot)); | 1073 static_cast<uint8_t>(feedback_slot)); |
1072 } else if (FitsInReg16Operand(callable) && | 1074 } else if (FitsInReg16Operand(callable) && |
1073 FitsInReg16Operand(receiver_args) && | 1075 FitsInReg16Operand(receiver_args) && |
1074 FitsInIdx16Operand(receiver_args_count) && | 1076 FitsInIdx16Operand(receiver_args_count) && |
1075 FitsInIdx16Operand(feedback_slot)) { | 1077 FitsInIdx16Operand(feedback_slot)) { |
1076 bytecode = BytecodeForWideOperands(bytecode); | 1078 bytecode = BytecodeForWideOperands(bytecode); |
1077 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), | 1079 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), |
1078 static_cast<uint16_t>(receiver_args_count), | 1080 static_cast<uint16_t>(receiver_args_count), |
1079 static_cast<uint16_t>(feedback_slot)); | 1081 static_cast<uint16_t>(feedback_slot)); |
1080 } else { | 1082 } else { |
1081 UNIMPLEMENTED(); | 1083 UNIMPLEMENTED(); |
1082 } | 1084 } |
1083 return *this; | 1085 return *this; |
1084 } | 1086 } |
1085 | 1087 |
1086 BytecodeArrayBuilder& BytecodeArrayBuilder::Call(Register callable, | |
1087 Register receiver_args, | |
1088 size_t receiver_args_count, | |
1089 TailCallMode tail_call_mode) { | |
1090 Bytecode bytecode = BytecodeForCall(tail_call_mode); | |
1091 if (FitsInReg8Operand(callable) && FitsInReg8Operand(receiver_args) && | |
1092 FitsInIdx8Operand(receiver_args_count)) { | |
1093 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), | |
1094 static_cast<uint8_t>(receiver_args_count)); | |
1095 } else if (FitsInReg16Operand(callable) && | |
1096 FitsInReg16Operand(receiver_args) && | |
1097 FitsInIdx16Operand(receiver_args_count)) { | |
1098 bytecode = BytecodeForWideOperands(bytecode); | |
1099 Output(bytecode, callable.ToRawOperand(), receiver_args.ToRawOperand(), | |
1100 static_cast<uint16_t>(receiver_args_count)); | |
1101 } else { | |
1102 UNIMPLEMENTED(); | |
1103 } | |
1104 return *this; | |
1105 } | |
1106 BytecodeArrayBuilder& BytecodeArrayBuilder::New(Register constructor, | 1088 BytecodeArrayBuilder& BytecodeArrayBuilder::New(Register constructor, |
1107 Register first_arg, | 1089 Register first_arg, |
1108 size_t arg_count) { | 1090 size_t arg_count) { |
1109 if (!first_arg.is_valid()) { | 1091 if (!first_arg.is_valid()) { |
1110 DCHECK_EQ(0u, arg_count); | 1092 DCHECK_EQ(0u, arg_count); |
1111 first_arg = Register(0); | 1093 first_arg = Register(0); |
1112 } | 1094 } |
1113 if (FitsInReg8Operand(constructor) && FitsInReg8Operand(first_arg) && | 1095 if (FitsInReg8Operand(constructor) && FitsInReg8Operand(first_arg) && |
1114 FitsInIdx8Operand(arg_count)) { | 1096 FitsInIdx8Operand(arg_count)) { |
1115 Output(Bytecode::kNew, constructor.ToRawOperand(), first_arg.ToRawOperand(), | 1097 Output(Bytecode::kNew, constructor.ToRawOperand(), first_arg.ToRawOperand(), |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 default: | 1419 default: |
1438 UNREACHABLE(); | 1420 UNREACHABLE(); |
1439 return static_cast<Bytecode>(-1); | 1421 return static_cast<Bytecode>(-1); |
1440 } | 1422 } |
1441 } | 1423 } |
1442 | 1424 |
1443 | 1425 |
1444 // static | 1426 // static |
1445 Bytecode BytecodeArrayBuilder::BytecodeForWideOperands(Bytecode bytecode) { | 1427 Bytecode BytecodeArrayBuilder::BytecodeForWideOperands(Bytecode bytecode) { |
1446 switch (bytecode) { | 1428 switch (bytecode) { |
1447 case Bytecode::kCallIC: | |
1448 return Bytecode::kCallICWide; | |
1449 case Bytecode::kTailCallIC: | |
1450 return Bytecode::kTailCallICWide; | |
1451 case Bytecode::kCall: | 1429 case Bytecode::kCall: |
1452 return Bytecode::kCallWide; | 1430 return Bytecode::kCallWide; |
1453 case Bytecode::kTailCall: | 1431 case Bytecode::kTailCall: |
1454 return Bytecode::kTailCallWide; | 1432 return Bytecode::kTailCallWide; |
1455 case Bytecode::kLoadIC: | 1433 case Bytecode::kLoadIC: |
1456 return Bytecode::kLoadICWide; | 1434 return Bytecode::kLoadICWide; |
1457 case Bytecode::kKeyedLoadIC: | 1435 case Bytecode::kKeyedLoadIC: |
1458 return Bytecode::kKeyedLoadICWide; | 1436 return Bytecode::kKeyedLoadICWide; |
1459 case Bytecode::kStoreICSloppy: | 1437 case Bytecode::kStoreICSloppy: |
1460 return Bytecode::kStoreICSloppyWide; | 1438 return Bytecode::kStoreICSloppyWide; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 return Bytecode::kDeletePropertyStrict; | 1563 return Bytecode::kDeletePropertyStrict; |
1586 case STRONG: | 1564 case STRONG: |
1587 UNIMPLEMENTED(); | 1565 UNIMPLEMENTED(); |
1588 default: | 1566 default: |
1589 UNREACHABLE(); | 1567 UNREACHABLE(); |
1590 } | 1568 } |
1591 return static_cast<Bytecode>(-1); | 1569 return static_cast<Bytecode>(-1); |
1592 } | 1570 } |
1593 | 1571 |
1594 // static | 1572 // static |
1595 Bytecode BytecodeArrayBuilder::BytecodeForCallIC(TailCallMode tail_call_mode) { | |
1596 switch (tail_call_mode) { | |
1597 case TailCallMode::kDisallow: | |
1598 return Bytecode::kCallIC; | |
1599 case TailCallMode::kAllow: | |
1600 return Bytecode::kTailCallIC; | |
1601 default: | |
1602 UNREACHABLE(); | |
1603 } | |
1604 return static_cast<Bytecode>(-1); | |
1605 } | |
1606 | |
1607 // static | |
1608 Bytecode BytecodeArrayBuilder::BytecodeForCall(TailCallMode tail_call_mode) { | 1573 Bytecode BytecodeArrayBuilder::BytecodeForCall(TailCallMode tail_call_mode) { |
1609 switch (tail_call_mode) { | 1574 switch (tail_call_mode) { |
1610 case TailCallMode::kDisallow: | 1575 case TailCallMode::kDisallow: |
1611 return Bytecode::kCall; | 1576 return Bytecode::kCall; |
1612 case TailCallMode::kAllow: | 1577 case TailCallMode::kAllow: |
1613 return Bytecode::kTailCall; | 1578 return Bytecode::kTailCall; |
1614 default: | 1579 default: |
1615 UNREACHABLE(); | 1580 UNREACHABLE(); |
1616 } | 1581 } |
1617 return static_cast<Bytecode>(-1); | 1582 return static_cast<Bytecode>(-1); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 } | 1629 } |
1665 | 1630 |
1666 // static | 1631 // static |
1667 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { | 1632 bool BytecodeArrayBuilder::FitsInReg16OperandUntranslated(Register value) { |
1668 return value.is_short_operand(); | 1633 return value.is_short_operand(); |
1669 } | 1634 } |
1670 | 1635 |
1671 } // namespace interpreter | 1636 } // namespace interpreter |
1672 } // namespace internal | 1637 } // namespace internal |
1673 } // namespace v8 | 1638 } // namespace v8 |
OLD | NEW |