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

Side by Side Diff: test/cctest/compiler/compiler/test-node.cc

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

Powered by Google App Engine
This is Rietveld 408576698