Skip to content

Commit 31a13f0

Browse files
committed
fixup! [SandboxVec] Move seed collection into its own separate pass
Adds test that checks that the region Aux vector and the corresponding metadata get updated when an instruction gets deleted
1 parent f51f986 commit 31a13f0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

llvm/unittests/SandboxIR/RegionTest.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,49 @@ define void @foo(i8 %v) {
386386
".*already.*");
387387
}
388388

389+
// Check that Aux automatically drops instructions that get deleted.
390+
TEST_F(RegionTest, AuxDeleteInstr) {
391+
parseIR(C, R"IR(
392+
define void @foo(i8 %v) {
393+
%Add0 = add i8 %v, 0, !sandboxvec !0, !sandboxaux !1
394+
%Add1 = add i8 %v, 1, !sandboxvec !0, !sandboxaux !2
395+
%Add2 = add i8 %v, 2, !sandboxvec !0, !sandboxaux !3
396+
%Add3 = add i8 %v, 2, !sandboxvec !0, !sandboxaux !4
397+
ret void
398+
}
399+
400+
!0 = distinct !{!"sandboxregion"}
401+
!1 = !{i32 0}
402+
!2 = !{i32 1}
403+
!3 = !{i32 2}
404+
!4 = !{i32 3}
405+
)IR");
406+
llvm::Function *LLVMF = &*M->getFunction("foo");
407+
sandboxir::Context Ctx(C);
408+
auto *F = Ctx.createFunction(LLVMF);
409+
auto *BB = &*F->begin();
410+
auto It = BB->begin();
411+
auto *Add0 = &*It++;
412+
auto *Add1 = &*It++;
413+
auto *Add2 = &*It++;
414+
auto *Add3 = &*It++;
415+
SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
416+
sandboxir::Region::createRegionsFromMD(*F, *TTI);
417+
auto &R = *Regions[0];
418+
EXPECT_THAT(R.getAux(), testing::ElementsAre(Add0, Add1, Add2, Add3));
419+
// Now delete Add1 and check that Aux contains nullptr instead of Add1.
420+
Add2->eraseFromParent();
421+
EXPECT_THAT(R.getAux(), testing::ElementsAre(Add0, Add1, Add3));
422+
{
423+
// Check that metadata have also been updated.
424+
// But first drop Add3 to create a legal Aux vector with no gaps.
425+
Add3->eraseFromParent();
426+
SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
427+
sandboxir::Region::createRegionsFromMD(*F, *TTI);
428+
EXPECT_THAT(Regions[0]->getAux(), testing::ElementsAre(Add0, Add1));
429+
}
430+
}
431+
389432
TEST_F(RegionTest, AuxRoundTrip) {
390433
parseIR(C, R"IR(
391434
define i8 @foo(i8 %v0, i8 %v1) {

0 commit comments

Comments
 (0)