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 |