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

Side by Side Diff: test/cctest/compiler/test-control-reducer.cc

Issue 1157023002: [turbofan] Change End to take a variable number of inputs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/v8.h" 5 #include "src/v8.h"
6 #include "test/cctest/cctest.h" 6 #include "test/cctest/cctest.h"
7 7
8 #include "src/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/compiler/all-nodes.h" 9 #include "src/compiler/all-nodes.h"
10 #include "src/compiler/common-operator.h" 10 #include "src/compiler/common-operator.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 // A helper for all tests dealing with ControlTester. 63 // A helper for all tests dealing with ControlTester.
64 class ControlReducerTester : HandleAndZoneScope { 64 class ControlReducerTester : HandleAndZoneScope {
65 public: 65 public:
66 ControlReducerTester() 66 ControlReducerTester()
67 : isolate(main_isolate()), 67 : isolate(main_isolate()),
68 common(main_zone()), 68 common(main_zone()),
69 graph(main_zone()), 69 graph(main_zone()),
70 jsgraph(main_isolate(), &graph, &common, NULL, NULL), 70 jsgraph(main_isolate(), &graph, &common, NULL, NULL),
71 start(graph.NewNode(common.Start(1))), 71 start(graph.NewNode(common.Start(1))),
72 end(graph.NewNode(common.End(), start)), 72 end(graph.NewNode(common.End(1), start)),
73 p0(graph.NewNode(common.Parameter(0), start)), 73 p0(graph.NewNode(common.Parameter(0), start)),
74 zero(jsgraph.Int32Constant(0)), 74 zero(jsgraph.Int32Constant(0)),
75 one(jsgraph.OneConstant()), 75 one(jsgraph.OneConstant()),
76 half(jsgraph.Constant(0.5)), 76 half(jsgraph.Constant(0.5)),
77 self(graph.NewNode(common.Int32Constant(0xaabbccdd))), 77 self(graph.NewNode(common.Int32Constant(0xaabbccdd))),
78 dead(graph.NewNode(common.Dead())) { 78 dead(graph.NewNode(common.Dead())) {
79 graph.SetEnd(end); 79 graph.SetEnd(end);
80 graph.SetStart(start); 80 graph.SetStart(start);
81 leaf[0] = zero; 81 leaf[0] = zero;
82 leaf[1] = one; 82 leaf[1] = one;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 // Checks one-step reduction of a phi. 155 // Checks one-step reduction of a phi.
156 void ReducePhiNonIterative(Node* expect, Node* phi) { 156 void ReducePhiNonIterative(Node* expect, Node* phi) {
157 Node* result = ControlReducer::ReducePhiForTesting(&jsgraph, phi); 157 Node* result = ControlReducer::ReducePhiForTesting(&jsgraph, phi);
158 CHECK_EQ(expect, result); 158 CHECK_EQ(expect, result);
159 } 159 }
160 160
161 void ReducePhiIterative(Node* expect, Node* phi) { 161 void ReducePhiIterative(Node* expect, Node* phi) {
162 p0->ReplaceInput(0, start); // hack: parameters may be trimmed. 162 p0->ReplaceInput(0, start); // hack: parameters may be trimmed.
163 Node* ret = graph.NewNode(common.Return(), phi, start, start); 163 Node* ret = graph.NewNode(common.Return(), phi, start, start);
164 Node* end = graph.NewNode(common.End(), ret); 164 Node* end = graph.NewNode(common.End(1), ret);
165 graph.SetEnd(end); 165 graph.SetEnd(end);
166 ControlReducer::ReduceGraph(main_zone(), &jsgraph); 166 ControlReducer::ReduceGraph(main_zone(), &jsgraph);
167 CheckInputs(end, ret); 167 CheckInputs(end, ret);
168 CheckInputs(ret, expect, start, start); 168 CheckInputs(ret, expect, start, start);
169 } 169 }
170 170
171 void ReduceMerge(Node* expect, Node* merge) { 171 void ReduceMerge(Node* expect, Node* merge) {
172 Node* result = ControlReducer::ReduceMerge(&jsgraph, merge); 172 Node* result = ControlReducer::ReduceMerge(&jsgraph, merge);
173 CHECK_EQ(expect, result); 173 CHECK_EQ(expect, result);
174 } 174 }
175 175
176 void ReduceMergeIterative(Node* expect, Node* merge) { 176 void ReduceMergeIterative(Node* expect, Node* merge) {
177 p0->ReplaceInput(0, start); // hack: parameters may be trimmed. 177 p0->ReplaceInput(0, start); // hack: parameters may be trimmed.
178 Node* end = graph.NewNode(common.End(), merge); 178 Node* end = graph.NewNode(common.End(1), merge);
179 graph.SetEnd(end); 179 graph.SetEnd(end);
180 ReduceGraph(); 180 ReduceGraph();
181 CheckInputs(end, expect); 181 CheckInputs(end, expect);
182 } 182 }
183 183
184 void ReduceBranch(Decision expected, Node* branch) { 184 void ReduceBranch(Decision expected, Node* branch) {
185 Node* control = branch->InputAt(1); 185 Node* control = branch->InputAt(1);
186 for (Node* use : branch->uses()) { 186 for (Node* use : branch->uses()) {
187 if (use->opcode() == IrOpcode::kIfTrue) { 187 if (use->opcode() == IrOpcode::kIfTrue) {
188 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use); 188 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 CHECK_EQ(i == 0 ? NULL : dead[i - 1], dead[i]->InputAt(0)); 405 CHECK_EQ(i == 0 ? NULL : dead[i - 1], dead[i]->InputAt(0));
406 CHECK_EQ(i == 0 ? T.start : live[i - 1], live[i]->InputAt(0)); 406 CHECK_EQ(i == 0 ? T.start : live[i - 1], live[i]->InputAt(0));
407 } 407 }
408 } 408 }
409 409
410 410
411 TEST(Trim_cycle1) { 411 TEST(Trim_cycle1) {
412 ControlReducerTester T; 412 ControlReducerTester T;
413 Node* loop = T.graph.NewNode(T.common.Loop(1), T.start, T.start); 413 Node* loop = T.graph.NewNode(T.common.Loop(1), T.start, T.start);
414 loop->ReplaceInput(1, loop); 414 loop->ReplaceInput(1, loop);
415 Node* end = T.graph.NewNode(T.common.End(), loop); 415 Node* end = T.graph.NewNode(T.common.End(1), loop);
416 T.graph.SetEnd(end); 416 T.graph.SetEnd(end);
417 417
418 CHECK(IsUsedBy(T.start, loop)); 418 CHECK(IsUsedBy(T.start, loop));
419 CHECK(IsUsedBy(loop, end)); 419 CHECK(IsUsedBy(loop, end));
420 CHECK(IsUsedBy(loop, loop)); 420 CHECK(IsUsedBy(loop, loop));
421 421
422 T.Trim(); 422 T.Trim();
423 423
424 // nothing should have happened to the loop itself. 424 // nothing should have happened to the loop itself.
425 CHECK(IsUsedBy(T.start, loop)); 425 CHECK(IsUsedBy(T.start, loop));
426 CHECK(IsUsedBy(loop, end)); 426 CHECK(IsUsedBy(loop, end));
427 CHECK(IsUsedBy(loop, loop)); 427 CHECK(IsUsedBy(loop, loop));
428 CheckInputs(loop, T.start, loop); 428 CheckInputs(loop, T.start, loop);
429 CheckInputs(end, loop); 429 CheckInputs(end, loop);
430 } 430 }
431 431
432 432
433 TEST(Trim_cycle2) { 433 TEST(Trim_cycle2) {
434 ControlReducerTester T; 434 ControlReducerTester T;
435 Node* loop = T.graph.NewNode(T.common.Loop(2), T.start, T.start); 435 Node* loop = T.graph.NewNode(T.common.Loop(2), T.start, T.start);
436 loop->ReplaceInput(1, loop); 436 loop->ReplaceInput(1, loop);
437 Node* end = T.graph.NewNode(T.common.End(), loop); 437 Node* end = T.graph.NewNode(T.common.End(1), loop);
438 Node* phi = 438 Node* phi =
439 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, loop); 439 T.graph.NewNode(T.common.Phi(kMachAnyTagged, 2), T.one, T.half, loop);
440 T.graph.SetEnd(end); 440 T.graph.SetEnd(end);
441 441
442 CHECK(IsUsedBy(T.start, loop)); 442 CHECK(IsUsedBy(T.start, loop));
443 CHECK(IsUsedBy(loop, end)); 443 CHECK(IsUsedBy(loop, end));
444 CHECK(IsUsedBy(loop, loop)); 444 CHECK(IsUsedBy(loop, loop));
445 CHECK(IsUsedBy(loop, phi)); 445 CHECK(IsUsedBy(loop, phi));
446 CHECK(IsUsedBy(T.one, phi)); 446 CHECK(IsUsedBy(T.one, phi));
447 CHECK(IsUsedBy(T.half, phi)); 447 CHECK(IsUsedBy(T.half, phi));
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 } 1065 }
1066 1066
1067 1067
1068 TEST(CMergeReduce_dead_chain1) { 1068 TEST(CMergeReduce_dead_chain1) {
1069 ControlReducerTester R; 1069 ControlReducerTester R;
1070 for (int i = 0; i < 5; i++) { 1070 for (int i = 0; i < 5; i++) {
1071 Node* merge = R.graph.NewNode(R.common.Merge(1), R.dead); 1071 Node* merge = R.graph.NewNode(R.common.Merge(1), R.dead);
1072 for (int j = 0; j < i; j++) { 1072 for (int j = 0; j < i; j++) {
1073 merge = R.graph.NewNode(R.common.Merge(1), merge); 1073 merge = R.graph.NewNode(R.common.Merge(1), merge);
1074 } 1074 }
1075 Node* end = R.graph.NewNode(R.common.End(), merge); 1075 Node* end = R.graph.NewNode(R.common.End(1), merge);
1076 R.graph.SetEnd(end); 1076 R.graph.SetEnd(end);
1077 R.ReduceGraph(); 1077 R.ReduceGraph();
1078 CHECK(merge->IsDead()); 1078 CHECK(merge->IsDead());
1079 CHECK(!end->InputAt(0)); // end dies. 1079 CHECK(!end->InputAt(0)); // end dies.
1080 } 1080 }
1081 } 1081 }
1082 1082
1083 1083
1084 TEST(CMergeReduce_dead_chain2) { 1084 TEST(CMergeReduce_dead_chain2) {
1085 ControlReducerTester R; 1085 ControlReducerTester R;
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 1632
1633 R.ReduceGraph(); // d1 gets folded true. 1633 R.ReduceGraph(); // d1 gets folded true.
1634 1634
1635 CheckInputs(ret, y2, R.start, R.start); 1635 CheckInputs(ret, y2, R.start, R.start);
1636 1636
1637 DeadChecker dead(&R.graph); 1637 DeadChecker dead(&R.graph);
1638 dead.Check(d1); 1638 dead.Check(d1);
1639 dead.Check(d2); 1639 dead.Check(d2);
1640 dead.Check(d3); 1640 dead.Check(d3);
1641 } 1641 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698