OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/effect-control-linearizer.h" | 5 #include "src/compiler/effect-control-linearizer.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/schedule.h" | 10 #include "src/compiler/schedule.h" |
11 #include "src/compiler/simplified-operator.h" | 11 #include "src/compiler/simplified-operator.h" |
12 #include "test/unittests/compiler/graph-unittest.h" | 12 #include "test/unittests/compiler/graph-unittest.h" |
13 #include "test/unittests/compiler/node-test-utils.h" | 13 #include "test/unittests/compiler/node-test-utils.h" |
14 #include "test/unittests/test-utils.h" | 14 #include "test/unittests/test-utils.h" |
| 15 #include "testing/gmock-support.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 | 17 |
17 namespace v8 { | 18 namespace v8 { |
18 namespace internal { | 19 namespace internal { |
19 namespace compiler { | 20 namespace compiler { |
20 | 21 |
| 22 using testing::Capture; |
| 23 |
21 class EffectControlLinearizerTest : public TypedGraphTest { | 24 class EffectControlLinearizerTest : public TypedGraphTest { |
22 public: | 25 public: |
23 EffectControlLinearizerTest() | 26 EffectControlLinearizerTest() |
24 : TypedGraphTest(3), | 27 : TypedGraphTest(3), |
25 machine_(zone()), | 28 machine_(zone()), |
26 javascript_(zone()), | 29 javascript_(zone()), |
27 simplified_(zone()), | 30 simplified_(zone()), |
28 jsgraph_(isolate(), graph(), common(), &javascript_, &simplified_, | 31 jsgraph_(isolate(), graph(), common(), &javascript_, &simplified_, |
29 &machine_) {} | 32 &machine_) {} |
30 | 33 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 319 |
317 // Run the state effect introducer. | 320 // Run the state effect introducer. |
318 EffectControlLinearizer introducer(jsgraph(), &schedule, zone()); | 321 EffectControlLinearizer introducer(jsgraph(), &schedule, zone()); |
319 introducer.Run(); | 322 introducer.Run(); |
320 | 323 |
321 ASSERT_THAT(ret, IsReturn(load, load, if_true)); | 324 ASSERT_THAT(ret, IsReturn(load, load, if_true)); |
322 EXPECT_THAT(load, IsLoadField(AccessBuilder::ForHeapNumberValue(), | 325 EXPECT_THAT(load, IsLoadField(AccessBuilder::ForHeapNumberValue(), |
323 heap_number, effect_phi, loop)); | 326 heap_number, effect_phi, loop)); |
324 } | 327 } |
325 | 328 |
| 329 TEST_F(EffectControlLinearizerTest, CloneBranch) { |
| 330 Schedule schedule(zone()); |
| 331 |
| 332 Node* cond0 = Parameter(0); |
| 333 Node* cond1 = Parameter(1); |
| 334 Node* cond2 = Parameter(2); |
| 335 Node* branch0 = graph()->NewNode(common()->Branch(), cond0, start()); |
| 336 Node* control1 = graph()->NewNode(common()->IfTrue(), branch0); |
| 337 Node* control2 = graph()->NewNode(common()->IfFalse(), branch0); |
| 338 Node* merge0 = graph()->NewNode(common()->Merge(2), control1, control2); |
| 339 Node* phi0 = graph()->NewNode(common()->Phi(MachineRepresentation::kBit, 2), |
| 340 cond1, cond2, merge0); |
| 341 Node* branch = graph()->NewNode(common()->Branch(), phi0, merge0); |
| 342 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 343 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 344 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 345 graph()->SetEnd(graph()->NewNode(common()->End(1), merge)); |
| 346 |
| 347 BasicBlock* start = schedule.start(); |
| 348 schedule.rpo_order()->push_back(start); |
| 349 start->set_rpo_number(0); |
| 350 |
| 351 BasicBlock* f1block = AddBlockToSchedule(&schedule); |
| 352 BasicBlock* t1block = AddBlockToSchedule(&schedule); |
| 353 BasicBlock* bblock = AddBlockToSchedule(&schedule); |
| 354 |
| 355 BasicBlock* f2block = AddBlockToSchedule(&schedule); |
| 356 BasicBlock* t2block = AddBlockToSchedule(&schedule); |
| 357 BasicBlock* mblock = AddBlockToSchedule(&schedule); |
| 358 |
| 359 // Populate the basic blocks with nodes. |
| 360 schedule.AddNode(start, graph()->start()); |
| 361 |
| 362 schedule.AddBranch(start, branch0, t1block, f1block); |
| 363 |
| 364 schedule.AddNode(t1block, control1); |
| 365 schedule.AddGoto(t1block, bblock); |
| 366 |
| 367 schedule.AddNode(f1block, control2); |
| 368 schedule.AddGoto(f1block, bblock); |
| 369 |
| 370 schedule.AddNode(bblock, merge0); |
| 371 schedule.AddNode(bblock, phi0); |
| 372 schedule.AddBranch(bblock, branch, t2block, f2block); |
| 373 |
| 374 schedule.AddNode(t2block, if_true); |
| 375 schedule.AddGoto(t2block, mblock); |
| 376 |
| 377 schedule.AddNode(f2block, if_false); |
| 378 schedule.AddGoto(f2block, mblock); |
| 379 |
| 380 schedule.AddNode(mblock, merge); |
| 381 schedule.AddNode(mblock, graph()->end()); |
| 382 |
| 383 EffectControlLinearizer introducer(jsgraph(), &schedule, zone()); |
| 384 introducer.Run(); |
| 385 |
| 386 Capture<Node *> branch1_capture, branch2_capture; |
| 387 EXPECT_THAT( |
| 388 end(), |
| 389 IsEnd(IsMerge(IsMerge(IsIfTrue(CaptureEq(&branch1_capture)), |
| 390 IsIfTrue(CaptureEq(&branch2_capture))), |
| 391 IsMerge(IsIfFalse(AllOf(CaptureEq(&branch1_capture), |
| 392 IsBranch(cond1, control1))), |
| 393 IsIfFalse(AllOf(CaptureEq(&branch2_capture), |
| 394 IsBranch(cond2, control2))))))); |
| 395 } |
| 396 |
326 } // namespace compiler | 397 } // namespace compiler |
327 } // namespace internal | 398 } // namespace internal |
328 } // namespace v8 | 399 } // namespace v8 |
OLD | NEW |