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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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/node-matchers.h" 5 #include "src/compiler/node-matchers.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace compiler { 9 namespace compiler {
10 10
11 bool NodeMatcher::IsComparison() const { 11 bool NodeMatcher::IsComparison() const {
12 return IrOpcode::IsComparisonOpcode(opcode()); 12 return IrOpcode::IsComparisonOpcode(opcode());
13 } 13 }
14 14
15
16 BranchMatcher::BranchMatcher(Node* branch)
17 : NodeMatcher(branch), if_true_(nullptr), if_false_(nullptr) {
18 if (branch->opcode() != IrOpcode::kBranch) return;
19 for (Node* use : branch->uses()) {
20 if (use->opcode() == IrOpcode::kIfTrue) {
21 DCHECK_NULL(if_true_);
22 if_true_ = use;
23 } else if (use->opcode() == IrOpcode::kIfFalse) {
24 DCHECK_NULL(if_false_);
25 if_false_ = use;
26 }
27 }
28 }
29
30
31 DiamondMatcher::DiamondMatcher(Node* merge)
32 : NodeMatcher(merge),
33 branch_(nullptr),
34 if_true_(nullptr),
35 if_false_(nullptr) {
36 if (merge->InputCount() != 2) return;
37 if (merge->opcode() != IrOpcode::kMerge) return;
38 Node* input0 = merge->InputAt(0);
39 if (input0->InputCount() != 1) return;
40 Node* input1 = merge->InputAt(1);
41 if (input1->InputCount() != 1) return;
42 Node* branch = input0->InputAt(0);
43 if (branch != input1->InputAt(0)) return;
44 if (branch->opcode() != IrOpcode::kBranch) return;
45 if (input0->opcode() == IrOpcode::kIfTrue &&
46 input1->opcode() == IrOpcode::kIfFalse) {
47 branch_ = branch;
48 if_true_ = input0;
49 if_false_ = input1;
50 }
51 if (input0->opcode() == IrOpcode::kIfFalse &&
Benedikt Meurer 2015/04/07 07:19:01 Nit: Use else if.
titzer 2015/04/07 08:41:00 Done.
52 input1->opcode() == IrOpcode::kIfTrue) {
53 branch_ = branch;
54 if_true_ = input1;
55 if_false_ = input0;
56 }
57 }
58
15 } // namespace compiler 59 } // namespace compiler
16 } // namespace internal 60 } // namespace internal
17 } // namespace v8 61 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698