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

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

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addrssed comments. Created 5 years, 10 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
(Empty)
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/control-flow-optimizer.h"
6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-operator.h"
8 #include "src/compiler/machine-operator.h"
9 #include "test/unittests/compiler/graph-unittest.h"
10 #include "test/unittests/compiler/node-test-utils.h"
11 #include "testing/gmock-support.h"
12
13 using testing::AllOf;
14 using testing::Capture;
15 using testing::CaptureEq;
16
17 namespace v8 {
18 namespace internal {
19 namespace compiler {
20
21 class ControlFlowOptimizerTest : public GraphTest {
22 public:
23 explicit ControlFlowOptimizerTest(int num_parameters = 3)
24 : GraphTest(num_parameters), machine_(zone()) {}
25 ~ControlFlowOptimizerTest() OVERRIDE {}
26
27 protected:
28 void Optimize() {
29 JSOperatorBuilder javascript(zone());
30 JSGraph jsgraph(isolate(), graph(), common(), &javascript, machine());
31 ControlFlowOptimizer optimizer(&jsgraph, zone());
32 optimizer.Optimize();
33 }
34
35 MachineOperatorBuilder* machine() { return &machine_; }
36
37 private:
38 MachineOperatorBuilder machine_;
39 };
40
41
42 TEST_F(ControlFlowOptimizerTest, Switch) {
43 Node* index = Parameter(0);
44 Node* branch0 = graph()->NewNode(
45 common()->Branch(),
46 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(0)),
47 start());
48 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
49 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
50 Node* branch1 = graph()->NewNode(
51 common()->Branch(),
52 graph()->NewNode(machine()->Word32Equal(), index, Int32Constant(1)),
53 if_false0);
54 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
55 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
56 Node* merge =
57 graph()->NewNode(common()->Merge(3), if_true0, if_true1, if_false1);
58 graph()->SetEnd(graph()->NewNode(common()->End(), merge));
59 Optimize();
60 Capture<Node*> switch_capture;
61 EXPECT_THAT(end(),
62 IsEnd(IsMerge(IsIfValue(0, CaptureEq(&switch_capture)),
63 IsIfValue(1, CaptureEq(&switch_capture)),
64 IsIfDefault(AllOf(CaptureEq(&switch_capture),
65 IsSwitch(index, start()))))));
66 }
67
68 } // namespace compiler
69 } // namespace internal
70 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/common-operator-unittest.cc ('k') | test/unittests/compiler/graph-unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698