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

Side by Side Diff: test/unittests/compiler/schedule-unittest.cc

Issue 864293002: [turbofan] Cleanup Schedule and related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address auto comments. Created 5 years, 11 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/cctest/compiler/test-scheduler.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/node.h"
6 #include "src/compiler/schedule.h"
7 #include "test/unittests/test-utils.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9
10 using testing::ElementsAre;
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 typedef TestWithZone ScheduleTest;
17
18
19 namespace {
20
21 const Operator kBranchOperator(IrOpcode::kBranch, Operator::kNoProperties,
22 "Branch", 0, 0, 0, 0, 0, 0);
23 const Operator kDummyOperator(IrOpcode::kParameter, Operator::kNoProperties,
24 "Dummy", 0, 0, 0, 0, 0, 0);
25
26 } // namespace
27
28
29 TEST_F(ScheduleTest, Constructor) {
30 Schedule schedule(zone());
31 EXPECT_NE(nullptr, schedule.start());
32 EXPECT_EQ(schedule.start(),
33 schedule.GetBlockById(BasicBlock::Id::FromInt(0)));
34 EXPECT_NE(nullptr, schedule.end());
35 EXPECT_EQ(schedule.end(), schedule.GetBlockById(BasicBlock::Id::FromInt(1)));
36 EXPECT_NE(schedule.start(), schedule.end());
37 }
38
39
40 TEST_F(ScheduleTest, AddNode) {
41 Schedule schedule(zone());
42 BasicBlock* start = schedule.start();
43
44 Node* node0 = Node::New(zone(), 0, &kDummyOperator, 0, nullptr, false);
45 EXPECT_EQ(nullptr, schedule.block(node0));
46 schedule.AddNode(start, node0);
47 EXPECT_EQ(start, schedule.block(node0));
48 EXPECT_THAT(*start, ElementsAre(node0));
49
50 Node* node1 = Node::New(zone(), 1, &kDummyOperator, 0, nullptr, false);
51 EXPECT_EQ(nullptr, schedule.block(node1));
52 schedule.AddNode(start, node1);
53 EXPECT_EQ(start, schedule.block(node1));
54 EXPECT_THAT(*start, ElementsAre(node0, node1));
55
56 EXPECT_TRUE(schedule.SameBasicBlock(node0, node1));
57 }
58
59
60 TEST_F(ScheduleTest, AddGoto) {
61 Schedule schedule(zone());
62 BasicBlock* start = schedule.start();
63 BasicBlock* end = schedule.end();
64
65 BasicBlock* block = schedule.NewBasicBlock();
66 schedule.AddGoto(start, block);
67
68 EXPECT_EQ(0u, start->PredecessorCount());
69 EXPECT_EQ(1u, start->SuccessorCount());
70 EXPECT_EQ(block, start->SuccessorAt(0));
71 EXPECT_THAT(start->successors(), ElementsAre(block));
72
73 EXPECT_EQ(1u, block->PredecessorCount());
74 EXPECT_EQ(0u, block->SuccessorCount());
75 EXPECT_EQ(start, block->PredecessorAt(0));
76 EXPECT_THAT(block->predecessors(), ElementsAre(start));
77
78 EXPECT_EQ(0u, end->PredecessorCount());
79 EXPECT_EQ(0u, end->SuccessorCount());
80 }
81
82
83 TEST_F(ScheduleTest, AddBranch) {
84 Schedule schedule(zone());
85 BasicBlock* start = schedule.start();
86
87 Node* branch = Node::New(zone(), 0, &kBranchOperator, 0, nullptr, false);
88 BasicBlock* tblock = schedule.NewBasicBlock();
89 BasicBlock* fblock = schedule.NewBasicBlock();
90 schedule.AddBranch(start, branch, tblock, fblock);
91
92 EXPECT_EQ(start, schedule.block(branch));
93
94 EXPECT_EQ(0u, start->PredecessorCount());
95 EXPECT_EQ(2u, start->SuccessorCount());
96 EXPECT_EQ(tblock, start->SuccessorAt(0));
97 EXPECT_EQ(fblock, start->SuccessorAt(1));
98 EXPECT_THAT(start->successors(), ElementsAre(tblock, fblock));
99
100 EXPECT_EQ(1u, tblock->PredecessorCount());
101 EXPECT_EQ(0u, tblock->SuccessorCount());
102 EXPECT_EQ(start, tblock->PredecessorAt(0));
103 EXPECT_THAT(tblock->predecessors(), ElementsAre(start));
104
105 EXPECT_EQ(1u, fblock->PredecessorCount());
106 EXPECT_EQ(0u, fblock->SuccessorCount());
107 EXPECT_EQ(start, fblock->PredecessorAt(0));
108 EXPECT_THAT(fblock->predecessors(), ElementsAre(start));
109 }
110
111
112 TEST_F(ScheduleTest, AddReturn) {
113 Schedule schedule(zone());
114 BasicBlock* start = schedule.start();
115 BasicBlock* end = schedule.end();
116
117 Node* node = Node::New(zone(), 0, &kDummyOperator, 0, nullptr, false);
118 schedule.AddReturn(start, node);
119
120 EXPECT_EQ(0u, start->PredecessorCount());
121 EXPECT_EQ(1u, start->SuccessorCount());
122 EXPECT_EQ(end, start->SuccessorAt(0));
123 EXPECT_THAT(start->successors(), ElementsAre(end));
124 }
125
126
127 TEST_F(ScheduleTest, InsertBranch) {
128 Schedule schedule(zone());
129 BasicBlock* start = schedule.start();
130 BasicBlock* end = schedule.end();
131
132 Node* node = Node::New(zone(), 0, &kDummyOperator, 0, nullptr, false);
133 Node* branch = Node::New(zone(), 0, &kBranchOperator, 0, nullptr, false);
134 BasicBlock* tblock = schedule.NewBasicBlock();
135 BasicBlock* fblock = schedule.NewBasicBlock();
136 BasicBlock* mblock = schedule.NewBasicBlock();
137
138 schedule.AddReturn(start, node);
139 schedule.AddGoto(tblock, mblock);
140 schedule.AddGoto(fblock, mblock);
141 schedule.InsertBranch(start, mblock, branch, tblock, fblock);
142
143 EXPECT_EQ(0u, start->PredecessorCount());
144 EXPECT_EQ(2u, start->SuccessorCount());
145 EXPECT_EQ(tblock, start->SuccessorAt(0));
146 EXPECT_EQ(fblock, start->SuccessorAt(1));
147 EXPECT_THAT(start->successors(), ElementsAre(tblock, fblock));
148
149 EXPECT_EQ(2u, mblock->PredecessorCount());
150 EXPECT_EQ(1u, mblock->SuccessorCount());
151 EXPECT_EQ(end, mblock->SuccessorAt(0));
152 EXPECT_THAT(mblock->predecessors(), ElementsAre(tblock, fblock));
153 EXPECT_THAT(mblock->successors(), ElementsAre(end));
154
155 EXPECT_EQ(1u, end->PredecessorCount());
156 EXPECT_EQ(0u, end->SuccessorCount());
157 EXPECT_EQ(mblock, end->PredecessorAt(0));
158 EXPECT_THAT(end->predecessors(), ElementsAre(mblock));
159 }
160
161 } // namespace compiler
162 } // namespace internal
163 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-scheduler.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698