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

Unified Diff: src/compiler/node-matchers.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.h ('k') | test/unittests/compiler/node-matchers-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/node-matchers.cc
diff --git a/src/compiler/node-matchers.cc b/src/compiler/node-matchers.cc
index c6ae39000c025ae98f6f1b8a0ad67faf148c185e..1627b88219181892e638ec84457a9248e6972bf1 100644
--- a/src/compiler/node-matchers.cc
+++ b/src/compiler/node-matchers.cc
@@ -12,6 +12,49 @@ bool NodeMatcher::IsComparison() const {
return IrOpcode::IsComparisonOpcode(opcode());
}
+
+BranchMatcher::BranchMatcher(Node* branch)
+ : NodeMatcher(branch), if_true_(nullptr), if_false_(nullptr) {
+ if (branch->opcode() != IrOpcode::kBranch) return;
+ for (Node* use : branch->uses()) {
+ if (use->opcode() == IrOpcode::kIfTrue) {
+ DCHECK_NULL(if_true_);
+ if_true_ = use;
+ } else if (use->opcode() == IrOpcode::kIfFalse) {
+ DCHECK_NULL(if_false_);
+ if_false_ = use;
+ }
+ }
+}
+
+
+DiamondMatcher::DiamondMatcher(Node* merge)
+ : NodeMatcher(merge),
+ branch_(nullptr),
+ if_true_(nullptr),
+ if_false_(nullptr) {
+ if (merge->InputCount() != 2) return;
+ if (merge->opcode() != IrOpcode::kMerge) return;
+ Node* input0 = merge->InputAt(0);
+ if (input0->InputCount() != 1) return;
+ Node* input1 = merge->InputAt(1);
+ if (input1->InputCount() != 1) return;
+ Node* branch = input0->InputAt(0);
+ if (branch != input1->InputAt(0)) return;
+ if (branch->opcode() != IrOpcode::kBranch) return;
+ if (input0->opcode() == IrOpcode::kIfTrue &&
+ input1->opcode() == IrOpcode::kIfFalse) {
+ branch_ = branch;
+ if_true_ = input0;
+ if_false_ = input1;
+ } else if (input0->opcode() == IrOpcode::kIfFalse &&
+ input1->opcode() == IrOpcode::kIfTrue) {
+ branch_ = branch;
+ if_true_ = input1;
+ if_false_ = input0;
+ }
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/node-matchers.h ('k') | test/unittests/compiler/node-matchers-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698