| 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 | 6 |
| 7 #include "src/globals.h" | 7 #include "src/globals.h" |
| 8 #include "src/interpreter/bytecode-array-writer.h" | 8 #include "src/interpreter/bytecode-array-writer.h" |
| 9 #include "src/interpreter/bytecode-dead-code-optimizer.h" | 9 #include "src/interpreter/bytecode-dead-code-optimizer.h" |
| 10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 int feedback_slot) { | 321 int feedback_slot) { |
| 322 if (op == Token::Value::ADD) { | 322 if (op == Token::Value::ADD) { |
| 323 OutputInc(feedback_slot); | 323 OutputInc(feedback_slot); |
| 324 } else { | 324 } else { |
| 325 DCHECK_EQ(op, Token::Value::SUB); | 325 DCHECK_EQ(op, Token::Value::SUB); |
| 326 OutputDec(feedback_slot); | 326 OutputDec(feedback_slot); |
| 327 } | 327 } |
| 328 return *this; | 328 return *this; |
| 329 } | 329 } |
| 330 | 330 |
| 331 BytecodeArrayBuilder& BytecodeArrayBuilder::LogicalNot() { | 331 BytecodeArrayBuilder& BytecodeArrayBuilder::LogicalNot(ToBooleanMode mode) { |
| 332 OutputToBooleanLogicalNot(); | 332 if (mode == ToBooleanMode::kAlreadyBoolean) { |
| 333 OutputLogicalNot(); |
| 334 } else { |
| 335 DCHECK_EQ(mode, ToBooleanMode::kConvertToBoolean); |
| 336 OutputToBooleanLogicalNot(); |
| 337 } |
| 333 return *this; | 338 return *this; |
| 334 } | 339 } |
| 335 | 340 |
| 336 BytecodeArrayBuilder& BytecodeArrayBuilder::TypeOf() { | 341 BytecodeArrayBuilder& BytecodeArrayBuilder::TypeOf() { |
| 337 OutputTypeOf(); | 342 OutputTypeOf(); |
| 338 return *this; | 343 return *this; |
| 339 } | 344 } |
| 340 | 345 |
| 341 BytecodeArrayBuilder& BytecodeArrayBuilder::GetSuperConstructor(Register out) { | 346 BytecodeArrayBuilder& BytecodeArrayBuilder::GetSuperConstructor(Register out) { |
| 342 OutputGetSuperConstructor(out); | 347 OutputGetSuperConstructor(out); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 LeaveBasicBlock(); | 893 LeaveBasicBlock(); |
| 889 return *this; | 894 return *this; |
| 890 } | 895 } |
| 891 | 896 |
| 892 BytecodeArrayBuilder& BytecodeArrayBuilder::Jump(BytecodeLabel* label) { | 897 BytecodeArrayBuilder& BytecodeArrayBuilder::Jump(BytecodeLabel* label) { |
| 893 DCHECK(!label->is_bound()); | 898 DCHECK(!label->is_bound()); |
| 894 OutputJump(label, 0); | 899 OutputJump(label, 0); |
| 895 return *this; | 900 return *this; |
| 896 } | 901 } |
| 897 | 902 |
| 898 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfTrue(BytecodeLabel* label) { | 903 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfTrue(ToBooleanMode mode, |
| 899 // The peephole optimizer attempts to simplify JumpIfToBooleanTrue | 904 BytecodeLabel* label) { |
| 900 // to JumpIfTrue. | |
| 901 DCHECK(!label->is_bound()); | 905 DCHECK(!label->is_bound()); |
| 902 OutputJumpIfToBooleanTrue(label, 0); | 906 if (mode == ToBooleanMode::kAlreadyBoolean) { |
| 907 OutputJumpIfTrue(label, 0); |
| 908 } else { |
| 909 DCHECK_EQ(mode, ToBooleanMode::kConvertToBoolean); |
| 910 OutputJumpIfToBooleanTrue(label, 0); |
| 911 } |
| 903 return *this; | 912 return *this; |
| 904 } | 913 } |
| 905 | 914 |
| 906 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(BytecodeLabel* label) { | 915 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfFalse(ToBooleanMode mode, |
| 916 BytecodeLabel* label) { |
| 907 DCHECK(!label->is_bound()); | 917 DCHECK(!label->is_bound()); |
| 908 OutputJumpIfToBooleanFalse(label, 0); | 918 if (mode == ToBooleanMode::kAlreadyBoolean) { |
| 919 OutputJumpIfFalse(label, 0); |
| 920 } else { |
| 921 DCHECK_EQ(mode, ToBooleanMode::kConvertToBoolean); |
| 922 OutputJumpIfToBooleanFalse(label, 0); |
| 923 } |
| 909 return *this; | 924 return *this; |
| 910 } | 925 } |
| 911 | 926 |
| 912 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNull(BytecodeLabel* label) { | 927 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNull(BytecodeLabel* label) { |
| 913 DCHECK(!label->is_bound()); | 928 DCHECK(!label->is_bound()); |
| 914 OutputJumpIfNull(label, 0); | 929 OutputJumpIfNull(label, 0); |
| 915 return *this; | 930 return *this; |
| 916 } | 931 } |
| 917 | 932 |
| 918 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotNull( | 933 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotNull( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 934 DCHECK(!label->is_bound()); | 949 DCHECK(!label->is_bound()); |
| 935 OutputJumpIfNotUndefined(label, 0); | 950 OutputJumpIfNotUndefined(label, 0); |
| 936 return *this; | 951 return *this; |
| 937 } | 952 } |
| 938 | 953 |
| 939 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNil(BytecodeLabel* label, | 954 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNil(BytecodeLabel* label, |
| 940 Token::Value op, | 955 Token::Value op, |
| 941 NilValue nil) { | 956 NilValue nil) { |
| 942 if (op == Token::EQ) { | 957 if (op == Token::EQ) { |
| 943 // TODO(rmcilroy): Implement JumpIfUndetectable. | 958 // TODO(rmcilroy): Implement JumpIfUndetectable. |
| 944 return CompareUndetectable().JumpIfTrue(label); | 959 return CompareUndetectable().JumpIfTrue(ToBooleanMode::kAlreadyBoolean, |
| 960 label); |
| 945 } else { | 961 } else { |
| 946 DCHECK_EQ(Token::EQ_STRICT, op); | 962 DCHECK_EQ(Token::EQ_STRICT, op); |
| 947 if (nil == kUndefinedValue) { | 963 if (nil == kUndefinedValue) { |
| 948 return JumpIfUndefined(label); | 964 return JumpIfUndefined(label); |
| 949 } else { | 965 } else { |
| 950 DCHECK_EQ(kNullValue, nil); | 966 DCHECK_EQ(kNullValue, nil); |
| 951 return JumpIfNull(label); | 967 return JumpIfNull(label); |
| 952 } | 968 } |
| 953 } | 969 } |
| 954 } | 970 } |
| 955 | 971 |
| 956 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotNil(BytecodeLabel* label, | 972 BytecodeArrayBuilder& BytecodeArrayBuilder::JumpIfNotNil(BytecodeLabel* label, |
| 957 Token::Value op, | 973 Token::Value op, |
| 958 NilValue nil) { | 974 NilValue nil) { |
| 959 if (op == Token::EQ) { | 975 if (op == Token::EQ) { |
| 960 // TODO(rmcilroy): Implement JumpIfUndetectable. | 976 // TODO(rmcilroy): Implement JumpIfUndetectable. |
| 961 return CompareUndetectable().JumpIfFalse(label); | 977 return CompareUndetectable().JumpIfFalse(ToBooleanMode::kAlreadyBoolean, |
| 978 label); |
| 962 } else { | 979 } else { |
| 963 DCHECK_EQ(Token::EQ_STRICT, op); | 980 DCHECK_EQ(Token::EQ_STRICT, op); |
| 964 if (nil == kUndefinedValue) { | 981 if (nil == kUndefinedValue) { |
| 965 return JumpIfNotUndefined(label); | 982 return JumpIfNotUndefined(label); |
| 966 } else { | 983 } else { |
| 967 DCHECK_EQ(kNullValue, nil); | 984 DCHECK_EQ(kNullValue, nil); |
| 968 return JumpIfNotNull(label); | 985 return JumpIfNotNull(label); |
| 969 } | 986 } |
| 970 } | 987 } |
| 971 } | 988 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 } | 1338 } |
| 1322 | 1339 |
| 1323 uint32_t BytecodeArrayBuilder::GetOutputRegisterListOperand( | 1340 uint32_t BytecodeArrayBuilder::GetOutputRegisterListOperand( |
| 1324 RegisterList reg_list) { | 1341 RegisterList reg_list) { |
| 1325 DCHECK(RegisterListIsValid(reg_list)); | 1342 DCHECK(RegisterListIsValid(reg_list)); |
| 1326 if (register_optimizer_) | 1343 if (register_optimizer_) |
| 1327 register_optimizer_->PrepareOutputRegisterList(reg_list); | 1344 register_optimizer_->PrepareOutputRegisterList(reg_list); |
| 1328 return static_cast<uint32_t>(reg_list.first_register().ToOperand()); | 1345 return static_cast<uint32_t>(reg_list.first_register().ToOperand()); |
| 1329 } | 1346 } |
| 1330 | 1347 |
| 1348 std::ostream& operator<<(std::ostream& os, |
| 1349 const BytecodeArrayBuilder::ToBooleanMode& mode) { |
| 1350 switch (mode) { |
| 1351 case BytecodeArrayBuilder::ToBooleanMode::kAlreadyBoolean: |
| 1352 return os << "AlreadyBoolean"; |
| 1353 case BytecodeArrayBuilder::ToBooleanMode::kConvertToBoolean: |
| 1354 return os << "ConvertToBoolean"; |
| 1355 } |
| 1356 } |
| 1357 |
| 1331 } // namespace interpreter | 1358 } // namespace interpreter |
| 1332 } // namespace internal | 1359 } // namespace internal |
| 1333 } // namespace v8 | 1360 } // namespace v8 |
| OLD | NEW |