[llvm] [SandboxVec] Tag insts in a Region with metadata. (PR #109353)
Sriraman Tallam via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 14:42:11 PDT 2024
================
@@ -79,3 +78,58 @@ define i8 @foo(i8 %v0, i8 %v1) {
EXPECT_EQ(Rgn, Other);
#endif
}
+
+TEST_F(RegionTest, MetadataFromIR) {
+ parseIR(C, R"IR(
+define i8 @foo(i8 %v0, i8 %v1) {
+ %t0 = add i8 %v0, 1, !sbvec !0
+ %t1 = add i8 %t0, %v1, !sbvec !1
+ %t2 = add i8 %t1, %v1, !sbvec !1
+ ret i8 %t2
+}
+
+!0 = distinct !{!"region"}
+!1 = distinct !{!"region"}
+)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++);
+ 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));
+ EXPECT_THAT(Regions[1]->insts(), testing::UnorderedElementsAre(T1, T2));
+}
+
+TEST_F(RegionTest, MetadataRoundTrip) {
+ parseIR(C, R"IR(
+define i8 @foo(i8 %v0, i8 %v1) {
+ %t0 = add i8 %v0, 1
+ %t1 = add i8 %t0, %v1
+ ret i8 %t1
+}
+)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++);
+ auto *T1 = cast<sandboxir::Instruction>(&*It++);
+
+ sandboxir::Region Rgn(Ctx);
+ Rgn.add(T0);
+ Rgn.add(T1);
+
+ SmallVector<std::unique_ptr<sandboxir::Region>> Regions =
+ sandboxir::Region::createRegionsFromMD(*F);
+ ASSERT_EQ(1U, Regions.size());
+#ifndef NDEBUG
+ EXPECT_EQ(Rgn, *Regions[0].get());
+#endif
----------------
tmsri wrote:
How about dumping the IR and explicitly check for required number of "distinct !{!"region"}" and create more than one region?
https://github.com/llvm/llvm-project/pull/109353
More information about the llvm-commits
mailing list