Skip to content

Commit

Permalink
[SandboxIR] Add a test for creating non-contiguous Regions. (llvm#112027
Browse files Browse the repository at this point in the history
)

It checks that a Region can have non-contiguous instructions, and that
when iterating through it you don't get the instructions in-between that
aren't part of the Region.
  • Loading branch information
slackito authored and DanielCChen committed Oct 16, 2024
1 parent bb92fb6 commit 23375e5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions llvm/unittests/SandboxIR/RegionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ define i8 @foo(i8 %v0, i8 %v1) {
EXPECT_THAT(Regions[1]->insts(), testing::UnorderedElementsAre(T1, T2));
}

TEST_F(RegionTest, NonContiguousRegion) {
parseIR(C, R"IR(
define i8 @foo(i8 %v0, i8 %v1) {
%t0 = add i8 %v0, 1, !sandboxvec !0
%t1 = add i8 %t0, %v1
%t2 = add i8 %t1, %v1, !sandboxvec !0
ret i8 %t2
}
!0 = distinct !{!"sandboxregion"}
)IR");
llvm::Function *LLVMF = &*M->getFunction("foo");
sandboxir::Context Ctx(C);
auto *F = Ctx.createFunction(LLVMF);
auto *BB = &*F->begin();
auto It = BB->begin();
auto *T0 = cast<sandboxir::Instruction>(&*It++);
[[maybe_unused]] auto *T1 = cast<sandboxir::Instruction>(&*It++);
auto *T2 = cast<sandboxir::Instruction>(&*It++);

SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
sandboxir::Region::createRegionsFromMD(*F);
EXPECT_THAT(Regions[0]->insts(), testing::UnorderedElementsAre(T0, T2));
}

TEST_F(RegionTest, DumpedMetadata) {
parseIR(C, R"IR(
define i8 @foo(i8 %v0, i8 %v1) {
Expand Down

0 comments on commit 23375e5

Please sign in to comment.