@@ -194,7 +194,7 @@ define void @foo(i8 %v1, ptr %ptr) {
194
194
auto *Call = cast<sandboxir::CallInst>(&*It++);
195
195
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
196
196
197
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
197
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
198
198
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
199
199
EXPECT_TRUE (isa<llvm::sandboxir::MemDGNode>(DAG.getNode (Store)));
200
200
EXPECT_TRUE (isa<llvm::sandboxir::MemDGNode>(DAG.getNode (Load)));
@@ -224,7 +224,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
224
224
auto *S0 = cast<sandboxir::StoreInst>(&*It++);
225
225
auto *S1 = cast<sandboxir::StoreInst>(&*It++);
226
226
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
227
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
227
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
228
228
auto Span = DAG.extend ({&*BB->begin (), BB->getTerminator ()});
229
229
// Check extend().
230
230
EXPECT_EQ (Span.top (), &*BB->begin ());
@@ -285,7 +285,7 @@ define i8 @foo(i8 %v0, i8 %v1) {
285
285
auto *F = Ctx.createFunction (LLVMF);
286
286
auto *BB = &*F->begin ();
287
287
auto It = BB->begin ();
288
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
288
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
289
289
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
290
290
291
291
auto *AddN0 = DAG.getNode (cast<sandboxir::BinaryOperator>(&*It++));
@@ -332,7 +332,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
332
332
auto *S1 = cast<sandboxir::StoreInst>(&*It++);
333
333
[[maybe_unused]] auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
334
334
335
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
335
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
336
336
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
337
337
338
338
auto *S0N = cast<sandboxir::MemDGNode>(DAG.getNode (S0));
@@ -366,7 +366,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
366
366
auto *S1 = cast<sandboxir::StoreInst>(&*It++);
367
367
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
368
368
369
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
369
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
370
370
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
371
371
372
372
auto *S0N = cast<sandboxir::MemDGNode>(DAG.getNode (S0));
@@ -436,7 +436,7 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
436
436
sandboxir::Context Ctx (C);
437
437
auto *F = Ctx.createFunction (LLVMF);
438
438
auto *BB = &*F->begin ();
439
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
439
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
440
440
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
441
441
auto It = BB->begin ();
442
442
auto *Store0N = cast<sandboxir::MemDGNode>(
@@ -461,7 +461,7 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v0, i8 %v1) {
461
461
sandboxir::Context Ctx (C);
462
462
auto *F = Ctx.createFunction (LLVMF);
463
463
auto *BB = &*F->begin ();
464
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
464
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
465
465
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
466
466
auto It = BB->begin ();
467
467
auto *Store0N = cast<sandboxir::MemDGNode>(
@@ -487,7 +487,7 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1) {
487
487
sandboxir::Context Ctx (C);
488
488
auto *F = Ctx.createFunction (LLVMF);
489
489
auto *BB = &*F->begin ();
490
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
490
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
491
491
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
492
492
auto It = BB->begin ();
493
493
auto *Ld0N = cast<sandboxir::MemDGNode>(
@@ -512,7 +512,7 @@ define void @foo(ptr noalias %ptr0, ptr noalias %ptr1, i8 %v) {
512
512
sandboxir::Context Ctx (C);
513
513
auto *F = Ctx.createFunction (LLVMF);
514
514
auto *BB = &*F->begin ();
515
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
515
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
516
516
DAG.extend ({&*BB->begin (), BB->getTerminator ()});
517
517
auto It = BB->begin ();
518
518
auto *Store0N = cast<sandboxir::MemDGNode>(
@@ -542,7 +542,7 @@ define void @foo(float %v1, float %v2) {
542
542
auto *F = Ctx.createFunction (LLVMF);
543
543
auto *BB = &*F->begin ();
544
544
545
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
545
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
546
546
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
547
547
548
548
auto It = BB->begin ();
@@ -574,7 +574,7 @@ define void @foo() {
574
574
auto *F = Ctx.createFunction (LLVMF);
575
575
auto *BB = &*F->begin ();
576
576
577
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
577
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
578
578
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
579
579
580
580
auto It = BB->begin ();
@@ -606,7 +606,7 @@ define void @foo(i8 %v0, i8 %v1, ptr %ptr) {
606
606
auto *F = Ctx.createFunction (LLVMF);
607
607
auto *BB = &*F->begin ();
608
608
609
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
609
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
610
610
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
611
611
612
612
auto It = BB->begin ();
@@ -637,7 +637,7 @@ define void @foo(ptr %ptr) {
637
637
auto *F = Ctx.createFunction (LLVMF);
638
638
auto *BB = &*F->begin ();
639
639
640
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
640
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
641
641
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
642
642
643
643
auto It = BB->begin ();
@@ -664,7 +664,7 @@ define void @foo(ptr %ptr) {
664
664
auto *F = Ctx.createFunction (LLVMF);
665
665
auto *BB = &*F->begin ();
666
666
667
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
667
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
668
668
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
669
669
670
670
auto It = BB->begin ();
@@ -695,7 +695,7 @@ define void @foo() {
695
695
auto *F = Ctx.createFunction (LLVMF);
696
696
auto *BB = &*F->begin ();
697
697
698
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
698
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
699
699
DAG.extend ({&*BB->begin (), BB->getTerminator ()->getPrevNode ()});
700
700
701
701
auto It = BB->begin ();
@@ -728,7 +728,7 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %v4, i8 %v5) {
728
728
auto *S3 = cast<sandboxir::StoreInst>(&*It++);
729
729
auto *S4 = cast<sandboxir::StoreInst>(&*It++);
730
730
auto *S5 = cast<sandboxir::StoreInst>(&*It++);
731
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
731
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
732
732
{
733
733
// Scenario 1: Build new DAG
734
734
auto NewIntvl = DAG.extend ({S3, S3});
@@ -788,7 +788,7 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %v4, i8 %v5) {
788
788
789
789
{
790
790
// Check UnscheduledSuccs when a node is scheduled
791
- sandboxir::DependencyGraph DAG (getAA (*LLVMF));
791
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx );
792
792
DAG.extend ({S2, S2});
793
793
auto *S2N = cast<sandboxir::MemDGNode>(DAG.getNode (S2));
794
794
S2N->setScheduled (true );
@@ -798,3 +798,35 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %v4, i8 %v5) {
798
798
EXPECT_EQ (S1N->getNumUnscheduledSuccs (), 0u ); // S1 is scheduled
799
799
}
800
800
}
801
+
802
+ TEST_F (DependencyGraphTest, CreateInstrCallback) {
803
+ parseIR (C, R"IR(
804
+ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
805
+ store i8 %v1, ptr %ptr
806
+ store i8 %v2, ptr %ptr
807
+ store i8 %v3, ptr %ptr
808
+ ret void
809
+ }
810
+ )IR" );
811
+ llvm::Function *LLVMF = &*M->getFunction (" foo" );
812
+ sandboxir::Context Ctx (C);
813
+ auto *F = Ctx.createFunction (LLVMF);
814
+ auto *BB = &*F->begin ();
815
+ auto It = BB->begin ();
816
+ auto *S1 = cast<sandboxir::StoreInst>(&*It++);
817
+ [[maybe_unused]] auto *S2 = cast<sandboxir::StoreInst>(&*It++);
818
+ auto *S3 = cast<sandboxir::StoreInst>(&*It++);
819
+
820
+ // Check new instruction callback.
821
+ sandboxir::DependencyGraph DAG (getAA (*LLVMF), Ctx);
822
+ DAG.extend ({S1, S3});
823
+ auto *Arg = F->getArg (3 );
824
+ auto *Ptr = S1->getPointerOperand ();
825
+ sandboxir::StoreInst *NewS =
826
+ sandboxir::StoreInst::create (Arg, Ptr, Align (8 ), S3->getIterator (),
827
+ /* IsVolatile=*/ true , Ctx);
828
+ auto *NewSN = DAG.getNode (NewS);
829
+ EXPECT_TRUE (NewSN != nullptr );
830
+ // TODO: Check the dependencies to/from NewSN after they land.
831
+ // TODO: Check the MemDGNode chain.
832
+ }
0 commit comments