| 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 "test/unittests/compiler/graph-unittest.h" | 6 #include "test/unittests/compiler/graph-unittest.h" |
| 7 #include "test/unittests/compiler/node-test-utils.h" | 7 #include "test/unittests/compiler/node-test-utils.h" |
| 8 #include "test/unittests/test-utils.h" | 8 #include "test/unittests/test-utils.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 EXPECT_EQ(count, i); | 89 EXPECT_EQ(count, i); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 TEST_F(StateValuesIteratorTest, TreeFromVector) { | 93 TEST_F(StateValuesIteratorTest, TreeFromVector) { |
| 94 int sizes[] = {0, 1, 2, 100, 5000, 30000}; | 94 int sizes[] = {0, 1, 2, 100, 5000, 30000}; |
| 95 TRACED_FOREACH(int, count, sizes) { | 95 TRACED_FOREACH(int, count, sizes) { |
| 96 JSOperatorBuilder javascript(zone()); | 96 JSOperatorBuilder javascript(zone()); |
| 97 MachineOperatorBuilder machine(zone()); | 97 MachineOperatorBuilder machine(zone()); |
| 98 JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine); | 98 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, |
| 99 &machine); |
| 99 | 100 |
| 100 // Generate the input vector. | 101 // Generate the input vector. |
| 101 NodeVector inputs(zone()); | 102 NodeVector inputs(zone()); |
| 102 for (int i = 0; i < count; i++) { | 103 for (int i = 0; i < count; i++) { |
| 103 inputs.push_back(Int32Constant(i)); | 104 inputs.push_back(Int32Constant(i)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Build the tree. | 107 // Build the tree. |
| 107 StateValuesCache builder(&jsgraph); | 108 StateValuesCache builder(&jsgraph); |
| 108 Node* values_node = builder.GetNodeForValues( | 109 Node* values_node = builder.GetNodeForValues( |
| 109 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 110 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); |
| 110 | 111 |
| 111 // Check the tree contents with vector. | 112 // Check the tree contents with vector. |
| 112 int i = 0; | 113 int i = 0; |
| 113 for (StateValuesAccess::TypedNode node : StateValuesAccess(values_node)) { | 114 for (StateValuesAccess::TypedNode node : StateValuesAccess(values_node)) { |
| 114 EXPECT_THAT(node.node, IsInt32Constant(i)); | 115 EXPECT_THAT(node.node, IsInt32Constant(i)); |
| 115 i++; | 116 i++; |
| 116 } | 117 } |
| 117 EXPECT_EQ(inputs.size(), static_cast<size_t>(i)); | 118 EXPECT_EQ(inputs.size(), static_cast<size_t>(i)); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 | 122 |
| 122 TEST_F(StateValuesIteratorTest, BuildTreeIdentical) { | 123 TEST_F(StateValuesIteratorTest, BuildTreeIdentical) { |
| 123 int sizes[] = {0, 1, 2, 100, 5000, 30000}; | 124 int sizes[] = {0, 1, 2, 100, 5000, 30000}; |
| 124 TRACED_FOREACH(int, count, sizes) { | 125 TRACED_FOREACH(int, count, sizes) { |
| 125 JSOperatorBuilder javascript(zone()); | 126 JSOperatorBuilder javascript(zone()); |
| 126 MachineOperatorBuilder machine(zone()); | 127 MachineOperatorBuilder machine(zone()); |
| 127 JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine); | 128 JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr, |
| 129 &machine); |
| 128 | 130 |
| 129 // Generate the input vector. | 131 // Generate the input vector. |
| 130 NodeVector inputs(zone()); | 132 NodeVector inputs(zone()); |
| 131 for (int i = 0; i < count; i++) { | 133 for (int i = 0; i < count; i++) { |
| 132 inputs.push_back(Int32Constant(i)); | 134 inputs.push_back(Int32Constant(i)); |
| 133 } | 135 } |
| 134 | 136 |
| 135 // Build two trees from the same data. | 137 // Build two trees from the same data. |
| 136 StateValuesCache builder(&jsgraph); | 138 StateValuesCache builder(&jsgraph); |
| 137 Node* node1 = builder.GetNodeForValues( | 139 Node* node1 = builder.GetNodeForValues( |
| 138 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 140 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); |
| 139 Node* node2 = builder.GetNodeForValues( | 141 Node* node2 = builder.GetNodeForValues( |
| 140 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); | 142 inputs.size() == 0 ? nullptr : &(inputs.front()), inputs.size()); |
| 141 | 143 |
| 142 // The trees should be equal since the data was the same. | 144 // The trees should be equal since the data was the same. |
| 143 EXPECT_EQ(node1, node2); | 145 EXPECT_EQ(node1, node2); |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 } // namespace compiler | 149 } // namespace compiler |
| 148 } // namespace internal | 150 } // namespace internal |
| 149 } // namespace v8 | 151 } // namespace v8 |
| OLD | NEW |