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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 // ----------------------------------------------------------------------------- | 208 // ----------------------------------------------------------------------------- |
209 // JSToBoolean | 209 // JSToBoolean |
210 | 210 |
211 | 211 |
212 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { | 212 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) { |
213 Node* input = Parameter(Type::Boolean(), 0); | 213 Node* input = Parameter(Type::Boolean(), 0); |
214 Node* context = Parameter(Type::Any(), 1); | 214 Node* context = Parameter(Type::Any(), 1); |
215 Reduction r = | 215 Reduction r = Reduce(graph()->NewNode( |
216 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 216 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
217 input, context, graph()->start())); | |
218 ASSERT_TRUE(r.Changed()); | 217 ASSERT_TRUE(r.Changed()); |
219 EXPECT_EQ(input, r.replacement()); | 218 EXPECT_EQ(input, r.replacement()); |
220 } | 219 } |
221 | 220 |
222 | 221 |
223 TEST_F(JSTypedLoweringTest, JSToBooleanWithFalsish) { | 222 TEST_F(JSTypedLoweringTest, JSToBooleanWithFalsish) { |
224 Node* input = Parameter( | 223 Node* input = Parameter( |
225 Type::Union( | 224 Type::Union( |
226 Type::MinusZero(), | 225 Type::MinusZero(), |
227 Type::Union( | 226 Type::Union( |
228 Type::NaN(), | 227 Type::NaN(), |
229 Type::Union( | 228 Type::Union( |
230 Type::Null(), | 229 Type::Null(), |
231 Type::Union( | 230 Type::Union( |
232 Type::Undefined(), | 231 Type::Undefined(), |
233 Type::Union( | 232 Type::Union( |
234 Type::Undetectable(), | 233 Type::Undetectable(), |
235 Type::Union( | 234 Type::Union( |
236 Type::Constant(factory()->false_value(), zone()), | 235 Type::Constant(factory()->false_value(), zone()), |
237 Type::Range(0.0, 0.0, zone()), zone()), | 236 Type::Range(0.0, 0.0, zone()), zone()), |
238 zone()), | 237 zone()), |
239 zone()), | 238 zone()), |
240 zone()), | 239 zone()), |
241 zone()), | 240 zone()), |
242 zone()), | 241 zone()), |
243 0); | 242 0); |
244 Node* context = Parameter(Type::Any(), 1); | 243 Node* context = Parameter(Type::Any(), 1); |
245 Reduction r = | 244 Reduction r = Reduce(graph()->NewNode( |
246 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 245 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
247 input, context, graph()->start())); | |
248 ASSERT_TRUE(r.Changed()); | 246 ASSERT_TRUE(r.Changed()); |
249 EXPECT_THAT(r.replacement(), IsFalseConstant()); | 247 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
250 } | 248 } |
251 | 249 |
252 | 250 |
253 TEST_F(JSTypedLoweringTest, JSToBooleanWithTruish) { | 251 TEST_F(JSTypedLoweringTest, JSToBooleanWithTruish) { |
254 Node* input = Parameter( | 252 Node* input = Parameter( |
255 Type::Union( | 253 Type::Union( |
256 Type::Constant(factory()->true_value(), zone()), | 254 Type::Constant(factory()->true_value(), zone()), |
257 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), | 255 Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), |
258 zone()), | 256 zone()), |
259 0); | 257 0); |
260 Node* context = Parameter(Type::Any(), 1); | 258 Node* context = Parameter(Type::Any(), 1); |
261 Reduction r = | 259 Reduction r = Reduce(graph()->NewNode( |
262 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 260 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
263 input, context, graph()->start())); | |
264 ASSERT_TRUE(r.Changed()); | 261 ASSERT_TRUE(r.Changed()); |
265 EXPECT_THAT(r.replacement(), IsTrueConstant()); | 262 EXPECT_THAT(r.replacement(), IsTrueConstant()); |
266 } | 263 } |
267 | 264 |
268 | 265 |
269 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) { | 266 TEST_F(JSTypedLoweringTest, JSToBooleanWithNonZeroPlainNumber) { |
270 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); | 267 Node* input = Parameter(Type::Range(1, V8_INFINITY, zone()), 0); |
271 Node* context = Parameter(Type::Any(), 1); | 268 Node* context = Parameter(Type::Any(), 1); |
272 Reduction r = | 269 Reduction r = Reduce(graph()->NewNode( |
273 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 270 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
274 input, context, graph()->start())); | |
275 ASSERT_TRUE(r.Changed()); | 271 ASSERT_TRUE(r.Changed()); |
276 EXPECT_THAT(r.replacement(), IsTrueConstant()); | 272 EXPECT_THAT(r.replacement(), IsTrueConstant()); |
277 } | 273 } |
278 | 274 |
279 | 275 |
280 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) { | 276 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) { |
281 Node* input = Parameter(Type::OrderedNumber(), 0); | 277 Node* input = Parameter(Type::OrderedNumber(), 0); |
282 Node* context = Parameter(Type::Any(), 1); | 278 Node* context = Parameter(Type::Any(), 1); |
283 Reduction r = | 279 Reduction r = Reduce(graph()->NewNode( |
284 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 280 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
285 input, context, graph()->start())); | |
286 ASSERT_TRUE(r.Changed()); | 281 ASSERT_TRUE(r.Changed()); |
287 EXPECT_THAT(r.replacement(), | 282 EXPECT_THAT(r.replacement(), |
288 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0)))); | 283 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0.0)))); |
289 } | 284 } |
290 | 285 |
291 | 286 |
292 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { | 287 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { |
293 Node* input = Parameter(Type::String(), 0); | 288 Node* input = Parameter(Type::String(), 0); |
294 Node* context = Parameter(Type::Any(), 1); | 289 Node* context = Parameter(Type::Any(), 1); |
295 Reduction r = | 290 Reduction r = Reduce(graph()->NewNode( |
296 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 291 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
297 input, context, graph()->start())); | |
298 ASSERT_TRUE(r.Changed()); | 292 ASSERT_TRUE(r.Changed()); |
299 EXPECT_THAT( | 293 EXPECT_THAT( |
300 r.replacement(), | 294 r.replacement(), |
301 IsNumberLessThan(IsNumberConstant(0.0), | 295 IsNumberLessThan(IsNumberConstant(0.0), |
302 IsLoadField(AccessBuilder::ForStringLength(), input, | 296 IsLoadField(AccessBuilder::ForStringLength(), input, |
303 graph()->start(), graph()->start()))); | 297 graph()->start(), graph()->start()))); |
304 } | 298 } |
305 | 299 |
306 | 300 |
307 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) { | 301 TEST_F(JSTypedLoweringTest, JSToBooleanWithAny) { |
308 Node* input = Parameter(Type::Any(), 0); | 302 Node* input = Parameter(Type::Any(), 0); |
309 Node* context = Parameter(Type::Any(), 1); | 303 Node* context = Parameter(Type::Any(), 1); |
310 Reduction r = | 304 Reduction r = Reduce(graph()->NewNode( |
311 Reduce(graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), | 305 javascript()->ToBoolean(ToBooleanHint::kAny), input, context)); |
312 input, context, graph()->start())); | |
313 ASSERT_FALSE(r.Changed()); | 306 ASSERT_FALSE(r.Changed()); |
314 } | 307 } |
315 | 308 |
316 | 309 |
317 // ----------------------------------------------------------------------------- | 310 // ----------------------------------------------------------------------------- |
318 // JSToNumber | 311 // JSToNumber |
319 | 312 |
320 | 313 |
321 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) { | 314 TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) { |
322 Node* const input = Parameter(Type::PlainPrimitive(), 0); | 315 Node* const input = Parameter(Type::PlainPrimitive(), 0); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 377 |
385 // ----------------------------------------------------------------------------- | 378 // ----------------------------------------------------------------------------- |
386 // JSStrictEqual | 379 // JSStrictEqual |
387 | 380 |
388 | 381 |
389 TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) { | 382 TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) { |
390 Node* const the_hole = HeapConstant(factory()->the_hole_value()); | 383 Node* const the_hole = HeapConstant(factory()->the_hole_value()); |
391 Node* const context = UndefinedConstant(); | 384 Node* const context = UndefinedConstant(); |
392 TRACED_FOREACH(Type*, type, kJSTypes) { | 385 TRACED_FOREACH(Type*, type, kJSTypes) { |
393 Node* const lhs = Parameter(type); | 386 Node* const lhs = Parameter(type); |
394 Reduction r = | 387 Reduction r = Reduce( |
395 Reduce(graph()->NewNode(javascript()->StrictEqual(), lhs, the_hole, | 388 graph()->NewNode(javascript()->StrictEqual(), lhs, the_hole, context)); |
396 context, graph()->start(), graph()->start())); | |
397 ASSERT_TRUE(r.Changed()); | 389 ASSERT_TRUE(r.Changed()); |
398 EXPECT_THAT(r.replacement(), IsFalseConstant()); | 390 EXPECT_THAT(r.replacement(), IsFalseConstant()); |
399 } | 391 } |
400 } | 392 } |
401 | 393 |
402 | 394 |
403 TEST_F(JSTypedLoweringTest, JSStrictEqualWithUnique) { | 395 TEST_F(JSTypedLoweringTest, JSStrictEqualWithUnique) { |
404 Node* const lhs = Parameter(Type::Unique(), 0); | 396 Node* const lhs = Parameter(Type::Unique(), 0); |
405 Node* const rhs = Parameter(Type::Unique(), 1); | 397 Node* const rhs = Parameter(Type::Unique(), 1); |
406 Node* const context = Parameter(Type::Any(), 2); | 398 Node* const context = Parameter(Type::Any(), 2); |
407 Reduction r = | 399 Reduction r = |
408 Reduce(graph()->NewNode(javascript()->StrictEqual(), lhs, rhs, context, | 400 Reduce(graph()->NewNode(javascript()->StrictEqual(), lhs, rhs, context)); |
409 graph()->start(), graph()->start())); | |
410 ASSERT_TRUE(r.Changed()); | 401 ASSERT_TRUE(r.Changed()); |
411 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs)); | 402 EXPECT_THAT(r.replacement(), IsReferenceEqual(Type::Unique(), lhs, rhs)); |
412 } | 403 } |
413 | 404 |
414 | 405 |
415 // ----------------------------------------------------------------------------- | 406 // ----------------------------------------------------------------------------- |
416 // JSShiftLeft | 407 // JSShiftLeft |
417 | 408 |
418 | 409 |
419 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { | 410 TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) { |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, | 916 Node* dummy = graph()->NewNode(javascript()->ToObject(), instanceOf, context, |
926 frame_state, effect, control); | 917 frame_state, effect, control); |
927 Reduction r = Reduce(instanceOf); | 918 Reduction r = Reduce(instanceOf); |
928 ASSERT_FALSE(r.Changed()); | 919 ASSERT_FALSE(r.Changed()); |
929 ASSERT_EQ(instanceOf, dummy->InputAt(0)); | 920 ASSERT_EQ(instanceOf, dummy->InputAt(0)); |
930 } | 921 } |
931 | 922 |
932 } // namespace compiler | 923 } // namespace compiler |
933 } // namespace internal | 924 } // namespace internal |
934 } // namespace v8 | 925 } // namespace v8 |
OLD | NEW |