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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/node-matchers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/node-matchers-unittest.cc
diff --git a/test/unittests/compiler/node-matchers-unittest.cc b/test/unittests/compiler/node-matchers-unittest.cc
index 85db9dbdca6f2a580c0ce72d719cad5d814677e3..a6239085dd75065a6072aa554f3eda0505b90500 100644
--- a/test/unittests/compiler/node-matchers-unittest.cc
+++ b/test/unittests/compiler/node-matchers-unittest.cc
@@ -728,6 +728,224 @@ TEST_F(NodeMatcherTest, ScaledWithOffset64Matcher) {
}
+TEST_F(NodeMatcherTest, BranchMatcher_match) {
+ Node* zero = graph()->NewNode(common()->Int32Constant(0));
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* other = graph()->NewNode(common()->IfValue(33), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ USE(other);
+ }
+}
+
+
+TEST_F(NodeMatcherTest, BranchMatcher_fail) {
+ Node* zero = graph()->NewNode(common()->Int32Constant(0));
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_FALSE(matcher.Matched());
+ USE(if_true);
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_FALSE(matcher.Matched());
+ USE(if_false);
+ }
+
+ {
+ BranchMatcher matcher(zero);
+ EXPECT_FALSE(matcher.Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ EXPECT_TRUE(BranchMatcher(branch).Matched());
+ EXPECT_FALSE(BranchMatcher(if_true).Matched());
+ EXPECT_FALSE(BranchMatcher(if_false).Matched());
+ }
+
+ {
+ Node* sw = graph()->NewNode(common()->Switch(5), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), sw);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), sw);
+ EXPECT_FALSE(BranchMatcher(sw).Matched());
+ EXPECT_FALSE(BranchMatcher(if_true).Matched());
+ EXPECT_FALSE(BranchMatcher(if_false).Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_value = graph()->NewNode(common()->IfValue(2), branch);
+ BranchMatcher matcher(branch);
+ EXPECT_FALSE(matcher.Matched());
+ EXPECT_FALSE(BranchMatcher(if_true).Matched());
+ EXPECT_FALSE(BranchMatcher(if_value).Matched());
+ }
+}
+
+
+TEST_F(NodeMatcherTest, DiamondMatcher_match) {
+ Node* zero = graph()->NewNode(common()->Int32Constant(0));
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ EXPECT_EQ(merge, matcher.Merge());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ EXPECT_EQ(merge, matcher.Merge());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_true);
+ DiamondMatcher matcher(merge);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ EXPECT_EQ(merge, matcher.Merge());
+ }
+}
+
+
+TEST_F(NodeMatcherTest, DiamondMatcher_fail) {
+ Node* zero = graph()->NewNode(common()->Int32Constant(0));
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_value);
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* if_value = graph()->NewNode(common()->IfValue(1), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_false, if_value);
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_TRUE(matcher.Matched());
+ EXPECT_EQ(branch, matcher.Branch());
+ EXPECT_EQ(if_true, matcher.IfTrue());
+ EXPECT_EQ(if_false, matcher.IfFalse());
+ EXPECT_EQ(merge, matcher.Merge());
+
+ EXPECT_FALSE(DiamondMatcher(branch).Matched()); // Must be the merge.
+ EXPECT_FALSE(DiamondMatcher(if_true).Matched());
+ EXPECT_FALSE(DiamondMatcher(if_false).Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(3), if_true, if_false,
+ graph()->start());
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched()); // Too many inputs to merge.
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
+ Node* if_false = graph()->start();
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched());
+ }
+
+ {
+ Node* branch = graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->start();
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched());
+ }
+
+ {
+ Node* branch1 =
+ graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* branch2 =
+ graph()->NewNode(common()->Branch(), zero, graph()->start());
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch1);
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch2);
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
+ DiamondMatcher matcher(merge);
+ EXPECT_FALSE(matcher.Matched());
+ }
+}
+
+
} // namespace compiler
} // namespace internal
} // namespace v8
« 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