OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 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 <functional> | 5 #include <functional> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "graph-tester.h" | 9 #include "graph-tester.h" |
10 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
11 #include "src/compiler/operator.h" | 11 #include "src/compiler/operator.h" |
12 | 12 |
13 using namespace v8::internal; | 13 using namespace v8::internal; |
14 using namespace v8::internal::compiler; | 14 using namespace v8::internal::compiler; |
15 | 15 |
| 16 #define NONE reinterpret_cast<Node*>(1) |
| 17 |
16 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, | 18 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
17 "dummy", 0, 0, 0, 1, 0, 0); | 19 "dummy", 0, 0, 0, 1, 0, 0); |
18 | 20 |
| 21 #define CHECK_USES(node, ...) \ |
| 22 do { \ |
| 23 Node* __array[] = {__VA_ARGS__}; \ |
| 24 int __size = \ |
| 25 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ |
| 26 CheckUseChain(node, __array, __size); \ |
| 27 } while (false) |
| 28 |
| 29 |
| 30 typedef std::multiset<Node*, std::less<Node*>> NodeMSet; |
| 31 |
| 32 static void CheckUseChain(Node* node, Node** uses, int use_count) { |
| 33 // Check ownership. |
| 34 if (use_count == 1) CHECK(node->OwnedBy(uses[0])); |
| 35 if (use_count > 1) { |
| 36 for (int i = 0; i < use_count; i++) { |
| 37 CHECK(!node->OwnedBy(uses[i])); |
| 38 } |
| 39 } |
| 40 |
| 41 // Check the self-reported use count. |
| 42 CHECK_EQ(use_count, node->UseCount()); |
| 43 |
| 44 // Build the expectation set. |
| 45 NodeMSet expect_set; |
| 46 for (int i = 0; i < use_count; i++) { |
| 47 expect_set.insert(uses[i]); |
| 48 } |
| 49 |
| 50 { |
| 51 // Check that iterating over the uses gives the right counts. |
| 52 NodeMSet use_set; |
| 53 for (auto use : node->uses()) { |
| 54 use_set.insert(use); |
| 55 } |
| 56 CHECK(expect_set == use_set); |
| 57 } |
| 58 |
| 59 { |
| 60 // Check that iterating over the use edges gives the right counts, |
| 61 // input indices, from(), and to() pointers. |
| 62 NodeMSet use_set; |
| 63 for (auto edge : node->use_edges()) { |
| 64 CHECK_EQ(node, edge.to()); |
| 65 CHECK_EQ(node, edge.from()->InputAt(edge.index())); |
| 66 use_set.insert(edge.from()); |
| 67 } |
| 68 CHECK(expect_set == use_set); |
| 69 } |
| 70 |
| 71 { |
| 72 // Check the use nodes actually have the node as inputs. |
| 73 for (Node* use : node->uses()) { |
| 74 size_t count = 0; |
| 75 for (Node* input : use->inputs()) { |
| 76 if (input == node) count++; |
| 77 } |
| 78 CHECK_EQ(count, expect_set.count(use)); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 |
| 84 #define CHECK_INPUTS(node, ...) \ |
| 85 do { \ |
| 86 Node* __array[] = {__VA_ARGS__}; \ |
| 87 int __size = \ |
| 88 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ |
| 89 CheckInputs(node, __array, __size); \ |
| 90 } while (false) |
| 91 |
| 92 |
| 93 static void CheckInputs(Node* node, Node** inputs, int input_count) { |
| 94 CHECK_EQ(input_count, node->InputCount()); |
| 95 // Check InputAt(). |
| 96 for (int i = 0; i < static_cast<int>(input_count); i++) { |
| 97 CHECK_EQ(inputs[i], node->InputAt(i)); |
| 98 } |
| 99 |
| 100 // Check input iterator. |
| 101 int index = 0; |
| 102 for (Node* input : node->inputs()) { |
| 103 CHECK_EQ(inputs[index], input); |
| 104 index++; |
| 105 } |
| 106 |
| 107 // Check use lists of inputs. |
| 108 for (int i = 0; i < static_cast<int>(input_count); i++) { |
| 109 Node* input = inputs[i]; |
| 110 if (!input) continue; // skip null inputs |
| 111 bool found = false; |
| 112 // Check regular use list. |
| 113 for (Node* use : input->uses()) { |
| 114 if (use == node) { |
| 115 found = true; |
| 116 break; |
| 117 } |
| 118 } |
| 119 CHECK(found); |
| 120 int count = 0; |
| 121 // Check use edge list. |
| 122 for (auto edge : input->use_edges()) { |
| 123 if (edge.from() == node && edge.to() == input && edge.index() == i) { |
| 124 count++; |
| 125 } |
| 126 } |
| 127 CHECK_EQ(1, count); |
| 128 } |
| 129 } |
| 130 |
| 131 |
19 TEST(NodeUseIteratorReplaceUses) { | 132 TEST(NodeUseIteratorReplaceUses) { |
20 GraphTester graph; | 133 GraphTester graph; |
21 Node* n0 = graph.NewNode(&dummy_operator); | 134 Node* n0 = graph.NewNode(&dummy_operator); |
22 Node* n1 = graph.NewNode(&dummy_operator, n0); | 135 Node* n1 = graph.NewNode(&dummy_operator, n0); |
23 Node* n2 = graph.NewNode(&dummy_operator, n0); | 136 Node* n2 = graph.NewNode(&dummy_operator, n0); |
24 Node* n3 = graph.NewNode(&dummy_operator); | 137 Node* n3 = graph.NewNode(&dummy_operator); |
25 auto i1(n0->uses().begin()); | 138 |
26 CHECK_EQ(n1, *i1); | 139 CHECK_USES(n0, n1, n2); |
27 ++i1; | 140 |
28 CHECK_EQ(n2, *i1); | 141 CHECK_INPUTS(n1, n0); |
| 142 CHECK_INPUTS(n2, n0); |
| 143 |
29 n0->ReplaceUses(n3); | 144 n0->ReplaceUses(n3); |
30 auto i2(n3->uses().begin()); | 145 |
31 CHECK_EQ(n1, *i2); | 146 CHECK_USES(n0, NONE); |
32 ++i2; | 147 CHECK_USES(n1, NONE); |
33 CHECK_EQ(n2, *i2); | 148 CHECK_USES(n2, NONE); |
34 auto i3(n1->inputs().begin()); | 149 CHECK_USES(n3, n1, n2); |
35 CHECK_EQ(n3, *i3); | 150 |
36 ++i3; | 151 CHECK_INPUTS(n1, n3); |
37 CHECK(n1->inputs().end() == i3); | 152 CHECK_INPUTS(n2, n3); |
38 auto i4(n2->inputs().begin()); | |
39 CHECK_EQ(n3, *i4); | |
40 ++i4; | |
41 CHECK(n2->inputs().end() == i4); | |
42 } | 153 } |
43 | 154 |
44 | 155 |
45 TEST(NodeUseIteratorReplaceUsesSelf) { | 156 TEST(NodeUseIteratorReplaceUsesSelf) { |
46 GraphTester graph; | 157 GraphTester graph; |
47 Node* n0 = graph.NewNode(&dummy_operator); | 158 Node* n0 = graph.NewNode(&dummy_operator); |
48 Node* n1 = graph.NewNode(&dummy_operator, n0); | 159 Node* n1 = graph.NewNode(&dummy_operator, n0); |
49 Node* n3 = graph.NewNode(&dummy_operator); | 160 |
| 161 CHECK_USES(n0, n1); |
| 162 CHECK_USES(n1, NONE); |
50 | 163 |
51 n1->ReplaceInput(0, n1); // Create self-reference. | 164 n1->ReplaceInput(0, n1); // Create self-reference. |
52 | 165 |
53 auto i1(n1->uses().begin()); | 166 CHECK_USES(n0, NONE); |
54 CHECK_EQ(n1, *i1); | 167 CHECK_USES(n1, n1); |
55 | 168 |
56 n1->ReplaceUses(n3); | 169 Node* n2 = graph.NewNode(&dummy_operator); |
57 | 170 |
58 CHECK(n1->uses().begin() == n1->uses().end()); | 171 n1->ReplaceUses(n2); |
59 | 172 |
60 auto i2(n3->uses().begin()); | 173 CHECK_USES(n0, NONE); |
61 CHECK_EQ(n1, *i2); | 174 CHECK_USES(n1, NONE); |
62 ++i2; | 175 CHECK_USES(n2, n1); |
63 CHECK(n1->uses().end() == i2); | |
64 } | 176 } |
65 | 177 |
66 | 178 |
67 TEST(ReplaceInput) { | 179 TEST(ReplaceInput) { |
68 GraphTester graph; | 180 GraphTester graph; |
69 Node* n0 = graph.NewNode(&dummy_operator); | 181 Node* n0 = graph.NewNode(&dummy_operator); |
70 Node* n1 = graph.NewNode(&dummy_operator); | 182 Node* n1 = graph.NewNode(&dummy_operator); |
71 Node* n2 = graph.NewNode(&dummy_operator); | 183 Node* n2 = graph.NewNode(&dummy_operator); |
72 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); | 184 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); |
73 auto i1(n3->inputs().begin()); | 185 Node* n4 = graph.NewNode(&dummy_operator); |
74 CHECK(n0 == *i1); | |
75 CHECK_EQ(n0, n3->InputAt(0)); | |
76 ++i1; | |
77 CHECK_EQ(n1, *i1); | |
78 CHECK_EQ(n1, n3->InputAt(1)); | |
79 ++i1; | |
80 CHECK_EQ(n2, *i1); | |
81 CHECK_EQ(n2, n3->InputAt(2)); | |
82 ++i1; | |
83 CHECK(i1 == n3->inputs().end()); | |
84 | 186 |
85 auto i2(n1->uses().begin()); | 187 CHECK_USES(n0, n3); |
86 CHECK_EQ(n3, *i2); | 188 CHECK_USES(n1, n3); |
87 ++i2; | 189 CHECK_USES(n2, n3); |
88 CHECK(i2 == n1->uses().end()); | 190 CHECK_USES(n3, NONE); |
| 191 CHECK_USES(n4, NONE); |
89 | 192 |
90 Node* n4 = graph.NewNode(&dummy_operator); | 193 CHECK_INPUTS(n3, n0, n1, n2); |
91 auto i3(n4->uses().begin()); | |
92 CHECK(i3 == n4->uses().end()); | |
93 | 194 |
94 n3->ReplaceInput(1, n4); | 195 n3->ReplaceInput(1, n4); |
95 | 196 |
96 auto i4(n1->uses().begin()); | 197 CHECK_USES(n1, NONE); |
97 CHECK(i4 == n1->uses().end()); | 198 CHECK_USES(n4, n3); |
98 | 199 |
99 auto i5(n4->uses().begin()); | 200 CHECK_INPUTS(n3, n0, n4, n2); |
100 CHECK_EQ(n3, *i5); | |
101 ++i5; | |
102 CHECK(i5 == n4->uses().end()); | |
103 | |
104 auto i6(n3->inputs().begin()); | |
105 CHECK(n0 == *i6); | |
106 CHECK_EQ(n0, n3->InputAt(0)); | |
107 ++i6; | |
108 CHECK_EQ(n4, *i6); | |
109 CHECK_EQ(n4, n3->InputAt(1)); | |
110 ++i6; | |
111 CHECK_EQ(n2, *i6); | |
112 CHECK_EQ(n2, n3->InputAt(2)); | |
113 ++i6; | |
114 CHECK(i6 == n3->inputs().end()); | |
115 } | 201 } |
116 | 202 |
117 | 203 |
118 TEST(OwnedBy) { | 204 TEST(OwnedBy) { |
119 GraphTester graph; | 205 GraphTester graph; |
120 | 206 |
121 { | 207 { |
122 Node* n0 = graph.NewNode(&dummy_operator); | 208 Node* n0 = graph.NewNode(&dummy_operator); |
123 Node* n1 = graph.NewNode(&dummy_operator); | 209 Node* n1 = graph.NewNode(&dummy_operator); |
124 | 210 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 CHECK(!n2->OwnedBy(n3)); | 248 CHECK(!n2->OwnedBy(n3)); |
163 } | 249 } |
164 } | 250 } |
165 | 251 |
166 | 252 |
167 TEST(Uses) { | 253 TEST(Uses) { |
168 GraphTester graph; | 254 GraphTester graph; |
169 | 255 |
170 Node* n0 = graph.NewNode(&dummy_operator); | 256 Node* n0 = graph.NewNode(&dummy_operator); |
171 Node* n1 = graph.NewNode(&dummy_operator, n0); | 257 Node* n1 = graph.NewNode(&dummy_operator, n0); |
172 CHECK_EQ(1, n0->UseCount()); | 258 |
173 printf("A: %d vs %d\n", n0->UseAt(0)->id(), n1->id()); | 259 CHECK_USES(n0, n1); |
174 CHECK(n0->UseAt(0) == n1); | 260 CHECK_USES(n1, NONE); |
| 261 |
175 Node* n2 = graph.NewNode(&dummy_operator, n0); | 262 Node* n2 = graph.NewNode(&dummy_operator, n0); |
176 CHECK_EQ(2, n0->UseCount()); | 263 |
177 printf("B: %d vs %d\n", n0->UseAt(1)->id(), n2->id()); | 264 CHECK_USES(n0, n1, n2); |
178 CHECK(n0->UseAt(1) == n2); | 265 CHECK_USES(n2, NONE); |
| 266 |
179 Node* n3 = graph.NewNode(&dummy_operator, n0); | 267 Node* n3 = graph.NewNode(&dummy_operator, n0); |
180 CHECK_EQ(3, n0->UseCount()); | 268 |
181 CHECK(n0->UseAt(2) == n3); | 269 CHECK_USES(n0, n1, n2, n3); |
| 270 CHECK_USES(n3, NONE); |
182 } | 271 } |
183 | 272 |
184 | 273 |
185 TEST(Inputs) { | 274 TEST(Inputs) { |
186 GraphTester graph; | 275 GraphTester graph; |
187 | 276 |
188 Node* n0 = graph.NewNode(&dummy_operator); | 277 Node* n0 = graph.NewNode(&dummy_operator); |
189 Node* n1 = graph.NewNode(&dummy_operator, n0); | 278 Node* n1 = graph.NewNode(&dummy_operator, n0); |
190 Node* n2 = graph.NewNode(&dummy_operator, n0); | 279 Node* n2 = graph.NewNode(&dummy_operator, n0); |
191 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); | 280 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); |
192 CHECK_EQ(3, n3->InputCount()); | 281 |
193 CHECK(n3->InputAt(0) == n0); | 282 CHECK_INPUTS(n3, n0, n1, n2); |
194 CHECK(n3->InputAt(1) == n1); | 283 |
195 CHECK(n3->InputAt(2) == n2); | |
196 Node* n4 = graph.NewNode(&dummy_operator, n0, n1, n2); | 284 Node* n4 = graph.NewNode(&dummy_operator, n0, n1, n2); |
197 n3->AppendInput(graph.zone(), n4); | 285 n3->AppendInput(graph.zone(), n4); |
198 CHECK_EQ(4, n3->InputCount()); | 286 |
199 CHECK(n3->InputAt(0) == n0); | 287 CHECK_INPUTS(n3, n0, n1, n2, n4); |
200 CHECK(n3->InputAt(1) == n1); | 288 CHECK_USES(n4, n3); |
201 CHECK(n3->InputAt(2) == n2); | 289 |
202 CHECK(n3->InputAt(3) == n4); | 290 n3->AppendInput(graph.zone(), n4); |
| 291 |
| 292 CHECK_INPUTS(n3, n0, n1, n2, n4, n4); |
| 293 CHECK_USES(n4, n3, n3); |
| 294 |
203 Node* n5 = graph.NewNode(&dummy_operator, n4); | 295 Node* n5 = graph.NewNode(&dummy_operator, n4); |
204 n3->AppendInput(graph.zone(), n4); | |
205 CHECK_EQ(5, n3->InputCount()); | |
206 CHECK(n3->InputAt(0) == n0); | |
207 CHECK(n3->InputAt(1) == n1); | |
208 CHECK(n3->InputAt(2) == n2); | |
209 CHECK(n3->InputAt(3) == n4); | |
210 CHECK(n3->InputAt(4) == n4); | |
211 | 296 |
212 // Make sure uses have been hooked op correctly. | 297 CHECK_USES(n4, n3, n3, n5); |
213 Node::Uses uses(n4->uses()); | |
214 auto current = uses.begin(); | |
215 CHECK(current != uses.end()); | |
216 CHECK(*current == n3); | |
217 ++current; | |
218 CHECK(current != uses.end()); | |
219 CHECK(*current == n5); | |
220 ++current; | |
221 CHECK(current != uses.end()); | |
222 CHECK(*current == n3); | |
223 ++current; | |
224 CHECK(current == uses.end()); | |
225 } | 298 } |
226 | 299 |
227 | 300 |
228 TEST(RemoveInput) { | 301 TEST(RemoveInput) { |
229 GraphTester graph; | 302 GraphTester graph; |
230 | 303 |
231 Node* n0 = graph.NewNode(&dummy_operator); | 304 Node* n0 = graph.NewNode(&dummy_operator); |
232 Node* n1 = graph.NewNode(&dummy_operator, n0); | 305 Node* n1 = graph.NewNode(&dummy_operator, n0); |
233 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 306 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
234 | 307 |
| 308 CHECK_INPUTS(n0, NONE); |
| 309 CHECK_INPUTS(n1, n0); |
| 310 CHECK_INPUTS(n2, n0, n1); |
| 311 CHECK_USES(n0, n1, n2); |
| 312 |
235 n1->RemoveInput(0); | 313 n1->RemoveInput(0); |
236 CHECK_EQ(0, n1->InputCount()); | 314 CHECK_INPUTS(n1, NONE); |
237 CHECK_EQ(1, n0->UseCount()); | 315 CHECK_USES(n0, n2); |
238 | 316 |
239 n2->RemoveInput(0); | 317 n2->RemoveInput(0); |
240 CHECK_EQ(1, n2->InputCount()); | 318 CHECK_INPUTS(n2, n1); |
241 CHECK_EQ(0, n0->UseCount()); | 319 CHECK_USES(n0, NONE); |
242 CHECK_EQ(1, n1->UseCount()); | 320 CHECK_USES(n1, n2); |
243 | 321 |
244 n2->RemoveInput(0); | 322 n2->RemoveInput(0); |
245 CHECK_EQ(0, n2->InputCount()); | 323 CHECK_INPUTS(n2, NONE); |
| 324 CHECK_USES(n0, NONE); |
| 325 CHECK_USES(n1, NONE); |
| 326 CHECK_USES(n2, NONE); |
246 } | 327 } |
247 | 328 |
248 | 329 |
249 TEST(AppendInputsAndIterator) { | 330 TEST(AppendInputsAndIterator) { |
250 GraphTester graph; | 331 GraphTester graph; |
251 | 332 |
252 Node* n0 = graph.NewNode(&dummy_operator); | 333 Node* n0 = graph.NewNode(&dummy_operator); |
253 Node* n1 = graph.NewNode(&dummy_operator, n0); | 334 Node* n1 = graph.NewNode(&dummy_operator, n0); |
254 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 335 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
255 | 336 |
256 Node::InputEdges inputs(n2->input_edges()); | 337 CHECK_INPUTS(n0, NONE); |
257 Node::InputEdges::iterator current = inputs.begin(); | 338 CHECK_INPUTS(n1, n0); |
258 CHECK(current != inputs.end()); | 339 CHECK_INPUTS(n2, n0, n1); |
259 CHECK((*current).to() == n0); | 340 CHECK_USES(n0, n1, n2); |
260 ++current; | |
261 CHECK(current != inputs.end()); | |
262 CHECK((*current).to() == n1); | |
263 ++current; | |
264 CHECK(current == inputs.end()); | |
265 | 341 |
266 Node* n3 = graph.NewNode(&dummy_operator); | 342 Node* n3 = graph.NewNode(&dummy_operator); |
| 343 |
267 n2->AppendInput(graph.zone(), n3); | 344 n2->AppendInput(graph.zone(), n3); |
268 inputs = n2->input_edges(); | 345 |
269 current = inputs.begin(); | 346 CHECK_INPUTS(n2, n0, n1, n3); |
270 CHECK(current != inputs.end()); | 347 CHECK_USES(n3, n2); |
271 CHECK((*current).to() == n0); | |
272 CHECK_EQ(0, (*current).index()); | |
273 ++current; | |
274 CHECK(current != inputs.end()); | |
275 CHECK((*current).to() == n1); | |
276 CHECK_EQ(1, (*current).index()); | |
277 ++current; | |
278 CHECK(current != inputs.end()); | |
279 CHECK((*current).to() == n3); | |
280 CHECK_EQ(2, (*current).index()); | |
281 ++current; | |
282 CHECK(current == inputs.end()); | |
283 } | 348 } |
284 | 349 |
285 | 350 |
286 TEST(NullInputsSimple) { | 351 TEST(NullInputsSimple) { |
287 GraphTester graph; | 352 GraphTester graph; |
288 | 353 |
289 Node* n0 = graph.NewNode(&dummy_operator); | 354 Node* n0 = graph.NewNode(&dummy_operator); |
290 Node* n1 = graph.NewNode(&dummy_operator, n0); | 355 Node* n1 = graph.NewNode(&dummy_operator, n0); |
291 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 356 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
292 CHECK_EQ(2, n2->InputCount()); | |
293 | 357 |
294 CHECK(n0 == n2->InputAt(0)); | 358 CHECK_INPUTS(n0, NONE); |
295 CHECK(n1 == n2->InputAt(1)); | 359 CHECK_INPUTS(n1, n0); |
296 CHECK_EQ(2, n0->UseCount()); | 360 CHECK_INPUTS(n2, n0, n1); |
297 n2->ReplaceInput(0, NULL); | 361 CHECK_USES(n0, n1, n2); |
298 CHECK(NULL == n2->InputAt(0)); | 362 |
299 CHECK(n1 == n2->InputAt(1)); | 363 n2->ReplaceInput(0, nullptr); |
300 CHECK_EQ(1, n0->UseCount()); | 364 |
| 365 CHECK_INPUTS(n2, NULL, n1); |
| 366 |
| 367 CHECK_USES(n0, n1); |
| 368 |
| 369 n2->ReplaceInput(1, nullptr); |
| 370 |
| 371 CHECK_INPUTS(n2, NULL, NULL); |
| 372 |
| 373 CHECK_USES(n1, NONE); |
301 } | 374 } |
302 | 375 |
303 | 376 |
304 TEST(NullInputsAppended) { | 377 TEST(NullInputsAppended) { |
305 GraphTester graph; | 378 GraphTester graph; |
306 | 379 |
307 Node* n0 = graph.NewNode(&dummy_operator); | 380 Node* n0 = graph.NewNode(&dummy_operator); |
308 Node* n1 = graph.NewNode(&dummy_operator, n0); | 381 Node* n1 = graph.NewNode(&dummy_operator, n0); |
309 Node* n2 = graph.NewNode(&dummy_operator, n0); | 382 Node* n2 = graph.NewNode(&dummy_operator, n0); |
310 Node* n3 = graph.NewNode(&dummy_operator, n0); | 383 Node* n3 = graph.NewNode(&dummy_operator, n0); |
311 n3->AppendInput(graph.zone(), n1); | 384 n3->AppendInput(graph.zone(), n1); |
312 n3->AppendInput(graph.zone(), n2); | 385 n3->AppendInput(graph.zone(), n2); |
313 CHECK_EQ(3, n3->InputCount()); | |
314 | 386 |
315 CHECK(n0 == n3->InputAt(0)); | 387 CHECK_INPUTS(n3, n0, n1, n2); |
316 CHECK(n1 == n3->InputAt(1)); | 388 CHECK_USES(n0, n1, n2, n3); |
317 CHECK(n2 == n3->InputAt(2)); | 389 CHECK_USES(n1, n3); |
318 CHECK_EQ(1, n1->UseCount()); | 390 CHECK_USES(n2, n3); |
| 391 |
319 n3->ReplaceInput(1, NULL); | 392 n3->ReplaceInput(1, NULL); |
320 CHECK(n0 == n3->InputAt(0)); | 393 CHECK_USES(n1, NONE); |
321 CHECK(NULL == n3->InputAt(1)); | 394 |
322 CHECK(n2 == n3->InputAt(2)); | 395 CHECK_INPUTS(n3, n0, NULL, n2); |
323 CHECK_EQ(0, n1->UseCount()); | |
324 } | 396 } |
325 | 397 |
326 | 398 |
327 TEST(ReplaceUsesFromAppendedInputs) { | 399 TEST(ReplaceUsesFromAppendedInputs) { |
328 GraphTester graph; | 400 GraphTester graph; |
329 | 401 |
330 Node* n0 = graph.NewNode(&dummy_operator); | 402 Node* n0 = graph.NewNode(&dummy_operator); |
331 Node* n1 = graph.NewNode(&dummy_operator, n0); | 403 Node* n1 = graph.NewNode(&dummy_operator, n0); |
332 Node* n2 = graph.NewNode(&dummy_operator, n0); | 404 Node* n2 = graph.NewNode(&dummy_operator, n0); |
333 Node* n3 = graph.NewNode(&dummy_operator); | 405 Node* n3 = graph.NewNode(&dummy_operator); |
| 406 |
| 407 CHECK_INPUTS(n2, n0); |
| 408 |
334 n2->AppendInput(graph.zone(), n1); | 409 n2->AppendInput(graph.zone(), n1); |
| 410 CHECK_INPUTS(n2, n0, n1); |
| 411 CHECK_USES(n1, n2); |
| 412 |
335 n2->AppendInput(graph.zone(), n0); | 413 n2->AppendInput(graph.zone(), n0); |
336 CHECK_EQ(0, n3->UseCount()); | 414 CHECK_INPUTS(n2, n0, n1, n0); |
337 CHECK_EQ(3, n0->UseCount()); | 415 CHECK_USES(n1, n2); |
| 416 CHECK_USES(n0, n2, n1, n2); |
| 417 |
338 n0->ReplaceUses(n3); | 418 n0->ReplaceUses(n3); |
339 CHECK_EQ(0, n0->UseCount()); | |
340 CHECK_EQ(3, n3->UseCount()); | |
341 | 419 |
342 Node::Uses uses(n3->uses()); | 420 CHECK_USES(n0, NONE); |
343 auto current = uses.begin(); | 421 CHECK_INPUTS(n2, n3, n1, n3); |
344 CHECK(current != uses.end()); | 422 CHECK_USES(n3, n2, n1, n2); |
345 CHECK(*current == n1); | |
346 ++current; | |
347 CHECK(current != uses.end()); | |
348 CHECK(*current == n2); | |
349 ++current; | |
350 CHECK(current != uses.end()); | |
351 CHECK(*current == n2); | |
352 ++current; | |
353 CHECK(current == uses.end()); | |
354 } | 423 } |
355 | 424 |
356 | 425 |
357 TEST(ReplaceInputMultipleUses) { | 426 TEST(ReplaceInputMultipleUses) { |
358 GraphTester graph; | 427 GraphTester graph; |
359 | 428 |
360 Node* n0 = graph.NewNode(&dummy_operator); | 429 Node* n0 = graph.NewNode(&dummy_operator); |
361 Node* n1 = graph.NewNode(&dummy_operator); | 430 Node* n1 = graph.NewNode(&dummy_operator); |
362 Node* n2 = graph.NewNode(&dummy_operator, n0); | 431 Node* n2 = graph.NewNode(&dummy_operator, n0); |
363 n2->ReplaceInput(0, n1); | 432 n2->ReplaceInput(0, n1); |
364 CHECK_EQ(0, n0->UseCount()); | 433 CHECK_EQ(0, n0->UseCount()); |
365 CHECK_EQ(1, n1->UseCount()); | 434 CHECK_EQ(1, n1->UseCount()); |
366 | 435 |
367 Node* n3 = graph.NewNode(&dummy_operator, n0); | 436 Node* n3 = graph.NewNode(&dummy_operator, n0); |
368 n3->ReplaceInput(0, n1); | 437 n3->ReplaceInput(0, n1); |
369 CHECK_EQ(0, n0->UseCount()); | 438 CHECK_EQ(0, n0->UseCount()); |
370 CHECK_EQ(2, n1->UseCount()); | 439 CHECK_EQ(2, n1->UseCount()); |
371 } | 440 } |
372 | 441 |
373 | 442 |
374 TEST(TrimInputCountInline) { | 443 TEST(TrimInputCountInline) { |
375 GraphTester graph; | 444 GraphTester graph; |
376 | 445 |
377 { | 446 { |
378 Node* n0 = graph.NewNode(&dummy_operator); | 447 Node* n0 = graph.NewNode(&dummy_operator); |
379 Node* n1 = graph.NewNode(&dummy_operator, n0); | 448 Node* n1 = graph.NewNode(&dummy_operator, n0); |
380 n1->TrimInputCount(1); | 449 n1->TrimInputCount(1); |
381 CHECK_EQ(1, n1->InputCount()); | 450 CHECK_INPUTS(n1, n0); |
382 CHECK_EQ(n0, n1->InputAt(0)); | 451 CHECK_USES(n0, n1); |
383 CHECK_EQ(1, n0->UseCount()); | |
384 } | 452 } |
385 | 453 |
386 { | 454 { |
387 Node* n0 = graph.NewNode(&dummy_operator); | 455 Node* n0 = graph.NewNode(&dummy_operator); |
388 Node* n1 = graph.NewNode(&dummy_operator, n0); | 456 Node* n1 = graph.NewNode(&dummy_operator, n0); |
389 n1->TrimInputCount(0); | 457 n1->TrimInputCount(0); |
390 CHECK_EQ(0, n1->InputCount()); | 458 CHECK_INPUTS(n1, NONE); |
391 CHECK_EQ(0, n0->UseCount()); | 459 CHECK_USES(n0, NONE); |
392 } | 460 } |
393 | 461 |
394 { | 462 { |
395 Node* n0 = graph.NewNode(&dummy_operator); | 463 Node* n0 = graph.NewNode(&dummy_operator); |
396 Node* n1 = graph.NewNode(&dummy_operator); | 464 Node* n1 = graph.NewNode(&dummy_operator); |
397 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 465 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
398 n2->TrimInputCount(2); | 466 n2->TrimInputCount(2); |
399 CHECK_EQ(2, n2->InputCount()); | 467 CHECK_INPUTS(n2, n0, n1); |
400 CHECK_EQ(1, n0->UseCount()); | 468 CHECK_USES(n0, n2); |
401 CHECK_EQ(1, n1->UseCount()); | 469 CHECK_USES(n1, n2); |
402 CHECK_EQ(0, n2->UseCount()); | |
403 } | 470 } |
404 | 471 |
405 { | 472 { |
406 Node* n0 = graph.NewNode(&dummy_operator); | 473 Node* n0 = graph.NewNode(&dummy_operator); |
407 Node* n1 = graph.NewNode(&dummy_operator); | 474 Node* n1 = graph.NewNode(&dummy_operator); |
408 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 475 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
409 n2->TrimInputCount(1); | 476 n2->TrimInputCount(1); |
410 CHECK_EQ(1, n2->InputCount()); | 477 CHECK_INPUTS(n2, n0); |
411 CHECK_EQ(1, n0->UseCount()); | 478 CHECK_USES(n0, n2); |
412 CHECK_EQ(0, n1->UseCount()); | 479 CHECK_USES(n1, NONE); |
413 CHECK_EQ(0, n2->UseCount()); | |
414 } | 480 } |
415 | 481 |
416 { | 482 { |
417 Node* n0 = graph.NewNode(&dummy_operator); | 483 Node* n0 = graph.NewNode(&dummy_operator); |
418 Node* n1 = graph.NewNode(&dummy_operator); | 484 Node* n1 = graph.NewNode(&dummy_operator); |
419 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 485 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); |
420 n2->TrimInputCount(0); | 486 n2->TrimInputCount(0); |
421 CHECK_EQ(0, n2->InputCount()); | 487 CHECK_INPUTS(n2, NONE); |
422 CHECK_EQ(0, n0->UseCount()); | 488 CHECK_USES(n0, NONE); |
423 CHECK_EQ(0, n1->UseCount()); | 489 CHECK_USES(n1, NONE); |
424 CHECK_EQ(0, n2->UseCount()); | |
425 } | 490 } |
426 | 491 |
427 { | 492 { |
428 Node* n0 = graph.NewNode(&dummy_operator); | 493 Node* n0 = graph.NewNode(&dummy_operator); |
429 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); | 494 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); |
430 n2->TrimInputCount(1); | 495 n2->TrimInputCount(1); |
431 CHECK_EQ(1, n2->InputCount()); | 496 CHECK_INPUTS(n2, n0); |
432 CHECK_EQ(1, n0->UseCount()); | 497 CHECK_USES(n0, n2); |
433 CHECK_EQ(0, n2->UseCount()); | |
434 } | 498 } |
435 | 499 |
436 { | 500 { |
437 Node* n0 = graph.NewNode(&dummy_operator); | 501 Node* n0 = graph.NewNode(&dummy_operator); |
438 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); | 502 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); |
439 n2->TrimInputCount(0); | 503 n2->TrimInputCount(0); |
440 CHECK_EQ(0, n2->InputCount()); | 504 CHECK_INPUTS(n2, NONE); |
441 CHECK_EQ(0, n0->UseCount()); | 505 CHECK_USES(n0, NONE); |
442 CHECK_EQ(0, n2->UseCount()); | |
443 } | 506 } |
444 } | 507 } |
445 | 508 |
446 | 509 |
447 TEST(TrimInputCountOutOfLine1) { | 510 TEST(TrimInputCountOutOfLine1) { |
448 GraphTester graph; | 511 GraphTester graph; |
449 | 512 |
450 { | 513 { |
451 Node* n0 = graph.NewNode(&dummy_operator); | 514 Node* n0 = graph.NewNode(&dummy_operator); |
452 Node* n1 = graph.NewNode(&dummy_operator); | 515 Node* n1 = graph.NewNode(&dummy_operator); |
453 n1->AppendInput(graph.zone(), n0); | 516 n1->AppendInput(graph.zone(), n0); |
| 517 CHECK_INPUTS(n1, n0); |
| 518 CHECK_USES(n0, n1); |
| 519 |
454 n1->TrimInputCount(1); | 520 n1->TrimInputCount(1); |
455 CHECK_EQ(1, n1->InputCount()); | 521 CHECK_INPUTS(n1, n0); |
456 CHECK_EQ(n0, n1->InputAt(0)); | 522 CHECK_USES(n0, n1); |
457 CHECK_EQ(1, n0->UseCount()); | |
458 } | 523 } |
459 | 524 |
460 { | 525 { |
461 Node* n0 = graph.NewNode(&dummy_operator); | 526 Node* n0 = graph.NewNode(&dummy_operator); |
462 Node* n1 = graph.NewNode(&dummy_operator); | 527 Node* n1 = graph.NewNode(&dummy_operator); |
463 n1->AppendInput(graph.zone(), n0); | 528 n1->AppendInput(graph.zone(), n0); |
464 CHECK_EQ(1, n1->InputCount()); | 529 CHECK_EQ(1, n1->InputCount()); |
465 n1->TrimInputCount(0); | 530 n1->TrimInputCount(0); |
466 CHECK_EQ(0, n1->InputCount()); | 531 CHECK_EQ(0, n1->InputCount()); |
467 CHECK_EQ(0, n0->UseCount()); | 532 CHECK_EQ(0, n0->UseCount()); |
468 } | 533 } |
469 | 534 |
470 { | 535 { |
471 Node* n0 = graph.NewNode(&dummy_operator); | 536 Node* n0 = graph.NewNode(&dummy_operator); |
472 Node* n1 = graph.NewNode(&dummy_operator); | 537 Node* n1 = graph.NewNode(&dummy_operator); |
473 Node* n2 = graph.NewNode(&dummy_operator); | 538 Node* n2 = graph.NewNode(&dummy_operator); |
474 n2->AppendInput(graph.zone(), n0); | 539 n2->AppendInput(graph.zone(), n0); |
475 n2->AppendInput(graph.zone(), n1); | 540 n2->AppendInput(graph.zone(), n1); |
476 CHECK_EQ(2, n2->InputCount()); | 541 CHECK_INPUTS(n2, n0, n1); |
477 n2->TrimInputCount(2); | 542 n2->TrimInputCount(2); |
478 CHECK_EQ(2, n2->InputCount()); | 543 CHECK_INPUTS(n2, n0, n1); |
479 CHECK_EQ(n0, n2->InputAt(0)); | 544 CHECK_USES(n0, n2); |
480 CHECK_EQ(n1, n2->InputAt(1)); | 545 CHECK_USES(n1, n2); |
481 CHECK_EQ(1, n0->UseCount()); | 546 CHECK_USES(n2, NONE); |
482 CHECK_EQ(1, n1->UseCount()); | |
483 CHECK_EQ(0, n2->UseCount()); | |
484 } | 547 } |
485 | 548 |
486 { | 549 { |
487 Node* n0 = graph.NewNode(&dummy_operator); | 550 Node* n0 = graph.NewNode(&dummy_operator); |
488 Node* n1 = graph.NewNode(&dummy_operator); | 551 Node* n1 = graph.NewNode(&dummy_operator); |
489 Node* n2 = graph.NewNode(&dummy_operator); | 552 Node* n2 = graph.NewNode(&dummy_operator); |
490 n2->AppendInput(graph.zone(), n0); | 553 n2->AppendInput(graph.zone(), n0); |
491 n2->AppendInput(graph.zone(), n1); | 554 n2->AppendInput(graph.zone(), n1); |
492 CHECK_EQ(2, n2->InputCount()); | 555 CHECK_INPUTS(n2, n0, n1); |
493 n2->TrimInputCount(1); | 556 n2->TrimInputCount(1); |
494 CHECK_EQ(1, n2->InputCount()); | 557 CHECK_INPUTS(n2, n0); |
495 CHECK_EQ(n0, n2->InputAt(0)); | 558 CHECK_USES(n0, n2); |
496 CHECK_EQ(1, n0->UseCount()); | 559 CHECK_USES(n1, NONE); |
497 CHECK_EQ(0, n1->UseCount()); | 560 CHECK_USES(n2, NONE); |
498 CHECK_EQ(0, n2->UseCount()); | |
499 } | 561 } |
500 | 562 |
501 { | 563 { |
502 Node* n0 = graph.NewNode(&dummy_operator); | 564 Node* n0 = graph.NewNode(&dummy_operator); |
503 Node* n1 = graph.NewNode(&dummy_operator); | 565 Node* n1 = graph.NewNode(&dummy_operator); |
504 Node* n2 = graph.NewNode(&dummy_operator); | 566 Node* n2 = graph.NewNode(&dummy_operator); |
505 n2->AppendInput(graph.zone(), n0); | 567 n2->AppendInput(graph.zone(), n0); |
506 n2->AppendInput(graph.zone(), n1); | 568 n2->AppendInput(graph.zone(), n1); |
507 CHECK_EQ(2, n2->InputCount()); | 569 CHECK_INPUTS(n2, n0, n1); |
508 n2->TrimInputCount(0); | 570 n2->TrimInputCount(0); |
509 CHECK_EQ(0, n2->InputCount()); | 571 CHECK_INPUTS(n2, NONE); |
510 CHECK_EQ(0, n0->UseCount()); | 572 CHECK_USES(n0, NONE); |
511 CHECK_EQ(0, n1->UseCount()); | 573 CHECK_USES(n1, NONE); |
512 CHECK_EQ(0, n2->UseCount()); | 574 CHECK_USES(n2, NONE); |
513 } | 575 } |
514 | 576 |
515 { | 577 { |
516 Node* n0 = graph.NewNode(&dummy_operator); | 578 Node* n0 = graph.NewNode(&dummy_operator); |
517 Node* n2 = graph.NewNode(&dummy_operator); | 579 Node* n2 = graph.NewNode(&dummy_operator); |
518 n2->AppendInput(graph.zone(), n0); | 580 n2->AppendInput(graph.zone(), n0); |
519 n2->AppendInput(graph.zone(), n0); | 581 n2->AppendInput(graph.zone(), n0); |
520 CHECK_EQ(2, n2->InputCount()); | 582 CHECK_INPUTS(n2, n0, n0); |
521 CHECK_EQ(2, n0->UseCount()); | 583 CHECK_USES(n0, n2, n2); |
522 n2->TrimInputCount(1); | 584 n2->TrimInputCount(1); |
523 CHECK_EQ(1, n2->InputCount()); | 585 CHECK_INPUTS(n2, n0); |
524 CHECK_EQ(1, n0->UseCount()); | 586 CHECK_USES(n0, n2); |
525 CHECK_EQ(0, n2->UseCount()); | |
526 } | 587 } |
527 | 588 |
528 { | 589 { |
529 Node* n0 = graph.NewNode(&dummy_operator); | 590 Node* n0 = graph.NewNode(&dummy_operator); |
530 Node* n2 = graph.NewNode(&dummy_operator); | 591 Node* n2 = graph.NewNode(&dummy_operator); |
531 n2->AppendInput(graph.zone(), n0); | 592 n2->AppendInput(graph.zone(), n0); |
532 n2->AppendInput(graph.zone(), n0); | 593 n2->AppendInput(graph.zone(), n0); |
533 CHECK_EQ(2, n2->InputCount()); | 594 CHECK_INPUTS(n2, n0, n0); |
534 CHECK_EQ(2, n0->UseCount()); | 595 CHECK_USES(n0, n2, n2); |
535 n2->TrimInputCount(0); | 596 n2->TrimInputCount(0); |
536 CHECK_EQ(0, n2->InputCount()); | 597 CHECK_INPUTS(n2, NONE); |
537 CHECK_EQ(0, n0->UseCount()); | 598 CHECK_USES(n0, NONE); |
538 CHECK_EQ(0, n2->UseCount()); | |
539 } | 599 } |
540 } | 600 } |
541 | 601 |
542 | 602 |
543 TEST(TrimInputCountOutOfLine2) { | 603 TEST(TrimInputCountOutOfLine2) { |
544 GraphTester graph; | 604 GraphTester graph; |
545 | 605 |
546 { | 606 { |
547 Node* n0 = graph.NewNode(&dummy_operator); | 607 Node* n0 = graph.NewNode(&dummy_operator); |
548 Node* n1 = graph.NewNode(&dummy_operator); | 608 Node* n1 = graph.NewNode(&dummy_operator); |
549 Node* n2 = graph.NewNode(&dummy_operator, n0); | 609 Node* n2 = graph.NewNode(&dummy_operator, n0); |
550 n2->AppendInput(graph.zone(), n1); | 610 n2->AppendInput(graph.zone(), n1); |
551 CHECK_EQ(2, n2->InputCount()); | 611 CHECK_INPUTS(n2, n0, n1); |
552 n2->TrimInputCount(2); | 612 n2->TrimInputCount(2); |
553 CHECK_EQ(2, n2->InputCount()); | 613 CHECK_INPUTS(n2, n0, n1); |
554 CHECK_EQ(n0, n2->InputAt(0)); | 614 CHECK_USES(n0, n2); |
555 CHECK_EQ(n1, n2->InputAt(1)); | 615 CHECK_USES(n1, n2); |
556 CHECK_EQ(1, n0->UseCount()); | 616 CHECK_USES(n2, NONE); |
557 CHECK_EQ(1, n1->UseCount()); | |
558 CHECK_EQ(0, n2->UseCount()); | |
559 } | 617 } |
560 | 618 |
561 { | 619 { |
562 Node* n0 = graph.NewNode(&dummy_operator); | 620 Node* n0 = graph.NewNode(&dummy_operator); |
563 Node* n1 = graph.NewNode(&dummy_operator); | 621 Node* n1 = graph.NewNode(&dummy_operator); |
564 Node* n2 = graph.NewNode(&dummy_operator, n0); | 622 Node* n2 = graph.NewNode(&dummy_operator, n0); |
565 n2->AppendInput(graph.zone(), n1); | 623 n2->AppendInput(graph.zone(), n1); |
566 CHECK_EQ(2, n2->InputCount()); | 624 CHECK_INPUTS(n2, n0, n1); |
567 n2->TrimInputCount(1); | 625 n2->TrimInputCount(1); |
568 CHECK_EQ(1, n2->InputCount()); | 626 CHECK_INPUTS(n2, n0); |
569 CHECK_EQ(n0, n2->InputAt(0)); | 627 CHECK_USES(n0, n2); |
570 CHECK_EQ(1, n0->UseCount()); | 628 CHECK_USES(n1, NONE); |
571 CHECK_EQ(0, n1->UseCount()); | 629 CHECK_USES(n2, NONE); |
572 CHECK_EQ(0, n2->UseCount()); | |
573 } | 630 } |
574 | 631 |
575 { | 632 { |
576 Node* n0 = graph.NewNode(&dummy_operator); | 633 Node* n0 = graph.NewNode(&dummy_operator); |
577 Node* n1 = graph.NewNode(&dummy_operator); | 634 Node* n1 = graph.NewNode(&dummy_operator); |
578 Node* n2 = graph.NewNode(&dummy_operator, n0); | 635 Node* n2 = graph.NewNode(&dummy_operator, n0); |
579 n2->AppendInput(graph.zone(), n1); | 636 n2->AppendInput(graph.zone(), n1); |
580 CHECK_EQ(2, n2->InputCount()); | 637 CHECK_INPUTS(n2, n0, n1); |
581 n2->TrimInputCount(0); | 638 n2->TrimInputCount(0); |
582 CHECK_EQ(0, n2->InputCount()); | 639 CHECK_INPUTS(n2, NONE); |
583 CHECK_EQ(0, n0->UseCount()); | 640 CHECK_USES(n0, NONE); |
584 CHECK_EQ(0, n1->UseCount()); | 641 CHECK_USES(n1, NONE); |
585 CHECK_EQ(0, n2->UseCount()); | 642 CHECK_USES(n2, NONE); |
586 } | 643 } |
587 | 644 |
588 { | 645 { |
589 Node* n0 = graph.NewNode(&dummy_operator); | 646 Node* n0 = graph.NewNode(&dummy_operator); |
590 Node* n2 = graph.NewNode(&dummy_operator, n0); | 647 Node* n2 = graph.NewNode(&dummy_operator, n0); |
591 n2->AppendInput(graph.zone(), n0); | 648 n2->AppendInput(graph.zone(), n0); |
592 CHECK_EQ(2, n2->InputCount()); | 649 CHECK_INPUTS(n2, n0, n0); |
593 CHECK_EQ(2, n0->UseCount()); | 650 CHECK_USES(n0, n2, n2); |
594 n2->TrimInputCount(1); | 651 n2->TrimInputCount(1); |
595 CHECK_EQ(1, n2->InputCount()); | 652 CHECK_INPUTS(n2, n0); |
596 CHECK_EQ(1, n0->UseCount()); | 653 CHECK_USES(n0, n2); |
597 CHECK_EQ(0, n2->UseCount()); | 654 CHECK_USES(n2, NONE); |
598 } | 655 } |
599 | 656 |
600 { | 657 { |
601 Node* n0 = graph.NewNode(&dummy_operator); | 658 Node* n0 = graph.NewNode(&dummy_operator); |
602 Node* n2 = graph.NewNode(&dummy_operator, n0); | 659 Node* n2 = graph.NewNode(&dummy_operator, n0); |
603 n2->AppendInput(graph.zone(), n0); | 660 n2->AppendInput(graph.zone(), n0); |
604 CHECK_EQ(2, n2->InputCount()); | 661 CHECK_EQ(2, n2->InputCount()); |
605 CHECK_EQ(2, n0->UseCount()); | 662 CHECK_EQ(2, n0->UseCount()); |
606 n2->TrimInputCount(0); | 663 n2->TrimInputCount(0); |
607 CHECK_EQ(0, n2->InputCount()); | 664 CHECK_EQ(0, n2->InputCount()); |
608 CHECK_EQ(0, n0->UseCount()); | 665 CHECK_EQ(0, n0->UseCount()); |
609 CHECK_EQ(0, n2->UseCount()); | 666 CHECK_EQ(0, n2->UseCount()); |
610 } | 667 } |
611 } | 668 } |
612 | 669 |
613 | 670 |
614 TEST(RemoveAllInputs) { | 671 TEST(RemoveAllInputs) { |
615 GraphTester graph; | 672 GraphTester graph; |
616 | 673 |
617 for (int i = 0; i < 2; i++) { | 674 for (int i = 0; i < 2; i++) { |
618 Node* n0 = graph.NewNode(&dummy_operator); | 675 Node* n0 = graph.NewNode(&dummy_operator); |
619 Node* n1 = graph.NewNode(&dummy_operator, n0); | 676 Node* n1 = graph.NewNode(&dummy_operator, n0); |
620 Node* n2; | 677 Node* n2; |
621 if (i == 0) { | 678 if (i == 0) { |
622 n2 = graph.NewNode(&dummy_operator, n0, n1); | 679 n2 = graph.NewNode(&dummy_operator, n0, n1); |
| 680 CHECK_INPUTS(n2, n0, n1); |
623 } else { | 681 } else { |
624 n2 = graph.NewNode(&dummy_operator, n0); | 682 n2 = graph.NewNode(&dummy_operator, n0); |
| 683 CHECK_INPUTS(n2, n0); |
625 n2->AppendInput(graph.zone(), n1); // with out-of-line input. | 684 n2->AppendInput(graph.zone(), n1); // with out-of-line input. |
| 685 CHECK_INPUTS(n2, n0, n1); |
626 } | 686 } |
627 | 687 |
628 n0->RemoveAllInputs(); | 688 n0->RemoveAllInputs(); |
629 CHECK_EQ(0, n0->InputCount()); | 689 CHECK_INPUTS(n0, NONE); |
630 | 690 |
631 CHECK_EQ(2, n0->UseCount()); | 691 CHECK_USES(n0, n1, n2); |
632 n1->RemoveAllInputs(); | 692 n1->RemoveAllInputs(); |
633 CHECK_EQ(1, n1->InputCount()); | 693 CHECK_INPUTS(n1, NULL); |
634 CHECK_EQ(1, n0->UseCount()); | 694 CHECK_INPUTS(n2, n0, n1); |
635 CHECK(!n1->InputAt(0)); | 695 CHECK_USES(n0, n2); |
636 | 696 |
637 CHECK_EQ(1, n1->UseCount()); | |
638 n2->RemoveAllInputs(); | 697 n2->RemoveAllInputs(); |
639 CHECK_EQ(2, n2->InputCount()); | 698 CHECK_INPUTS(n1, NULL); |
640 CHECK_EQ(0, n0->UseCount()); | 699 CHECK_INPUTS(n2, NULL, NULL); |
641 CHECK_EQ(0, n1->UseCount()); | 700 CHECK_USES(n0, NONE); |
642 CHECK(!n2->InputAt(0)); | |
643 CHECK(!n2->InputAt(1)); | |
644 } | 701 } |
645 | 702 |
646 { | 703 { |
647 Node* n0 = graph.NewNode(&dummy_operator); | 704 Node* n0 = graph.NewNode(&dummy_operator); |
648 Node* n1 = graph.NewNode(&dummy_operator, n0); | 705 Node* n1 = graph.NewNode(&dummy_operator, n0); |
649 n1->ReplaceInput(0, n1); // self-reference. | 706 n1->ReplaceInput(0, n1); // self-reference. |
650 | 707 |
651 CHECK_EQ(0, n0->UseCount()); | 708 CHECK_INPUTS(n0, NONE); |
652 CHECK_EQ(1, n1->UseCount()); | 709 CHECK_INPUTS(n1, n1); |
| 710 CHECK_USES(n0, NONE); |
| 711 CHECK_USES(n1, n1); |
653 n1->RemoveAllInputs(); | 712 n1->RemoveAllInputs(); |
654 CHECK_EQ(1, n1->InputCount()); | 713 |
655 CHECK_EQ(0, n1->UseCount()); | 714 CHECK_INPUTS(n0, NONE); |
656 CHECK(!n1->InputAt(0)); | 715 CHECK_INPUTS(n1, NULL); |
| 716 CHECK_USES(n0, NONE); |
| 717 CHECK_USES(n1, NONE); |
657 } | 718 } |
658 } | 719 } |
| 720 |
| 721 |
| 722 TEST(AppendAndTrim) { |
| 723 GraphTester graph; |
| 724 |
| 725 Node* nodes[] = { |
| 726 graph.NewNode(&dummy_operator), graph.NewNode(&dummy_operator), |
| 727 graph.NewNode(&dummy_operator), graph.NewNode(&dummy_operator), |
| 728 graph.NewNode(&dummy_operator)}; |
| 729 |
| 730 int max = static_cast<int>(arraysize(nodes)); |
| 731 |
| 732 Node* last = graph.NewNode(&dummy_operator); |
| 733 |
| 734 for (int i = 0; i < max; i++) { |
| 735 last->AppendInput(graph.zone(), nodes[i]); |
| 736 CheckInputs(last, nodes, i + 1); |
| 737 |
| 738 for (int j = 0; j < max; j++) { |
| 739 if (j <= i) CHECK_USES(nodes[j], last); |
| 740 if (j > i) CHECK_USES(nodes[j], NONE); |
| 741 } |
| 742 |
| 743 CHECK_USES(last, NONE); |
| 744 } |
| 745 |
| 746 for (int i = max; i >= 0; i--) { |
| 747 last->TrimInputCount(i); |
| 748 CheckInputs(last, nodes, i); |
| 749 |
| 750 for (int j = 0; j < i; j++) { |
| 751 if (j < i) CHECK_USES(nodes[j], last); |
| 752 if (j >= i) CHECK_USES(nodes[j], NONE); |
| 753 } |
| 754 |
| 755 CHECK_USES(last, NONE); |
| 756 } |
| 757 } |
OLD | NEW |