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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 | 68 |
69 STATIC_ASSERT(LANGUAGE_END == 3); | 69 STATIC_ASSERT(LANGUAGE_END == 3); |
70 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; | 70 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 | 74 |
75 class JSTypedLoweringTest : public TypedGraphTest { | 75 class JSTypedLoweringTest : public TypedGraphTest { |
76 public: | 76 public: |
77 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} | 77 JSTypedLoweringTest() |
| 78 : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) {} |
78 ~JSTypedLoweringTest() override {} | 79 ~JSTypedLoweringTest() override {} |
79 | 80 |
80 protected: | 81 protected: |
81 Reduction Reduce(Node* node) { | 82 Reduction Reduce(Node* node) { |
82 MachineOperatorBuilder machine(zone()); | 83 MachineOperatorBuilder machine(zone()); |
83 SimplifiedOperatorBuilder simplified(zone()); | 84 SimplifiedOperatorBuilder simplified(zone()); |
84 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, | 85 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified, |
85 &machine); | 86 &machine); |
86 // TODO(titzer): mock the GraphReducer here for better unit testing. | 87 // TODO(titzer): mock the GraphReducer here for better unit testing. |
87 GraphReducer graph_reducer(zone(), graph()); | 88 GraphReducer graph_reducer(zone(), graph()); |
88 JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); | 89 JSTypedLowering reducer(&graph_reducer, &deps_, |
| 90 JSTypedLowering::kDeoptimizationEnabled, &jsgraph, |
| 91 zone()); |
89 return reducer.Reduce(node); | 92 return reducer.Reduce(node); |
90 } | 93 } |
91 | 94 |
92 Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) { | 95 Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) { |
93 Node* state_values = graph()->NewNode(common()->StateValues(0)); | 96 Node* state_values = graph()->NewNode(common()->StateValues(0)); |
94 return graph()->NewNode( | 97 return graph()->NewNode( |
95 common()->FrameState(BailoutId::None(), | 98 common()->FrameState(BailoutId::None(), |
96 OutputFrameStateCombine::Ignore(), | 99 OutputFrameStateCombine::Ignore(), |
97 common()->CreateFrameStateFunctionInfo( | 100 common()->CreateFrameStateFunctionInfo( |
98 FrameStateType::kJavaScriptFunction, 1, 0, | 101 FrameStateType::kJavaScriptFunction, 1, 0, |
(...skipping 10 matching lines...) Expand all Loading... |
109 | 112 |
110 Matcher<Node*> IsIntPtrConstant(intptr_t value) { | 113 Matcher<Node*> IsIntPtrConstant(intptr_t value) { |
111 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) | 114 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) |
112 : IsInt64Constant(static_cast<int64_t>(value)); | 115 : IsInt64Constant(static_cast<int64_t>(value)); |
113 } | 116 } |
114 | 117 |
115 JSOperatorBuilder* javascript() { return &javascript_; } | 118 JSOperatorBuilder* javascript() { return &javascript_; } |
116 | 119 |
117 private: | 120 private: |
118 JSOperatorBuilder javascript_; | 121 JSOperatorBuilder javascript_; |
| 122 CompilationDependencies deps_; |
119 }; | 123 }; |
120 | 124 |
121 | 125 |
122 // ----------------------------------------------------------------------------- | 126 // ----------------------------------------------------------------------------- |
123 // JSUnaryNot | 127 // JSUnaryNot |
124 | 128 |
125 | 129 |
126 TEST_F(JSTypedLoweringTest, JSUnaryNotWithBoolean) { | 130 TEST_F(JSTypedLoweringTest, JSUnaryNotWithBoolean) { |
127 Node* input = Parameter(Type::Boolean(), 0); | 131 Node* input = Parameter(Type::Boolean(), 0); |
128 Node* context = Parameter(Type::Any(), 1); | 132 Node* context = Parameter(Type::Any(), 1); |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object, | 1165 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object, |
1162 closure, context, frame_state, effect, control)); | 1166 closure, context, frame_state, effect, control)); |
1163 ASSERT_TRUE(r.Changed()); | 1167 ASSERT_TRUE(r.Changed()); |
1164 EXPECT_THAT(r.replacement(), | 1168 EXPECT_THAT(r.replacement(), |
1165 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor( | 1169 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor( |
1166 Context::MIN_CONTEXT_SLOTS)), | 1170 Context::MIN_CONTEXT_SLOTS)), |
1167 IsBeginRegion(effect), control), | 1171 IsBeginRegion(effect), control), |
1168 _)); | 1172 _)); |
1169 } | 1173 } |
1170 | 1174 |
| 1175 |
| 1176 // ----------------------------------------------------------------------------- |
| 1177 // JSInstanceOf |
| 1178 // Test that instanceOf is reduced if and only if the right-hand side is a |
| 1179 // function constant. Functional correctness is ensured elsewhere. |
| 1180 |
| 1181 |
| 1182 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithoutSmiCheck) { |
| 1183 Node* const context = Parameter(Type::Any()); |
| 1184 Node* const frame_state = EmptyFrameState(); |
| 1185 Node* const effect = graph()->start(); |
| 1186 Node* const control = graph()->start(); |
| 1187 |
| 1188 // Reduce if left-hand side is known to be an object. |
| 1189 Node* instanceOf = |
| 1190 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Object(), 0), |
| 1191 HeapConstant(isolate()->object_function()), context, |
| 1192 frame_state, effect, control); |
| 1193 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| 1194 frame_state, effect, control); |
| 1195 Reduction r = Reduce(instanceOf); |
| 1196 ASSERT_TRUE(r.Changed()); |
| 1197 ASSERT_EQ(r.replacement(), dummy->InputAt(0)); |
| 1198 ASSERT_NE(instanceOf, dummy->InputAt(0)); |
| 1199 } |
| 1200 |
| 1201 |
| 1202 TEST_F(JSTypedLoweringTest, JSInstanceOfSpecializationWithSmiCheck) { |
| 1203 Node* const context = Parameter(Type::Any()); |
| 1204 Node* const frame_state = EmptyFrameState(); |
| 1205 Node* const effect = graph()->start(); |
| 1206 Node* const control = graph()->start(); |
| 1207 |
| 1208 // Reduce if left-hand side could be a Smi. |
| 1209 Node* instanceOf = |
| 1210 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0), |
| 1211 HeapConstant(isolate()->object_function()), context, |
| 1212 frame_state, effect, control); |
| 1213 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| 1214 frame_state, effect, control); |
| 1215 Reduction r = Reduce(instanceOf); |
| 1216 ASSERT_TRUE(r.Changed()); |
| 1217 ASSERT_EQ(r.replacement(), dummy->InputAt(0)); |
| 1218 ASSERT_NE(instanceOf, dummy->InputAt(0)); |
| 1219 } |
| 1220 |
| 1221 |
| 1222 TEST_F(JSTypedLoweringTest, JSInstanceOfNoSpecialization) { |
| 1223 Node* const context = Parameter(Type::Any()); |
| 1224 Node* const frame_state = EmptyFrameState(); |
| 1225 Node* const effect = graph()->start(); |
| 1226 Node* const control = graph()->start(); |
| 1227 |
| 1228 // Do not reduce if right-hand side is not a function constant. |
| 1229 Node* instanceOf = graph()->NewNode( |
| 1230 javascript()->InstanceOf(), Parameter(Type::Any(), 0), |
| 1231 Parameter(Type::Any()), context, frame_state, effect, control); |
| 1232 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
| 1233 frame_state, effect, control); |
| 1234 Reduction r = Reduce(instanceOf); |
| 1235 ASSERT_FALSE(r.Changed()); |
| 1236 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
| 1237 } |
| 1238 |
1171 } // namespace compiler | 1239 } // namespace compiler |
1172 } // namespace internal | 1240 } // namespace internal |
1173 } // namespace v8 | 1241 } // namespace v8 |
OLD | NEW |