Skip to content

Commit cf4c3a6

Browse files
committed
[Coroutines] Unit tests for addSplitRefRecursiveFunctions.
1 parent 6e3631d commit cf4c3a6

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

llvm/unittests/Analysis/LazyCallGraphTest.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,4 +3027,58 @@ TEST(LazyCallGraphTest, AddSplitFunctions5) {
30273027
EXPECT_EQ(RC, CG.lookupRefSCC(F2N));
30283028
EXPECT_EQ(CG.postorder_ref_scc_end(), I);
30293029
}
3030+
3031+
TEST(LazyCallGraphTest, AddSplitFunctions6) {
3032+
LLVMContext Context;
3033+
std::unique_ptr<Module> M = parseAssembly(Context, "define void @f() {\n"
3034+
" ret void\n"
3035+
"}\n");
3036+
LazyCallGraph CG = buildCG(*M);
3037+
3038+
Function &F = lookupFunction(*M, "f");
3039+
LazyCallGraph::Node &FN = CG.get(F);
3040+
3041+
// Force the graph to be fully expanded.
3042+
CG.buildRefSCCs();
3043+
auto I = CG.postorder_ref_scc_begin();
3044+
LazyCallGraph::RefSCC *ORC = &*I++;
3045+
EXPECT_EQ(CG.postorder_ref_scc_end(), I);
3046+
3047+
auto *G1 = Function::Create(F.getFunctionType(), F.getLinkage(),
3048+
F.getAddressSpace(), "g1", F.getParent());
3049+
auto *G2 = Function::Create(F.getFunctionType(), F.getLinkage(),
3050+
F.getAddressSpace(), "g2", F.getParent());
3051+
BasicBlock *G1BB = BasicBlock::Create(Context, "", G1);
3052+
BasicBlock *G2BB = BasicBlock::Create(Context, "", G2);
3053+
// Create g1 -ref-> g2 and g2 has no references.
3054+
(void)CastInst::CreatePointerCast(G2, PointerType::getUnqual(Context), "",
3055+
G1BB);
3056+
(void)ReturnInst::Create(Context, G1BB);
3057+
(void)ReturnInst::Create(Context, G2BB);
3058+
3059+
// Create f -ref-> g1 and f -ref-> g2.
3060+
(void)CastInst::CreatePointerCast(G1, PointerType::getUnqual(Context), "",
3061+
F.getEntryBlock().begin());
3062+
(void)CastInst::CreatePointerCast(G2, PointerType::getUnqual(Context), "",
3063+
F.getEntryBlock().begin());
3064+
3065+
EXPECT_FALSE(verifyModule(*M, &errs()));
3066+
3067+
CG.addSplitRefRecursiveFunctions(F, SmallVector<Function *, 1>({G1, G2}));
3068+
3069+
LazyCallGraph::Node *G1N = CG.lookup(*G1);
3070+
EXPECT_TRUE(G1N);
3071+
LazyCallGraph::Node *G2N = CG.lookup(*G2);
3072+
EXPECT_TRUE(G2N);
3073+
3074+
I = CG.postorder_ref_scc_begin();
3075+
LazyCallGraph::RefSCC *RC1 = &*I++;
3076+
EXPECT_EQ(2, RC1->size());
3077+
EXPECT_EQ(RC1, CG.lookupRefSCC(*G1N));
3078+
EXPECT_EQ(RC1, CG.lookupRefSCC(*G2N));
3079+
LazyCallGraph::RefSCC *RC2 = &*I++;
3080+
EXPECT_EQ(RC2, ORC);
3081+
EXPECT_EQ(RC2, CG.lookupRefSCC(FN));
3082+
EXPECT_EQ(CG.postorder_ref_scc_end(), I);
3083+
}
30303084
}

0 commit comments

Comments
 (0)