@@ -50,10 +50,10 @@ struct DependencyGraphTest : public testing::Test {
50
50
return *AA;
51
51
}
52
52
// / \Returns true if there is a dependency: SrcN->DstN.
53
- bool dependency (sandboxir::DGNode *SrcN, sandboxir::DGNode *DstN) {
54
- const auto &Preds = DstN-> memPreds ();
55
- auto It = find (Preds, SrcN);
56
- return It != Preds. end () ;
53
+ bool memDependency (sandboxir::DGNode *SrcN, sandboxir::DGNode *DstN) {
54
+ if ( auto *MemDstN = dyn_cast<sandboxir::MemDGNode>(DstN))
55
+ return MemDstN-> hasMemPred ( SrcN);
56
+ return false ;
57
57
}
58
58
};
59
59
@@ -230,9 +230,10 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
230
230
EXPECT_EQ (Span.top (), &*BB->begin ());
231
231
EXPECT_EQ (Span.bottom (), BB->getTerminator ());
232
232
233
- sandboxir::DGNode *N0 = DAG.getNode (S0);
234
- sandboxir::DGNode *N1 = DAG.getNode (S1);
235
- sandboxir::DGNode *N2 = DAG.getNode (Ret);
233
+ auto *N0 = cast<sandboxir::MemDGNode>(DAG.getNode (S0));
234
+ auto *N1 = cast<sandboxir::MemDGNode>(DAG.getNode (S1));
235
+ auto *N2 = DAG.getNode (Ret);
236
+
236
237
// Check getInstruction().
237
238
EXPECT_EQ (N0->getInstruction (), S0);
238
239
EXPECT_EQ (N1->getInstruction (), S1);
@@ -247,7 +248,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
247
248
// Check memPreds().
248
249
EXPECT_TRUE (N0->memPreds ().empty ());
249
250
EXPECT_THAT (N1->memPreds (), testing::ElementsAre (N0));
250
- EXPECT_TRUE (N2->memPreds ( ).empty ());
251
+ EXPECT_TRUE (N2->preds (DAG ).empty ());
251
252
}
252
253
253
254
TEST_F (DependencyGraphTest, Preds) {
@@ -399,12 +400,14 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
399
400
sandboxir::DependencyGraph DAG (getAA (*LLVMF));
400
401
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
401
402
auto It = BB->begin ();
402
- auto *Store0N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
403
- auto *Store1N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
403
+ auto *Store0N = cast<sandboxir::MemDGNode>(
404
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
405
+ auto *Store1N = cast<sandboxir::MemDGNode>(
406
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
404
407
auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
405
408
EXPECT_TRUE (Store0N->memPreds ().empty ());
406
409
EXPECT_THAT (Store1N->memPreds (), testing::ElementsAre (Store0N));
407
- EXPECT_TRUE (RetN->memPreds ( ).empty ());
410
+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
408
411
}
409
412
410
413
TEST_F (DependencyGraphTest, NonAliasingStores) {
@@ -422,13 +425,15 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v0, i8 %v1) {
422
425
sandboxir::DependencyGraph DAG (getAA (*LLVMF));
423
426
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
424
427
auto It = BB->begin ();
425
- auto *Store0N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
426
- auto *Store1N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
428
+ auto *Store0N = cast<sandboxir::MemDGNode>(
429
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
430
+ auto *Store1N = cast<sandboxir::MemDGNode>(
431
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
427
432
auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
428
433
// We expect no dependencies because the stores don't alias.
429
434
EXPECT_TRUE (Store0N->memPreds ().empty ());
430
435
EXPECT_TRUE (Store1N->memPreds ().empty ());
431
- EXPECT_TRUE (RetN->memPreds ( ).empty ());
436
+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
432
437
}
433
438
434
439
TEST_F (DependencyGraphTest, VolatileLoads) {
@@ -446,12 +451,14 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1) {
446
451
sandboxir::DependencyGraph DAG (getAA (*LLVMF));
447
452
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
448
453
auto It = BB->begin ();
449
- auto *Ld0N = DAG.getNode (cast<sandboxir::LoadInst>(&*It++));
450
- auto *Ld1N = DAG.getNode (cast<sandboxir::LoadInst>(&*It++));
454
+ auto *Ld0N = cast<sandboxir::MemDGNode>(
455
+ DAG.getNode (cast<sandboxir::LoadInst>(&*It++)));
456
+ auto *Ld1N = cast<sandboxir::MemDGNode>(
457
+ DAG.getNode (cast<sandboxir::LoadInst>(&*It++)));
451
458
auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
452
459
EXPECT_TRUE (Ld0N->memPreds ().empty ());
453
460
EXPECT_THAT (Ld1N->memPreds (), testing::ElementsAre (Ld0N));
454
- EXPECT_TRUE (RetN->memPreds ( ).empty ());
461
+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
455
462
}
456
463
457
464
TEST_F (DependencyGraphTest, VolatileSotres) {
@@ -469,12 +476,14 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v) {
469
476
sandboxir::DependencyGraph DAG (getAA (*LLVMF));
470
477
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
471
478
auto It = BB->begin ();
472
- auto *Store0N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
473
- auto *Store1N = DAG.getNode (cast<sandboxir::StoreInst>(&*It++));
479
+ auto *Store0N = cast<sandboxir::MemDGNode>(
480
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
481
+ auto *Store1N = cast<sandboxir::MemDGNode>(
482
+ DAG.getNode (cast<sandboxir::StoreInst>(&*It++)));
474
483
auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
475
484
EXPECT_TRUE (Store0N->memPreds ().empty ());
476
485
EXPECT_THAT (Store1N->memPreds (), testing::ElementsAre (Store0N));
477
- EXPECT_TRUE (RetN->memPreds ( ).empty ());
486
+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
478
487
}
479
488
480
489
TEST_F (DependencyGraphTest, Call) {
@@ -498,12 +507,12 @@ define void @foo(float %v1, float %v2) {
498
507
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
499
508
500
509
auto It = BB->begin ();
501
- auto *Call1N = DAG.getNode (&*It++);
510
+ auto *Call1N = cast<sandboxir::MemDGNode>( DAG.getNode (&*It++) );
502
511
auto *AddN = DAG.getNode (&*It++);
503
- auto *Call2N = DAG.getNode (&*It++);
512
+ auto *Call2N = cast<sandboxir::MemDGNode>( DAG.getNode (&*It++) );
504
513
505
514
EXPECT_THAT (Call1N->memPreds (), testing::ElementsAre ());
506
- EXPECT_THAT (AddN->memPreds ( ), testing::ElementsAre ());
515
+ EXPECT_THAT (AddN->preds (DAG ), testing::ElementsAre ());
507
516
EXPECT_THAT (Call2N->memPreds (), testing::ElementsAre (Call1N));
508
517
}
509
518
@@ -534,8 +543,8 @@ define void @foo() {
534
543
auto *AllocaN = DAG.getNode (&*It++);
535
544
auto *StackRestoreN = DAG.getNode (&*It++);
536
545
537
- EXPECT_TRUE (dependency (AllocaN, StackRestoreN));
538
- EXPECT_TRUE (dependency (StackSaveN, AllocaN));
546
+ EXPECT_TRUE (memDependency (AllocaN, StackRestoreN));
547
+ EXPECT_TRUE (memDependency (StackSaveN, AllocaN));
539
548
}
540
549
541
550
// Checks that stacksave and stackrestore depend on other mem instrs.
@@ -567,9 +576,9 @@ define void @foo(i8 %v0, i8 %v1, ptr %ptr) {
567
576
auto *StackRestoreN = DAG.getNode (&*It++);
568
577
auto *Store1N = DAG.getNode (&*It++);
569
578
570
- EXPECT_TRUE (dependency (Store0N, StackSaveN));
571
- EXPECT_TRUE (dependency (StackSaveN, StackRestoreN));
572
- EXPECT_TRUE (dependency (StackRestoreN, Store1N));
579
+ EXPECT_TRUE (memDependency (Store0N, StackSaveN));
580
+ EXPECT_TRUE (memDependency (StackSaveN, StackRestoreN));
581
+ EXPECT_TRUE (memDependency (StackRestoreN, Store1N));
573
582
}
574
583
575
584
// Make sure there is a dependency between a stackrestore and an alloca.
@@ -596,7 +605,7 @@ define void @foo(ptr %ptr) {
596
605
auto *StackRestoreN = DAG.getNode (&*It++);
597
606
auto *AllocaN = DAG.getNode (&*It++);
598
607
599
- EXPECT_TRUE (dependency (StackRestoreN, AllocaN));
608
+ EXPECT_TRUE (memDependency (StackRestoreN, AllocaN));
600
609
}
601
610
602
611
// Make sure there is a dependency between the alloca and stacksave
@@ -623,7 +632,7 @@ define void @foo(ptr %ptr) {
623
632
auto *AllocaN = DAG.getNode (&*It++);
624
633
auto *StackSaveN = DAG.getNode (&*It++);
625
634
626
- EXPECT_TRUE (dependency (AllocaN, StackSaveN));
635
+ EXPECT_TRUE (memDependency (AllocaN, StackSaveN));
627
636
}
628
637
629
638
// A non-InAlloca in a stacksave-stackrestore region does not need extra
@@ -655,6 +664,6 @@ define void @foo() {
655
664
auto *AllocaN = DAG.getNode (&*It++);
656
665
auto *StackRestoreN = DAG.getNode (&*It++);
657
666
658
- EXPECT_FALSE (dependency (StackSaveN, AllocaN));
659
- EXPECT_FALSE (dependency (AllocaN, StackRestoreN));
667
+ EXPECT_FALSE (memDependency (StackSaveN, AllocaN));
668
+ EXPECT_FALSE (memDependency (AllocaN, StackRestoreN));
660
669
}
0 commit comments