| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(1), 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.DeadControl())) { |
| 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; |
| 83 leaf[2] = half; | 83 leaf[2] = half; |
| 84 leaf[3] = p0; | 84 leaf[3] = p0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 Isolate* isolate; | 87 Isolate* isolate; |
| 88 CommonOperatorBuilder common; | 88 CommonOperatorBuilder common; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 ReduceGraph(); | 178 ReduceGraph(); |
| 179 CheckInputs(end, expect); | 179 CheckInputs(end, expect); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ReduceBranch(Decision expected, Node* branch) { | 182 void ReduceBranch(Decision expected, Node* branch) { |
| 183 Node* control = branch->InputAt(1); | 183 Node* control = branch->InputAt(1); |
| 184 for (Node* use : branch->uses()) { | 184 for (Node* use : branch->uses()) { |
| 185 if (use->opcode() == IrOpcode::kIfTrue) { | 185 if (use->opcode() == IrOpcode::kIfTrue) { |
| 186 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use); | 186 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use); |
| 187 if (expected == kTrue) CHECK_EQ(control, result); | 187 if (expected == kTrue) CHECK_EQ(control, result); |
| 188 if (expected == kFalse) CHECK_EQ(IrOpcode::kDead, result->opcode()); | 188 if (expected == kFalse) { |
| 189 CHECK_EQ(IrOpcode::kDeadControl, result->opcode()); |
| 190 } |
| 189 if (expected == kUnknown) CHECK_EQ(use, result); | 191 if (expected == kUnknown) CHECK_EQ(use, result); |
| 190 } else if (use->opcode() == IrOpcode::kIfFalse) { | 192 } else if (use->opcode() == IrOpcode::kIfFalse) { |
| 191 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use); | 193 Node* result = ControlReducer::ReduceIfNodeForTesting(&jsgraph, use); |
| 192 if (expected == kFalse) CHECK_EQ(control, result); | 194 if (expected == kFalse) CHECK_EQ(control, result); |
| 193 if (expected == kTrue) CHECK_EQ(IrOpcode::kDead, result->opcode()); | 195 if (expected == kTrue) { |
| 196 CHECK_EQ(IrOpcode::kDeadControl, result->opcode()); |
| 197 } |
| 194 if (expected == kUnknown) CHECK_EQ(use, result); | 198 if (expected == kUnknown) CHECK_EQ(use, result); |
| 195 } else { | 199 } else { |
| 196 UNREACHABLE(); | 200 UNREACHABLE(); |
| 197 } | 201 } |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 | 204 |
| 201 Node* Return(Node* val, Node* effect, Node* control) { | 205 Node* Return(Node* val, Node* effect, Node* control) { |
| 202 Node* ret = graph.NewNode(common.Return(), val, effect, control); | 206 Node* ret = graph.NewNode(common.Return(), val, effect, control); |
| 203 end->ReplaceInput(0, ret); | 207 end->ReplaceInput(0, ret); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 | 790 |
| 787 for (int i = 0; i < kSelectorSize; i++) { // set up dead merge inputs. | 791 for (int i = 0; i < kSelectorSize; i++) { // set up dead merge inputs. |
| 788 if (!selector.is_selected(i)) merge->ReplaceInput(i, R.dead); | 792 if (!selector.is_selected(i)) merge->ReplaceInput(i, R.dead); |
| 789 } | 793 } |
| 790 | 794 |
| 791 Node* result = ControlReducer::ReduceMerge(&R.jsgraph, merge); | 795 Node* result = ControlReducer::ReduceMerge(&R.jsgraph, merge); |
| 792 | 796 |
| 793 int count = selector.count; | 797 int count = selector.count; |
| 794 if (count == 0) { | 798 if (count == 0) { |
| 795 // result should be dead. | 799 // result should be dead. |
| 796 CHECK_EQ(IrOpcode::kDead, result->opcode()); | 800 CHECK_EQ(IrOpcode::kDeadControl, result->opcode()); |
| 797 } else if (count == 1) { | 801 } else if (count == 1) { |
| 798 // merge should be replaced with one of the controls. | 802 // merge should be replaced with one of the controls. |
| 799 CHECK_EQ(controls[selector.single_index()], result); | 803 CHECK_EQ(controls[selector.single_index()], result); |
| 800 // Phis should have been directly replaced. | 804 // Phis should have been directly replaced. |
| 801 CHECK_EQ(values[selector.single_index()], phi_use->InputAt(0)); | 805 CHECK_EQ(values[selector.single_index()], phi_use->InputAt(0)); |
| 802 CHECK_EQ(effects[selector.single_index()], ephi_use->InputAt(0)); | 806 CHECK_EQ(effects[selector.single_index()], ephi_use->InputAt(0)); |
| 803 } else { | 807 } else { |
| 804 // Otherwise, nodes should be edited in place. | 808 // Otherwise, nodes should be edited in place. |
| 805 CHECK_EQ(merge, result); | 809 CHECK_EQ(merge, result); |
| 806 selector.CheckNode(merge, IrOpcode::kMerge, controls, NULL); | 810 selector.CheckNode(merge, IrOpcode::kMerge, controls, NULL); |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 | 1409 |
| 1406 R.ReduceGraph(); // d1 gets folded true. | 1410 R.ReduceGraph(); // d1 gets folded true. |
| 1407 | 1411 |
| 1408 CheckInputs(ret, y2, R.start, R.start); | 1412 CheckInputs(ret, y2, R.start, R.start); |
| 1409 | 1413 |
| 1410 DeadChecker dead(&R.graph); | 1414 DeadChecker dead(&R.graph); |
| 1411 dead.Check(d1); | 1415 dead.Check(d1); |
| 1412 dead.Check(d2); | 1416 dead.Check(d2); |
| 1413 dead.Check(d3); | 1417 dead.Check(d3); |
| 1414 } | 1418 } |
| OLD | NEW |