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

Side by Side Diff: test/unittests/compiler/state-values-utils-unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698