OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <functional> | 5 #include <functional> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 | 9 |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
11 #include "src/compiler/node.h" | 11 #include "src/compiler/node.h" |
12 #include "src/compiler/operator.h" | 12 #include "src/compiler/operator.h" |
13 | 13 |
14 using namespace v8::internal; | 14 using namespace v8::internal; |
15 using namespace v8::internal::compiler; | 15 using namespace v8::internal::compiler; |
16 | 16 |
17 #define NONE reinterpret_cast<Node*>(1) | 17 #define NONE reinterpret_cast<Node*>(1) |
18 | 18 |
19 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, | 19 static Operator dummy_operator0(IrOpcode::kParameter, Operator::kNoWrite, |
20 "dummy", 0, 0, 0, 1, 0, 0); | 20 "dummy", 0, 0, 0, 1, 0, 0); |
| 21 static Operator dummy_operator1(IrOpcode::kParameter, Operator::kNoWrite, |
| 22 "dummy", 1, 0, 0, 1, 0, 0); |
| 23 static Operator dummy_operator2(IrOpcode::kParameter, Operator::kNoWrite, |
| 24 "dummy", 2, 0, 0, 1, 0, 0); |
| 25 static Operator dummy_operator3(IrOpcode::kParameter, Operator::kNoWrite, |
| 26 "dummy", 3, 0, 0, 1, 0, 0); |
21 | 27 |
22 #define CHECK_USES(node, ...) \ | 28 #define CHECK_USES(node, ...) \ |
23 do { \ | 29 do { \ |
24 Node* __array[] = {__VA_ARGS__}; \ | 30 Node* __array[] = {__VA_ARGS__}; \ |
25 int __size = \ | 31 int __size = \ |
26 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ | 32 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ |
27 CheckUseChain(node, __array, __size); \ | 33 CheckUseChain(node, __array, __size); \ |
28 } while (false) | 34 } while (false) |
29 | 35 |
30 | 36 |
| 37 namespace { |
| 38 |
31 typedef std::multiset<Node*, std::less<Node*>> NodeMSet; | 39 typedef std::multiset<Node*, std::less<Node*>> NodeMSet; |
32 | 40 |
33 static void CheckUseChain(Node* node, Node** uses, int use_count) { | 41 |
| 42 void CheckUseChain(Node* node, Node** uses, int use_count) { |
34 // Check ownership. | 43 // Check ownership. |
35 if (use_count == 1) CHECK(node->OwnedBy(uses[0])); | 44 if (use_count == 1) CHECK(node->OwnedBy(uses[0])); |
36 if (use_count > 1) { | 45 if (use_count > 1) { |
37 for (int i = 0; i < use_count; i++) { | 46 for (int i = 0; i < use_count; i++) { |
38 CHECK(!node->OwnedBy(uses[i])); | 47 CHECK(!node->OwnedBy(uses[i])); |
39 } | 48 } |
40 } | 49 } |
41 | 50 |
42 // Check the self-reported use count. | 51 // Check the self-reported use count. |
43 CHECK_EQ(use_count, node->UseCount()); | 52 CHECK_EQ(use_count, node->UseCount()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 size_t count = 0; | 84 size_t count = 0; |
76 for (Node* input : use->inputs()) { | 85 for (Node* input : use->inputs()) { |
77 if (input == node) count++; | 86 if (input == node) count++; |
78 } | 87 } |
79 CHECK_EQ(count, expect_set.count(use)); | 88 CHECK_EQ(count, expect_set.count(use)); |
80 } | 89 } |
81 } | 90 } |
82 } | 91 } |
83 | 92 |
84 | 93 |
85 #define CHECK_INPUTS(node, ...) \ | 94 void CheckInputs(Node* node, Node** inputs, int input_count) { |
86 do { \ | |
87 Node* __array[] = {__VA_ARGS__}; \ | |
88 int __size = \ | |
89 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ | |
90 CheckInputs(node, __array, __size); \ | |
91 } while (false) | |
92 | |
93 | |
94 static void CheckInputs(Node* node, Node** inputs, int input_count) { | |
95 CHECK_EQ(input_count, node->InputCount()); | 95 CHECK_EQ(input_count, node->InputCount()); |
96 // Check InputAt(). | 96 // Check InputAt(). |
97 for (int i = 0; i < static_cast<int>(input_count); i++) { | 97 for (int i = 0; i < static_cast<int>(input_count); i++) { |
98 CHECK_EQ(inputs[i], node->InputAt(i)); | 98 CHECK_EQ(inputs[i], node->InputAt(i)); |
99 } | 99 } |
100 | 100 |
101 // Check input iterator. | 101 // Check input iterator. |
102 int index = 0; | 102 int index = 0; |
103 for (Node* input : node->inputs()) { | 103 for (Node* input : node->inputs()) { |
104 CHECK_EQ(inputs[index], input); | 104 CHECK_EQ(inputs[index], input); |
(...skipping 17 matching lines...) Expand all Loading... |
122 // Check use edge list. | 122 // Check use edge list. |
123 for (auto edge : input->use_edges()) { | 123 for (auto edge : input->use_edges()) { |
124 if (edge.from() == node && edge.to() == input && edge.index() == i) { | 124 if (edge.from() == node && edge.to() == input && edge.index() == i) { |
125 count++; | 125 count++; |
126 } | 126 } |
127 } | 127 } |
128 CHECK_EQ(1, count); | 128 CHECK_EQ(1, count); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
| 132 } // namespace |
| 133 |
| 134 |
| 135 #define CHECK_INPUTS(node, ...) \ |
| 136 do { \ |
| 137 Node* __array[] = {__VA_ARGS__}; \ |
| 138 int __size = \ |
| 139 __array[0] != NONE ? static_cast<int>(arraysize(__array)) : 0; \ |
| 140 CheckInputs(node, __array, __size); \ |
| 141 } while (false) |
| 142 |
132 | 143 |
133 TEST(NodeUseIteratorReplaceUses) { | 144 TEST(NodeUseIteratorReplaceUses) { |
134 Zone zone; | 145 Zone zone; |
135 Graph graph(&zone); | 146 Graph graph(&zone); |
136 Node* n0 = graph.NewNode(&dummy_operator); | 147 Node* n0 = graph.NewNode(&dummy_operator0); |
137 Node* n1 = graph.NewNode(&dummy_operator, n0); | 148 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
138 Node* n2 = graph.NewNode(&dummy_operator, n0); | 149 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
139 Node* n3 = graph.NewNode(&dummy_operator); | 150 Node* n3 = graph.NewNode(&dummy_operator0); |
140 | 151 |
141 CHECK_USES(n0, n1, n2); | 152 CHECK_USES(n0, n1, n2); |
142 | 153 |
143 CHECK_INPUTS(n1, n0); | 154 CHECK_INPUTS(n1, n0); |
144 CHECK_INPUTS(n2, n0); | 155 CHECK_INPUTS(n2, n0); |
145 | 156 |
146 n0->ReplaceUses(n3); | 157 n0->ReplaceUses(n3); |
147 | 158 |
148 CHECK_USES(n0, NONE); | 159 CHECK_USES(n0, NONE); |
149 CHECK_USES(n1, NONE); | 160 CHECK_USES(n1, NONE); |
150 CHECK_USES(n2, NONE); | 161 CHECK_USES(n2, NONE); |
151 CHECK_USES(n3, n1, n2); | 162 CHECK_USES(n3, n1, n2); |
152 | 163 |
153 CHECK_INPUTS(n1, n3); | 164 CHECK_INPUTS(n1, n3); |
154 CHECK_INPUTS(n2, n3); | 165 CHECK_INPUTS(n2, n3); |
155 } | 166 } |
156 | 167 |
157 | 168 |
158 TEST(NodeUseIteratorReplaceUsesSelf) { | 169 TEST(NodeUseIteratorReplaceUsesSelf) { |
159 Zone zone; | 170 Zone zone; |
160 Graph graph(&zone); | 171 Graph graph(&zone); |
161 Node* n0 = graph.NewNode(&dummy_operator); | 172 Node* n0 = graph.NewNode(&dummy_operator0); |
162 Node* n1 = graph.NewNode(&dummy_operator, n0); | 173 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
163 | 174 |
164 CHECK_USES(n0, n1); | 175 CHECK_USES(n0, n1); |
165 CHECK_USES(n1, NONE); | 176 CHECK_USES(n1, NONE); |
166 | 177 |
167 n1->ReplaceInput(0, n1); // Create self-reference. | 178 n1->ReplaceInput(0, n1); // Create self-reference. |
168 | 179 |
169 CHECK_USES(n0, NONE); | 180 CHECK_USES(n0, NONE); |
170 CHECK_USES(n1, n1); | 181 CHECK_USES(n1, n1); |
171 | 182 |
172 Node* n2 = graph.NewNode(&dummy_operator); | 183 Node* n2 = graph.NewNode(&dummy_operator0); |
173 | 184 |
174 n1->ReplaceUses(n2); | 185 n1->ReplaceUses(n2); |
175 | 186 |
176 CHECK_USES(n0, NONE); | 187 CHECK_USES(n0, NONE); |
177 CHECK_USES(n1, NONE); | 188 CHECK_USES(n1, NONE); |
178 CHECK_USES(n2, n1); | 189 CHECK_USES(n2, n1); |
179 } | 190 } |
180 | 191 |
181 | 192 |
182 TEST(ReplaceInput) { | 193 TEST(ReplaceInput) { |
183 Zone zone; | 194 Zone zone; |
184 Graph graph(&zone); | 195 Graph graph(&zone); |
185 Node* n0 = graph.NewNode(&dummy_operator); | 196 Node* n0 = graph.NewNode(&dummy_operator0); |
186 Node* n1 = graph.NewNode(&dummy_operator); | 197 Node* n1 = graph.NewNode(&dummy_operator0); |
187 Node* n2 = graph.NewNode(&dummy_operator); | 198 Node* n2 = graph.NewNode(&dummy_operator0); |
188 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); | 199 Node* n3 = graph.NewNode(&dummy_operator3, n0, n1, n2); |
189 Node* n4 = graph.NewNode(&dummy_operator); | 200 Node* n4 = graph.NewNode(&dummy_operator0); |
190 | 201 |
191 CHECK_USES(n0, n3); | 202 CHECK_USES(n0, n3); |
192 CHECK_USES(n1, n3); | 203 CHECK_USES(n1, n3); |
193 CHECK_USES(n2, n3); | 204 CHECK_USES(n2, n3); |
194 CHECK_USES(n3, NONE); | 205 CHECK_USES(n3, NONE); |
195 CHECK_USES(n4, NONE); | 206 CHECK_USES(n4, NONE); |
196 | 207 |
197 CHECK_INPUTS(n3, n0, n1, n2); | 208 CHECK_INPUTS(n3, n0, n1, n2); |
198 | 209 |
199 n3->ReplaceInput(1, n4); | 210 n3->ReplaceInput(1, n4); |
200 | 211 |
201 CHECK_USES(n1, NONE); | 212 CHECK_USES(n1, NONE); |
202 CHECK_USES(n4, n3); | 213 CHECK_USES(n4, n3); |
203 | 214 |
204 CHECK_INPUTS(n3, n0, n4, n2); | 215 CHECK_INPUTS(n3, n0, n4, n2); |
205 } | 216 } |
206 | 217 |
207 | 218 |
208 TEST(OwnedBy) { | 219 TEST(OwnedBy) { |
209 Zone zone; | 220 Zone zone; |
210 Graph graph(&zone); | 221 Graph graph(&zone); |
211 | 222 |
212 { | 223 { |
213 Node* n0 = graph.NewNode(&dummy_operator); | 224 Node* n0 = graph.NewNode(&dummy_operator0); |
214 Node* n1 = graph.NewNode(&dummy_operator); | 225 Node* n1 = graph.NewNode(&dummy_operator0); |
215 | 226 |
216 CHECK(!n0->OwnedBy(n1)); | 227 CHECK(!n0->OwnedBy(n1)); |
217 CHECK(!n1->OwnedBy(n0)); | 228 CHECK(!n1->OwnedBy(n0)); |
218 | 229 |
219 Node* n2 = graph.NewNode(&dummy_operator, n0); | 230 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
220 CHECK(n0->OwnedBy(n2)); | 231 CHECK(n0->OwnedBy(n2)); |
221 CHECK(!n2->OwnedBy(n0)); | 232 CHECK(!n2->OwnedBy(n0)); |
222 | 233 |
223 Node* n3 = graph.NewNode(&dummy_operator, n0); | 234 Node* n3 = graph.NewNode(&dummy_operator1, n0); |
224 CHECK(!n0->OwnedBy(n2)); | 235 CHECK(!n0->OwnedBy(n2)); |
225 CHECK(!n0->OwnedBy(n3)); | 236 CHECK(!n0->OwnedBy(n3)); |
226 CHECK(!n2->OwnedBy(n0)); | 237 CHECK(!n2->OwnedBy(n0)); |
227 CHECK(!n3->OwnedBy(n0)); | 238 CHECK(!n3->OwnedBy(n0)); |
228 } | 239 } |
229 | 240 |
230 { | 241 { |
231 Node* n0 = graph.NewNode(&dummy_operator); | 242 Node* n0 = graph.NewNode(&dummy_operator0); |
232 Node* n1 = graph.NewNode(&dummy_operator, n0); | 243 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
233 CHECK(n0->OwnedBy(n1)); | 244 CHECK(n0->OwnedBy(n1)); |
234 CHECK(!n1->OwnedBy(n0)); | 245 CHECK(!n1->OwnedBy(n0)); |
235 Node* n2 = graph.NewNode(&dummy_operator, n0); | 246 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
236 CHECK(!n0->OwnedBy(n1)); | 247 CHECK(!n0->OwnedBy(n1)); |
237 CHECK(!n0->OwnedBy(n2)); | 248 CHECK(!n0->OwnedBy(n2)); |
238 CHECK(!n1->OwnedBy(n0)); | 249 CHECK(!n1->OwnedBy(n0)); |
239 CHECK(!n1->OwnedBy(n2)); | 250 CHECK(!n1->OwnedBy(n2)); |
240 CHECK(!n2->OwnedBy(n0)); | 251 CHECK(!n2->OwnedBy(n0)); |
241 CHECK(!n2->OwnedBy(n1)); | 252 CHECK(!n2->OwnedBy(n1)); |
242 | 253 |
243 Node* n3 = graph.NewNode(&dummy_operator); | 254 Node* n3 = graph.NewNode(&dummy_operator0); |
244 n2->ReplaceInput(0, n3); | 255 n2->ReplaceInput(0, n3); |
245 | 256 |
246 CHECK(n0->OwnedBy(n1)); | 257 CHECK(n0->OwnedBy(n1)); |
247 CHECK(!n1->OwnedBy(n0)); | 258 CHECK(!n1->OwnedBy(n0)); |
248 CHECK(!n1->OwnedBy(n0)); | 259 CHECK(!n1->OwnedBy(n0)); |
249 CHECK(!n1->OwnedBy(n2)); | 260 CHECK(!n1->OwnedBy(n2)); |
250 CHECK(!n2->OwnedBy(n0)); | 261 CHECK(!n2->OwnedBy(n0)); |
251 CHECK(!n2->OwnedBy(n1)); | 262 CHECK(!n2->OwnedBy(n1)); |
252 CHECK(n3->OwnedBy(n2)); | 263 CHECK(n3->OwnedBy(n2)); |
253 CHECK(!n2->OwnedBy(n3)); | 264 CHECK(!n2->OwnedBy(n3)); |
254 } | 265 } |
255 } | 266 } |
256 | 267 |
257 | 268 |
258 TEST(Uses) { | 269 TEST(Uses) { |
259 Zone zone; | 270 Zone zone; |
260 Graph graph(&zone); | 271 Graph graph(&zone); |
261 | 272 |
262 Node* n0 = graph.NewNode(&dummy_operator); | 273 Node* n0 = graph.NewNode(&dummy_operator0); |
263 Node* n1 = graph.NewNode(&dummy_operator, n0); | 274 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
264 | 275 |
265 CHECK_USES(n0, n1); | 276 CHECK_USES(n0, n1); |
266 CHECK_USES(n1, NONE); | 277 CHECK_USES(n1, NONE); |
267 | 278 |
268 Node* n2 = graph.NewNode(&dummy_operator, n0); | 279 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
269 | 280 |
270 CHECK_USES(n0, n1, n2); | 281 CHECK_USES(n0, n1, n2); |
271 CHECK_USES(n2, NONE); | 282 CHECK_USES(n2, NONE); |
272 | 283 |
273 Node* n3 = graph.NewNode(&dummy_operator, n0); | 284 Node* n3 = graph.NewNode(&dummy_operator1, n0); |
274 | 285 |
275 CHECK_USES(n0, n1, n2, n3); | 286 CHECK_USES(n0, n1, n2, n3); |
276 CHECK_USES(n3, NONE); | 287 CHECK_USES(n3, NONE); |
277 } | 288 } |
278 | 289 |
279 | 290 |
280 TEST(Inputs) { | 291 TEST(Inputs) { |
281 Zone zone; | 292 Zone zone; |
282 Graph graph(&zone); | 293 Graph graph(&zone); |
283 | 294 |
284 Node* n0 = graph.NewNode(&dummy_operator); | 295 Node* n0 = graph.NewNode(&dummy_operator0); |
285 Node* n1 = graph.NewNode(&dummy_operator, n0); | 296 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
286 Node* n2 = graph.NewNode(&dummy_operator, n0); | 297 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
287 Node* n3 = graph.NewNode(&dummy_operator, n0, n1, n2); | 298 Node* n3 = graph.NewNode(&dummy_operator3, n0, n1, n2); |
288 | 299 |
289 CHECK_INPUTS(n3, n0, n1, n2); | 300 CHECK_INPUTS(n3, n0, n1, n2); |
290 | 301 |
291 Node* n4 = graph.NewNode(&dummy_operator, n0, n1, n2); | 302 Node* n4 = graph.NewNode(&dummy_operator3, n0, n1, n2); |
292 n3->AppendInput(graph.zone(), n4); | 303 n3->AppendInput(graph.zone(), n4); |
293 | 304 |
294 CHECK_INPUTS(n3, n0, n1, n2, n4); | 305 CHECK_INPUTS(n3, n0, n1, n2, n4); |
295 CHECK_USES(n4, n3); | 306 CHECK_USES(n4, n3); |
296 | 307 |
297 n3->AppendInput(graph.zone(), n4); | 308 n3->AppendInput(graph.zone(), n4); |
298 | 309 |
299 CHECK_INPUTS(n3, n0, n1, n2, n4, n4); | 310 CHECK_INPUTS(n3, n0, n1, n2, n4, n4); |
300 CHECK_USES(n4, n3, n3); | 311 CHECK_USES(n4, n3, n3); |
301 | 312 |
302 Node* n5 = graph.NewNode(&dummy_operator, n4); | 313 Node* n5 = graph.NewNode(&dummy_operator1, n4); |
303 | 314 |
304 CHECK_USES(n4, n3, n3, n5); | 315 CHECK_USES(n4, n3, n3, n5); |
305 } | 316 } |
306 | 317 |
307 | 318 |
308 TEST(RemoveInput) { | 319 TEST(RemoveInput) { |
309 Zone zone; | 320 Zone zone; |
310 Graph graph(&zone); | 321 Graph graph(&zone); |
311 | 322 |
312 Node* n0 = graph.NewNode(&dummy_operator); | 323 Node* n0 = graph.NewNode(&dummy_operator0); |
313 Node* n1 = graph.NewNode(&dummy_operator, n0); | 324 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
314 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 325 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
315 | 326 |
316 CHECK_INPUTS(n0, NONE); | 327 CHECK_INPUTS(n0, NONE); |
317 CHECK_INPUTS(n1, n0); | 328 CHECK_INPUTS(n1, n0); |
318 CHECK_INPUTS(n2, n0, n1); | 329 CHECK_INPUTS(n2, n0, n1); |
319 CHECK_USES(n0, n1, n2); | 330 CHECK_USES(n0, n1, n2); |
320 | 331 |
321 n1->RemoveInput(0); | 332 n1->RemoveInput(0); |
322 CHECK_INPUTS(n1, NONE); | 333 CHECK_INPUTS(n1, NONE); |
323 CHECK_USES(n0, n2); | 334 CHECK_USES(n0, n2); |
324 | 335 |
325 n2->RemoveInput(0); | 336 n2->RemoveInput(0); |
326 CHECK_INPUTS(n2, n1); | 337 CHECK_INPUTS(n2, n1); |
327 CHECK_USES(n0, NONE); | 338 CHECK_USES(n0, NONE); |
328 CHECK_USES(n1, n2); | 339 CHECK_USES(n1, n2); |
329 | 340 |
330 n2->RemoveInput(0); | 341 n2->RemoveInput(0); |
331 CHECK_INPUTS(n2, NONE); | 342 CHECK_INPUTS(n2, NONE); |
332 CHECK_USES(n0, NONE); | 343 CHECK_USES(n0, NONE); |
333 CHECK_USES(n1, NONE); | 344 CHECK_USES(n1, NONE); |
334 CHECK_USES(n2, NONE); | 345 CHECK_USES(n2, NONE); |
335 } | 346 } |
336 | 347 |
337 | 348 |
338 TEST(AppendInputsAndIterator) { | 349 TEST(AppendInputsAndIterator) { |
339 Zone zone; | 350 Zone zone; |
340 Graph graph(&zone); | 351 Graph graph(&zone); |
341 | 352 |
342 Node* n0 = graph.NewNode(&dummy_operator); | 353 Node* n0 = graph.NewNode(&dummy_operator0); |
343 Node* n1 = graph.NewNode(&dummy_operator, n0); | 354 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
344 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 355 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
345 | 356 |
346 CHECK_INPUTS(n0, NONE); | 357 CHECK_INPUTS(n0, NONE); |
347 CHECK_INPUTS(n1, n0); | 358 CHECK_INPUTS(n1, n0); |
348 CHECK_INPUTS(n2, n0, n1); | 359 CHECK_INPUTS(n2, n0, n1); |
349 CHECK_USES(n0, n1, n2); | 360 CHECK_USES(n0, n1, n2); |
350 | 361 |
351 Node* n3 = graph.NewNode(&dummy_operator); | 362 Node* n3 = graph.NewNode(&dummy_operator0); |
352 | 363 |
353 n2->AppendInput(graph.zone(), n3); | 364 n2->AppendInput(graph.zone(), n3); |
354 | 365 |
355 CHECK_INPUTS(n2, n0, n1, n3); | 366 CHECK_INPUTS(n2, n0, n1, n3); |
356 CHECK_USES(n3, n2); | 367 CHECK_USES(n3, n2); |
357 } | 368 } |
358 | 369 |
359 | 370 |
360 TEST(NullInputsSimple) { | 371 TEST(NullInputsSimple) { |
361 Zone zone; | 372 Zone zone; |
362 Graph graph(&zone); | 373 Graph graph(&zone); |
363 | 374 |
364 Node* n0 = graph.NewNode(&dummy_operator); | 375 Node* n0 = graph.NewNode(&dummy_operator0); |
365 Node* n1 = graph.NewNode(&dummy_operator, n0); | 376 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
366 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 377 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
367 | 378 |
368 CHECK_INPUTS(n0, NONE); | 379 CHECK_INPUTS(n0, NONE); |
369 CHECK_INPUTS(n1, n0); | 380 CHECK_INPUTS(n1, n0); |
370 CHECK_INPUTS(n2, n0, n1); | 381 CHECK_INPUTS(n2, n0, n1); |
371 CHECK_USES(n0, n1, n2); | 382 CHECK_USES(n0, n1, n2); |
372 | 383 |
373 n2->ReplaceInput(0, nullptr); | 384 n2->ReplaceInput(0, nullptr); |
374 | 385 |
375 CHECK_INPUTS(n2, NULL, n1); | 386 CHECK_INPUTS(n2, NULL, n1); |
376 | 387 |
377 CHECK_USES(n0, n1); | 388 CHECK_USES(n0, n1); |
378 | 389 |
379 n2->ReplaceInput(1, nullptr); | 390 n2->ReplaceInput(1, nullptr); |
380 | 391 |
381 CHECK_INPUTS(n2, NULL, NULL); | 392 CHECK_INPUTS(n2, NULL, NULL); |
382 | 393 |
383 CHECK_USES(n1, NONE); | 394 CHECK_USES(n1, NONE); |
384 } | 395 } |
385 | 396 |
386 | 397 |
387 TEST(NullInputsAppended) { | 398 TEST(NullInputsAppended) { |
388 Zone zone; | 399 Zone zone; |
389 Graph graph(&zone); | 400 Graph graph(&zone); |
390 | 401 |
391 Node* n0 = graph.NewNode(&dummy_operator); | 402 Node* n0 = graph.NewNode(&dummy_operator0); |
392 Node* n1 = graph.NewNode(&dummy_operator, n0); | 403 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
393 Node* n2 = graph.NewNode(&dummy_operator, n0); | 404 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
394 Node* n3 = graph.NewNode(&dummy_operator, n0); | 405 Node* n3 = graph.NewNode(&dummy_operator1, n0); |
395 n3->AppendInput(graph.zone(), n1); | 406 n3->AppendInput(graph.zone(), n1); |
396 n3->AppendInput(graph.zone(), n2); | 407 n3->AppendInput(graph.zone(), n2); |
397 | 408 |
398 CHECK_INPUTS(n3, n0, n1, n2); | 409 CHECK_INPUTS(n3, n0, n1, n2); |
399 CHECK_USES(n0, n1, n2, n3); | 410 CHECK_USES(n0, n1, n2, n3); |
400 CHECK_USES(n1, n3); | 411 CHECK_USES(n1, n3); |
401 CHECK_USES(n2, n3); | 412 CHECK_USES(n2, n3); |
402 | 413 |
403 n3->ReplaceInput(1, NULL); | 414 n3->ReplaceInput(1, NULL); |
404 CHECK_USES(n1, NONE); | 415 CHECK_USES(n1, NONE); |
405 | 416 |
406 CHECK_INPUTS(n3, n0, NULL, n2); | 417 CHECK_INPUTS(n3, n0, NULL, n2); |
407 } | 418 } |
408 | 419 |
409 | 420 |
410 TEST(ReplaceUsesFromAppendedInputs) { | 421 TEST(ReplaceUsesFromAppendedInputs) { |
411 Zone zone; | 422 Zone zone; |
412 Graph graph(&zone); | 423 Graph graph(&zone); |
413 | 424 |
414 Node* n0 = graph.NewNode(&dummy_operator); | 425 Node* n0 = graph.NewNode(&dummy_operator0); |
415 Node* n1 = graph.NewNode(&dummy_operator, n0); | 426 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
416 Node* n2 = graph.NewNode(&dummy_operator, n0); | 427 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
417 Node* n3 = graph.NewNode(&dummy_operator); | 428 Node* n3 = graph.NewNode(&dummy_operator0); |
418 | 429 |
419 CHECK_INPUTS(n2, n0); | 430 CHECK_INPUTS(n2, n0); |
420 | 431 |
421 n2->AppendInput(graph.zone(), n1); | 432 n2->AppendInput(graph.zone(), n1); |
422 CHECK_INPUTS(n2, n0, n1); | 433 CHECK_INPUTS(n2, n0, n1); |
423 CHECK_USES(n1, n2); | 434 CHECK_USES(n1, n2); |
424 | 435 |
425 n2->AppendInput(graph.zone(), n0); | 436 n2->AppendInput(graph.zone(), n0); |
426 CHECK_INPUTS(n2, n0, n1, n0); | 437 CHECK_INPUTS(n2, n0, n1, n0); |
427 CHECK_USES(n1, n2); | 438 CHECK_USES(n1, n2); |
428 CHECK_USES(n0, n2, n1, n2); | 439 CHECK_USES(n0, n2, n1, n2); |
429 | 440 |
430 n0->ReplaceUses(n3); | 441 n0->ReplaceUses(n3); |
431 | 442 |
432 CHECK_USES(n0, NONE); | 443 CHECK_USES(n0, NONE); |
433 CHECK_INPUTS(n2, n3, n1, n3); | 444 CHECK_INPUTS(n2, n3, n1, n3); |
434 CHECK_USES(n3, n2, n1, n2); | 445 CHECK_USES(n3, n2, n1, n2); |
435 } | 446 } |
436 | 447 |
437 | 448 |
438 TEST(ReplaceInputMultipleUses) { | 449 TEST(ReplaceInputMultipleUses) { |
439 Zone zone; | 450 Zone zone; |
440 Graph graph(&zone); | 451 Graph graph(&zone); |
441 | 452 |
442 Node* n0 = graph.NewNode(&dummy_operator); | 453 Node* n0 = graph.NewNode(&dummy_operator0); |
443 Node* n1 = graph.NewNode(&dummy_operator); | 454 Node* n1 = graph.NewNode(&dummy_operator0); |
444 Node* n2 = graph.NewNode(&dummy_operator, n0); | 455 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
445 n2->ReplaceInput(0, n1); | 456 n2->ReplaceInput(0, n1); |
446 CHECK_EQ(0, n0->UseCount()); | 457 CHECK_EQ(0, n0->UseCount()); |
447 CHECK_EQ(1, n1->UseCount()); | 458 CHECK_EQ(1, n1->UseCount()); |
448 | 459 |
449 Node* n3 = graph.NewNode(&dummy_operator, n0); | 460 Node* n3 = graph.NewNode(&dummy_operator1, n0); |
450 n3->ReplaceInput(0, n1); | 461 n3->ReplaceInput(0, n1); |
451 CHECK_EQ(0, n0->UseCount()); | 462 CHECK_EQ(0, n0->UseCount()); |
452 CHECK_EQ(2, n1->UseCount()); | 463 CHECK_EQ(2, n1->UseCount()); |
453 } | 464 } |
454 | 465 |
455 | 466 |
456 TEST(TrimInputCountInline) { | 467 TEST(TrimInputCountInline) { |
457 Zone zone; | 468 Zone zone; |
458 Graph graph(&zone); | 469 Graph graph(&zone); |
459 | 470 |
460 { | 471 { |
461 Node* n0 = graph.NewNode(&dummy_operator); | 472 Node* n0 = graph.NewNode(&dummy_operator0); |
462 Node* n1 = graph.NewNode(&dummy_operator, n0); | 473 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
463 n1->TrimInputCount(1); | 474 n1->TrimInputCount(1); |
464 CHECK_INPUTS(n1, n0); | 475 CHECK_INPUTS(n1, n0); |
465 CHECK_USES(n0, n1); | 476 CHECK_USES(n0, n1); |
466 } | 477 } |
467 | 478 |
468 { | 479 { |
469 Node* n0 = graph.NewNode(&dummy_operator); | 480 Node* n0 = graph.NewNode(&dummy_operator0); |
470 Node* n1 = graph.NewNode(&dummy_operator, n0); | 481 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
471 n1->TrimInputCount(0); | 482 n1->TrimInputCount(0); |
472 CHECK_INPUTS(n1, NONE); | 483 CHECK_INPUTS(n1, NONE); |
473 CHECK_USES(n0, NONE); | 484 CHECK_USES(n0, NONE); |
474 } | 485 } |
475 | 486 |
476 { | 487 { |
477 Node* n0 = graph.NewNode(&dummy_operator); | 488 Node* n0 = graph.NewNode(&dummy_operator0); |
478 Node* n1 = graph.NewNode(&dummy_operator); | 489 Node* n1 = graph.NewNode(&dummy_operator0); |
479 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 490 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
480 n2->TrimInputCount(2); | 491 n2->TrimInputCount(2); |
481 CHECK_INPUTS(n2, n0, n1); | 492 CHECK_INPUTS(n2, n0, n1); |
482 CHECK_USES(n0, n2); | 493 CHECK_USES(n0, n2); |
483 CHECK_USES(n1, n2); | 494 CHECK_USES(n1, n2); |
484 } | 495 } |
485 | 496 |
486 { | 497 { |
487 Node* n0 = graph.NewNode(&dummy_operator); | 498 Node* n0 = graph.NewNode(&dummy_operator0); |
488 Node* n1 = graph.NewNode(&dummy_operator); | 499 Node* n1 = graph.NewNode(&dummy_operator0); |
489 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 500 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
490 n2->TrimInputCount(1); | 501 n2->TrimInputCount(1); |
491 CHECK_INPUTS(n2, n0); | 502 CHECK_INPUTS(n2, n0); |
492 CHECK_USES(n0, n2); | 503 CHECK_USES(n0, n2); |
493 CHECK_USES(n1, NONE); | 504 CHECK_USES(n1, NONE); |
494 } | 505 } |
495 | 506 |
496 { | 507 { |
497 Node* n0 = graph.NewNode(&dummy_operator); | 508 Node* n0 = graph.NewNode(&dummy_operator0); |
498 Node* n1 = graph.NewNode(&dummy_operator); | 509 Node* n1 = graph.NewNode(&dummy_operator0); |
499 Node* n2 = graph.NewNode(&dummy_operator, n0, n1); | 510 Node* n2 = graph.NewNode(&dummy_operator2, n0, n1); |
500 n2->TrimInputCount(0); | 511 n2->TrimInputCount(0); |
501 CHECK_INPUTS(n2, NONE); | 512 CHECK_INPUTS(n2, NONE); |
502 CHECK_USES(n0, NONE); | 513 CHECK_USES(n0, NONE); |
503 CHECK_USES(n1, NONE); | 514 CHECK_USES(n1, NONE); |
504 } | 515 } |
505 | 516 |
506 { | 517 { |
507 Node* n0 = graph.NewNode(&dummy_operator); | 518 Node* n0 = graph.NewNode(&dummy_operator0); |
508 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); | 519 Node* n2 = graph.NewNode(&dummy_operator2, n0, n0); |
509 n2->TrimInputCount(1); | 520 n2->TrimInputCount(1); |
510 CHECK_INPUTS(n2, n0); | 521 CHECK_INPUTS(n2, n0); |
511 CHECK_USES(n0, n2); | 522 CHECK_USES(n0, n2); |
512 } | 523 } |
513 | 524 |
514 { | 525 { |
515 Node* n0 = graph.NewNode(&dummy_operator); | 526 Node* n0 = graph.NewNode(&dummy_operator0); |
516 Node* n2 = graph.NewNode(&dummy_operator, n0, n0); | 527 Node* n2 = graph.NewNode(&dummy_operator2, n0, n0); |
517 n2->TrimInputCount(0); | 528 n2->TrimInputCount(0); |
518 CHECK_INPUTS(n2, NONE); | 529 CHECK_INPUTS(n2, NONE); |
519 CHECK_USES(n0, NONE); | 530 CHECK_USES(n0, NONE); |
520 } | 531 } |
521 } | 532 } |
522 | 533 |
523 | 534 |
524 TEST(TrimInputCountOutOfLine1) { | 535 TEST(TrimInputCountOutOfLine1) { |
525 Zone zone; | 536 Zone zone; |
526 Graph graph(&zone); | 537 Graph graph(&zone); |
527 | 538 |
528 { | 539 { |
529 Node* n0 = graph.NewNode(&dummy_operator); | 540 Node* n0 = graph.NewNode(&dummy_operator0); |
530 Node* n1 = graph.NewNode(&dummy_operator); | 541 Node* n1 = graph.NewNode(&dummy_operator0); |
531 n1->AppendInput(graph.zone(), n0); | 542 n1->AppendInput(graph.zone(), n0); |
532 CHECK_INPUTS(n1, n0); | 543 CHECK_INPUTS(n1, n0); |
533 CHECK_USES(n0, n1); | 544 CHECK_USES(n0, n1); |
534 | 545 |
535 n1->TrimInputCount(1); | 546 n1->TrimInputCount(1); |
536 CHECK_INPUTS(n1, n0); | 547 CHECK_INPUTS(n1, n0); |
537 CHECK_USES(n0, n1); | 548 CHECK_USES(n0, n1); |
538 } | 549 } |
539 | 550 |
540 { | 551 { |
541 Node* n0 = graph.NewNode(&dummy_operator); | 552 Node* n0 = graph.NewNode(&dummy_operator0); |
542 Node* n1 = graph.NewNode(&dummy_operator); | 553 Node* n1 = graph.NewNode(&dummy_operator0); |
543 n1->AppendInput(graph.zone(), n0); | 554 n1->AppendInput(graph.zone(), n0); |
544 CHECK_EQ(1, n1->InputCount()); | 555 CHECK_EQ(1, n1->InputCount()); |
545 n1->TrimInputCount(0); | 556 n1->TrimInputCount(0); |
546 CHECK_EQ(0, n1->InputCount()); | 557 CHECK_EQ(0, n1->InputCount()); |
547 CHECK_EQ(0, n0->UseCount()); | 558 CHECK_EQ(0, n0->UseCount()); |
548 } | 559 } |
549 | 560 |
550 { | 561 { |
551 Node* n0 = graph.NewNode(&dummy_operator); | 562 Node* n0 = graph.NewNode(&dummy_operator0); |
552 Node* n1 = graph.NewNode(&dummy_operator); | 563 Node* n1 = graph.NewNode(&dummy_operator0); |
553 Node* n2 = graph.NewNode(&dummy_operator); | 564 Node* n2 = graph.NewNode(&dummy_operator0); |
554 n2->AppendInput(graph.zone(), n0); | 565 n2->AppendInput(graph.zone(), n0); |
555 n2->AppendInput(graph.zone(), n1); | 566 n2->AppendInput(graph.zone(), n1); |
556 CHECK_INPUTS(n2, n0, n1); | 567 CHECK_INPUTS(n2, n0, n1); |
557 n2->TrimInputCount(2); | 568 n2->TrimInputCount(2); |
558 CHECK_INPUTS(n2, n0, n1); | 569 CHECK_INPUTS(n2, n0, n1); |
559 CHECK_USES(n0, n2); | 570 CHECK_USES(n0, n2); |
560 CHECK_USES(n1, n2); | 571 CHECK_USES(n1, n2); |
561 CHECK_USES(n2, NONE); | 572 CHECK_USES(n2, NONE); |
562 } | 573 } |
563 | 574 |
564 { | 575 { |
565 Node* n0 = graph.NewNode(&dummy_operator); | 576 Node* n0 = graph.NewNode(&dummy_operator0); |
566 Node* n1 = graph.NewNode(&dummy_operator); | 577 Node* n1 = graph.NewNode(&dummy_operator0); |
567 Node* n2 = graph.NewNode(&dummy_operator); | 578 Node* n2 = graph.NewNode(&dummy_operator0); |
568 n2->AppendInput(graph.zone(), n0); | 579 n2->AppendInput(graph.zone(), n0); |
569 n2->AppendInput(graph.zone(), n1); | 580 n2->AppendInput(graph.zone(), n1); |
570 CHECK_INPUTS(n2, n0, n1); | 581 CHECK_INPUTS(n2, n0, n1); |
571 n2->TrimInputCount(1); | 582 n2->TrimInputCount(1); |
572 CHECK_INPUTS(n2, n0); | 583 CHECK_INPUTS(n2, n0); |
573 CHECK_USES(n0, n2); | 584 CHECK_USES(n0, n2); |
574 CHECK_USES(n1, NONE); | 585 CHECK_USES(n1, NONE); |
575 CHECK_USES(n2, NONE); | 586 CHECK_USES(n2, NONE); |
576 } | 587 } |
577 | 588 |
578 { | 589 { |
579 Node* n0 = graph.NewNode(&dummy_operator); | 590 Node* n0 = graph.NewNode(&dummy_operator0); |
580 Node* n1 = graph.NewNode(&dummy_operator); | 591 Node* n1 = graph.NewNode(&dummy_operator0); |
581 Node* n2 = graph.NewNode(&dummy_operator); | 592 Node* n2 = graph.NewNode(&dummy_operator0); |
582 n2->AppendInput(graph.zone(), n0); | 593 n2->AppendInput(graph.zone(), n0); |
583 n2->AppendInput(graph.zone(), n1); | 594 n2->AppendInput(graph.zone(), n1); |
584 CHECK_INPUTS(n2, n0, n1); | 595 CHECK_INPUTS(n2, n0, n1); |
585 n2->TrimInputCount(0); | 596 n2->TrimInputCount(0); |
586 CHECK_INPUTS(n2, NONE); | 597 CHECK_INPUTS(n2, NONE); |
587 CHECK_USES(n0, NONE); | 598 CHECK_USES(n0, NONE); |
588 CHECK_USES(n1, NONE); | 599 CHECK_USES(n1, NONE); |
589 CHECK_USES(n2, NONE); | 600 CHECK_USES(n2, NONE); |
590 } | 601 } |
591 | 602 |
592 { | 603 { |
593 Node* n0 = graph.NewNode(&dummy_operator); | 604 Node* n0 = graph.NewNode(&dummy_operator0); |
594 Node* n2 = graph.NewNode(&dummy_operator); | 605 Node* n2 = graph.NewNode(&dummy_operator0); |
595 n2->AppendInput(graph.zone(), n0); | 606 n2->AppendInput(graph.zone(), n0); |
596 n2->AppendInput(graph.zone(), n0); | 607 n2->AppendInput(graph.zone(), n0); |
597 CHECK_INPUTS(n2, n0, n0); | 608 CHECK_INPUTS(n2, n0, n0); |
598 CHECK_USES(n0, n2, n2); | 609 CHECK_USES(n0, n2, n2); |
599 n2->TrimInputCount(1); | 610 n2->TrimInputCount(1); |
600 CHECK_INPUTS(n2, n0); | 611 CHECK_INPUTS(n2, n0); |
601 CHECK_USES(n0, n2); | 612 CHECK_USES(n0, n2); |
602 } | 613 } |
603 | 614 |
604 { | 615 { |
605 Node* n0 = graph.NewNode(&dummy_operator); | 616 Node* n0 = graph.NewNode(&dummy_operator0); |
606 Node* n2 = graph.NewNode(&dummy_operator); | 617 Node* n2 = graph.NewNode(&dummy_operator0); |
607 n2->AppendInput(graph.zone(), n0); | 618 n2->AppendInput(graph.zone(), n0); |
608 n2->AppendInput(graph.zone(), n0); | 619 n2->AppendInput(graph.zone(), n0); |
609 CHECK_INPUTS(n2, n0, n0); | 620 CHECK_INPUTS(n2, n0, n0); |
610 CHECK_USES(n0, n2, n2); | 621 CHECK_USES(n0, n2, n2); |
611 n2->TrimInputCount(0); | 622 n2->TrimInputCount(0); |
612 CHECK_INPUTS(n2, NONE); | 623 CHECK_INPUTS(n2, NONE); |
613 CHECK_USES(n0, NONE); | 624 CHECK_USES(n0, NONE); |
614 } | 625 } |
615 } | 626 } |
616 | 627 |
617 | 628 |
618 TEST(TrimInputCountOutOfLine2) { | 629 TEST(TrimInputCountOutOfLine2) { |
619 Zone zone; | 630 Zone zone; |
620 Graph graph(&zone); | 631 Graph graph(&zone); |
621 | 632 |
622 { | 633 { |
623 Node* n0 = graph.NewNode(&dummy_operator); | 634 Node* n0 = graph.NewNode(&dummy_operator0); |
624 Node* n1 = graph.NewNode(&dummy_operator); | 635 Node* n1 = graph.NewNode(&dummy_operator0); |
625 Node* n2 = graph.NewNode(&dummy_operator, n0); | 636 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
626 n2->AppendInput(graph.zone(), n1); | 637 n2->AppendInput(graph.zone(), n1); |
627 CHECK_INPUTS(n2, n0, n1); | 638 CHECK_INPUTS(n2, n0, n1); |
628 n2->TrimInputCount(2); | 639 n2->TrimInputCount(2); |
629 CHECK_INPUTS(n2, n0, n1); | 640 CHECK_INPUTS(n2, n0, n1); |
630 CHECK_USES(n0, n2); | 641 CHECK_USES(n0, n2); |
631 CHECK_USES(n1, n2); | 642 CHECK_USES(n1, n2); |
632 CHECK_USES(n2, NONE); | 643 CHECK_USES(n2, NONE); |
633 } | 644 } |
634 | 645 |
635 { | 646 { |
636 Node* n0 = graph.NewNode(&dummy_operator); | 647 Node* n0 = graph.NewNode(&dummy_operator0); |
637 Node* n1 = graph.NewNode(&dummy_operator); | 648 Node* n1 = graph.NewNode(&dummy_operator0); |
638 Node* n2 = graph.NewNode(&dummy_operator, n0); | 649 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
639 n2->AppendInput(graph.zone(), n1); | 650 n2->AppendInput(graph.zone(), n1); |
640 CHECK_INPUTS(n2, n0, n1); | 651 CHECK_INPUTS(n2, n0, n1); |
641 n2->TrimInputCount(1); | 652 n2->TrimInputCount(1); |
642 CHECK_INPUTS(n2, n0); | 653 CHECK_INPUTS(n2, n0); |
643 CHECK_USES(n0, n2); | 654 CHECK_USES(n0, n2); |
644 CHECK_USES(n1, NONE); | 655 CHECK_USES(n1, NONE); |
645 CHECK_USES(n2, NONE); | 656 CHECK_USES(n2, NONE); |
646 } | 657 } |
647 | 658 |
648 { | 659 { |
649 Node* n0 = graph.NewNode(&dummy_operator); | 660 Node* n0 = graph.NewNode(&dummy_operator0); |
650 Node* n1 = graph.NewNode(&dummy_operator); | 661 Node* n1 = graph.NewNode(&dummy_operator0); |
651 Node* n2 = graph.NewNode(&dummy_operator, n0); | 662 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
652 n2->AppendInput(graph.zone(), n1); | 663 n2->AppendInput(graph.zone(), n1); |
653 CHECK_INPUTS(n2, n0, n1); | 664 CHECK_INPUTS(n2, n0, n1); |
654 n2->TrimInputCount(0); | 665 n2->TrimInputCount(0); |
655 CHECK_INPUTS(n2, NONE); | 666 CHECK_INPUTS(n2, NONE); |
656 CHECK_USES(n0, NONE); | 667 CHECK_USES(n0, NONE); |
657 CHECK_USES(n1, NONE); | 668 CHECK_USES(n1, NONE); |
658 CHECK_USES(n2, NONE); | 669 CHECK_USES(n2, NONE); |
659 } | 670 } |
660 | 671 |
661 { | 672 { |
662 Node* n0 = graph.NewNode(&dummy_operator); | 673 Node* n0 = graph.NewNode(&dummy_operator0); |
663 Node* n2 = graph.NewNode(&dummy_operator, n0); | 674 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
664 n2->AppendInput(graph.zone(), n0); | 675 n2->AppendInput(graph.zone(), n0); |
665 CHECK_INPUTS(n2, n0, n0); | 676 CHECK_INPUTS(n2, n0, n0); |
666 CHECK_USES(n0, n2, n2); | 677 CHECK_USES(n0, n2, n2); |
667 n2->TrimInputCount(1); | 678 n2->TrimInputCount(1); |
668 CHECK_INPUTS(n2, n0); | 679 CHECK_INPUTS(n2, n0); |
669 CHECK_USES(n0, n2); | 680 CHECK_USES(n0, n2); |
670 CHECK_USES(n2, NONE); | 681 CHECK_USES(n2, NONE); |
671 } | 682 } |
672 | 683 |
673 { | 684 { |
674 Node* n0 = graph.NewNode(&dummy_operator); | 685 Node* n0 = graph.NewNode(&dummy_operator0); |
675 Node* n2 = graph.NewNode(&dummy_operator, n0); | 686 Node* n2 = graph.NewNode(&dummy_operator1, n0); |
676 n2->AppendInput(graph.zone(), n0); | 687 n2->AppendInput(graph.zone(), n0); |
677 CHECK_EQ(2, n2->InputCount()); | 688 CHECK_EQ(2, n2->InputCount()); |
678 CHECK_EQ(2, n0->UseCount()); | 689 CHECK_EQ(2, n0->UseCount()); |
679 n2->TrimInputCount(0); | 690 n2->TrimInputCount(0); |
680 CHECK_EQ(0, n2->InputCount()); | 691 CHECK_EQ(0, n2->InputCount()); |
681 CHECK_EQ(0, n0->UseCount()); | 692 CHECK_EQ(0, n0->UseCount()); |
682 CHECK_EQ(0, n2->UseCount()); | 693 CHECK_EQ(0, n2->UseCount()); |
683 } | 694 } |
684 } | 695 } |
685 | 696 |
686 | 697 |
687 TEST(NullAllInputs) { | 698 TEST(NullAllInputs) { |
688 Zone zone; | 699 Zone zone; |
689 Graph graph(&zone); | 700 Graph graph(&zone); |
690 | 701 |
691 for (int i = 0; i < 2; i++) { | 702 for (int i = 0; i < 2; i++) { |
692 Node* n0 = graph.NewNode(&dummy_operator); | 703 Node* n0 = graph.NewNode(&dummy_operator0); |
693 Node* n1 = graph.NewNode(&dummy_operator, n0); | 704 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
694 Node* n2; | 705 Node* n2; |
695 if (i == 0) { | 706 if (i == 0) { |
696 n2 = graph.NewNode(&dummy_operator, n0, n1); | 707 n2 = graph.NewNode(&dummy_operator2, n0, n1); |
697 CHECK_INPUTS(n2, n0, n1); | 708 CHECK_INPUTS(n2, n0, n1); |
698 } else { | 709 } else { |
699 n2 = graph.NewNode(&dummy_operator, n0); | 710 n2 = graph.NewNode(&dummy_operator1, n0); |
700 CHECK_INPUTS(n2, n0); | 711 CHECK_INPUTS(n2, n0); |
701 n2->AppendInput(graph.zone(), n1); // with out-of-line input. | 712 n2->AppendInput(graph.zone(), n1); // with out-of-line input. |
702 CHECK_INPUTS(n2, n0, n1); | 713 CHECK_INPUTS(n2, n0, n1); |
703 } | 714 } |
704 | 715 |
705 n0->NullAllInputs(); | 716 n0->NullAllInputs(); |
706 CHECK_INPUTS(n0, NONE); | 717 CHECK_INPUTS(n0, NONE); |
707 | 718 |
708 CHECK_USES(n0, n1, n2); | 719 CHECK_USES(n0, n1, n2); |
709 n1->NullAllInputs(); | 720 n1->NullAllInputs(); |
710 CHECK_INPUTS(n1, NULL); | 721 CHECK_INPUTS(n1, NULL); |
711 CHECK_INPUTS(n2, n0, n1); | 722 CHECK_INPUTS(n2, n0, n1); |
712 CHECK_USES(n0, n2); | 723 CHECK_USES(n0, n2); |
713 | 724 |
714 n2->NullAllInputs(); | 725 n2->NullAllInputs(); |
715 CHECK_INPUTS(n1, NULL); | 726 CHECK_INPUTS(n1, NULL); |
716 CHECK_INPUTS(n2, NULL, NULL); | 727 CHECK_INPUTS(n2, NULL, NULL); |
717 CHECK_USES(n0, NONE); | 728 CHECK_USES(n0, NONE); |
718 } | 729 } |
719 | 730 |
720 { | 731 { |
721 Node* n0 = graph.NewNode(&dummy_operator); | 732 Node* n0 = graph.NewNode(&dummy_operator0); |
722 Node* n1 = graph.NewNode(&dummy_operator, n0); | 733 Node* n1 = graph.NewNode(&dummy_operator1, n0); |
723 n1->ReplaceInput(0, n1); // self-reference. | 734 n1->ReplaceInput(0, n1); // self-reference. |
724 | 735 |
725 CHECK_INPUTS(n0, NONE); | 736 CHECK_INPUTS(n0, NONE); |
726 CHECK_INPUTS(n1, n1); | 737 CHECK_INPUTS(n1, n1); |
727 CHECK_USES(n0, NONE); | 738 CHECK_USES(n0, NONE); |
728 CHECK_USES(n1, n1); | 739 CHECK_USES(n1, n1); |
729 n1->NullAllInputs(); | 740 n1->NullAllInputs(); |
730 | 741 |
731 CHECK_INPUTS(n0, NONE); | 742 CHECK_INPUTS(n0, NONE); |
732 CHECK_INPUTS(n1, NULL); | 743 CHECK_INPUTS(n1, NULL); |
733 CHECK_USES(n0, NONE); | 744 CHECK_USES(n0, NONE); |
734 CHECK_USES(n1, NONE); | 745 CHECK_USES(n1, NONE); |
735 } | 746 } |
736 } | 747 } |
737 | 748 |
738 | 749 |
739 TEST(AppendAndTrim) { | 750 TEST(AppendAndTrim) { |
740 Zone zone; | 751 Zone zone; |
741 Graph graph(&zone); | 752 Graph graph(&zone); |
742 | 753 |
743 Node* nodes[] = { | 754 Node* nodes[] = { |
744 graph.NewNode(&dummy_operator), graph.NewNode(&dummy_operator), | 755 graph.NewNode(&dummy_operator0), graph.NewNode(&dummy_operator0), |
745 graph.NewNode(&dummy_operator), graph.NewNode(&dummy_operator), | 756 graph.NewNode(&dummy_operator0), graph.NewNode(&dummy_operator0), |
746 graph.NewNode(&dummy_operator)}; | 757 graph.NewNode(&dummy_operator0)}; |
747 | 758 |
748 int max = static_cast<int>(arraysize(nodes)); | 759 int max = static_cast<int>(arraysize(nodes)); |
749 | 760 |
750 Node* last = graph.NewNode(&dummy_operator); | 761 Node* last = graph.NewNode(&dummy_operator0); |
751 | 762 |
752 for (int i = 0; i < max; i++) { | 763 for (int i = 0; i < max; i++) { |
753 last->AppendInput(graph.zone(), nodes[i]); | 764 last->AppendInput(graph.zone(), nodes[i]); |
754 CheckInputs(last, nodes, i + 1); | 765 CheckInputs(last, nodes, i + 1); |
755 | 766 |
756 for (int j = 0; j < max; j++) { | 767 for (int j = 0; j < max; j++) { |
757 if (j <= i) CHECK_USES(nodes[j], last); | 768 if (j <= i) CHECK_USES(nodes[j], last); |
758 if (j > i) CHECK_USES(nodes[j], NONE); | 769 if (j > i) CHECK_USES(nodes[j], NONE); |
759 } | 770 } |
760 | 771 |
761 CHECK_USES(last, NONE); | 772 CHECK_USES(last, NONE); |
762 } | 773 } |
763 | 774 |
764 for (int i = max; i >= 0; i--) { | 775 for (int i = max; i >= 0; i--) { |
765 last->TrimInputCount(i); | 776 last->TrimInputCount(i); |
766 CheckInputs(last, nodes, i); | 777 CheckInputs(last, nodes, i); |
767 | 778 |
768 for (int j = 0; j < i; j++) { | 779 for (int j = 0; j < i; j++) { |
769 if (j < i) CHECK_USES(nodes[j], last); | 780 if (j < i) CHECK_USES(nodes[j], last); |
770 if (j >= i) CHECK_USES(nodes[j], NONE); | 781 if (j >= i) CHECK_USES(nodes[j], NONE); |
771 } | 782 } |
772 | 783 |
773 CHECK_USES(last, NONE); | 784 CHECK_USES(last, NONE); |
774 } | 785 } |
775 } | 786 } |
OLD | NEW |