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

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

Issue 1200983004: Revert of [turbofan] Run DeadCodeElimination together with the advanced reducers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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); 295 GraphReducer graph_reducer(zone(), graph(), nullptr, 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); 311 GraphReducer graph_reducer(zone(), graph(), nullptr, 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); 329 GraphReducer graph_reducer(zone(), graph(), nullptr, 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);
349 Node* replacement = graph()->NewNode(&kMockOperator); 350 Node* replacement = graph()->NewNode(&kMockOperator);
350 GraphReducer graph_reducer(zone(), graph(), dead); 351 GraphReducer graph_reducer(zone(), graph(), nullptr, dead);
351 ReplaceWithValueReducer r(&graph_reducer); 352 ReplaceWithValueReducer r(&graph_reducer);
352 r.ReplaceWithValue(node, replacement); 353 r.ReplaceWithValue(node, replacement);
353 EXPECT_EQ(start, use_control->InputAt(0)); 354 EXPECT_EQ(start, use_control->InputAt(0));
354 EXPECT_EQ(dead, exception->InputAt(1)); 355 EXPECT_EQ(dead, use_exception_control->InputAt(0));
355 EXPECT_EQ(0, node->UseCount()); 356 EXPECT_EQ(0, node->UseCount());
356 EXPECT_EQ(2, start->UseCount()); 357 EXPECT_EQ(2, start->UseCount());
357 EXPECT_EQ(1, dead->UseCount()); 358 EXPECT_EQ(1, dead->UseCount());
358 EXPECT_EQ(0, replacement->UseCount()); 359 EXPECT_EQ(0, replacement->UseCount());
359 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); 360 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
360 EXPECT_THAT(dead->uses(), ElementsAre(exception)); 361 EXPECT_THAT(dead->uses(), ElementsAre(use_exception_control));
361 } 362 }
362 363
363 364
364 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse3) { 365 TEST_F(AdvancedReducerTest, ReplaceWithValue_ControlUse3) {
365 CommonOperatorBuilder common(zone()); 366 CommonOperatorBuilder common(zone());
366 Node* start = graph()->NewNode(common.Start(1)); 367 Node* start = graph()->NewNode(common.Start(1));
367 Node* effect = graph()->NewNode(&kMockOperator); 368 Node* effect = graph()->NewNode(&kMockOperator);
368 Node* dead = graph()->NewNode(&kMockOperator); 369 Node* dead = graph()->NewNode(&kMockOperator);
369 Node* node = graph()->NewNode(&kMockOpControl, start); 370 Node* node = graph()->NewNode(&kMockOpControl, start);
370 Node* success = graph()->NewNode(common.IfSuccess(), node); 371 Node* success = graph()->NewNode(common.IfSuccess(), node);
371 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node); 372 Node* exception = graph()->NewNode(common.IfException(kNoHint), effect, node);
372 Node* use_control = graph()->NewNode(common.Merge(1), success); 373 Node* use_control = graph()->NewNode(common.Merge(1), success);
374 Node* use_exception_value = graph()->NewNode(common.Return(), exception);
373 Node* replacement = graph()->NewNode(&kMockOperator); 375 Node* replacement = graph()->NewNode(&kMockOperator);
374 GraphReducer graph_reducer(zone(), graph(), dead); 376 GraphReducer graph_reducer(zone(), graph(), dead, nullptr);
375 ReplaceWithValueReducer r(&graph_reducer); 377 ReplaceWithValueReducer r(&graph_reducer);
376 r.ReplaceWithValue(node, replacement); 378 r.ReplaceWithValue(node, replacement);
377 EXPECT_EQ(start, use_control->InputAt(0)); 379 EXPECT_EQ(start, use_control->InputAt(0));
378 EXPECT_EQ(dead, exception->InputAt(1)); 380 EXPECT_EQ(dead, use_exception_value->InputAt(0));
379 EXPECT_EQ(0, node->UseCount()); 381 EXPECT_EQ(0, node->UseCount());
380 EXPECT_EQ(2, start->UseCount()); 382 EXPECT_EQ(2, start->UseCount());
381 EXPECT_EQ(1, dead->UseCount()); 383 EXPECT_EQ(1, dead->UseCount());
382 EXPECT_EQ(0, replacement->UseCount()); 384 EXPECT_EQ(0, replacement->UseCount());
383 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node)); 385 EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
384 EXPECT_THAT(dead->uses(), ElementsAre(exception)); 386 EXPECT_THAT(dead->uses(), ElementsAre(use_exception_value));
385 } 387 }
386 388
387 389
388 class GraphReducerTest : public TestWithZone { 390 class GraphReducerTest : public TestWithZone {
389 public: 391 public:
390 GraphReducerTest() : graph_(zone()) {} 392 GraphReducerTest() : graph_(zone()) {}
391 393
392 static void SetUpTestCase() { 394 static void SetUpTestCase() {
393 TestWithZone::SetUpTestCase(); 395 TestWithZone::SetUpTestCase();
394 DefaultValue<Reduction>::Set(Reducer::NoChange()); 396 DefaultValue<Reduction>::Set(Reducer::NoChange());
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 EXPECT_EQ(&kOpC0, n1->op()); 850 EXPECT_EQ(&kOpC0, n1->op());
849 EXPECT_EQ(&kOpC1, end->op()); 851 EXPECT_EQ(&kOpC1, end->op());
850 EXPECT_EQ(n1, end->InputAt(0)); 852 EXPECT_EQ(n1, end->InputAt(0));
851 } 853 }
852 } 854 }
853 } 855 }
854 856
855 } // namespace compiler 857 } // namespace compiler
856 } // namespace internal 858 } // namespace internal
857 } // namespace v8 859 } // 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