aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/LazyCallGraphTest.cpp
diff options
context:
space:
mode:
authorJohannes Doerfert <johannes@jdoerfert.de>2019-11-29 13:11:24 -0600
committerJohannes Doerfert <johannes@jdoerfert.de>2020-02-08 14:16:48 -0600
commit72277ecd62e28a01bb98866c1b15d5f172ed30dc (patch)
treeb44704bc5d6227d472dbeb90dcda2801231ccd1b /llvm/unittests/Analysis/LazyCallGraphTest.cpp
parentf8c9ceb1ce9c71574d413a6391812d46d9f9edb3 (diff)
downloadllvm-72277ecd62e28a01bb98866c1b15d5f172ed30dc.zip
llvm-72277ecd62e28a01bb98866c1b15d5f172ed30dc.tar.gz
llvm-72277ecd62e28a01bb98866c1b15d5f172ed30dc.tar.bz2
Introduce a CallGraph updater helper class
The CallGraphUpdater is a helper that simplifies the process of updating the call graph, both old and new style, while running an CGSCC pass. The uses are contained in different commits, e.g. D70767. More functionality is added as we need it. Reviewed By: modocache, hfinkel Differential Revision: https://reviews.llvm.org/D70927
Diffstat (limited to 'llvm/unittests/Analysis/LazyCallGraphTest.cpp')
-rw-r--r--llvm/unittests/Analysis/LazyCallGraphTest.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
index 0da34eb..be7d458 100644
--- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp
+++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
@@ -450,6 +450,47 @@ TEST(LazyCallGraphTest, BasicGraphMutation) {
EXPECT_EQ(0, std::distance(B->begin(), B->end()));
}
+TEST(LazyCallGraphTest, BasicGraphMutationOutlining) {
+ LLVMContext Context;
+ std::unique_ptr<Module> M = parseAssembly(Context, "define void @a() {\n"
+ "entry:\n"
+ " call void @b()\n"
+ " call void @c()\n"
+ " ret void\n"
+ "}\n"
+ "define void @b() {\n"
+ "entry:\n"
+ " ret void\n"
+ "}\n"
+ "define void @c() {\n"
+ "entry:\n"
+ " ret void\n"
+ "}\n");
+ LazyCallGraph CG = buildCG(*M);
+
+ LazyCallGraph::Node &A = CG.get(lookupFunction(*M, "a"));
+ LazyCallGraph::Node &B = CG.get(lookupFunction(*M, "b"));
+ LazyCallGraph::Node &C = CG.get(lookupFunction(*M, "c"));
+ A.populate();
+ B.populate();
+ C.populate();
+ CG.buildRefSCCs();
+
+ // Add a new function that is called from @b and verify it is in the same SCC.
+ Function &BFn = B.getFunction();
+ Function *NewFn =
+ Function::Create(BFn.getFunctionType(), BFn.getLinkage(), "NewFn", *M);
+ auto IP = BFn.getEntryBlock().getFirstInsertionPt();
+ CallInst::Create(NewFn, "", &*IP);
+ CG.addNewFunctionIntoSCC(*NewFn, *CG.lookupSCC(B));
+
+ EXPECT_EQ(CG.lookupSCC(A)->size(), 1U);
+ EXPECT_EQ(CG.lookupSCC(B)->size(), 2U);
+ EXPECT_EQ(CG.lookupSCC(C)->size(), 1U);
+ EXPECT_EQ(CG.lookupSCC(*CG.lookup(*NewFn))->size(), 2U);
+ EXPECT_EQ(CG.lookupSCC(*CG.lookup(*NewFn))->size(), CG.lookupSCC(B)->size());
+}
+
TEST(LazyCallGraphTest, InnerSCCFormation) {
LLVMContext Context;
std::unique_ptr<Module> M = parseAssembly(Context, DiamondOfTriangles);