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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 EXPECT_FALSE(r.Changed()); | 228 EXPECT_FALSE(r.Changed()); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 TEST_F(JSTypedLoweringTest, ParameterWithNull) { | 233 TEST_F(JSTypedLoweringTest, ParameterWithNull) { |
234 Handle<HeapObject> null = factory()->null_value(); | 234 Handle<HeapObject> null = factory()->null_value(); |
235 { | 235 { |
236 Reduction r = Reduce(Parameter(Type::Constant(null, zone()))); | 236 Reduction r = Reduce(Parameter(Type::Constant(null, zone()))); |
237 ASSERT_TRUE(r.Changed()); | 237 ASSERT_TRUE(r.Changed()); |
238 EXPECT_THAT(r.replacement(), | 238 EXPECT_THAT(r.replacement(), IsHeapConstant(null)); |
239 IsHeapConstant(Unique<HeapObject>::CreateImmovable(null))); | |
240 } | 239 } |
241 { | 240 { |
242 Reduction r = Reduce(Parameter(Type::Null())); | 241 Reduction r = Reduce(Parameter(Type::Null())); |
243 ASSERT_TRUE(r.Changed()); | 242 ASSERT_TRUE(r.Changed()); |
244 EXPECT_THAT(r.replacement(), | 243 EXPECT_THAT(r.replacement(), IsHeapConstant(null)); |
245 IsHeapConstant(Unique<HeapObject>::CreateImmovable(null))); | |
246 } | 244 } |
247 } | 245 } |
248 | 246 |
249 | 247 |
250 TEST_F(JSTypedLoweringTest, ParameterWithNaN) { | 248 TEST_F(JSTypedLoweringTest, ParameterWithNaN) { |
251 const double kNaNs[] = {-std::numeric_limits<double>::quiet_NaN(), | 249 const double kNaNs[] = {-std::numeric_limits<double>::quiet_NaN(), |
252 std::numeric_limits<double>::quiet_NaN(), | 250 std::numeric_limits<double>::quiet_NaN(), |
253 std::numeric_limits<double>::signaling_NaN()}; | 251 std::numeric_limits<double>::signaling_NaN()}; |
254 TRACED_FOREACH(double, nan, kNaNs) { | 252 TRACED_FOREACH(double, nan, kNaNs) { |
255 Handle<Object> constant = factory()->NewNumber(nan); | 253 Handle<Object> constant = factory()->NewNumber(nan); |
(...skipping 28 matching lines...) Expand all Loading... |
284 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); | 282 EXPECT_THAT(r.replacement(), IsNumberConstant(value)); |
285 } | 283 } |
286 } | 284 } |
287 | 285 |
288 | 286 |
289 TEST_F(JSTypedLoweringTest, ParameterWithUndefined) { | 287 TEST_F(JSTypedLoweringTest, ParameterWithUndefined) { |
290 Handle<HeapObject> undefined = factory()->undefined_value(); | 288 Handle<HeapObject> undefined = factory()->undefined_value(); |
291 { | 289 { |
292 Reduction r = Reduce(Parameter(Type::Undefined())); | 290 Reduction r = Reduce(Parameter(Type::Undefined())); |
293 ASSERT_TRUE(r.Changed()); | 291 ASSERT_TRUE(r.Changed()); |
294 EXPECT_THAT(r.replacement(), | 292 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); |
295 IsHeapConstant(Unique<HeapObject>::CreateImmovable(undefined))); | |
296 } | 293 } |
297 { | 294 { |
298 Reduction r = Reduce(Parameter(Type::Constant(undefined, zone()))); | 295 Reduction r = Reduce(Parameter(Type::Constant(undefined, zone()))); |
299 ASSERT_TRUE(r.Changed()); | 296 ASSERT_TRUE(r.Changed()); |
300 EXPECT_THAT(r.replacement(), | 297 EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); |
301 IsHeapConstant(Unique<HeapObject>::CreateImmovable(undefined))); | |
302 } | 298 } |
303 } | 299 } |
304 | 300 |
305 | 301 |
306 // ----------------------------------------------------------------------------- | 302 // ----------------------------------------------------------------------------- |
307 // JSToBoolean | 303 // JSToBoolean |
308 | 304 |
309 | 305 |
310 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { | 306 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { |
311 Node* input = Parameter(Type::Boolean(), 0); | 307 Node* input = Parameter(Type::Boolean(), 0); |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 // JSLoadGlobal | 874 // JSLoadGlobal |
879 | 875 |
880 | 876 |
881 TEST_F(JSTypedLoweringTest, JSLoadGlobalConstants) { | 877 TEST_F(JSTypedLoweringTest, JSLoadGlobalConstants) { |
882 Handle<String> names[] = { | 878 Handle<String> names[] = { |
883 Handle<String>(isolate()->heap()->undefined_string(), isolate()), | 879 Handle<String>(isolate()->heap()->undefined_string(), isolate()), |
884 Handle<String>(isolate()->heap()->infinity_string(), isolate()), | 880 Handle<String>(isolate()->heap()->infinity_string(), isolate()), |
885 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- | 881 Handle<String>(isolate()->heap()->nan_string(), isolate()) // -- |
886 }; | 882 }; |
887 Matcher<Node*> matches[] = { | 883 Matcher<Node*> matches[] = { |
888 IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 884 IsHeapConstant( |
889 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate()))), | 885 Handle<HeapObject>(isolate()->heap()->undefined_value(), isolate())), |
890 IsNumberConstant(std::numeric_limits<double>::infinity()), | 886 IsNumberConstant(std::numeric_limits<double>::infinity()), |
891 IsNumberConstant(IsNaN()) // -- | 887 IsNumberConstant(IsNaN()) // -- |
892 }; | 888 }; |
893 | 889 |
894 VectorSlotPair feedback; | 890 VectorSlotPair feedback; |
895 Node* global = UndefinedConstant(); | 891 Node* global = UndefinedConstant(); |
896 Node* vector = UndefinedConstant(); | 892 Node* vector = UndefinedConstant(); |
897 Node* context = UndefinedConstant(); | 893 Node* context = UndefinedConstant(); |
898 Node* effect = graph()->start(); | 894 Node* effect = graph()->start(); |
899 Node* control = graph()->start(); | 895 Node* control = graph()->start(); |
900 | 896 |
901 for (size_t i = 0; i < arraysize(names); i++) { | 897 for (size_t i = 0; i < arraysize(names); i++) { |
902 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | |
903 Reduction r = Reduce(graph()->NewNode( | 898 Reduction r = Reduce(graph()->NewNode( |
904 javascript()->LoadGlobal(name, feedback), context, global, vector, | 899 javascript()->LoadGlobal(names[i], feedback), context, global, vector, |
905 context, EmptyFrameState(), EmptyFrameState(), effect, control)); | 900 context, EmptyFrameState(), EmptyFrameState(), effect, control)); |
906 | 901 |
907 ASSERT_TRUE(r.Changed()); | 902 ASSERT_TRUE(r.Changed()); |
908 EXPECT_THAT(r.replacement(), matches[i]); | 903 EXPECT_THAT(r.replacement(), matches[i]); |
909 } | 904 } |
910 } | 905 } |
911 | 906 |
912 | 907 |
913 // ----------------------------------------------------------------------------- | 908 // ----------------------------------------------------------------------------- |
914 // JSLoadNamed | 909 // JSLoadNamed |
915 | 910 |
916 | 911 |
917 TEST_F(JSTypedLoweringTest, JSLoadNamedStringLength) { | 912 TEST_F(JSTypedLoweringTest, JSLoadNamedStringLength) { |
918 VectorSlotPair feedback; | 913 VectorSlotPair feedback; |
919 Unique<Name> name = Unique<Name>::CreateImmovable(factory()->length_string()); | 914 Handle<Name> name = factory()->length_string(); |
920 Node* const receiver = Parameter(Type::String(), 0); | 915 Node* const receiver = Parameter(Type::String(), 0); |
921 Node* const vector = Parameter(Type::Internal(), 1); | 916 Node* const vector = Parameter(Type::Internal(), 1); |
922 Node* const context = UndefinedConstant(); | 917 Node* const context = UndefinedConstant(); |
923 Node* const effect = graph()->start(); | 918 Node* const effect = graph()->start(); |
924 Node* const control = graph()->start(); | 919 Node* const control = graph()->start(); |
925 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 920 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
926 Reduction const r = Reduce( | 921 Reduction const r = Reduce( |
927 graph()->NewNode(javascript()->LoadNamed(name, feedback, language_mode), | 922 graph()->NewNode(javascript()->LoadNamed(name, feedback, language_mode), |
928 receiver, vector, context, EmptyFrameState(), | 923 receiver, vector, context, EmptyFrameState(), |
929 EmptyFrameState(), effect, control)); | 924 EmptyFrameState(), effect, control)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 Node* rhs = Parameter(Type::String(), 1); | 1010 Node* rhs = Parameter(Type::String(), 1); |
1016 Node* context = Parameter(Type::Any(), 2); | 1011 Node* context = Parameter(Type::Any(), 2); |
1017 Node* frame_state0 = EmptyFrameState(); | 1012 Node* frame_state0 = EmptyFrameState(); |
1018 Node* frame_state1 = EmptyFrameState(); | 1013 Node* frame_state1 = EmptyFrameState(); |
1019 Node* effect = graph()->start(); | 1014 Node* effect = graph()->start(); |
1020 Node* control = graph()->start(); | 1015 Node* control = graph()->start(); |
1021 Reduction r = Reduce(graph()->NewNode(javascript()->Add(language_mode), lhs, | 1016 Reduction r = Reduce(graph()->NewNode(javascript()->Add(language_mode), lhs, |
1022 rhs, context, frame_state0, | 1017 rhs, context, frame_state0, |
1023 frame_state1, effect, control)); | 1018 frame_state1, effect, control)); |
1024 ASSERT_TRUE(r.Changed()); | 1019 ASSERT_TRUE(r.Changed()); |
1025 EXPECT_THAT( | 1020 EXPECT_THAT(r.replacement(), |
1026 r.replacement(), | 1021 IsCall(_, IsHeapConstant(CodeFactory::StringAdd( |
1027 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 1022 isolate(), STRING_ADD_CHECK_NONE, |
1028 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, | 1023 NOT_TENURED).code()), |
1029 NOT_TENURED).code())), | 1024 lhs, rhs, context, frame_state0, effect, control)); |
1030 lhs, rhs, context, frame_state0, effect, control)); | |
1031 } | 1025 } |
1032 } | 1026 } |
1033 | 1027 |
1034 | 1028 |
1035 // ----------------------------------------------------------------------------- | 1029 // ----------------------------------------------------------------------------- |
1036 // JSCreateClosure | 1030 // JSCreateClosure |
1037 | 1031 |
1038 | 1032 |
1039 TEST_F(JSTypedLoweringTest, JSCreateClosure) { | 1033 TEST_F(JSTypedLoweringTest, JSCreateClosure) { |
1040 Node* const context = UndefinedConstant(); | 1034 Node* const context = UndefinedConstant(); |
1041 Node* const effect = graph()->start(); | 1035 Node* const effect = graph()->start(); |
1042 Node* const control = graph()->start(); | 1036 Node* const control = graph()->start(); |
1043 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared()); | 1037 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared()); |
1044 Reduction r = | 1038 Reduction r = |
1045 Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED), | 1039 Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED), |
1046 context, context, effect, control)); | 1040 context, context, effect, control)); |
1047 ASSERT_TRUE(r.Changed()); | 1041 ASSERT_TRUE(r.Changed()); |
1048 EXPECT_THAT( | 1042 EXPECT_THAT(r.replacement(), |
1049 r.replacement(), | 1043 IsCall(_, IsHeapConstant(CodeFactory::FastNewClosure( |
1050 IsCall(_, | 1044 isolate(), shared->language_mode(), |
1051 IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 1045 shared->kind()).code()), |
1052 CodeFactory::FastNewClosure(isolate(), shared->language_mode(), | 1046 IsHeapConstant(shared), effect, control)); |
1053 shared->kind()).code())), | |
1054 IsHeapConstant(Unique<HeapObject>::CreateImmovable(shared)), | |
1055 effect, control)); | |
1056 } | 1047 } |
1057 | 1048 |
1058 | 1049 |
1059 // ----------------------------------------------------------------------------- | 1050 // ----------------------------------------------------------------------------- |
1060 // JSCreateLiteralArray | 1051 // JSCreateLiteralArray |
1061 | 1052 |
1062 | 1053 |
1063 TEST_F(JSTypedLoweringTest, JSCreateLiteralArray) { | 1054 TEST_F(JSTypedLoweringTest, JSCreateLiteralArray) { |
1064 Node* const input0 = Parameter(0); | 1055 Node* const input0 = Parameter(0); |
1065 Node* const input1 = Parameter(1); | 1056 Node* const input1 = Parameter(1); |
1066 Node* const input2 = HeapConstant(factory()->NewFixedArray(12)); | 1057 Node* const input2 = HeapConstant(factory()->NewFixedArray(12)); |
1067 Node* const context = UndefinedConstant(); | 1058 Node* const context = UndefinedConstant(); |
1068 Node* const frame_state = EmptyFrameState(); | 1059 Node* const frame_state = EmptyFrameState(); |
1069 Node* const effect = graph()->start(); | 1060 Node* const effect = graph()->start(); |
1070 Node* const control = graph()->start(); | 1061 Node* const control = graph()->start(); |
1071 Reduction const r = Reduce(graph()->NewNode( | 1062 Reduction const r = Reduce(graph()->NewNode( |
1072 javascript()->CreateLiteralArray(ArrayLiteral::kShallowElements), input0, | 1063 javascript()->CreateLiteralArray(ArrayLiteral::kShallowElements), input0, |
1073 input1, input2, context, frame_state, effect, control)); | 1064 input1, input2, context, frame_state, effect, control)); |
1074 ASSERT_TRUE(r.Changed()); | 1065 ASSERT_TRUE(r.Changed()); |
1075 EXPECT_THAT( | 1066 EXPECT_THAT( |
1076 r.replacement(), | 1067 r.replacement(), |
1077 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 1068 IsCall(_, IsHeapConstant( |
1078 CodeFactory::FastCloneShallowArray(isolate()).code())), | 1069 CodeFactory::FastCloneShallowArray(isolate()).code()), |
1079 input0, input1, input2, context, frame_state, effect, control)); | 1070 input0, input1, input2, context, frame_state, effect, control)); |
1080 } | 1071 } |
1081 | 1072 |
1082 | 1073 |
1083 // ----------------------------------------------------------------------------- | 1074 // ----------------------------------------------------------------------------- |
1084 // JSCreateLiteralObject | 1075 // JSCreateLiteralObject |
1085 | 1076 |
1086 | 1077 |
1087 TEST_F(JSTypedLoweringTest, JSCreateLiteralObject) { | 1078 TEST_F(JSTypedLoweringTest, JSCreateLiteralObject) { |
1088 Node* const input0 = Parameter(0); | 1079 Node* const input0 = Parameter(0); |
1089 Node* const input1 = Parameter(1); | 1080 Node* const input1 = Parameter(1); |
1090 Node* const input2 = HeapConstant(factory()->NewFixedArray(2 * 6)); | 1081 Node* const input2 = HeapConstant(factory()->NewFixedArray(2 * 6)); |
1091 Node* const context = UndefinedConstant(); | 1082 Node* const context = UndefinedConstant(); |
1092 Node* const frame_state = EmptyFrameState(); | 1083 Node* const frame_state = EmptyFrameState(); |
1093 Node* const effect = graph()->start(); | 1084 Node* const effect = graph()->start(); |
1094 Node* const control = graph()->start(); | 1085 Node* const control = graph()->start(); |
1095 Reduction const r = Reduce(graph()->NewNode( | 1086 Reduction const r = Reduce(graph()->NewNode( |
1096 javascript()->CreateLiteralObject(ObjectLiteral::kShallowProperties), | 1087 javascript()->CreateLiteralObject(ObjectLiteral::kShallowProperties), |
1097 input0, input1, input2, context, frame_state, effect, control)); | 1088 input0, input1, input2, context, frame_state, effect, control)); |
1098 ASSERT_TRUE(r.Changed()); | 1089 ASSERT_TRUE(r.Changed()); |
1099 EXPECT_THAT( | 1090 EXPECT_THAT( |
1100 r.replacement(), | 1091 r.replacement(), |
1101 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 1092 IsCall(_, IsHeapConstant( |
1102 CodeFactory::FastCloneShallowObject(isolate(), 6).code())), | 1093 CodeFactory::FastCloneShallowObject(isolate(), 6).code()), |
1103 input0, input1, input2, _, context, frame_state, effect, control)); | 1094 input0, input1, input2, _, context, frame_state, effect, control)); |
1104 } | 1095 } |
1105 | 1096 |
1106 | 1097 |
1107 // ----------------------------------------------------------------------------- | 1098 // ----------------------------------------------------------------------------- |
1108 // JSCreateWithContext | 1099 // JSCreateWithContext |
1109 | 1100 |
1110 | 1101 |
1111 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { | 1102 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { |
1112 FLAG_turbo_allocate = true; | 1103 FLAG_turbo_allocate = true; |
(...skipping 10 matching lines...) Expand all Loading... |
1123 EXPECT_THAT(r.replacement(), | 1114 EXPECT_THAT(r.replacement(), |
1124 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1115 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
1125 Context::MIN_CONTEXT_SLOTS)), | 1116 Context::MIN_CONTEXT_SLOTS)), |
1126 effect, control), | 1117 effect, control), |
1127 _)); | 1118 _)); |
1128 } | 1119 } |
1129 | 1120 |
1130 } // namespace compiler | 1121 } // namespace compiler |
1131 } // namespace internal | 1122 } // namespace internal |
1132 } // namespace v8 | 1123 } // namespace v8 |
OLD | NEW |