Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1112)

Side by Side Diff: test/unittests/compiler/graph-reducer-unittest.cc

Issue 1178403004: [turbofan] Use appropriate type for NodeId. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix useless static_cast. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/compiler/common-operator.h" 5 #include "src/compiler/common-operator.h"
6 #include "src/compiler/graph.h" 6 #include "src/compiler/graph.h"
7 #include "src/compiler/node.h" 7 #include "src/compiler/node.h"
8 #include "src/compiler/operator.h" 8 #include "src/compiler/operator.h"
9 #include "test/unittests/compiler/graph-reducer-unittest.h" 9 #include "test/unittests/compiler/graph-reducer-unittest.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 517
518 518
519 TEST_F(GraphReducerTest, ReduceInPlace1) { 519 TEST_F(GraphReducerTest, ReduceInPlace1) {
520 Node* n1 = graph()->NewNode(&kOpA0); 520 Node* n1 = graph()->NewNode(&kOpA0);
521 Node* end = graph()->NewNode(&kOpA1, n1); 521 Node* end = graph()->NewNode(&kOpA1, n1);
522 graph()->SetEnd(end); 522 graph()->SetEnd(end);
523 523
524 // Tests A* => B* with in-place updates. 524 // Tests A* => B* with in-place updates.
525 InPlaceABReducer r; 525 InPlaceABReducer r;
526 for (int i = 0; i < 3; i++) { 526 for (int i = 0; i < 3; i++) {
527 int before = graph()->NodeCount(); 527 size_t before = graph()->NodeCount();
528 ReduceGraph(&r); 528 ReduceGraph(&r);
529 EXPECT_EQ(before, graph()->NodeCount()); 529 EXPECT_EQ(before, graph()->NodeCount());
530 EXPECT_EQ(&kOpB0, n1->op()); 530 EXPECT_EQ(&kOpB0, n1->op());
531 EXPECT_EQ(&kOpB1, end->op()); 531 EXPECT_EQ(&kOpB1, end->op());
532 EXPECT_EQ(n1, end->InputAt(0)); 532 EXPECT_EQ(n1, end->InputAt(0));
533 } 533 }
534 } 534 }
535 535
536 536
537 TEST_F(GraphReducerTest, ReduceInPlace2) { 537 TEST_F(GraphReducerTest, ReduceInPlace2) {
538 Node* n1 = graph()->NewNode(&kOpA0); 538 Node* n1 = graph()->NewNode(&kOpA0);
539 Node* n2 = graph()->NewNode(&kOpA1, n1); 539 Node* n2 = graph()->NewNode(&kOpA1, n1);
540 Node* n3 = graph()->NewNode(&kOpA1, n1); 540 Node* n3 = graph()->NewNode(&kOpA1, n1);
541 Node* end = graph()->NewNode(&kOpA2, n2, n3); 541 Node* end = graph()->NewNode(&kOpA2, n2, n3);
542 graph()->SetEnd(end); 542 graph()->SetEnd(end);
543 543
544 // Tests A* => B* with in-place updates. 544 // Tests A* => B* with in-place updates.
545 InPlaceABReducer r; 545 InPlaceABReducer r;
546 for (int i = 0; i < 3; i++) { 546 for (int i = 0; i < 3; i++) {
547 int before = graph()->NodeCount(); 547 size_t before = graph()->NodeCount();
548 ReduceGraph(&r); 548 ReduceGraph(&r);
549 EXPECT_EQ(before, graph()->NodeCount()); 549 EXPECT_EQ(before, graph()->NodeCount());
550 EXPECT_EQ(&kOpB0, n1->op()); 550 EXPECT_EQ(&kOpB0, n1->op());
551 EXPECT_EQ(&kOpB1, n2->op()); 551 EXPECT_EQ(&kOpB1, n2->op());
552 EXPECT_EQ(n1, n2->InputAt(0)); 552 EXPECT_EQ(n1, n2->InputAt(0));
553 EXPECT_EQ(&kOpB1, n3->op()); 553 EXPECT_EQ(&kOpB1, n3->op());
554 EXPECT_EQ(n1, n3->InputAt(0)); 554 EXPECT_EQ(n1, n3->InputAt(0));
555 EXPECT_EQ(&kOpB2, end->op()); 555 EXPECT_EQ(&kOpB2, end->op());
556 EXPECT_EQ(n2, end->InputAt(0)); 556 EXPECT_EQ(n2, end->InputAt(0));
557 EXPECT_EQ(n3, end->InputAt(1)); 557 EXPECT_EQ(n3, end->InputAt(1));
558 } 558 }
559 } 559 }
560 560
561 561
562 TEST_F(GraphReducerTest, ReduceNew1) { 562 TEST_F(GraphReducerTest, ReduceNew1) {
563 Node* n1 = graph()->NewNode(&kOpA0); 563 Node* n1 = graph()->NewNode(&kOpA0);
564 Node* n2 = graph()->NewNode(&kOpA1, n1); 564 Node* n2 = graph()->NewNode(&kOpA1, n1);
565 Node* n3 = graph()->NewNode(&kOpA1, n1); 565 Node* n3 = graph()->NewNode(&kOpA1, n1);
566 Node* end = graph()->NewNode(&kOpA2, n2, n3); 566 Node* end = graph()->NewNode(&kOpA2, n2, n3);
567 graph()->SetEnd(end); 567 graph()->SetEnd(end);
568 568
569 NewABReducer r(graph()); 569 NewABReducer r(graph());
570 // Tests A* => B* while creating new nodes. 570 // Tests A* => B* while creating new nodes.
571 for (int i = 0; i < 3; i++) { 571 for (int i = 0; i < 3; i++) {
572 int before = graph()->NodeCount(); 572 size_t before = graph()->NodeCount();
573 ReduceGraph(&r); 573 ReduceGraph(&r);
574 if (i == 0) { 574 if (i == 0) {
575 EXPECT_NE(before, graph()->NodeCount()); 575 EXPECT_NE(before, graph()->NodeCount());
576 } else { 576 } else {
577 EXPECT_EQ(before, graph()->NodeCount()); 577 EXPECT_EQ(before, graph()->NodeCount());
578 } 578 }
579 Node* nend = graph()->end(); 579 Node* nend = graph()->end();
580 EXPECT_NE(end, nend); // end() should be updated too. 580 EXPECT_NE(end, nend); // end() should be updated too.
581 581
582 Node* nn2 = nend->InputAt(0); 582 Node* nn2 = nend->InputAt(0);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 636
637 TEST_F(GraphReducerTest, Forwarding1) { 637 TEST_F(GraphReducerTest, Forwarding1) {
638 Node* n1 = graph()->NewNode(&kOpA0); 638 Node* n1 = graph()->NewNode(&kOpA0);
639 Node* end = graph()->NewNode(&kOpA1, n1); 639 Node* end = graph()->NewNode(&kOpA1, n1);
640 graph()->SetEnd(end); 640 graph()->SetEnd(end);
641 641
642 A1Forwarder r; 642 A1Forwarder r;
643 643
644 // Tests A1(x) => x 644 // Tests A1(x) => x
645 for (int i = 0; i < 3; i++) { 645 for (int i = 0; i < 3; i++) {
646 int before = graph()->NodeCount(); 646 size_t before = graph()->NodeCount();
647 ReduceGraph(&r); 647 ReduceGraph(&r);
648 EXPECT_EQ(before, graph()->NodeCount()); 648 EXPECT_EQ(before, graph()->NodeCount());
649 EXPECT_EQ(&kOpA0, n1->op()); 649 EXPECT_EQ(&kOpA0, n1->op());
650 EXPECT_EQ(n1, graph()->end()); 650 EXPECT_EQ(n1, graph()->end());
651 } 651 }
652 } 652 }
653 653
654 654
655 TEST_F(GraphReducerTest, Forwarding2) { 655 TEST_F(GraphReducerTest, Forwarding2) {
656 Node* n1 = graph()->NewNode(&kOpA0); 656 Node* n1 = graph()->NewNode(&kOpA0);
657 Node* n2 = graph()->NewNode(&kOpA1, n1); 657 Node* n2 = graph()->NewNode(&kOpA1, n1);
658 Node* n3 = graph()->NewNode(&kOpA1, n1); 658 Node* n3 = graph()->NewNode(&kOpA1, n1);
659 Node* end = graph()->NewNode(&kOpA2, n2, n3); 659 Node* end = graph()->NewNode(&kOpA2, n2, n3);
660 graph()->SetEnd(end); 660 graph()->SetEnd(end);
661 661
662 A1Forwarder r; 662 A1Forwarder r;
663 663
664 // Tests reducing A2(A1(x), A1(y)) => A2(x, y). 664 // Tests reducing A2(A1(x), A1(y)) => A2(x, y).
665 for (int i = 0; i < 3; i++) { 665 for (int i = 0; i < 3; i++) {
666 int before = graph()->NodeCount(); 666 size_t before = graph()->NodeCount();
667 ReduceGraph(&r); 667 ReduceGraph(&r);
668 EXPECT_EQ(before, graph()->NodeCount()); 668 EXPECT_EQ(before, graph()->NodeCount());
669 EXPECT_EQ(&kOpA0, n1->op()); 669 EXPECT_EQ(&kOpA0, n1->op());
670 EXPECT_EQ(n1, end->InputAt(0)); 670 EXPECT_EQ(n1, end->InputAt(0));
671 EXPECT_EQ(n1, end->InputAt(1)); 671 EXPECT_EQ(n1, end->InputAt(1));
672 EXPECT_EQ(&kOpA2, end->op()); 672 EXPECT_EQ(&kOpA2, end->op());
673 EXPECT_EQ(0, n2->UseCount()); 673 EXPECT_EQ(0, n2->UseCount());
674 EXPECT_EQ(0, n3->UseCount()); 674 EXPECT_EQ(0, n3->UseCount());
675 } 675 }
676 } 676 }
677 677
678 678
679 TEST_F(GraphReducerTest, Forwarding3) { 679 TEST_F(GraphReducerTest, Forwarding3) {
680 // Tests reducing a chain of A1(A1(A1(A1(x)))) => x. 680 // Tests reducing a chain of A1(A1(A1(A1(x)))) => x.
681 for (int i = 0; i < 8; i++) { 681 for (int i = 0; i < 8; i++) {
682 Node* n1 = graph()->NewNode(&kOpA0); 682 Node* n1 = graph()->NewNode(&kOpA0);
683 Node* end = n1; 683 Node* end = n1;
684 for (int j = 0; j < i; j++) { 684 for (int j = 0; j < i; j++) {
685 end = graph()->NewNode(&kOpA1, end); 685 end = graph()->NewNode(&kOpA1, end);
686 } 686 }
687 graph()->SetEnd(end); 687 graph()->SetEnd(end);
688 688
689 A1Forwarder r; 689 A1Forwarder r;
690 690
691 for (int i = 0; i < 3; i++) { 691 for (size_t i = 0; i < 3; i++) {
692 int before = graph()->NodeCount(); 692 size_t before = graph()->NodeCount();
693 ReduceGraph(&r); 693 ReduceGraph(&r);
694 EXPECT_EQ(before, graph()->NodeCount()); 694 EXPECT_EQ(before, graph()->NodeCount());
695 EXPECT_EQ(&kOpA0, n1->op()); 695 EXPECT_EQ(&kOpA0, n1->op());
696 EXPECT_EQ(n1, graph()->end()); 696 EXPECT_EQ(n1, graph()->end());
697 } 697 }
698 } 698 }
699 } 699 }
700 700
701 701
702 TEST_F(GraphReducerTest, ReduceForward1) { 702 TEST_F(GraphReducerTest, ReduceForward1) {
703 Node* n1 = graph()->NewNode(&kOpA0); 703 Node* n1 = graph()->NewNode(&kOpA0);
704 Node* n2 = graph()->NewNode(&kOpA1, n1); 704 Node* n2 = graph()->NewNode(&kOpA1, n1);
705 Node* n3 = graph()->NewNode(&kOpA1, n1); 705 Node* n3 = graph()->NewNode(&kOpA1, n1);
706 Node* end = graph()->NewNode(&kOpA2, n2, n3); 706 Node* end = graph()->NewNode(&kOpA2, n2, n3);
707 graph()->SetEnd(end); 707 graph()->SetEnd(end);
708 708
709 InPlaceABReducer r; 709 InPlaceABReducer r;
710 B1Forwarder f; 710 B1Forwarder f;
711 711
712 // Tests first reducing A => B, then B1(x) => x. 712 // Tests first reducing A => B, then B1(x) => x.
713 for (int i = 0; i < 3; i++) { 713 for (size_t i = 0; i < 3; i++) {
714 int before = graph()->NodeCount(); 714 size_t before = graph()->NodeCount();
715 ReduceGraph(&r, &f); 715 ReduceGraph(&r, &f);
716 EXPECT_EQ(before, graph()->NodeCount()); 716 EXPECT_EQ(before, graph()->NodeCount());
717 EXPECT_EQ(&kOpB0, n1->op()); 717 EXPECT_EQ(&kOpB0, n1->op());
718 EXPECT_TRUE(n2->IsDead()); 718 EXPECT_TRUE(n2->IsDead());
719 EXPECT_EQ(n1, end->InputAt(0)); 719 EXPECT_EQ(n1, end->InputAt(0));
720 EXPECT_TRUE(n3->IsDead()); 720 EXPECT_TRUE(n3->IsDead());
721 EXPECT_EQ(n1, end->InputAt(0)); 721 EXPECT_EQ(n1, end->InputAt(0));
722 EXPECT_EQ(&kOpB2, end->op()); 722 EXPECT_EQ(&kOpB2, end->op());
723 EXPECT_EQ(0, n2->UseCount()); 723 EXPECT_EQ(0, n2->UseCount());
724 EXPECT_EQ(0, n3->UseCount()); 724 EXPECT_EQ(0, n3->UseCount());
(...skipping 11 matching lines...) Expand all
736 736
737 if (i == 0) end = graph()->NewNode(&kOpA2, n2, n3); 737 if (i == 0) end = graph()->NewNode(&kOpA2, n2, n3);
738 if (i == 1) end = graph()->NewNode(&kOpA2, n3, n2); 738 if (i == 1) end = graph()->NewNode(&kOpA2, n3, n2);
739 if (i == 2) end = graph()->NewNode(&kOpA2, n2, n1); 739 if (i == 2) end = graph()->NewNode(&kOpA2, n2, n1);
740 if (i == 3) end = graph()->NewNode(&kOpA2, n1, n2); 740 if (i == 3) end = graph()->NewNode(&kOpA2, n1, n2);
741 if (i == 4) end = graph()->NewNode(&kOpA2, n3, n1); 741 if (i == 4) end = graph()->NewNode(&kOpA2, n3, n1);
742 if (i == 5) end = graph()->NewNode(&kOpA2, n1, n3); 742 if (i == 5) end = graph()->NewNode(&kOpA2, n1, n3);
743 743
744 graph()->SetEnd(end); 744 graph()->SetEnd(end);
745 745
746 int before = graph()->NodeCount(); 746 size_t before = graph()->NodeCount();
747 ReduceGraph(&r); 747 ReduceGraph(&r);
748 EXPECT_EQ(before, graph()->NodeCount()); 748 EXPECT_EQ(before, graph()->NodeCount());
749 EXPECT_EQ(&kOpA0, n1->op()); 749 EXPECT_EQ(&kOpA0, n1->op());
750 EXPECT_EQ(&kOpA1, n2->op()); 750 EXPECT_EQ(&kOpA1, n2->op());
751 EXPECT_EQ(&kOpA1, n3->op()); 751 EXPECT_EQ(&kOpA1, n3->op());
752 EXPECT_EQ(&kOpA2, end->op()); 752 EXPECT_EQ(&kOpA2, end->op());
753 EXPECT_EQ(end, graph()->end()); 753 EXPECT_EQ(end, graph()->end());
754 EXPECT_LE(end->InputAt(0)->id(), end->InputAt(1)->id()); 754 EXPECT_LE(end->InputAt(0)->id(), end->InputAt(1)->id());
755 } 755 }
756 } 756 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // rerun for changed nodes. 831 // rerun for changed nodes.
832 for (int i = 0; i < 2; i++) { 832 for (int i = 0; i < 2; i++) {
833 Node* n1 = graph()->NewNode(&kOpA0); 833 Node* n1 = graph()->NewNode(&kOpA0);
834 Node* end = graph()->NewNode(&kOpA1, n1); 834 Node* end = graph()->NewNode(&kOpA1, n1);
835 graph()->SetEnd(end); 835 graph()->SetEnd(end);
836 836
837 InPlaceABReducer abr; 837 InPlaceABReducer abr;
838 InPlaceBCReducer bcr; 838 InPlaceBCReducer bcr;
839 839
840 // Tests A* => C* with in-place updates. 840 // Tests A* => C* with in-place updates.
841 for (int j = 0; j < 3; j++) { 841 for (size_t j = 0; j < 3; j++) {
842 int before = graph()->NodeCount(); 842 size_t before = graph()->NodeCount();
843 if (i == 0) { 843 if (i == 0) {
844 ReduceGraph(&abr, &bcr); 844 ReduceGraph(&abr, &bcr);
845 } else { 845 } else {
846 ReduceGraph(&bcr, &abr); 846 ReduceGraph(&bcr, &abr);
847 } 847 }
848 848
849 EXPECT_EQ(before, graph()->NodeCount()); 849 EXPECT_EQ(before, graph()->NodeCount());
850 EXPECT_EQ(&kOpC0, n1->op()); 850 EXPECT_EQ(&kOpC0, n1->op());
851 EXPECT_EQ(&kOpC1, end->op()); 851 EXPECT_EQ(&kOpC1, end->op());
852 EXPECT_EQ(n1, end->InputAt(0)); 852 EXPECT_EQ(n1, end->InputAt(0));
853 } 853 }
854 } 854 }
855 } 855 }
856 856
857 } // namespace compiler 857 } // namespace compiler
858 } // namespace internal 858 } // namespace internal
859 } // namespace v8 859 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/control-equivalence-unittest.cc ('k') | test/unittests/compiler/graph-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698