[llvm] 2aa1dbf - [SandboxIR] Add a test for creating non-contiguous Regions. (#112027)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 11:01:56 PDT 2024


Author: Jorge Gorbe Moya
Date: 2024-10-11T11:01:52-07:00
New Revision: 2aa1dbf9c92e3b27954ba9166c927616625073e8

URL: https://github.com/llvm/llvm-project/commit/2aa1dbf9c92e3b27954ba9166c927616625073e8
DIFF: https://github.com/llvm/llvm-project/commit/2aa1dbf9c92e3b27954ba9166c927616625073e8.diff

LOG: [SandboxIR] Add a test for creating non-contiguous Regions. (#112027)

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.

Added: 
    

Modified: 
    llvm/unittests/SandboxIR/RegionTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/SandboxIR/RegionTest.cpp b/llvm/unittests/SandboxIR/RegionTest.cpp
index 602534530e248c..a2efe551c8ff2c 100644
--- a/llvm/unittests/SandboxIR/RegionTest.cpp
+++ b/llvm/unittests/SandboxIR/RegionTest.cpp
@@ -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) {


        


More information about the llvm-commits mailing list