Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: test/unittests/compiler/js-typed-lowering-unittest.cc

Issue 1678833002: [turbofan] Introduce JSCreateLowering for optimizing JSCreate nodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/unittests/compiler/js-create-lowering-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, 85 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified,
86 &machine); 86 &machine);
87 // TODO(titzer): mock the GraphReducer here for better unit testing. 87 // TODO(titzer): mock the GraphReducer here for better unit testing.
88 GraphReducer graph_reducer(zone(), graph()); 88 GraphReducer graph_reducer(zone(), graph());
89 JSTypedLowering reducer(&graph_reducer, &deps_, 89 JSTypedLowering reducer(&graph_reducer, &deps_,
90 JSTypedLowering::kDeoptimizationEnabled, &jsgraph, 90 JSTypedLowering::kDeoptimizationEnabled, &jsgraph,
91 zone()); 91 zone());
92 return reducer.Reduce(node); 92 return reducer.Reduce(node);
93 } 93 }
94 94
95 Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) {
96 Node* state_values = graph()->NewNode(common()->StateValues(0));
97 return graph()->NewNode(
98 common()->FrameState(BailoutId::None(),
99 OutputFrameStateCombine::Ignore(),
100 common()->CreateFrameStateFunctionInfo(
101 FrameStateType::kJavaScriptFunction, 1, 0,
102 shared, CALL_MAINTAINS_NATIVE_CONTEXT)),
103 state_values, state_values, state_values, NumberConstant(0),
104 UndefinedConstant(), outer_frame_state);
105 }
106
107 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { 95 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
108 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); 96 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
109 JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length); 97 JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length);
110 return buffer; 98 return buffer;
111 } 99 }
112 100
113 Matcher<Node*> IsIntPtrConstant(intptr_t value) { 101 Matcher<Node*> IsIntPtrConstant(intptr_t value) {
114 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) 102 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value))
115 : IsInt64Constant(static_cast<int64_t>(value)); 103 : IsInt64Constant(static_cast<int64_t>(value));
116 } 104 }
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 EXPECT_THAT(r.replacement(), 889 EXPECT_THAT(r.replacement(),
902 IsCall(_, IsHeapConstant(CodeFactory::StringAdd( 890 IsCall(_, IsHeapConstant(CodeFactory::StringAdd(
903 isolate(), STRING_ADD_CHECK_NONE, 891 isolate(), STRING_ADD_CHECK_NONE,
904 NOT_TENURED).code()), 892 NOT_TENURED).code()),
905 lhs, rhs, context, frame_state0, effect, control)); 893 lhs, rhs, context, frame_state0, effect, control));
906 } 894 }
907 } 895 }
908 896
909 897
910 // ----------------------------------------------------------------------------- 898 // -----------------------------------------------------------------------------
911 // JSCreate
912
913
914 TEST_F(JSTypedLoweringTest, JSCreate) {
915 Handle<JSFunction> function = isolate()->object_function();
916 Node* const target = Parameter(Type::Constant(function, graph()->zone()));
917 Node* const context = Parameter(Type::Any());
918 Node* const effect = graph()->start();
919 Reduction r = Reduce(graph()->NewNode(javascript()->Create(), target, target,
920 context, EmptyFrameState(), effect));
921 ASSERT_TRUE(r.Changed());
922 EXPECT_THAT(
923 r.replacement(),
924 IsFinishRegion(
925 IsAllocate(IsNumberConstant(function->initial_map()->instance_size()),
926 IsBeginRegion(effect), _),
927 _));
928 }
929
930
931 // -----------------------------------------------------------------------------
932 // JSCreateArguments
933
934
935 TEST_F(JSTypedLoweringTest, JSCreateArgumentsViaStub) {
936 Node* const closure = Parameter(Type::Any());
937 Node* const context = UndefinedConstant();
938 Node* const effect = graph()->start();
939 Node* const control = graph()->start();
940 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
941 Node* const frame_state = FrameState(shared, graph()->start());
942 Reduction r = Reduce(
943 graph()->NewNode(javascript()->CreateArguments(
944 CreateArgumentsType::kMappedArguments),
945 closure, context, frame_state, effect, control));
946 ASSERT_TRUE(r.Changed());
947 EXPECT_THAT(r.replacement(),
948 IsCall(_, IsHeapConstant(CodeFactory::ArgumentsAccess(
949 isolate(), false, false)
950 .code()),
951 closure, IsNumberConstant(0), _, effect, control));
952 }
953
954
955 TEST_F(JSTypedLoweringTest, JSCreateArgumentsRestParameterViaStub) {
956 Node* const closure = Parameter(Type::Any());
957 Node* const context = UndefinedConstant();
958 Node* const effect = graph()->start();
959 Node* const control = graph()->start();
960 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
961 Node* const frame_state = FrameState(shared, graph()->start());
962 Reduction r = Reduce(graph()->NewNode(
963 javascript()->CreateArguments(CreateArgumentsType::kRestParameter),
964 closure, context, frame_state, effect, control));
965 ASSERT_TRUE(r.Changed());
966 EXPECT_THAT(
967 r.replacement(),
968 IsCall(_, IsHeapConstant(
969 CodeFactory::FastNewRestParameter(isolate()).code()),
970 closure, context, frame_state, effect, control));
971 }
972
973
974 TEST_F(JSTypedLoweringTest, JSCreateArgumentsInlinedMapped) {
975 Node* const closure = Parameter(Type::Any());
976 Node* const context = UndefinedConstant();
977 Node* const effect = graph()->start();
978 Node* const control = graph()->start();
979 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
980 Node* const frame_state_outer = FrameState(shared, graph()->start());
981 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
982 Reduction r = Reduce(
983 graph()->NewNode(javascript()->CreateArguments(
984 CreateArgumentsType::kMappedArguments),
985 closure, context, frame_state_inner, effect, control));
986 ASSERT_TRUE(r.Changed());
987 EXPECT_THAT(r.replacement(),
988 IsFinishRegion(
989 IsAllocate(IsNumberConstant(Heap::kSloppyArgumentsObjectSize),
990 _, control),
991 _));
992 }
993
994
995 TEST_F(JSTypedLoweringTest, JSCreateArgumentsInlinedUnmapped) {
996 Node* const closure = Parameter(Type::Any());
997 Node* const context = UndefinedConstant();
998 Node* const effect = graph()->start();
999 Node* const control = graph()->start();
1000 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
1001 Node* const frame_state_outer = FrameState(shared, graph()->start());
1002 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
1003 Reduction r = Reduce(
1004 graph()->NewNode(javascript()->CreateArguments(
1005 CreateArgumentsType::kUnmappedArguments),
1006 closure, context, frame_state_inner, effect, control));
1007 ASSERT_TRUE(r.Changed());
1008 EXPECT_THAT(r.replacement(),
1009 IsFinishRegion(
1010 IsAllocate(IsNumberConstant(Heap::kStrictArgumentsObjectSize),
1011 _, control),
1012 _));
1013 }
1014
1015
1016 TEST_F(JSTypedLoweringTest, JSCreateArgumentsInlinedRestArray) {
1017 Node* const closure = Parameter(Type::Any());
1018 Node* const context = UndefinedConstant();
1019 Node* const effect = graph()->start();
1020 Node* const control = graph()->start();
1021 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
1022 Node* const frame_state_outer = FrameState(shared, graph()->start());
1023 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
1024 Reduction r = Reduce(graph()->NewNode(
1025 javascript()->CreateArguments(CreateArgumentsType::kRestParameter),
1026 closure, context, frame_state_inner, effect, control));
1027 ASSERT_TRUE(r.Changed());
1028 EXPECT_THAT(r.replacement(),
1029 IsFinishRegion(
1030 IsAllocate(IsNumberConstant(JSArray::kSize), _, control), _));
1031 }
1032
1033
1034 // -----------------------------------------------------------------------------
1035 // JSCreateFunctionContext
1036
1037
1038 TEST_F(JSTypedLoweringTest, JSCreateFunctionContextViaInlinedAllocation) {
1039 Node* const closure = Parameter(Type::Any());
1040 Node* const context = Parameter(Type::Any());
1041 Node* const effect = graph()->start();
1042 Node* const control = graph()->start();
1043 Reduction const r =
1044 Reduce(graph()->NewNode(javascript()->CreateFunctionContext(8), closure,
1045 context, effect, control));
1046 ASSERT_TRUE(r.Changed());
1047 EXPECT_THAT(r.replacement(),
1048 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
1049 8 + Context::MIN_CONTEXT_SLOTS)),
1050 IsBeginRegion(_), control),
1051 _));
1052 }
1053
1054
1055 // -----------------------------------------------------------------------------
1056 // JSCreateWithContext
1057
1058
1059 TEST_F(JSTypedLoweringTest, JSCreateWithContext) {
1060 Node* const object = Parameter(Type::Receiver());
1061 Node* const closure = Parameter(Type::Function());
1062 Node* const context = Parameter(Type::Any());
1063 Node* const effect = graph()->start();
1064 Node* const control = graph()->start();
1065 Reduction r =
1066 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object,
1067 closure, context, effect, control));
1068 ASSERT_TRUE(r.Changed());
1069 EXPECT_THAT(r.replacement(),
1070 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
1071 Context::MIN_CONTEXT_SLOTS)),
1072 IsBeginRegion(_), control),
1073 _));
1074 }
1075
1076
1077 // -----------------------------------------------------------------------------
1078 // JSCreateCatchContext
1079
1080
1081 TEST_F(JSTypedLoweringTest, JSCreateCatchContext) {
1082 Handle<String> name = factory()->length_string();
1083 Node* const exception = Parameter(Type::Receiver());
1084 Node* const closure = Parameter(Type::Function());
1085 Node* const context = Parameter(Type::Any());
1086 Node* const effect = graph()->start();
1087 Node* const control = graph()->start();
1088 Reduction r =
1089 Reduce(graph()->NewNode(javascript()->CreateCatchContext(name), exception,
1090 closure, context, effect, control));
1091 ASSERT_TRUE(r.Changed());
1092 EXPECT_THAT(r.replacement(),
1093 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
1094 Context::MIN_CONTEXT_SLOTS + 1)),
1095 IsBeginRegion(_), control),
1096 _));
1097 }
1098
1099
1100 // -----------------------------------------------------------------------------
1101 // JSInstanceOf 899 // JSInstanceOf
1102 // Test that instanceOf is reduced if and only if the right-hand side is a 900 // Test that instanceOf is reduced if and only if the right-hand side is a
1103 // function constant. Functional correctness is ensured elsewhere. 901 // function constant. Functional correctness is ensured elsewhere.
1104 902
1105 903
1106 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { 904 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) {
1107 Node* const context = Parameter(Type::Any()); 905 Node* const context = Parameter(Type::Any());
1108 Node* const frame_state = EmptyFrameState(); 906 Node* const frame_state = EmptyFrameState();
1109 Node* const effect = graph()->start(); 907 Node* const effect = graph()->start();
1110 Node* const control = graph()->start(); 908 Node* const control = graph()->start();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, 954 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context,
1157 frame_state, effect, control); 955 frame_state, effect, control);
1158 Reduction r = Reduce(instanceOf); 956 Reduction r = Reduce(instanceOf);
1159 ASSERT_FALSE(r.Changed()); 957 ASSERT_FALSE(r.Changed());
1160 ASSERT_EQ(instanceOf, dummy->InputAt(0)); 958 ASSERT_EQ(instanceOf, dummy->InputAt(0));
1161 } 959 }
1162 960
1163 } // namespace compiler 961 } // namespace compiler
1164 } // namespace internal 962 } // namespace internal
1165 } // namespace v8 963 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/js-create-lowering-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698