| 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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 javascript()->CreateArguments(CreateArgumentsParameters::kRestArray, 0), | 1025 javascript()->CreateArguments(CreateArgumentsParameters::kRestArray, 0), |
| 1026 closure, context, frame_state_inner, effect, control)); | 1026 closure, context, frame_state_inner, effect, control)); |
| 1027 ASSERT_TRUE(r.Changed()); | 1027 ASSERT_TRUE(r.Changed()); |
| 1028 EXPECT_THAT(r.replacement(), | 1028 EXPECT_THAT(r.replacement(), |
| 1029 IsFinishRegion( | 1029 IsFinishRegion( |
| 1030 IsAllocate(IsNumberConstant(JSArray::kSize), _, control), _)); | 1030 IsAllocate(IsNumberConstant(JSArray::kSize), _, control), _)); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 | 1033 |
| 1034 // ----------------------------------------------------------------------------- | 1034 // ----------------------------------------------------------------------------- |
| 1035 // JSCreateClosure | |
| 1036 | |
| 1037 | |
| 1038 TEST_F(JSTypedLoweringTest, JSCreateClosure) { | |
| 1039 Node* const context = UndefinedConstant(); | |
| 1040 Node* const effect = graph()->start(); | |
| 1041 Node* const control = graph()->start(); | |
| 1042 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared()); | |
| 1043 Reduction r = | |
| 1044 Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED), | |
| 1045 context, effect, control)); | |
| 1046 ASSERT_TRUE(r.Changed()); | |
| 1047 EXPECT_THAT(r.replacement(), | |
| 1048 IsCall(_, IsHeapConstant(CodeFactory::FastNewClosure( | |
| 1049 isolate(), shared->language_mode(), | |
| 1050 shared->kind()).code()), | |
| 1051 IsHeapConstant(shared), effect, control)); | |
| 1052 } | |
| 1053 | |
| 1054 | |
| 1055 // ----------------------------------------------------------------------------- | |
| 1056 // JSCreateLiteralArray | |
| 1057 | |
| 1058 | |
| 1059 TEST_F(JSTypedLoweringTest, JSCreateLiteralArray) { | |
| 1060 Handle<FixedArray> const constant_elements = factory()->NewFixedArray(12); | |
| 1061 int const literal_flags = ArrayLiteral::kShallowElements; | |
| 1062 int const literal_index = 1; | |
| 1063 Node* const closure = Parameter(0); | |
| 1064 Node* const context = Parameter(1); | |
| 1065 Node* const frame_state = EmptyFrameState(); | |
| 1066 Node* const effect = graph()->start(); | |
| 1067 Node* const control = graph()->start(); | |
| 1068 Reduction const r = Reduce( | |
| 1069 graph()->NewNode(javascript()->CreateLiteralArray( | |
| 1070 constant_elements, literal_flags, literal_index), | |
| 1071 closure, context, frame_state, effect, control)); | |
| 1072 ASSERT_TRUE(r.Changed()); | |
| 1073 EXPECT_THAT( | |
| 1074 r.replacement(), | |
| 1075 IsCall(_, IsHeapConstant( | |
| 1076 CodeFactory::FastCloneShallowArray(isolate()).code()), | |
| 1077 closure, IsNumberConstant(literal_index), | |
| 1078 IsHeapConstant(constant_elements), context, frame_state, effect, | |
| 1079 control)); | |
| 1080 } | |
| 1081 | |
| 1082 | |
| 1083 // ----------------------------------------------------------------------------- | |
| 1084 // JSCreateLiteralObject | |
| 1085 | |
| 1086 | |
| 1087 TEST_F(JSTypedLoweringTest, JSCreateLiteralObject) { | |
| 1088 Handle<FixedArray> const constant_properties = | |
| 1089 factory()->NewFixedArray(6 * 2); | |
| 1090 int const literal_flags = ObjectLiteral::kShallowProperties; | |
| 1091 int const literal_index = 1; | |
| 1092 Node* const closure = Parameter(0); | |
| 1093 Node* const context = Parameter(1); | |
| 1094 Node* const frame_state = EmptyFrameState(); | |
| 1095 Node* const effect = graph()->start(); | |
| 1096 Node* const control = graph()->start(); | |
| 1097 Reduction const r = Reduce( | |
| 1098 graph()->NewNode(javascript()->CreateLiteralObject( | |
| 1099 constant_properties, literal_flags, literal_index), | |
| 1100 closure, context, frame_state, effect, control)); | |
| 1101 ASSERT_TRUE(r.Changed()); | |
| 1102 EXPECT_THAT( | |
| 1103 r.replacement(), | |
| 1104 IsCall(_, IsHeapConstant( | |
| 1105 CodeFactory::FastCloneShallowObject(isolate(), 6).code()), | |
| 1106 closure, IsNumberConstant(literal_index), | |
| 1107 IsHeapConstant(constant_properties), _, context, frame_state, | |
| 1108 effect, control)); | |
| 1109 } | |
| 1110 | |
| 1111 | |
| 1112 // ----------------------------------------------------------------------------- | |
| 1113 // JSCreateFunctionContext | 1035 // JSCreateFunctionContext |
| 1114 | 1036 |
| 1115 | 1037 |
| 1116 TEST_F(JSTypedLoweringTest, JSCreateFunctionContextViaInlinedAllocation) { | 1038 TEST_F(JSTypedLoweringTest, JSCreateFunctionContextViaInlinedAllocation) { |
| 1117 Node* const closure = Parameter(Type::Any()); | 1039 Node* const closure = Parameter(Type::Any()); |
| 1118 Node* const context = Parameter(Type::Any()); | 1040 Node* const context = Parameter(Type::Any()); |
| 1119 Node* const effect = graph()->start(); | 1041 Node* const effect = graph()->start(); |
| 1120 Node* const control = graph()->start(); | 1042 Node* const control = graph()->start(); |
| 1121 Reduction const r = | 1043 Reduction const r = |
| 1122 Reduce(graph()->NewNode(javascript()->CreateFunctionContext(8), closure, | 1044 Reduce(graph()->NewNode(javascript()->CreateFunctionContext(8), closure, |
| 1123 context, effect, control)); | 1045 context, effect, control)); |
| 1124 ASSERT_TRUE(r.Changed()); | 1046 ASSERT_TRUE(r.Changed()); |
| 1125 EXPECT_THAT(r.replacement(), | 1047 EXPECT_THAT(r.replacement(), |
| 1126 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor( | 1048 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor( |
| 1127 8 + Context::MIN_CONTEXT_SLOTS)), | 1049 8 + Context::MIN_CONTEXT_SLOTS)), |
| 1128 IsBeginRegion(_), control), | 1050 IsBeginRegion(_), control), |
| 1129 _)); | 1051 _)); |
| 1130 } | 1052 } |
| 1131 | 1053 |
| 1132 | 1054 |
| 1133 TEST_F(JSTypedLoweringTest, JSCreateFunctionContextViaStub) { | |
| 1134 Node* const closure = Parameter(Type::Any()); | |
| 1135 Node* const context = Parameter(Type::Any()); | |
| 1136 Node* const effect = graph()->start(); | |
| 1137 Node* const control = graph()->start(); | |
| 1138 Reduction const r = | |
| 1139 Reduce(graph()->NewNode(javascript()->CreateFunctionContext(32), closure, | |
| 1140 context, effect, control)); | |
| 1141 ASSERT_TRUE(r.Changed()); | |
| 1142 EXPECT_THAT(r.replacement(), | |
| 1143 IsCall(_, IsHeapConstant( | |
| 1144 CodeFactory::FastNewContext(isolate(), 32).code()), | |
| 1145 closure, context, effect, control)); | |
| 1146 } | |
| 1147 | |
| 1148 | |
| 1149 // ----------------------------------------------------------------------------- | 1055 // ----------------------------------------------------------------------------- |
| 1150 // JSCreateWithContext | 1056 // JSCreateWithContext |
| 1151 | 1057 |
| 1152 | 1058 |
| 1153 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { | 1059 TEST_F(JSTypedLoweringTest, JSCreateWithContext) { |
| 1154 Node* const object = Parameter(Type::Receiver()); | 1060 Node* const object = Parameter(Type::Receiver()); |
| 1155 Node* const closure = Parameter(Type::Function()); | 1061 Node* const closure = Parameter(Type::Function()); |
| 1156 Node* const context = Parameter(Type::Any()); | 1062 Node* const context = Parameter(Type::Any()); |
| 1157 Node* const effect = graph()->start(); | 1063 Node* const effect = graph()->start(); |
| 1158 Node* const control = graph()->start(); | 1064 Node* const control = graph()->start(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 1156 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| 1251 frame_state, effect, control); | 1157 frame_state, effect, control); |
| 1252 Reduction r = Reduce(instanceOf); | 1158 Reduction r = Reduce(instanceOf); |
| 1253 ASSERT_FALSE(r.Changed()); | 1159 ASSERT_FALSE(r.Changed()); |
| 1254 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 1160 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
| 1255 } | 1161 } |
| 1256 | 1162 |
| 1257 } // namespace compiler | 1163 } // namespace compiler |
| 1258 } // namespace internal | 1164 } // namespace internal |
| 1259 } // namespace v8 | 1165 } // namespace v8 |
| OLD | NEW |