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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 protected: | 79 protected: |
80 Reduction Reduce(Node* node) { | 80 Reduction Reduce(Node* node) { |
81 MachineOperatorBuilder machine(zone()); | 81 MachineOperatorBuilder machine(zone()); |
82 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); | 82 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); |
83 // TODO(titzer): mock the GraphReducer here for better unit testing. | 83 // TODO(titzer): mock the GraphReducer here for better unit testing. |
84 GraphReducer graph_reducer(graph(), zone()); | 84 GraphReducer graph_reducer(graph(), zone()); |
85 JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); | 85 JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); |
86 return reducer.Reduce(node); | 86 return reducer.Reduce(node); |
87 } | 87 } |
88 | 88 |
89 Node* EmptyFrameState() { | |
90 MachineOperatorBuilder machine(zone()); | |
91 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); | |
92 return jsgraph.EmptyFrameState(); | |
93 } | |
94 | |
95 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { | 89 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { |
96 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); | 90 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); |
97 Runtime::SetupArrayBuffer(isolate(), buffer, true, bytes, byte_length); | 91 Runtime::SetupArrayBuffer(isolate(), buffer, true, bytes, byte_length); |
98 return buffer; | 92 return buffer; |
99 } | 93 } |
100 | 94 |
101 Matcher<Node*> IsIntPtrConstant(intptr_t value) { | 95 Matcher<Node*> IsIntPtrConstant(intptr_t value) { |
102 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) | 96 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) |
103 : IsInt64Constant(static_cast<int64_t>(value)); | 97 : IsInt64Constant(static_cast<int64_t>(value)); |
104 } | 98 } |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); | 889 Unique<Name> name = Unique<Name>::CreateImmovable(names[i]); |
896 Reduction r = Reduce(graph()->NewNode( | 890 Reduction r = Reduce(graph()->NewNode( |
897 javascript()->LoadNamed(name, feedback), global, context, | 891 javascript()->LoadNamed(name, feedback), global, context, |
898 EmptyFrameState(), EmptyFrameState(), effect, control)); | 892 EmptyFrameState(), EmptyFrameState(), effect, control)); |
899 | 893 |
900 ASSERT_TRUE(r.Changed()); | 894 ASSERT_TRUE(r.Changed()); |
901 EXPECT_THAT(r.replacement(), matches[i]); | 895 EXPECT_THAT(r.replacement(), matches[i]); |
902 } | 896 } |
903 } | 897 } |
904 | 898 |
| 899 #if V8_TURBOFAN_TARGET |
| 900 |
| 901 // ----------------------------------------------------------------------------- |
| 902 // JSAdd |
| 903 |
| 904 |
| 905 TEST_F(JSTypedLoweringTest, JSAddWithString) { |
| 906 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
| 907 Node* lhs = Parameter(Type::String(), 0); |
| 908 Node* rhs = Parameter(Type::String(), 1); |
| 909 Node* context = Parameter(Type::Any(), 2); |
| 910 Node* frame_state0 = EmptyFrameState(); |
| 911 Node* frame_state1 = EmptyFrameState(); |
| 912 Node* effect = graph()->start(); |
| 913 Node* control = graph()->start(); |
| 914 Reduction r = Reduce(graph()->NewNode(javascript()->Add(language_mode), lhs, |
| 915 rhs, context, frame_state0, |
| 916 frame_state1, effect, control)); |
| 917 ASSERT_TRUE(r.Changed()); |
| 918 EXPECT_THAT( |
| 919 r.replacement(), |
| 920 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
| 921 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, |
| 922 NOT_TENURED).code())), |
| 923 lhs, rhs, context, frame_state0, effect, control)); |
| 924 } |
| 925 } |
| 926 |
905 | 927 |
906 // ----------------------------------------------------------------------------- | 928 // ----------------------------------------------------------------------------- |
907 // JSCreateClosure | 929 // JSCreateClosure |
908 | 930 |
909 #if V8_TURBOFAN_TARGET | 931 |
910 TEST_F(JSTypedLoweringTest, JSCreateClosure) { | 932 TEST_F(JSTypedLoweringTest, JSCreateClosure) { |
911 Node* const context = UndefinedConstant(); | 933 Node* const context = UndefinedConstant(); |
912 Node* const effect = graph()->start(); | 934 Node* const effect = graph()->start(); |
913 Node* const control = graph()->start(); | 935 Node* const control = graph()->start(); |
914 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared()); | 936 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared()); |
915 Reduction r = | 937 Reduction r = |
916 Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED), | 938 Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED), |
917 context, context, effect, control)); | 939 context, context, effect, control)); |
918 ASSERT_TRUE(r.Changed()); | 940 ASSERT_TRUE(r.Changed()); |
919 EXPECT_THAT( | 941 EXPECT_THAT( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 Reduction const r = Reduce(graph()->NewNode( | 988 Reduction const r = Reduce(graph()->NewNode( |
967 javascript()->CreateLiteralObject(ObjectLiteral::kShallowProperties), | 989 javascript()->CreateLiteralObject(ObjectLiteral::kShallowProperties), |
968 input0, input1, input2, context, frame_state, effect, control)); | 990 input0, input1, input2, context, frame_state, effect, control)); |
969 ASSERT_TRUE(r.Changed()); | 991 ASSERT_TRUE(r.Changed()); |
970 EXPECT_THAT( | 992 EXPECT_THAT( |
971 r.replacement(), | 993 r.replacement(), |
972 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 994 IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
973 CodeFactory::FastCloneShallowObject(isolate(), 6).code())), | 995 CodeFactory::FastCloneShallowObject(isolate(), 6).code())), |
974 input0, input1, input2, _, context, frame_state, effect, control)); | 996 input0, input1, input2, _, context, frame_state, effect, control)); |
975 } | 997 } |
976 #endif | 998 |
| 999 #endif // V8_TURBOFAN_TARGET |
977 | 1000 |
978 | 1001 |
979 // ----------------------------------------------------------------------------- | 1002 // ----------------------------------------------------------------------------- |
980 // JSCreateWithContext | 1003 // JSCreateWithContext |
981 | 1004 |
982 | 1005 |
983 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { | 1006 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { |
984 FLAG_turbo_allocate = true; | 1007 FLAG_turbo_allocate = true; |
985 Node* const object = Parameter(Type::Receiver()); | 1008 Node* const object = Parameter(Type::Receiver()); |
986 Node* const closure = Parameter(Type::Any()); | 1009 Node* const closure = Parameter(Type::Any()); |
987 Node* const context = Parameter(Type::Any()); | 1010 Node* const context = Parameter(Type::Any()); |
988 Node* const frame_state = EmptyFrameState(); | 1011 Node* const frame_state = EmptyFrameState(); |
989 Node* const effect = graph()->start(); | 1012 Node* const effect = graph()->start(); |
990 Node* const control = graph()->start(); | 1013 Node* const control = graph()->start(); |
991 Reduction r = | 1014 Reduction r = |
992 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object, | 1015 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object, |
993 closure, context, frame_state, effect, control)); | 1016 closure, context, frame_state, effect, control)); |
994 ASSERT_TRUE(r.Changed()); | 1017 ASSERT_TRUE(r.Changed()); |
995 EXPECT_THAT(r.replacement(), | 1018 EXPECT_THAT(r.replacement(), |
996 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( | 1019 IsFinish(IsAllocate(IsNumberConstant(Context::SizeFor( |
997 Context::MIN_CONTEXT_SLOTS)), | 1020 Context::MIN_CONTEXT_SLOTS)), |
998 effect, control), | 1021 effect, control), |
999 _)); | 1022 _)); |
1000 } | 1023 } |
1001 | 1024 |
1002 } // namespace compiler | 1025 } // namespace compiler |
1003 } // namespace internal | 1026 } // namespace internal |
1004 } // namespace v8 | 1027 } // namespace v8 |
OLD | NEW |