@@ -50,10 +50,10 @@ struct DependencyGraphTest : public testing::Test {
5050 return *AA;
5151 }
5252 // / \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 ;
5757 }
5858};
5959
@@ -230,9 +230,10 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
230230 EXPECT_EQ (Span.top (), &*BB->begin ());
231231 EXPECT_EQ (Span.bottom (), BB->getTerminator ());
232232
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+
236237 // Check getInstruction().
237238 EXPECT_EQ (N0->getInstruction (), S0);
238239 EXPECT_EQ (N1->getInstruction (), S1);
@@ -247,7 +248,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
247248 // Check memPreds().
248249 EXPECT_TRUE (N0->memPreds ().empty ());
249250 EXPECT_THAT (N1->memPreds (), testing::ElementsAre (N0));
250- EXPECT_TRUE (N2->memPreds ( ).empty ());
251+ EXPECT_TRUE (N2->preds (DAG ).empty ());
251252}
252253
253254TEST_F (DependencyGraphTest, Preds) {
@@ -399,12 +400,14 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
399400 sandboxir::DependencyGraph DAG (getAA (*LLVMF));
400401 DAG.extend ({&*BB->begin (), BB->getTerminator ()});
401402 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++)));
404407 auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
405408 EXPECT_TRUE (Store0N->memPreds ().empty ());
406409 EXPECT_THAT (Store1N->memPreds (), testing::ElementsAre (Store0N));
407- EXPECT_TRUE (RetN->memPreds ( ).empty ());
410+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
408411}
409412
410413TEST_F (DependencyGraphTest, NonAliasingStores) {
@@ -422,13 +425,15 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v0, i8 %v1) {
422425 sandboxir::DependencyGraph DAG (getAA (*LLVMF));
423426 DAG.extend ({&*BB->begin (), BB->getTerminator ()});
424427 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++)));
427432 auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
428433 // We expect no dependencies because the stores don't alias.
429434 EXPECT_TRUE (Store0N->memPreds ().empty ());
430435 EXPECT_TRUE (Store1N->memPreds ().empty ());
431- EXPECT_TRUE (RetN->memPreds ( ).empty ());
436+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
432437}
433438
434439TEST_F (DependencyGraphTest, VolatileLoads) {
@@ -446,12 +451,14 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1) {
446451 sandboxir::DependencyGraph DAG (getAA (*LLVMF));
447452 DAG.extend ({&*BB->begin (), BB->getTerminator ()});
448453 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++)));
451458 auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
452459 EXPECT_TRUE (Ld0N->memPreds ().empty ());
453460 EXPECT_THAT (Ld1N->memPreds (), testing::ElementsAre (Ld0N));
454- EXPECT_TRUE (RetN->memPreds ( ).empty ());
461+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
455462}
456463
457464TEST_F (DependencyGraphTest, VolatileSotres) {
@@ -469,12 +476,14 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v) {
469476 sandboxir::DependencyGraph DAG (getAA (*LLVMF));
470477 DAG.extend ({&*BB->begin (), BB->getTerminator ()});
471478 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++)));
474483 auto *RetN = DAG.getNode (cast<sandboxir::ReturnInst>(&*It++));
475484 EXPECT_TRUE (Store0N->memPreds ().empty ());
476485 EXPECT_THAT (Store1N->memPreds (), testing::ElementsAre (Store0N));
477- EXPECT_TRUE (RetN->memPreds ( ).empty ());
486+ EXPECT_TRUE (RetN->preds (DAG ).empty ());
478487}
479488
480489TEST_F (DependencyGraphTest, Call) {
@@ -498,12 +507,12 @@ define void @foo(float %v1, float %v2) {
498507 DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
499508
500509 auto It = BB->begin ();
501- auto *Call1N = DAG.getNode (&*It++);
510+ auto *Call1N = cast<sandboxir::MemDGNode>( DAG.getNode (&*It++) );
502511 auto *AddN = DAG.getNode (&*It++);
503- auto *Call2N = DAG.getNode (&*It++);
512+ auto *Call2N = cast<sandboxir::MemDGNode>( DAG.getNode (&*It++) );
504513
505514 EXPECT_THAT (Call1N->memPreds (), testing::ElementsAre ());
506- EXPECT_THAT (AddN->memPreds ( ), testing::ElementsAre ());
515+ EXPECT_THAT (AddN->preds (DAG ), testing::ElementsAre ());
507516 EXPECT_THAT (Call2N->memPreds (), testing::ElementsAre (Call1N));
508517}
509518
@@ -534,8 +543,8 @@ define void @foo() {
534543 auto *AllocaN = DAG.getNode (&*It++);
535544 auto *StackRestoreN = DAG.getNode (&*It++);
536545
537- EXPECT_TRUE (dependency (AllocaN, StackRestoreN));
538- EXPECT_TRUE (dependency (StackSaveN, AllocaN));
546+ EXPECT_TRUE (memDependency (AllocaN, StackRestoreN));
547+ EXPECT_TRUE (memDependency (StackSaveN, AllocaN));
539548}
540549
541550// Checks that stacksave and stackrestore depend on other mem instrs.
@@ -567,9 +576,9 @@ define void @foo(i8 %v0, i8 %v1, ptr %ptr) {
567576 auto *StackRestoreN = DAG.getNode (&*It++);
568577 auto *Store1N = DAG.getNode (&*It++);
569578
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));
573582}
574583
575584// Make sure there is a dependency between a stackrestore and an alloca.
@@ -596,7 +605,7 @@ define void @foo(ptr %ptr) {
596605 auto *StackRestoreN = DAG.getNode (&*It++);
597606 auto *AllocaN = DAG.getNode (&*It++);
598607
599- EXPECT_TRUE (dependency (StackRestoreN, AllocaN));
608+ EXPECT_TRUE (memDependency (StackRestoreN, AllocaN));
600609}
601610
602611// Make sure there is a dependency between the alloca and stacksave
@@ -623,7 +632,7 @@ define void @foo(ptr %ptr) {
623632 auto *AllocaN = DAG.getNode (&*It++);
624633 auto *StackSaveN = DAG.getNode (&*It++);
625634
626- EXPECT_TRUE (dependency (AllocaN, StackSaveN));
635+ EXPECT_TRUE (memDependency (AllocaN, StackSaveN));
627636}
628637
629638// A non-InAlloca in a stacksave-stackrestore region does not need extra
@@ -655,6 +664,6 @@ define void @foo() {
655664 auto *AllocaN = DAG.getNode (&*It++);
656665 auto *StackRestoreN = DAG.getNode (&*It++);
657666
658- EXPECT_FALSE (dependency (StackSaveN, AllocaN));
659- EXPECT_FALSE (dependency (AllocaN, StackRestoreN));
667+ EXPECT_FALSE (memDependency (StackSaveN, AllocaN));
668+ EXPECT_FALSE (memDependency (AllocaN, StackRestoreN));
660669}
0 commit comments