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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
8 #include "src/compiler/value-numbering-reducer.h" | 8 #include "src/compiler/value-numbering-reducer.h" |
9 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const SimpleOperator kOp0(0, Operator::kNoProperties, 0, 1, "op0"); | 17 const SimpleOperator kOp0(0, Operator::kEliminatable, 0, 1, "op0"); |
18 const SimpleOperator kOp1(1, Operator::kNoProperties, 1, 1, "op1"); | 18 const SimpleOperator kOp1(1, Operator::kEliminatable, 1, 1, "op1"); |
19 | 19 |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 | 22 |
23 class ValueNumberingReducerTest : public TestWithZone { | 23 class ValueNumberingReducerTest : public TestWithZone { |
24 public: | 24 public: |
25 ValueNumberingReducerTest() : graph_(zone()), reducer_(zone()) {} | 25 ValueNumberingReducerTest() : graph_(zone()), reducer_(zone()) {} |
26 | 26 |
27 protected: | 27 protected: |
28 Reduction Reduce(Node* node) { return reducer_.Reduce(node); } | 28 Reduction Reduce(Node* node) { return reducer_.Reduce(node); } |
(...skipping 18 matching lines...) Expand all Loading... |
47 | 47 |
48 TEST_F(ValueNumberingReducerTest, DeadNodesAreNeverReturned) { | 48 TEST_F(ValueNumberingReducerTest, DeadNodesAreNeverReturned) { |
49 Node* n0 = graph()->NewNode(&kOp0); | 49 Node* n0 = graph()->NewNode(&kOp0); |
50 Node* n1 = graph()->NewNode(&kOp1, n0); | 50 Node* n1 = graph()->NewNode(&kOp1, n0); |
51 EXPECT_FALSE(Reduce(n1).Changed()); | 51 EXPECT_FALSE(Reduce(n1).Changed()); |
52 n1->Kill(); | 52 n1->Kill(); |
53 EXPECT_FALSE(Reduce(graph()->NewNode(&kOp1, n0)).Changed()); | 53 EXPECT_FALSE(Reduce(graph()->NewNode(&kOp1, n0)).Changed()); |
54 } | 54 } |
55 | 55 |
56 | 56 |
| 57 TEST_F(ValueNumberingReducerTest, OnlyEliminatableNodesAreReduced) { |
| 58 SimpleOperator op(0, Operator::kNoProperties, 0, 1, "op"); |
| 59 Node* n0 = graph()->NewNode(&op); |
| 60 Node* n1 = graph()->NewNode(&op); |
| 61 EXPECT_FALSE(Reduce(n0).Changed()); |
| 62 EXPECT_FALSE(Reduce(n1).Changed()); |
| 63 } |
| 64 |
| 65 |
57 TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) { | 66 TEST_F(ValueNumberingReducerTest, OperatorEqualityNotIdentity) { |
58 static const size_t kMaxInputCount = 16; | 67 static const size_t kMaxInputCount = 16; |
59 Node* inputs[kMaxInputCount]; | 68 Node* inputs[kMaxInputCount]; |
60 for (size_t i = 0; i < arraysize(inputs); ++i) { | 69 for (size_t i = 0; i < arraysize(inputs); ++i) { |
61 Operator::Opcode opcode = static_cast<Operator::Opcode>( | 70 Operator::Opcode opcode = static_cast<Operator::Opcode>( |
62 std::numeric_limits<Operator::Opcode>::max() - i); | 71 std::numeric_limits<Operator::Opcode>::max() - i); |
63 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( | 72 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( |
64 opcode, Operator::kNoProperties, 0, 1, "Operator")); | 73 opcode, Operator::kEliminatable, 0, 1, "Operator")); |
65 } | 74 } |
66 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { | 75 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
67 const SimpleOperator op1(static_cast<Operator::Opcode>(input_count), | 76 const SimpleOperator op1(static_cast<Operator::Opcode>(input_count), |
68 Operator::kNoProperties, | 77 Operator::kEliminatable, |
69 static_cast<int>(input_count), 1, "op"); | 78 static_cast<int>(input_count), 1, "op"); |
70 Node* n1 = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); | 79 Node* n1 = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); |
71 Reduction r1 = Reduce(n1); | 80 Reduction r1 = Reduce(n1); |
72 EXPECT_FALSE(r1.Changed()); | 81 EXPECT_FALSE(r1.Changed()); |
73 | 82 |
74 const SimpleOperator op2(static_cast<Operator::Opcode>(input_count), | 83 const SimpleOperator op2(static_cast<Operator::Opcode>(input_count), |
75 Operator::kNoProperties, | 84 Operator::kEliminatable, |
76 static_cast<int>(input_count), 1, "op"); | 85 static_cast<int>(input_count), 1, "op"); |
77 Node* n2 = graph()->NewNode(&op2, static_cast<int>(input_count), inputs); | 86 Node* n2 = graph()->NewNode(&op2, static_cast<int>(input_count), inputs); |
78 Reduction r2 = Reduce(n2); | 87 Reduction r2 = Reduce(n2); |
79 EXPECT_TRUE(r2.Changed()); | 88 EXPECT_TRUE(r2.Changed()); |
80 EXPECT_EQ(n1, r2.replacement()); | 89 EXPECT_EQ(n1, r2.replacement()); |
81 } | 90 } |
82 } | 91 } |
83 | 92 |
84 | 93 |
85 TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) { | 94 TEST_F(ValueNumberingReducerTest, SubsequentReductionsYieldTheSameNode) { |
86 static const size_t kMaxInputCount = 16; | 95 static const size_t kMaxInputCount = 16; |
87 Node* inputs[kMaxInputCount]; | 96 Node* inputs[kMaxInputCount]; |
88 for (size_t i = 0; i < arraysize(inputs); ++i) { | 97 for (size_t i = 0; i < arraysize(inputs); ++i) { |
89 Operator::Opcode opcode = static_cast<Operator::Opcode>( | 98 Operator::Opcode opcode = static_cast<Operator::Opcode>( |
90 std::numeric_limits<Operator::Opcode>::max() - i); | 99 std::numeric_limits<Operator::Opcode>::max() - i); |
91 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( | 100 inputs[i] = graph()->NewNode(new (zone()) SimpleOperator( |
92 opcode, Operator::kNoProperties, 0, 1, "Operator")); | 101 opcode, Operator::kEliminatable, 0, 1, "Operator")); |
93 } | 102 } |
94 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { | 103 TRACED_FORRANGE(size_t, input_count, 0, arraysize(inputs)) { |
95 const SimpleOperator op1(1, Operator::kNoProperties, | 104 const SimpleOperator op1(1, Operator::kEliminatable, |
96 static_cast<int>(input_count), 1, "op1"); | 105 static_cast<int>(input_count), 1, "op1"); |
97 Node* n = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); | 106 Node* n = graph()->NewNode(&op1, static_cast<int>(input_count), inputs); |
98 Reduction r = Reduce(n); | 107 Reduction r = Reduce(n); |
99 EXPECT_FALSE(r.Changed()); | 108 EXPECT_FALSE(r.Changed()); |
100 | 109 |
101 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); | 110 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); |
102 ASSERT_TRUE(r.Changed()); | 111 ASSERT_TRUE(r.Changed()); |
103 EXPECT_EQ(n, r.replacement()); | 112 EXPECT_EQ(n, r.replacement()); |
104 | 113 |
105 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); | 114 r = Reduce(graph()->NewNode(&op1, static_cast<int>(input_count), inputs)); |
106 ASSERT_TRUE(r.Changed()); | 115 ASSERT_TRUE(r.Changed()); |
107 EXPECT_EQ(n, r.replacement()); | 116 EXPECT_EQ(n, r.replacement()); |
108 } | 117 } |
109 } | 118 } |
110 | 119 |
111 | 120 |
112 TEST_F(ValueNumberingReducerTest, WontReplaceNodeWithItself) { | 121 TEST_F(ValueNumberingReducerTest, WontReplaceNodeWithItself) { |
113 Node* n = graph()->NewNode(&kOp0); | 122 Node* n = graph()->NewNode(&kOp0); |
114 EXPECT_FALSE(Reduce(n).Changed()); | 123 EXPECT_FALSE(Reduce(n).Changed()); |
115 EXPECT_FALSE(Reduce(n).Changed()); | 124 EXPECT_FALSE(Reduce(n).Changed()); |
116 } | 125 } |
117 | 126 |
118 } // namespace compiler | 127 } // namespace compiler |
119 } // namespace internal | 128 } // namespace internal |
120 } // namespace v8 | 129 } // namespace v8 |
OLD | NEW |