[llvm] [SandboxIR] Add a test for creating non-contiguous Regions. (PR #112027)
Jorge Gorbe Moya via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 10:38:37 PDT 2024
https://github.com/slackito created https://github.com/llvm/llvm-project/pull/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.
>From 45eb06cd464ef00a8cf029d96e76ad584f1e1648 Mon Sep 17 00:00:00 2001
From: Jorge Gorbe Moya <jgorbe at google.com>
Date: Fri, 11 Oct 2024 10:30:57 -0700
Subject: [PATCH] [SandboxIR] Add a test for creating non-contiguous Regions.
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.
---
llvm/unittests/SandboxIR/RegionTest.cpp | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
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