Line data Source code
1 : // Copyright 2015 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/compiler/node-matchers.h"
6 :
7 : namespace v8 {
8 : namespace internal {
9 : namespace compiler {
10 :
11 754961 : bool NodeMatcher::IsComparison() const {
12 754961 : return IrOpcode::IsComparisonOpcode(opcode());
13 : }
14 :
15 :
16 290116 : BranchMatcher::BranchMatcher(Node* branch)
17 290116 : : NodeMatcher(branch), if_true_(nullptr), if_false_(nullptr) {
18 290116 : if (branch->opcode() != IrOpcode::kBranch) return;
19 870323 : for (Node* use : branch->uses()) {
20 580215 : if (use->opcode() == IrOpcode::kIfTrue) {
21 : DCHECK_NULL(if_true_);
22 290107 : if_true_ = use;
23 290108 : } else if (use->opcode() == IrOpcode::kIfFalse) {
24 : DCHECK_NULL(if_false_);
25 290106 : if_false_ = use;
26 : }
27 : }
28 : }
29 :
30 :
31 13 : DiamondMatcher::DiamondMatcher(Node* merge)
32 : : NodeMatcher(merge),
33 : branch_(nullptr),
34 : if_true_(nullptr),
35 13 : if_false_(nullptr) {
36 13 : if (merge->InputCount() != 2) return;
37 10 : if (merge->opcode() != IrOpcode::kMerge) return;
38 : Node* input0 = merge->InputAt(0);
39 9 : if (input0->InputCount() != 1) return;
40 : Node* input1 = merge->InputAt(1);
41 8 : if (input1->InputCount() != 1) return;
42 : Node* branch = input0->InputAt(0);
43 7 : if (branch != input1->InputAt(0)) return;
44 6 : if (branch->opcode() != IrOpcode::kBranch) return;
45 10 : if (input0->opcode() == IrOpcode::kIfTrue &&
46 : input1->opcode() == IrOpcode::kIfFalse) {
47 3 : branch_ = branch;
48 3 : if_true_ = input0;
49 3 : if_false_ = input1;
50 5 : } else if (input0->opcode() == IrOpcode::kIfFalse &&
51 : input1->opcode() == IrOpcode::kIfTrue) {
52 1 : branch_ = branch;
53 1 : if_true_ = input1;
54 1 : if_false_ = input0;
55 : }
56 : }
57 :
58 : } // namespace compiler
59 : } // namespace internal
60 121996 : } // namespace v8
|