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

Side by Side Diff: test/unittests/compiler/node-matchers-unittest.cc

Issue 1054963002: [turbofan] Introduce BranchMatcher and DiamondMatcher helpers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « src/compiler/node-matchers.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/machine-operator.h" 7 #include "src/compiler/machine-operator.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/compiler/node-matchers.h" 9 #include "src/compiler/node-matchers.h"
10 #include "src/compiler/opcodes.h" 10 #include "src/compiler/opcodes.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 721
722 // (M3 + (D15 + B0)) -> [m3, 0, b0, D15] 722 // (M3 + (D15 + B0)) -> [m3, 0, b0, D15]
723 m3 = graph()->NewNode(m_op, p1, d3); 723 m3 = graph()->NewNode(m_op, p1, d3);
724 temp = graph()->NewNode(a_op, b0, d15); 724 temp = graph()->NewNode(a_op, b0, d15);
725 BaseWithIndexAndDisplacement64Matcher match50( 725 BaseWithIndexAndDisplacement64Matcher match50(
726 graph()->NewNode(a_op, m3, temp)); 726 graph()->NewNode(a_op, m3, temp));
727 CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15); 727 CheckBaseWithIndexAndDisplacement(&match50, m3, 0, b0, d15);
728 } 728 }
729 729
730 730
731 TEST_F(NodeMatcherTest, BranchMatcher_match) {
732 Node* zero = graph()->NewNode(common()->Int32Constant(0));
733
734 {
735 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
736 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
737 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
738 BranchMatcher matcher(branch);
739 EXPECT_TRUE(matcher.Matched());
740 EXPECT_EQ(branch, matcher.Branch());
741 EXPECT_EQ(if_true, matcher.IfTrue());
742 EXPECT_EQ(if_false, matcher.IfFalse());
743 }
744
745 {
746 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
747 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
748 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
749 BranchMatcher matcher(branch);
750 EXPECT_TRUE(matcher.Matched());
751 EXPECT_EQ(branch, matcher.Branch());
752 EXPECT_EQ(if_true, matcher.IfTrue());
753 EXPECT_EQ(if_false, matcher.IfFalse());
754 }
755
756 {
757 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
758 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
759 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
760 Node* other = graph()->NewNode(common()->IfValue(33), branch);
761 BranchMatcher matcher(branch);
762 EXPECT_TRUE(matcher.Matched());
763 EXPECT_EQ(branch, matcher.Branch());
764 EXPECT_EQ(if_true, matcher.IfTrue());
765 EXPECT_EQ(if_false, matcher.IfFalse());
766 USE(other);
767 }
768 }
769
770
771 TEST_F(NodeMatcherTest, BranchMatcher_fail) {
772 Node* zero = graph()->NewNode(common()->Int32Constant(0));
773
774 {
775 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
776 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
777 BranchMatcher matcher(branch);
778 EXPECT_FALSE(matcher.Matched());
779 USE(if_true);
780 }
781
782 {
783 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
784 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
785 BranchMatcher matcher(branch);
786 EXPECT_FALSE(matcher.Matched());
787 USE(if_false);
788 }
789
790 {
791 BranchMatcher matcher(zero);
792 EXPECT_FALSE(matcher.Matched());
793 }
794
795 {
796 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
797 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
798 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
799 EXPECT_TRUE(BranchMatcher(branch).Matched());
800 EXPECT_FALSE(BranchMatcher(if_true).Matched());
801 EXPECT_FALSE(BranchMatcher(if_false).Matched());
802 }
803
804 {
805 Node* sw = graph()->NewNode(common()->Switch(5), zero, graph()->start());
806 Node* if_true = graph()->NewNode(common()->IfTrue(), sw);
807 Node* if_false = graph()->NewNode(common()->IfFalse(), sw);
808 EXPECT_FALSE(BranchMatcher(sw).Matched());
809 EXPECT_FALSE(BranchMatcher(if_true).Matched());
810 EXPECT_FALSE(BranchMatcher(if_false).Matched());
811 }
812
813 {
814 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
815 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
816 Node* if_value = graph()->NewNode(common()->IfValue(2), branch);
817 BranchMatcher matcher(branch);
818 EXPECT_FALSE(matcher.Matched());
819 EXPECT_FALSE(BranchMatcher(if_true).Matched());
820 EXPECT_FALSE(BranchMatcher(if_value).Matched());
821 }
822 }
823
824
825 TEST_F(NodeMatcherTest, DiamondMatcher_match) {
826 Node* zero = graph()->NewNode(common()->Int32Constant(0));
827
828 {
829 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
830 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
831 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
832 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
833 DiamondMatcher matcher(merge);
834 EXPECT_TRUE(matcher.Matched());
835 EXPECT_EQ(branch, matcher.Branch());
836 EXPECT_EQ(if_true, matcher.IfTrue());
837 EXPECT_EQ(if_false, matcher.IfFalse());
838 EXPECT_EQ(merge, matcher.Merge());
839 }
840
841 {
842 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
843 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
844 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
845 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
846 DiamondMatcher matcher(merge);
847 EXPECT_TRUE(matcher.Matched());
848 EXPECT_EQ(branch, matcher.Branch());
849 EXPECT_EQ(if_true, matcher.IfTrue());
850 EXPECT_EQ(if_false, matcher.IfFalse());
851 EXPECT_EQ(merge, matcher.Merge());
852 }
853
854 {
855 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
856 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
857 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
858 Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_true);
859 DiamondMatcher matcher(merge);
860 EXPECT_TRUE(matcher.Matched());
861 EXPECT_EQ(branch, matcher.Branch());
862 EXPECT_EQ(if_true, matcher.IfTrue());
863 EXPECT_EQ(if_false, matcher.IfFalse());
864 EXPECT_EQ(merge, matcher.Merge());
865 }
866 }
867
868
869 TEST_F(NodeMatcherTest, DiamondMatcher_fail) {
870 Node* zero = graph()->NewNode(common()->Int32Constant(0));
871
872 {
873 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
874 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
875 Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
876 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_value);
877 DiamondMatcher matcher(merge);
878 EXPECT_FALSE(matcher.Matched());
879 }
880
881 {
882 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
883 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
884 Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
885 Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_value);
886 DiamondMatcher matcher(merge);
887 EXPECT_FALSE(matcher.Matched());
888 }
889
890 {
891 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
892 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
893 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
894 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
895 DiamondMatcher matcher(merge);
896 EXPECT_TRUE(matcher.Matched());
897 EXPECT_EQ(branch, matcher.Branch());
898 EXPECT_EQ(if_true, matcher.IfTrue());
899 EXPECT_EQ(if_false, matcher.IfFalse());
900 EXPECT_EQ(merge, matcher.Merge());
901
902 EXPECT_FALSE(DiamondMatcher(branch).Matched()); // Must be the merge.
903 EXPECT_FALSE(DiamondMatcher(if_true).Matched());
904 EXPECT_FALSE(DiamondMatcher(if_false).Matched());
905 }
906
907 {
908 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
909 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
910 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
911 Node* merge = graph()->NewNode(common()->Merge(3), if_true, if_false,
912 graph()->start());
913 DiamondMatcher matcher(merge);
914 EXPECT_FALSE(matcher.Matched()); // Too many inputs to merge.
915 }
916
917 {
918 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
919 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
920 Node* if_false = graph()->start();
921 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
922 DiamondMatcher matcher(merge);
923 EXPECT_FALSE(matcher.Matched());
924 }
925
926 {
927 Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
928 Node* if_true = graph()->start();
929 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
930 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
931 DiamondMatcher matcher(merge);
932 EXPECT_FALSE(matcher.Matched());
933 }
934
935 {
936 Node* branch1 =
937 graph()->NewNode(common()->Branch(), zero, graph()->start());
938 Node* branch2 =
939 graph()->NewNode(common()->Branch(), zero, graph()->start());
940 Node* if_true = graph()->NewNode(common()->IfTrue(), branch1);
941 Node* if_false = graph()->NewNode(common()->IfFalse(), branch2);
942 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
943 DiamondMatcher matcher(merge);
944 EXPECT_FALSE(matcher.Matched());
945 }
946 }
947
948
731 } // namespace compiler 949 } // namespace compiler
732 } // namespace internal 950 } // namespace internal
733 } // namespace v8 951 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/node-matchers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698