summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-07-27 22:31:04 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-07-27 22:31:04 +0000
commit991a6241d37f3a32c3bcabc327888ee9907639ca (patch)
treed4f075e4dcf2a4e7f07dcf6748bc46a398ac474c /llvm/unittests
parent4ea707555a9c6b5f38e7a990f8b1549cfd657cf3 (diff)
downloadbcm5719-llvm-991a6241d37f3a32c3bcabc327888ee9907639ca.tar.gz
bcm5719-llvm-991a6241d37f3a32c3bcabc327888ee9907639ca.zip
IR: Expose the method 'getLocalSlot' in the module slot tracker.
This commit publicly exposes the method 'getLocalSlot' in the 'ModuleSlotTracker' class. This change is useful for MIR serialization, to serialize the unnamed basic block and unnamed alloca references. Reviewers: Duncan P. N. Exon Smith llvm-svn: 243336
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/IR/ValueTest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ValueTest.cpp b/llvm/unittests/IR/ValueTest.cpp
index 32d66a1b472..7a4c2f696f7 100644
--- a/llvm/unittests/IR/ValueTest.cpp
+++ b/llvm/unittests/IR/ValueTest.cpp
@@ -175,4 +175,64 @@ TEST(ValueTest, printSlots) {
#undef CHECK_PRINT_AS_OPERAND
}
+TEST(ValueTest, getLocalSlots) {
+ // Verify that the getLocalSlot method returns the correct slot numbers.
+ LLVMContext C;
+ const char *ModuleString = "define void @f(i32 %x, i32 %y) {\n"
+ "entry:\n"
+ " %0 = add i32 %y, 1\n"
+ " %1 = add i32 %y, 1\n"
+ " br label %2\n"
+ "\n"
+ " ret void\n"
+ "}\n";
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString(ModuleString, Err, C);
+
+ Function *F = M->getFunction("f");
+ ASSERT_TRUE(F);
+ ASSERT_FALSE(F->empty());
+ BasicBlock &EntryBB = F->getEntryBlock();
+ ASSERT_EQ(3u, EntryBB.size());
+ BasicBlock *BB2 = ++F->begin();
+ ASSERT_TRUE(BB2);
+
+ Instruction *I0 = EntryBB.begin();
+ ASSERT_TRUE(I0);
+ Instruction *I1 = ++EntryBB.begin();
+ ASSERT_TRUE(I1);
+
+ ModuleSlotTracker MST(M.get());
+ MST.incorporateFunction(*F);
+ EXPECT_EQ(MST.getLocalSlot(I0), 0);
+ EXPECT_EQ(MST.getLocalSlot(I1), 1);
+ EXPECT_EQ(MST.getLocalSlot(&EntryBB), -1);
+ EXPECT_EQ(MST.getLocalSlot(BB2), 2);
+}
+
+#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
+TEST(ValueTest, getLocalSlotDeath) {
+ LLVMContext C;
+ const char *ModuleString = "define void @f(i32 %x, i32 %y) {\n"
+ "entry:\n"
+ " %0 = add i32 %y, 1\n"
+ " %1 = add i32 %y, 1\n"
+ " br label %2\n"
+ "\n"
+ " ret void\n"
+ "}\n";
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString(ModuleString, Err, C);
+
+ Function *F = M->getFunction("f");
+ ASSERT_TRUE(F);
+ ASSERT_FALSE(F->empty());
+ BasicBlock *BB2 = ++F->begin();
+ ASSERT_TRUE(BB2);
+
+ ModuleSlotTracker MST(M.get());
+ EXPECT_DEATH(MST.getLocalSlot(BB2), "No function incorporated");
+}
+#endif
+
} // end anonymous namespace
OpenPOWER on IntegriCloud