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 // InstanceOf | |
Michael Starzinger
2015/11/10 09:48:48
nit: s/InstanceOf/JSInstanceOf
sigurds
2015/11/10 10:01:24
Done.
| |
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, InstanceOfSpecialization) { | |
Michael Starzinger
2015/11/10 09:48:48
nit: Let's split this into three separate unit tes
Michael Starzinger
2015/11/10 09:49:49
nit: s/InstanceOfSpecialization/JSInstanceOf/ here
sigurds
2015/11/10 10:01:24
Done.
sigurds
2015/11/10 10:01:24
Done.
| |
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 // Reduce if left-hand side could be a Smi. | |
1201 instanceOf = | |
1202 graph()->NewNode(javascript()->InstanceOf(), Parameter(Type::Any(), 0), | |
1203 HeapConstant(isolate()->object_function()), context, | |
1204 frame_state, effect, control); | |
1205 dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | |
1206 frame_state, effect, control); | |
1207 r = Reduce(instanceOf); | |
1208 ASSERT_TRUE(r.Changed()); | |
1209 ASSERT_EQ(r.replacement(), dummy->InputAt(0)); | |
1210 ASSERT_NE(instanceOf, dummy->InputAt(0)); | |
1211 | |
1212 // Do not reduce if right-hand side is not a function constant. | |
1213 instanceOf = graph()->NewNode( | |
1214 javascript()->InstanceOf(), Parameter(Type::Any(), 0), | |
1215 Parameter(Type::Any()), context, frame_state, effect, control); | |
1216 dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | |
1217 frame_state, effect, control); | |
1218 r = Reduce(instanceOf); | |
1219 ASSERT_FALSE(r.Changed()); | |
1220 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | |
1221 } | |
1222 | |
1171 } // namespace compiler | 1223 } // namespace compiler |
1172 } // namespace internal | 1224 } // namespace internal |
1173 } // namespace v8 | 1225 } // namespace v8 |
OLD | NEW |