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-stubs.h" | 5 #include "src/code-stubs.h" |
6 #include "src/compiler/change-lowering.h" | 6 #include "src/compiler/change-lowering.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 8 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "test/unittests/compiler/compiler-test-utils.h" | 10 #include "test/unittests/compiler/compiler-test-utils.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 _, IsHeapConstant(Unique<HeapObject>::CreateImmovable( | 83 _, IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
84 CEntryStub(isolate(), 1).GetCode())), | 84 CEntryStub(isolate(), 1).GetCode())), |
85 IsExternalConstant(ExternalReference( | 85 IsExternalConstant(ExternalReference( |
86 Runtime::FunctionForId(Runtime::kAllocateHeapNumber), isolate())), | 86 Runtime::FunctionForId(Runtime::kAllocateHeapNumber), isolate())), |
87 IsInt32Constant(0), IsNumberConstant(0.0), effect_matcher, | 87 IsInt32Constant(0), IsNumberConstant(0.0), effect_matcher, |
88 control_matcher); | 88 control_matcher); |
89 } | 89 } |
90 Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher, | 90 Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher, |
91 const Matcher<Node*>& control_matcher) { | 91 const Matcher<Node*>& control_matcher) { |
92 return IsLoad(kMachFloat64, value_matcher, | 92 return IsLoad(kMachFloat64, value_matcher, |
93 IsInt32Constant(HeapNumberValueOffset()), graph()->start(), | 93 IsIntPtrConstant(HeapNumberValueOffset()), graph()->start(), |
94 control_matcher); | 94 control_matcher); |
95 } | 95 } |
| 96 Matcher<Node*> IsIntPtrConstant(int value) { |
| 97 return Is32() ? IsInt32Constant(value) : IsInt64Constant(value); |
| 98 } |
96 Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher, | 99 Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher, |
97 const Matcher<Node*>& rhs_matcher) { | 100 const Matcher<Node*>& rhs_matcher) { |
98 return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher) | 101 return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher) |
99 : IsWord64Equal(lhs_matcher, rhs_matcher); | 102 : IsWord64Equal(lhs_matcher, rhs_matcher); |
100 } | 103 } |
101 | 104 |
102 private: | 105 private: |
103 SimplifiedOperatorBuilder simplified_; | 106 SimplifiedOperatorBuilder simplified_; |
104 }; | 107 }; |
105 | 108 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 158 |
156 Node* finish = reduction.replacement(); | 159 Node* finish = reduction.replacement(); |
157 Capture<Node*> heap_number; | 160 Capture<Node*> heap_number; |
158 EXPECT_THAT( | 161 EXPECT_THAT( |
159 finish, | 162 finish, |
160 IsFinish( | 163 IsFinish( |
161 AllOf(CaptureEq(&heap_number), | 164 AllOf(CaptureEq(&heap_number), |
162 IsAllocateHeapNumber(IsValueEffect(val), graph()->start())), | 165 IsAllocateHeapNumber(IsValueEffect(val), graph()->start())), |
163 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), | 166 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), |
164 CaptureEq(&heap_number), | 167 CaptureEq(&heap_number), |
165 IsInt32Constant(HeapNumberValueOffset()), val, | 168 IsIntPtrConstant(HeapNumberValueOffset()), val, |
166 CaptureEq(&heap_number), graph()->start()))); | 169 CaptureEq(&heap_number), graph()->start()))); |
167 } | 170 } |
168 | 171 |
169 | 172 |
170 TARGET_TEST_P(ChangeLoweringCommonTest, StringAdd) { | 173 TARGET_TEST_P(ChangeLoweringCommonTest, StringAdd) { |
171 Node* node = | 174 Node* node = |
172 graph()->NewNode(simplified()->StringAdd(), Parameter(0), Parameter(1)); | 175 graph()->NewNode(simplified()->StringAdd(), Parameter(0), Parameter(1)); |
173 Reduction reduction = Reduce(node); | 176 Reduction reduction = Reduce(node); |
174 EXPECT_FALSE(reduction.Changed()); | 177 EXPECT_FALSE(reduction.Changed()); |
175 } | 178 } |
(...skipping 24 matching lines...) Expand all Loading... |
200 | 203 |
201 Node* phi = reduction.replacement(); | 204 Node* phi = reduction.replacement(); |
202 Capture<Node*> add, branch, heap_number, if_true; | 205 Capture<Node*> add, branch, heap_number, if_true; |
203 EXPECT_THAT( | 206 EXPECT_THAT( |
204 phi, | 207 phi, |
205 IsPhi(kMachAnyTagged, | 208 IsPhi(kMachAnyTagged, |
206 IsFinish(AllOf(CaptureEq(&heap_number), | 209 IsFinish(AllOf(CaptureEq(&heap_number), |
207 IsAllocateHeapNumber(_, CaptureEq(&if_true))), | 210 IsAllocateHeapNumber(_, CaptureEq(&if_true))), |
208 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), | 211 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), |
209 CaptureEq(&heap_number), | 212 CaptureEq(&heap_number), |
210 IsInt32Constant(HeapNumberValueOffset()), | 213 IsIntPtrConstant(HeapNumberValueOffset()), |
211 IsChangeInt32ToFloat64(val), | 214 IsChangeInt32ToFloat64(val), |
212 CaptureEq(&heap_number), CaptureEq(&if_true))), | 215 CaptureEq(&heap_number), CaptureEq(&if_true))), |
213 IsProjection( | 216 IsProjection( |
214 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))), | 217 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))), |
215 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 218 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
216 IsIfFalse(AllOf(CaptureEq(&branch), | 219 IsIfFalse(AllOf(CaptureEq(&branch), |
217 IsBranch(IsProjection(1, CaptureEq(&add)), | 220 IsBranch(IsProjection(1, CaptureEq(&add)), |
218 graph()->start())))))); | 221 graph()->start())))))); |
219 } | 222 } |
220 | 223 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 342 |
340 | 343 |
341 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { | 344 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { |
342 Node* val = Parameter(0); | 345 Node* val = Parameter(0); |
343 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 346 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
344 Reduction reduction = Reduce(node); | 347 Reduction reduction = Reduce(node); |
345 ASSERT_TRUE(reduction.Changed()); | 348 ASSERT_TRUE(reduction.Changed()); |
346 | 349 |
347 EXPECT_THAT(reduction.replacement(), | 350 EXPECT_THAT(reduction.replacement(), |
348 IsWord64Shl(IsChangeInt32ToInt64(val), | 351 IsWord64Shl(IsChangeInt32ToInt64(val), |
349 IsInt32Constant(SmiShiftAmount()))); | 352 IsInt64Constant(SmiShiftAmount()))); |
350 } | 353 } |
351 | 354 |
352 | 355 |
353 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { | 356 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { |
354 STATIC_ASSERT(kSmiTag == 0); | 357 STATIC_ASSERT(kSmiTag == 0); |
355 STATIC_ASSERT(kSmiTagSize == 1); | 358 STATIC_ASSERT(kSmiTagSize == 1); |
356 | 359 |
357 Node* val = Parameter(0); | 360 Node* val = Parameter(0); |
358 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 361 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
359 Reduction reduction = Reduce(node); | 362 Reduction reduction = Reduce(node); |
360 ASSERT_TRUE(reduction.Changed()); | 363 ASSERT_TRUE(reduction.Changed()); |
361 | 364 |
362 Node* phi = reduction.replacement(); | 365 Node* phi = reduction.replacement(); |
363 Capture<Node*> branch, if_true; | 366 Capture<Node*> branch, if_true; |
364 EXPECT_THAT( | 367 EXPECT_THAT( |
365 phi, | 368 phi, |
366 IsPhi( | 369 IsPhi( |
367 kMachFloat64, IsLoadHeapNumber(val, CaptureEq(&if_true)), | 370 kMachFloat64, IsLoadHeapNumber(val, CaptureEq(&if_true)), |
368 IsChangeInt32ToFloat64(IsTruncateInt64ToInt32( | 371 IsChangeInt32ToFloat64(IsTruncateInt64ToInt32( |
369 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount())))), | 372 IsWord64Sar(val, IsInt64Constant(SmiShiftAmount())))), |
370 IsMerge( | 373 IsMerge( |
371 AllOf(CaptureEq(&if_true), | 374 AllOf(CaptureEq(&if_true), |
372 IsIfTrue(AllOf( | 375 IsIfTrue(AllOf( |
373 CaptureEq(&branch), | 376 CaptureEq(&branch), |
374 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 377 IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)), |
375 graph()->start())))), | 378 graph()->start())))), |
376 IsIfFalse(CaptureEq(&branch))))); | 379 IsIfFalse(CaptureEq(&branch))))); |
377 } | 380 } |
378 | 381 |
379 | 382 |
380 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) { | 383 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) { |
381 STATIC_ASSERT(kSmiTag == 0); | 384 STATIC_ASSERT(kSmiTag == 0); |
382 STATIC_ASSERT(kSmiTagSize == 1); | 385 STATIC_ASSERT(kSmiTagSize == 1); |
383 | 386 |
384 Node* val = Parameter(0); | 387 Node* val = Parameter(0); |
385 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val); | 388 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val); |
386 Reduction reduction = Reduce(node); | 389 Reduction reduction = Reduce(node); |
387 ASSERT_TRUE(reduction.Changed()); | 390 ASSERT_TRUE(reduction.Changed()); |
388 | 391 |
389 Node* phi = reduction.replacement(); | 392 Node* phi = reduction.replacement(); |
390 Capture<Node*> branch, if_true; | 393 Capture<Node*> branch, if_true; |
391 EXPECT_THAT( | 394 EXPECT_THAT( |
392 phi, | 395 phi, |
393 IsPhi(kMachInt32, | 396 IsPhi(kMachInt32, |
394 IsChangeFloat64ToInt32(IsLoadHeapNumber(val, CaptureEq(&if_true))), | 397 IsChangeFloat64ToInt32(IsLoadHeapNumber(val, CaptureEq(&if_true))), |
395 IsTruncateInt64ToInt32( | 398 IsTruncateInt64ToInt32( |
396 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount()))), | 399 IsWord64Sar(val, IsInt64Constant(SmiShiftAmount()))), |
397 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 400 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
398 IsIfFalse(AllOf( | 401 IsIfFalse(AllOf( |
399 CaptureEq(&branch), | 402 CaptureEq(&branch), |
400 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 403 IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)), |
401 graph()->start())))))); | 404 graph()->start())))))); |
402 } | 405 } |
403 | 406 |
404 | 407 |
405 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToUint32) { | 408 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToUint32) { |
406 STATIC_ASSERT(kSmiTag == 0); | 409 STATIC_ASSERT(kSmiTag == 0); |
407 STATIC_ASSERT(kSmiTagSize == 1); | 410 STATIC_ASSERT(kSmiTagSize == 1); |
408 | 411 |
409 Node* val = Parameter(0); | 412 Node* val = Parameter(0); |
410 Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), val); | 413 Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), val); |
411 Reduction reduction = Reduce(node); | 414 Reduction reduction = Reduce(node); |
412 ASSERT_TRUE(reduction.Changed()); | 415 ASSERT_TRUE(reduction.Changed()); |
413 | 416 |
414 Node* phi = reduction.replacement(); | 417 Node* phi = reduction.replacement(); |
415 Capture<Node*> branch, if_true; | 418 Capture<Node*> branch, if_true; |
416 EXPECT_THAT( | 419 EXPECT_THAT( |
417 phi, | 420 phi, |
418 IsPhi(kMachUint32, | 421 IsPhi(kMachUint32, |
419 IsChangeFloat64ToUint32(IsLoadHeapNumber(val, CaptureEq(&if_true))), | 422 IsChangeFloat64ToUint32(IsLoadHeapNumber(val, CaptureEq(&if_true))), |
420 IsTruncateInt64ToInt32( | 423 IsTruncateInt64ToInt32( |
421 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount()))), | 424 IsWord64Sar(val, IsInt64Constant(SmiShiftAmount()))), |
422 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 425 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
423 IsIfFalse(AllOf( | 426 IsIfFalse(AllOf( |
424 CaptureEq(&branch), | 427 CaptureEq(&branch), |
425 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 428 IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)), |
426 graph()->start())))))); | 429 graph()->start())))))); |
427 } | 430 } |
428 | 431 |
429 | 432 |
430 TARGET_TEST_F(ChangeLowering64Test, ChangeUint32ToTagged) { | 433 TARGET_TEST_F(ChangeLowering64Test, ChangeUint32ToTagged) { |
431 STATIC_ASSERT(kSmiTag == 0); | 434 STATIC_ASSERT(kSmiTag == 0); |
432 STATIC_ASSERT(kSmiTagSize == 1); | 435 STATIC_ASSERT(kSmiTagSize == 1); |
433 | 436 |
434 Node* val = Parameter(0); | 437 Node* val = Parameter(0); |
435 Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), val); | 438 Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), val); |
436 Reduction reduction = Reduce(node); | 439 Reduction reduction = Reduce(node); |
437 ASSERT_TRUE(reduction.Changed()); | 440 ASSERT_TRUE(reduction.Changed()); |
438 | 441 |
439 Node* phi = reduction.replacement(); | 442 Node* phi = reduction.replacement(); |
440 Capture<Node*> branch, heap_number, if_false; | 443 Capture<Node*> branch, heap_number, if_false; |
441 EXPECT_THAT( | 444 EXPECT_THAT( |
442 phi, | 445 phi, |
443 IsPhi( | 446 IsPhi( |
444 kMachAnyTagged, IsWord64Shl(IsChangeUint32ToUint64(val), | 447 kMachAnyTagged, IsWord64Shl(IsChangeUint32ToUint64(val), |
445 IsInt32Constant(SmiShiftAmount())), | 448 IsInt64Constant(SmiShiftAmount())), |
446 IsFinish(AllOf(CaptureEq(&heap_number), | 449 IsFinish(AllOf(CaptureEq(&heap_number), |
447 IsAllocateHeapNumber(_, CaptureEq(&if_false))), | 450 IsAllocateHeapNumber(_, CaptureEq(&if_false))), |
448 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), | 451 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), |
449 CaptureEq(&heap_number), | 452 CaptureEq(&heap_number), |
450 IsInt32Constant(HeapNumberValueOffset()), | 453 IsInt64Constant(HeapNumberValueOffset()), |
451 IsChangeUint32ToFloat64(val), | 454 IsChangeUint32ToFloat64(val), |
452 CaptureEq(&heap_number), CaptureEq(&if_false))), | 455 CaptureEq(&heap_number), CaptureEq(&if_false))), |
453 IsMerge( | 456 IsMerge( |
454 IsIfTrue(AllOf(CaptureEq(&branch), | 457 IsIfTrue(AllOf(CaptureEq(&branch), |
455 IsBranch(IsUint32LessThanOrEqual( | 458 IsBranch(IsUint32LessThanOrEqual( |
456 val, IsInt32Constant(SmiMaxValue())), | 459 val, IsInt64Constant(SmiMaxValue())), |
457 graph()->start()))), | 460 graph()->start()))), |
458 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 461 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
459 } | 462 } |
460 | 463 |
461 } // namespace compiler | 464 } // namespace compiler |
462 } // namespace internal | 465 } // namespace internal |
463 } // namespace v8 | 466 } // namespace v8 |
OLD | NEW |