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

Side by Side Diff: test/unittests/compiler/control-flow-optimizer-unittest.cc

Issue 947963002: [turbofan] Initial version of branch cloning. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tests and documentation. Created 5 years, 9 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
« no previous file with comments | « test/mjsunit/asm/if-cloning.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/control-flow-optimizer.h" 5 #include "src/compiler/control-flow-optimizer.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-operator.h" 7 #include "src/compiler/js-operator.h"
8 #include "src/compiler/machine-operator.h" 8 #include "src/compiler/machine-operator.h"
9 #include "test/unittests/compiler/graph-unittest.h" 9 #include "test/unittests/compiler/graph-unittest.h"
10 #include "test/unittests/compiler/node-test-utils.h" 10 #include "test/unittests/compiler/node-test-utils.h"
(...skipping 21 matching lines...) Expand all
32 optimizer.Optimize(); 32 optimizer.Optimize();
33 } 33 }
34 34
35 MachineOperatorBuilder* machine() { return &machine_; } 35 MachineOperatorBuilder* machine() { return &machine_; }
36 36
37 private: 37 private:
38 MachineOperatorBuilder machine_; 38 MachineOperatorBuilder machine_;
39 }; 39 };
40 40
41 41
42 TEST_F(ControlFlowOptimizerTest, Switch) { 42 TEST_F(ControlFlowOptimizerTest, BuildSwitch) {
43 Node* index = Parameter(0); 43 Node* index = Parameter(0);
44 Node* branch0 = graph()->NewNode( 44 Node* branch0 = graph()->NewNode(
45 common()->Branch(), 45 common()->Branch(),
46 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(0)), 46 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(0)),
47 start()); 47 start());
48 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0); 48 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
49 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0); 49 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
50 Node* branch1 = graph()->NewNode( 50 Node* branch1 = graph()->NewNode(
51 common()->Branch(), 51 common()->Branch(),
52 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)), 52 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)),
53 if_false0); 53 if_false0);
54 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); 54 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
55 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); 55 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
56 Node* merge = 56 Node* merge =
57 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1); 57 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1);
58 graph()->SetEnd(graph()->NewNode(common()->End(), merge)); 58 graph()->SetEnd(graph()->NewNode(common()->End(), merge));
59 Optimize(); 59 Optimize();
60 Capture<Node*> switch_capture; 60 Capture<Node*> switch_capture;
61 EXPECT_THAT(end(), 61 EXPECT_THAT(end(),
62 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)), 62 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)),
63 IsIfValue(1, CaptureEq(&switch_capture)), 63 IsIfValue(1, CaptureEq(&switch_capture)),
64 IsIfDefault(AllOf(CaptureEq(&switch_capture), 64 IsIfDefault(AllOf(CaptureEq(&switch_capture),
65 IsSwitch(index, start())))))); 65 IsSwitch(index, start()))))));
66 } 66 }
67 67
68
69 TEST_F(ControlFlowOptimizerTest, CloneBranch) {
70 Node* cond0 = Parameter(0);
71 Node* cond1 = Parameter(1);
72 Node* cond2 = Parameter(2);
73 Node* branch0 = graph()->NewNode(common()->Branch(), cond0, start());
74 Node* control1 = graph()->NewNode(common()->IfTrue(), branch0);
75 Node* control2 = graph()->NewNode(common()->IfFalse(), branch0);
76 Node* merge0 = graph()->NewNode(common()->Merge(2), control1, control2);
77 Node* phi0 =
78 graph()->NewNode(common()->Phi(kRepBit, 2), cond1, cond2, merge0);
79 Node* branch = graph()->NewNode(common()->Branch(), phi0, merge0);
80 Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
81 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
82 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
83 graph()->SetEnd(graph()->NewNode(common()->End(), merge));
84 Optimize();
85 Capture<Node*> branch1_capture, branch2_capture;
86 EXPECT_THAT(
87 end(),
88 IsEnd(IsMerge(IsMerge(IsIfTrue(CaptureEq(&branch1_capture)),
89 IsIfTrue(CaptureEq(&branch2_capture))),
90 IsMerge(IsIfFalse(AllOf(CaptureEq(&branch1_capture),
91 IsBranch(cond1, control1))),
92 IsIfFalse(AllOf(CaptureEq(&branch2_capture),
93 IsBranch(cond2, control2)))))));
94 }
95
68 } // namespace compiler 96 } // namespace compiler
69 } // namespace internal 97 } // namespace internal
70 } // namespace v8 98 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/asm/if-cloning.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698