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

Side by Side Diff: test/cctest/compiler/test-schedule.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-instruction.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('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 2013 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/v8.h"
6
7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/graph.h"
9 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node.h"
11 #include "src/compiler/operator.h"
12 #include "src/compiler/schedule.h"
13 #include "test/cctest/cctest.h"
14
15 using namespace v8::internal;
16 using namespace v8::internal::compiler;
17
18 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
19 "dummy", 0, 0, 0, 0, 0, 0);
20
21 TEST(TestScheduleAllocation) {
22 HandleAndZoneScope scope;
23 Schedule schedule(scope.main_zone());
24
25 CHECK_NE(NULL, schedule.start());
26 CHECK_EQ(schedule.start(), schedule.GetBlockById(BasicBlock::Id::FromInt(0)));
27 }
28
29
30 TEST(TestScheduleAddNode) {
31 HandleAndZoneScope scope;
32 Schedule schedule(scope.main_zone());
33 Graph graph(scope.main_zone());
34 Node* n0 = graph.NewNode(&dummy_operator);
35 Node* n1 = graph.NewNode(&dummy_operator);
36
37 BasicBlock* entry = schedule.start();
38 schedule.AddNode(entry, n0);
39 schedule.AddNode(entry, n1);
40
41 CHECK_EQ(entry, schedule.block(n0));
42 CHECK_EQ(entry, schedule.block(n1));
43 CHECK(schedule.SameBasicBlock(n0, n1));
44
45 Node* n2 = graph.NewNode(&dummy_operator);
46 CHECK_EQ(NULL, schedule.block(n2));
47 }
48
49
50 TEST(TestScheduleAddGoto) {
51 HandleAndZoneScope scope;
52 Schedule schedule(scope.main_zone());
53
54 BasicBlock* entry = schedule.start();
55 BasicBlock* next = schedule.NewBasicBlock();
56
57 schedule.AddGoto(entry, next);
58
59 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
60 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount()));
61 CHECK_EQ(next, entry->SuccessorAt(0));
62
63 CHECK_EQ(1, static_cast<int>(next->PredecessorCount()));
64 CHECK_EQ(entry, next->PredecessorAt(0));
65 CHECK_EQ(0, static_cast<int>(next->SuccessorCount()));
66 }
67
68
69 TEST(TestScheduleAddBranch) {
70 HandleAndZoneScope scope;
71 Schedule schedule(scope.main_zone());
72 Graph graph(scope.main_zone());
73 CommonOperatorBuilder common(scope.main_zone());
74 Node* n0 = graph.NewNode(&dummy_operator);
75 Node* b = graph.NewNode(common.Branch(), n0);
76
77 BasicBlock* entry = schedule.start();
78 BasicBlock* tblock = schedule.NewBasicBlock();
79 BasicBlock* fblock = schedule.NewBasicBlock();
80
81 schedule.AddBranch(entry, b, tblock, fblock);
82
83 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
84 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount()));
85 CHECK_EQ(tblock, entry->SuccessorAt(0));
86 CHECK_EQ(fblock, entry->SuccessorAt(1));
87
88 CHECK_EQ(1, static_cast<int>(tblock->PredecessorCount()));
89 CHECK_EQ(entry, tblock->PredecessorAt(0));
90 CHECK_EQ(0, static_cast<int>(tblock->SuccessorCount()));
91
92 CHECK_EQ(1, static_cast<int>(fblock->PredecessorCount()));
93 CHECK_EQ(entry, fblock->PredecessorAt(0));
94 CHECK_EQ(0, static_cast<int>(fblock->SuccessorCount()));
95 }
96
97
98 TEST(TestScheduleAddReturn) {
99 HandleAndZoneScope scope;
100 Schedule schedule(scope.main_zone());
101 Graph graph(scope.main_zone());
102 Node* n0 = graph.NewNode(&dummy_operator);
103 BasicBlock* entry = schedule.start();
104 schedule.AddReturn(entry, n0);
105
106 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
107 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount()));
108 CHECK_EQ(schedule.end(), entry->SuccessorAt(0));
109 }
110
111
112 TEST(TestScheduleAddThrow) {
113 HandleAndZoneScope scope;
114 Schedule schedule(scope.main_zone());
115 Graph graph(scope.main_zone());
116 Node* n0 = graph.NewNode(&dummy_operator);
117 BasicBlock* entry = schedule.start();
118 schedule.AddThrow(entry, n0);
119
120 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
121 CHECK_EQ(1, static_cast<int>(entry->SuccessorCount()));
122 CHECK_EQ(schedule.end(), entry->SuccessorAt(0));
123 }
124
125
126 TEST(TestScheduleInsertBranch) {
127 HandleAndZoneScope scope;
128 Schedule schedule(scope.main_zone());
129 Graph graph(scope.main_zone());
130 CommonOperatorBuilder common(scope.main_zone());
131 Node* n0 = graph.NewNode(&dummy_operator);
132 Node* n1 = graph.NewNode(&dummy_operator);
133 Node* b = graph.NewNode(common.Branch(), n1);
134
135 BasicBlock* entry = schedule.start();
136 BasicBlock* tblock = schedule.NewBasicBlock();
137 BasicBlock* fblock = schedule.NewBasicBlock();
138 BasicBlock* merge = schedule.NewBasicBlock();
139 schedule.AddReturn(entry, n0);
140 schedule.AddGoto(tblock, merge);
141 schedule.AddGoto(fblock, merge);
142
143 schedule.InsertBranch(entry, merge, b, tblock, fblock);
144
145 CHECK_EQ(0, static_cast<int>(entry->PredecessorCount()));
146 CHECK_EQ(2, static_cast<int>(entry->SuccessorCount()));
147 CHECK_EQ(tblock, entry->SuccessorAt(0));
148 CHECK_EQ(fblock, entry->SuccessorAt(1));
149
150 CHECK_EQ(2, static_cast<int>(merge->PredecessorCount()));
151 CHECK_EQ(1, static_cast<int>(merge->SuccessorCount()));
152 CHECK_EQ(schedule.end(), merge->SuccessorAt(0));
153
154 CHECK_EQ(1, static_cast<int>(schedule.end()->PredecessorCount()));
155 CHECK_EQ(0, static_cast<int>(schedule.end()->SuccessorCount()));
156 CHECK_EQ(merge, schedule.end()->PredecessorAt(0));
157 }
158
159
160 TEST(BuildMulNodeGraph) {
161 HandleAndZoneScope scope;
162 Schedule schedule(scope.main_zone());
163 Graph graph(scope.main_zone());
164 CommonOperatorBuilder common(scope.main_zone());
165 // TODO(titzer): use test operators.
166 MachineOperatorBuilder machine(scope.main_zone());
167
168 Node* start = graph.NewNode(common.Start(0));
169 graph.SetStart(start);
170 Node* param0 = graph.NewNode(common.Parameter(0), graph.start());
171 Node* param1 = graph.NewNode(common.Parameter(1), graph.start());
172
173 Node* mul = graph.NewNode(machine.Int32Mul(), param0, param1);
174 Node* ret = graph.NewNode(common.Return(), mul, start);
175
176 USE(ret);
177 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-instruction.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698