| 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/compiler/state-values-utils.h" | 5 #include "src/compiler/state-values-utils.h" |
| 6 #include "src/bit-vector.h" |
| 6 #include "test/unittests/compiler/graph-unittest.h" | 7 #include "test/unittests/compiler/graph-unittest.h" |
| 7 #include "test/unittests/compiler/node-test-utils.h" | 8 #include "test/unittests/compiler/node-test-utils.h" |
| 8 #include "test/unittests/test-utils.h" | 9 #include "test/unittests/test-utils.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 10 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 namespace compiler { | 14 namespace compiler { |
| 14 | 15 |
| 15 class StateValuesIteratorTest : public GraphTest { | 16 class StateValuesIteratorTest : public GraphTest { |
| 16 public: | 17 public: |
| 17 StateValuesIteratorTest() : GraphTest(3) {} | 18 StateValuesIteratorTest() : GraphTest(3) {} |
| 18 | 19 |
| 19 Node* StateValuesFromVector(NodeVector* nodes) { | 20 Node* StateValuesFromVector(NodeVector* nodes) { |
| 20 int count = static_cast<int>(nodes->size()); | 21 int count = static_cast<int>(nodes->size()); |
| 21 return graph()->NewNode(common()->StateValues(count), count, | 22 return graph()->NewNode( |
| 22 count == 0 ? nullptr : &(nodes->front())); | 23 common()->StateValues(count, SparseInputMask::Dense()), count, |
| 24 count == 0 ? nullptr : &(nodes->front())); |
| 23 } | 25 } |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 | 28 |
| 27 TEST_F(StateValuesIteratorTest, SimpleIteration) { | 29 TEST_F(StateValuesIteratorTest, SimpleIteration) { |
| 28 NodeVector inputs(zone()); | 30 NodeVector inputs(zone()); |
| 29 const int count = 10; | 31 const int count = 10; |
| 30 for (int i = 0; i < count; i++) { | 32 for (int i = 0; i < count; i++) { |
| 31 inputs.push_back(Int32Constant(i)); | 33 inputs.push_back(Int32Constant(i)); |
| 32 } | 34 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 102 |
| 101 // Generate the input vector. | 103 // Generate the input vector. |
| 102 NodeVector inputs(zone()); | 104 NodeVector inputs(zone()); |
| 103 for (int i = 0; i < count; i++) { | 105 for (int i = 0; i < count; i++) { |
| 104 inputs.push_back(Int32Constant(i)); | 106 inputs.push_back(Int32Constant(i)); |
| 105 } | 107 } |
| 106 | 108 |
| 107 // Build the tree. | 109 // Build the tree. |
| 108 StateValuesCache builder(&jsgraph); | 110 StateValuesCache builder(&jsgraph); |
| 109 Node* values_node = builder.GetNodeForValues( | 111 Node* values_node = builder.GetNodeForValues( |
| 110 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 112 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 113 nullptr); |
| 111 | 114 |
| 112 // Check the tree contents with vector. | 115 // Check the tree contents with vector. |
| 113 int i = 0; | 116 int i = 0; |
| 114 for (StateValuesAccess::TypedNode node : StateValuesAccess(values_node)) { | 117 for (StateValuesAccess::TypedNode node : StateValuesAccess(values_node)) { |
| 115 EXPECT_THAT(node.node, IsInt32Constant(i)); | 118 EXPECT_THAT(node.node, IsInt32Constant(i)); |
| 116 i++; | 119 i++; |
| 117 } | 120 } |
| 118 EXPECT_EQ(inputs.size(), static_cast<size_t>(i)); | 121 EXPECT_EQ(inputs.size(), static_cast<size_t>(i)); |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 | 124 |
| 125 TEST_F(StateValuesIteratorTest, TreeFromVectorWithLiveness) { |
| 126 int sizes[] = {0, 1, 2, 100, 5000, 30000}; |
| 127 TRACED_FOREACH(int, count, sizes) { |
| 128 JSOperatorBuilder javascript(zone()); |
| 129 MachineOperatorBuilder machine(zone()); |
| 130 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, |
| 131 &machine); |
| 132 |
| 133 // Generate the input vector. |
| 134 NodeVector inputs(zone()); |
| 135 for (int i = 0; i < count; i++) { |
| 136 inputs.push_back(Int32Constant(i)); |
| 137 } |
| 138 // Generate the input liveness. |
| 139 BitVector liveness(count, zone()); |
| 140 for (int i = 0; i < count; i++) { |
| 141 if (i % 3 == 0) { |
| 142 liveness.Add(i); |
| 143 } |
| 144 } |
| 145 |
| 146 // Build the tree. |
| 147 StateValuesCache builder(&jsgraph); |
| 148 Node* values_node = builder.GetNodeForValues( |
| 149 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 150 &liveness); |
| 151 |
| 152 // Check the tree contents with vector. |
| 153 int i = 0; |
| 154 for (StateValuesAccess::TypedNode node : StateValuesAccess(values_node)) { |
| 155 if (liveness.Contains(i)) { |
| 156 EXPECT_THAT(node.node, IsInt32Constant(i)); |
| 157 } else { |
| 158 EXPECT_EQ(node.node, nullptr); |
| 159 } |
| 160 i++; |
| 161 } |
| 162 EXPECT_EQ(inputs.size(), static_cast<size_t>(i)); |
| 163 } |
| 164 } |
| 122 | 165 |
| 123 TEST_F(StateValuesIteratorTest, BuildTreeIdentical) { | 166 TEST_F(StateValuesIteratorTest, BuildTreeIdentical) { |
| 124 int sizes[] = {0, 1, 2, 100, 5000, 30000}; | 167 int sizes[] = {0, 1, 2, 100, 5000, 30000}; |
| 125 TRACED_FOREACH(int, count, sizes) { | 168 TRACED_FOREACH(int, count, sizes) { |
| 126 JSOperatorBuilder javascript(zone()); | 169 JSOperatorBuilder javascript(zone()); |
| 127 MachineOperatorBuilder machine(zone()); | 170 MachineOperatorBuilder machine(zone()); |
| 128 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, | 171 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, |
| 129 &machine); | 172 &machine); |
| 130 | 173 |
| 131 // Generate the input vector. | 174 // Generate the input vector. |
| 132 NodeVector inputs(zone()); | 175 NodeVector inputs(zone()); |
| 133 for (int i = 0; i < count; i++) { | 176 for (int i = 0; i < count; i++) { |
| 134 inputs.push_back(Int32Constant(i)); | 177 inputs.push_back(Int32Constant(i)); |
| 135 } | 178 } |
| 136 | 179 |
| 137 // Build two trees from the same data. | 180 // Build two trees from the same data. |
| 138 StateValuesCache builder(&jsgraph); | 181 StateValuesCache builder(&jsgraph); |
| 139 Node* node1 = builder.GetNodeForValues( | 182 Node* node1 = builder.GetNodeForValues( |
| 140 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 183 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 184 nullptr); |
| 141 Node* node2 = builder.GetNodeForValues( | 185 Node* node2 = builder.GetNodeForValues( |
| 142 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 186 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 187 nullptr); |
| 143 | 188 |
| 144 // The trees should be equal since the data was the same. | 189 // The trees should be equal since the data was the same. |
| 145 EXPECT_EQ(node1, node2); | 190 EXPECT_EQ(node1, node2); |
| 191 } |
| 192 } |
| 193 |
| 194 TEST_F(StateValuesIteratorTest, BuildTreeWithLivenessIdentical) { |
| 195 int sizes[] = {0, 1, 2, 100, 5000, 30000}; |
| 196 TRACED_FOREACH(int, count, sizes) { |
| 197 JSOperatorBuilder javascript(zone()); |
| 198 MachineOperatorBuilder machine(zone()); |
| 199 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, |
| 200 &machine); |
| 201 |
| 202 // Generate the input vector. |
| 203 NodeVector inputs(zone()); |
| 204 for (int i = 0; i < count; i++) { |
| 205 inputs.push_back(Int32Constant(i)); |
| 206 } |
| 207 // Generate the input liveness. |
| 208 BitVector liveness(count, zone()); |
| 209 for (int i = 0; i < count; i++) { |
| 210 if (i % 3 == 0) { |
| 211 liveness.Add(i); |
| 212 } |
| 213 } |
| 214 |
| 215 // Build two trees from the same data. |
| 216 StateValuesCache builder(&jsgraph); |
| 217 Node* node1 = builder.GetNodeForValues( |
| 218 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 219 &liveness); |
| 220 Node* node2 = builder.GetNodeForValues( |
| 221 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size(), |
| 222 &liveness); |
| 223 |
| 224 // The trees should be equal since the data was the same. |
| 225 EXPECT_EQ(node1, node2); |
| 146 } | 226 } |
| 147 } | 227 } |
| 148 | 228 |
| 149 } // namespace compiler | 229 } // namespace compiler |
| 150 } // namespace internal | 230 } // namespace internal |
| 151 } // namespace v8 | 231 } // namespace v8 |
| OLD | NEW |