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

Side by Side Diff: test/unittests/compiler/graph-reducer-unittest.cc

Issue 1206533002: [turbofan] Run DeadCodeElimination together with the advanced reducers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test262 test failure Created 5 years, 6 months 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
« no previous file with comments | « src/compiler/verifier.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common-operator.h" 5 #include "src/compiler/common-operator.h"
6 #include "src/compiler/graph.h" 6 #include "src/compiler/graph.h"
7 #include "src/compiler/node.h" 7 #include "src/compiler/node.h"
8 #include "src/compiler/operator.h" 8 #include "src/compiler/operator.h"
9 #include "test/unittests/compiler/graph-reducer-unittest.h" 9 #include "test/unittests/compiler/graph-reducer-unittest.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught; 285 const IfExceptionHint kNoHint = IfExceptionHint::kLocallyCaught;
286 286
287 } // namespace 287 } // namespace
288 288
289 289
290 TEST_F(AdvancedReducerTest, ReplaceWithValue_ValueUse) { 290 TEST_F(AdvancedReducerTest, ReplaceWithValue_ValueUse) {
291 CommonOperatorBuilder common(zone()); 291 CommonOperatorBuilder common(zone());
292 Node* node = graph()->NewNode(&kMockOperator); 292 Node* node = graph()->NewNode(&kMockOperator);
293 Node* use_value = graph()->NewNode(common.Return(), node); 293 Node* use_value = graph()->NewNode(common.Return(), node);
294 Node* replacement = graph()->NewNode(&kMockOperator); 294 Node* replacement = graph()->NewNode(&kMockOperator);
295 GraphReducer graph_reducer(zone(), graph(), nullptr, nullptr); 295 GraphReducer graph_reducer(zone(), graph(), nullptr);
296 ReplaceWithValueReducer r(&graph_reducer); 296 ReplaceWithValueReducer r(&graph_reducer);
297 r.ReplaceWithValue(node, replacement); 297 r.ReplaceWithValue(node, replacement);
298 EXPECT_EQ(replacement, use_value->InputAt(0)); 298 EXPECT_EQ(replacement, use_value->InputAt(0));
299 EXPECT_EQ(0, node->UseCount()); 299 EXPECT_EQ(0, node->UseCount());
300 EXPECT_EQ(1, replacement->UseCount()); 300 EXPECT_EQ(1, replacement->UseCount());
301 EXPECT_THAT(replacement->uses(), ElementsAre(use_value)); 301 EXPECT_THAT(replacement->uses(), ElementsAre(use_value));
302 } 302 }
303 303
304 304
305 TEST_F(AdvancedReducerTest, ReplaceWithValue_EffectUse) { 305 TEST_F(AdvancedReducerTest, ReplaceWithValue_EffectUse) {
306 CommonOperatorBuilder common(zone()); 306 CommonOperatorBuilder common(zone());
307 Node* start = graph()->NewNode(common.Start(1)); 307 Node* start = graph()->NewNode(common.Start(1));
308 Node* node = graph()->NewNode(&kMockOpEffect, start); 308 Node* node = graph()->NewNode(&kMockOpEffect, start);
309 Node* use_effect = graph()->NewNode(common.EffectPhi(1), node); 309 Node* use_effect = graph()->NewNode(common.EffectPhi(1), node);
310 Node* replacement = graph()->NewNode(&kMockOperator); 310 Node* replacement = graph()->NewNode(&kMockOperator);
311 GraphReducer graph_reducer(zone(), graph(), nullptr, nullptr); 311 GraphReducer graph_reducer(zone(), graph(), nullptr);
312 ReplaceWithValueReducer r(&graph_reducer); 312 ReplaceWithValueReducer r(&graph_reducer);
313 r.ReplaceWithValue(node, replacement); 313 r.ReplaceWithValue(node, replacement);
314 EXPECT_EQ(start, use_effect->InputAt(0)); 314 EXPECT_EQ(start, use_effect->InputAt(0));
315 EXPECT_EQ(0, node->UseCount()); 315 EXPECT_EQ(0, node->UseCount());
316 EXPECT_EQ(2, start->UseCount()); 316 EXPECT_EQ(2, start->UseCount());
317 EXPECT_EQ(0, replacement->UseCount()); 317 EXPECT_EQ(0, replacement->UseCount());
318 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_effect, node)); 318 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_effect, node));
319 } 319 }
320 320
321 321
322 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse1) { 322 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse1) {
323 CommonOperatorBuilder common(zone()); 323 CommonOperatorBuilder common(zone());
324 Node* start = graph()->NewNode(common.Start(1)); 324 Node* start = graph()->NewNode(common.Start(1));
325 Node* node = graph()->NewNode(&kMockOpControl, start); 325 Node* node = graph()->NewNode(&kMockOpControl, start);
326 Node* success = graph()->NewNode(common.IfSuccess(), node); 326 Node* success = graph()->NewNode(common.IfSuccess(), node);
327 Node* use_control = graph()->NewNode(common.Merge(1), success); 327 Node* use_control = graph()->NewNode(common.Merge(1), success);
328 Node* replacement = graph()->NewNode(&kMockOperator); 328 Node* replacement = graph()->NewNode(&kMockOperator);
329 GraphReducer graph_reducer(zone(), graph(), nullptr, nullptr); 329 GraphReducer graph_reducer(zone(), graph(), nullptr);
330 ReplaceWithValueReducer r(&graph_reducer); 330 ReplaceWithValueReducer r(&graph_reducer);
331 r.ReplaceWithValue(node, replacement); 331 r.ReplaceWithValue(node, replacement);
332 EXPECT_EQ(start, use_control->InputAt(0)); 332 EXPECT_EQ(start, use_control->InputAt(0));
333 EXPECT_EQ(0, node->UseCount()); 333 EXPECT_EQ(0, node->UseCount());
334 EXPECT_EQ(2, start->UseCount()); 334 EXPECT_EQ(2, start->UseCount());
335 EXPECT_EQ(0, replacement->UseCount()); 335 EXPECT_EQ(0, replacement->UseCount());
336 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); 336 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
337 } 337 }
338 338
339 339
340 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse2) { 340 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse2) {
341 CommonOperatorBuilder common(zone()); 341 CommonOperatorBuilder common(zone());
342 Node* start = graph()->NewNode(common.Start(1)); 342 Node* start = graph()->NewNode(common.Start(1));
343 Node* effect = graph()->NewNode(&kMockOperator); 343 Node* effect = graph()->NewNode(&kMockOperator);
344 Node* dead = graph()->NewNode(&kMockOperator); 344 Node* dead = graph()->NewNode(&kMockOperator);
345 Node* node = graph()->NewNode(&kMockOpControl, start); 345 Node* node = graph()->NewNode(&kMockOpControl, start);
346 Node* success = graph()->NewNode(common.IfSuccess(), node); 346 Node* success = graph()->NewNode(common.IfSuccess(), node);
347 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node); 347 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node);
348 Node* use_control = graph()->NewNode(common.Merge(1), success); 348 Node* use_control = graph()->NewNode(common.Merge(1), success);
349 Node* use_exception_control = graph()->NewNode(common.Merge(1), exception);
350 Node* replacement = graph()->NewNode(&kMockOperator); 349 Node* replacement = graph()->NewNode(&kMockOperator);
351 GraphReducer graph_reducer(zone(), graph(), nullptr, dead); 350 GraphReducer graph_reducer(zone(), graph(), dead);
352 ReplaceWithValueReducer r(&graph_reducer); 351 ReplaceWithValueReducer r(&graph_reducer);
353 r.ReplaceWithValue(node, replacement); 352 r.ReplaceWithValue(node, replacement);
354 EXPECT_EQ(start, use_control->InputAt(0)); 353 EXPECT_EQ(start, use_control->InputAt(0));
355 EXPECT_EQ(dead, use_exception_control->InputAt(0)); 354 EXPECT_EQ(dead, exception->InputAt(1));
356 EXPECT_EQ(0, node->UseCount()); 355 EXPECT_EQ(0, node->UseCount());
357 EXPECT_EQ(2, start->UseCount()); 356 EXPECT_EQ(2, start->UseCount());
358 EXPECT_EQ(1, dead->UseCount()); 357 EXPECT_EQ(1, dead->UseCount());
359 EXPECT_EQ(0, replacement->UseCount()); 358 EXPECT_EQ(0, replacement->UseCount());
360 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); 359 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
361 EXPECT_THAT(dead->uses(), ElementsAre(use_exception_control)); 360 EXPECT_THAT(dead->uses(), ElementsAre(exception));
362 } 361 }
363 362
364 363
365 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse3) { 364 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse3) {
366 CommonOperatorBuilder common(zone()); 365 CommonOperatorBuilder common(zone());
367 Node* start = graph()->NewNode(common.Start(1)); 366 Node* start = graph()->NewNode(common.Start(1));
368 Node* effect = graph()->NewNode(&kMockOperator); 367 Node* effect = graph()->NewNode(&kMockOperator);
369 Node* dead = graph()->NewNode(&kMockOperator); 368 Node* dead = graph()->NewNode(&kMockOperator);
370 Node* node = graph()->NewNode(&kMockOpControl, start); 369 Node* node = graph()->NewNode(&kMockOpControl, start);
371 Node* success = graph()->NewNode(common.IfSuccess(), node); 370 Node* success = graph()->NewNode(common.IfSuccess(), node);
372 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node); 371 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node);
373 Node* use_control = graph()->NewNode(common.Merge(1), success); 372 Node* use_control = graph()->NewNode(common.Merge(1), success);
374 Node* use_exception_value = graph()->NewNode(common.Return(), exception);
375 Node* replacement = graph()->NewNode(&kMockOperator); 373 Node* replacement = graph()->NewNode(&kMockOperator);
376 GraphReducer graph_reducer(zone(), graph(), dead, nullptr); 374 GraphReducer graph_reducer(zone(), graph(), dead);
377 ReplaceWithValueReducer r(&graph_reducer); 375 ReplaceWithValueReducer r(&graph_reducer);
378 r.ReplaceWithValue(node, replacement); 376 r.ReplaceWithValue(node, replacement);
379 EXPECT_EQ(start, use_control->InputAt(0)); 377 EXPECT_EQ(start, use_control->InputAt(0));
380 EXPECT_EQ(dead, use_exception_value->InputAt(0)); 378 EXPECT_EQ(dead, exception->InputAt(1));
381 EXPECT_EQ(0, node->UseCount()); 379 EXPECT_EQ(0, node->UseCount());
382 EXPECT_EQ(2, start->UseCount()); 380 EXPECT_EQ(2, start->UseCount());
383 EXPECT_EQ(1, dead->UseCount()); 381 EXPECT_EQ(1, dead->UseCount());
384 EXPECT_EQ(0, replacement->UseCount()); 382 EXPECT_EQ(0, replacement->UseCount());
385 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); 383 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
386 EXPECT_THAT(dead->uses(), ElementsAre(use_exception_value)); 384 EXPECT_THAT(dead->uses(), ElementsAre(exception));
387 } 385 }
388 386
389 387
390 class GraphReducerTest : public TestWithZone { 388 class GraphReducerTest : public TestWithZone {
391 public: 389 public:
392 GraphReducerTest() : graph_(zone()) {} 390 GraphReducerTest() : graph_(zone()) {}
393 391
394 static void SetUpTestCase() { 392 static void SetUpTestCase() {
395 TestWithZone::SetUpTestCase(); 393 TestWithZone::SetUpTestCase();
396 DefaultValue<Reduction>::Set(Reducer::NoChange()); 394 DefaultValue<Reduction>::Set(Reducer::NoChange());
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 EXPECT_EQ(&kOpC0, n1->op()); 848 EXPECT_EQ(&kOpC0, n1->op());
851 EXPECT_EQ(&kOpC1, end->op()); 849 EXPECT_EQ(&kOpC1, end->op());
852 EXPECT_EQ(n1, end->InputAt(0)); 850 EXPECT_EQ(n1, end->InputAt(0));
853 } 851 }
854 } 852 }
855 } 853 }
856 854
857 } // namespace compiler 855 } // namespace compiler
858 } // namespace internal 856 } // namespace internal
859 } // namespace v8 857 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/verifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698