| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/js-typed-lowering.h" | 5 #include "src/compiler/js-typed-lowering.h" |
| 6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
| 7 #include "src/compilation-dependencies.h" | 7 #include "src/compilation-dependencies.h" |
| 8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/js-operator.h" | 10 #include "src/compiler/js-operator.h" |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 EXPECT_THAT(r.replacement(), | 1019 EXPECT_THAT(r.replacement(), |
| 1020 IsSpeculativeNumberSubtract(NumberOperationHint::kSignedSmall, | 1020 IsSpeculativeNumberSubtract(NumberOperationHint::kSignedSmall, |
| 1021 lhs, rhs, effect, control)); | 1021 lhs, rhs, effect, control)); |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 // ----------------------------------------------------------------------------- | 1024 // ----------------------------------------------------------------------------- |
| 1025 // JSInstanceOf | 1025 // JSInstanceOf |
| 1026 // Test that instanceOf is reduced if and only if the right-hand side is a | 1026 // Test that instanceOf is reduced if and only if the right-hand side is a |
| 1027 // function constant. Functional correctness is ensured elsewhere. | 1027 // function constant. Functional correctness is ensured elsewhere. |
| 1028 | 1028 |
| 1029 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { | 1029 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecialization) { |
| 1030 Node* const context = Parameter(Type::Any()); | 1030 Node* const context = Parameter(Type::Any()); |
| 1031 Node* const frame_state = EmptyFrameState(); | 1031 Node* const frame_state = EmptyFrameState(); |
| 1032 Node* const effect = graph()->start(); | 1032 Node* const effect = graph()->start(); |
| 1033 Node* const control = graph()->start(); | 1033 Node* const control = graph()->start(); |
| 1034 | 1034 |
| 1035 // Reduce if left-hand side is known to be an object. | |
| 1036 Node* instanceOf = | |
| 1037 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Object(), 0), | |
| 1038 HeapConstant(isolate()->object_function()), context, | |
| 1039 frame_state, effect, control); | |
| 1040 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | |
| 1041 frame_state, effect, control); | |
| 1042 Reduction r = Reduce(instanceOf); | |
| 1043 ASSERT_TRUE(r.Changed()); | |
| 1044 ASSERT_EQ(r.replacement(), dummy->InputAt(0)); | |
| 1045 ASSERT_NE(instanceOf, dummy->InputAt(0)); | |
| 1046 } | |
| 1047 | |
| 1048 | |
| 1049 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithSmiCheck) { | |
| 1050 Node* const context = Parameter(Type::Any()); | |
| 1051 Node* const frame_state = EmptyFrameState(); | |
| 1052 Node* const effect = graph()->start(); | |
| 1053 Node* const control = graph()->start(); | |
| 1054 | |
| 1055 // Reduce if left-hand side could be a Smi. | |
| 1056 Node* instanceOf = | 1035 Node* instanceOf = |
| 1057 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0), | 1036 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0), |
| 1058 HeapConstant(isolate()->object_function()), context, | 1037 HeapConstant(isolate()->object_function()), context, |
| 1059 frame_state, effect, control); | 1038 frame_state, effect, control); |
| 1060 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | |
| 1061 frame_state, effect, control); | |
| 1062 Reduction r = Reduce(instanceOf); | 1039 Reduction r = Reduce(instanceOf); |
| 1063 ASSERT_TRUE(r.Changed()); | 1040 ASSERT_TRUE(r.Changed()); |
| 1064 ASSERT_EQ(r.replacement(), dummy->InputAt(0)); | |
| 1065 ASSERT_NE(instanceOf, dummy->InputAt(0)); | |
| 1066 } | 1041 } |
| 1067 | 1042 |
| 1068 | 1043 |
| 1069 TEST_F(JSTypedLoweringTest, JSInstanceOfNoSpecialization) { | 1044 TEST_F(JSTypedLoweringTest, JSInstanceOfNoSpecialization) { |
| 1070 Node* const context = Parameter(Type::Any()); | 1045 Node* const context = Parameter(Type::Any()); |
| 1071 Node* const frame_state = EmptyFrameState(); | 1046 Node* const frame_state = EmptyFrameState(); |
| 1072 Node* const effect = graph()->start(); | 1047 Node* const effect = graph()->start(); |
| 1073 Node* const control = graph()->start(); | 1048 Node* const control = graph()->start(); |
| 1074 | 1049 |
| 1075 // Do not reduce if right-hand side is not a function constant. | 1050 // Do not reduce if right-hand side is not a function constant. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 EmptyFrameState(), effect, control)); | 1198 EmptyFrameState(), effect, control)); |
| 1224 ASSERT_TRUE(r.Changed()); | 1199 ASSERT_TRUE(r.Changed()); |
| 1225 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor( | 1200 EXPECT_THAT(r.replacement(), IsSpeculativeNumberBitwiseXor( |
| 1226 NumberOperationHint::kNumberOrOddball, lhs, | 1201 NumberOperationHint::kNumberOrOddball, lhs, |
| 1227 rhs, effect, control)); | 1202 rhs, effect, control)); |
| 1228 } | 1203 } |
| 1229 | 1204 |
| 1230 } // namespace compiler | 1205 } // namespace compiler |
| 1231 } // namespace internal | 1206 } // namespace internal |
| 1232 } // namespace v8 | 1207 } // namespace v8 |
| OLD | NEW |