diff options
author | Brian Gesiak <modocache@gmail.com> | 2020-02-17 16:46:33 -0500 |
---|---|---|
committer | Brian Gesiak <modocache@gmail.com> | 2020-02-17 16:59:25 -0500 |
commit | 0deef2e164e1db5e262fb14906c97b01b74a24dd (patch) | |
tree | 72895ae07dfea549e3f7b2bb610fc3af84eda54a /llvm/unittests/Analysis/LazyCallGraphTest.cpp | |
parent | 612c4bf09e014a110c722835d6158ea48ab94cce (diff) | |
download | llvm-0deef2e164e1db5e262fb14906c97b01b74a24dd.zip llvm-0deef2e164e1db5e262fb14906c97b01b74a24dd.tar.gz llvm-0deef2e164e1db5e262fb14906c97b01b74a24dd.tar.bz2 |
Re-land "Add LazyCallGraph API to add function to RefSCC"
This re-commits https://reviews.llvm.org/D70927, which I reverted in
https://reviews.llvm.org/rG28213680b2a7d1fdeea16aa3f3a368879472c72a due
to a buildbot error:
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/13251
I no longer include a test case that appears to crash when built with the
buildbot's compiler, GCC 5.4.0.
Diffstat (limited to 'llvm/unittests/Analysis/LazyCallGraphTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/LazyCallGraphTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp index 3be4636..a507367 100644 --- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp +++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp @@ -2210,4 +2210,46 @@ TEST(LazyCallGraphTest, RemoveFunctionWithSpurriousRef) { EXPECT_EQ(&RC2, &*I++); EXPECT_EQ(CG.postorder_ref_scc_end(), I); } + +TEST(LazyCallGraphTest, AddNewFunctionIntoRefSCC) { + LLVMContext Context; + // Build and populate a graph composed of a single, self-referential node. + std::unique_ptr<Module> M = parseAssembly(Context, "define void @f() {\n" + "entry:\n" + " call void @f()\n" + " ret void\n" + "}\n"); + LazyCallGraph CG = buildCG(*M); + CG.buildRefSCCs(); + + // At this point 'f' is in the call graph. + auto &F = lookupFunction(*M, "f"); + LazyCallGraph::Node *FN = CG.lookup(F); + EXPECT_NE(FN, nullptr); + + // And it has an SCC, of course. + auto *FSCC = CG.lookupSCC(*FN); + EXPECT_NE(FSCC, nullptr); + + // Now, create a new function 'g'. + auto *G = Function::Create(F.getFunctionType(), F.getLinkage(), + F.getAddressSpace(), "g", F.getParent()); + BasicBlock::Create(F.getParent()->getContext(), "entry", G); + + // Instruct the LazyCallGraph to create a new node for 'g', within the same + // RefSCC as 'f', but in a separate SCC. + CG.addNewFunctionIntoRefSCC(*G, FSCC->getOuterRefSCC()); + + // 'g' should now be in the call graph. + LazyCallGraph::Node *GN = CG.lookup(*G); + EXPECT_NE(GN, nullptr); + // 'g' should have an SCC, composed of the singular node 'g'. + // ('f' should not be included in the 'g' SCC.) + LazyCallGraph::SCC *GSCC = CG.lookupSCC(*GN); + EXPECT_NE(GSCC, nullptr); + EXPECT_EQ(GSCC->size(), 1); + EXPECT_NE(GSCC, FSCC); + // 'g' and 'f' should be part of the same RefSCC. + EXPECT_EQ(&GSCC->getOuterRefSCC(), &FSCC->getOuterRefSCC()); +} } |