2222
2323using namespace llvm ;
2424
25- struct SeedBundleTest : public testing ::Test {
25+ // We need several LLVM data structures to collect seeds from llvm-ir, but they
26+ // have to be constructed as only after parsing the asm string, and most are
27+ // never referred to again. Constructing them as member variables is awkward,
28+ // because gUnit doesn't support custom constructors, so we can't pass the asm
29+ // string as part of test construction. They would have to go in a sub-object
30+ // created after parsing.
31+
32+ #define createLLVMF (FName, AsmString ) \
33+ parseIR (C, AsmString); \
34+ Function &LLVMF = *M->getFunction (FName); \
35+ DominatorTree DT (LLVMF); \
36+ TargetLibraryInfoImpl TLII; \
37+ TargetLibraryInfo TLI (TLII); \
38+ DataLayout DL (M->getDataLayout ()); \
39+ LoopInfo LI (DT); \
40+ AssumptionCache AC (LLVMF); \
41+ ScalarEvolution SE (LLVMF, TLI, AC, DT, LI);
42+
43+ struct SeedCollectorTest : public testing ::Test {
2644 LLVMContext C;
2745 std::unique_ptr<Module> M;
2846
@@ -49,8 +67,8 @@ class SeedBundleForTest : public sandboxir::SeedBundle {
4967 }
5068};
5169
52- TEST_F (SeedBundleTest , SeedBundle) {
53- parseIR (C , R"IR(
70+ TEST_F (SeedCollectorTest , SeedBundle) {
71+ createLLVMF ( " foo " , R"IR(
5472define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
5573bb:
5674 %add0 = fadd float %v0, %v0
@@ -64,10 +82,8 @@ define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
6482 ret void
6583}
6684)IR" );
67- Function &LLVMF = *M->getFunction (" foo" );
6885 sandboxir::Context Ctx (C);
6986 auto &F = *Ctx.createFunction (&LLVMF);
70- DataLayout DL (M->getDataLayout ());
7187 auto *BB = &*F.begin ();
7288 auto It = BB->begin ();
7389 auto *I0 = &*It++;
@@ -145,8 +161,8 @@ define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
145161 EXPECT_EQ (Slice4.size (), 0u );
146162}
147163
148- TEST_F (SeedBundleTest , MemSeedBundle) {
149- parseIR (C , R"IR(
164+ TEST_F (SeedCollectorTest , MemSeedBundle) {
165+ createLLVMF ( " foo " , R"IR(
150166define void @foo(ptr %ptrA, float %val, ptr %ptr) {
151167bb:
152168 %gep0 = getelementptr float, ptr %ptr, i32 0
@@ -166,15 +182,6 @@ define void @foo(ptr %ptrA, float %val, ptr %ptr) {
166182 ret void
167183}
168184)IR" );
169- Function &LLVMF = *M->getFunction (" foo" );
170-
171- DominatorTree DT (LLVMF);
172- TargetLibraryInfoImpl TLII;
173- TargetLibraryInfo TLI (TLII);
174- DataLayout DL (M->getDataLayout ());
175- LoopInfo LI (DT);
176- AssumptionCache AC (LLVMF);
177- ScalarEvolution SE (LLVMF, TLI, AC, DT, LI);
178185
179186 sandboxir::Context Ctx (C);
180187 auto &F = *Ctx.createFunction (&LLVMF);
@@ -206,8 +213,8 @@ define void @foo(ptr %ptrA, float %val, ptr %ptr) {
206213 EXPECT_THAT (LB, testing::ElementsAre (L0, L1, L2, L3));
207214}
208215
209- TEST_F (SeedBundleTest , Container) {
210- parseIR (C , R"IR(
216+ TEST_F (SeedCollectorTest , Container) {
217+ createLLVMF ( " foo " , R"IR(
211218define void @foo(ptr %ptrA, float %val, ptr %ptrB) {
212219bb:
213220 %gepA0 = getelementptr float, ptr %ptrA, i32 0
@@ -221,16 +228,6 @@ define void @foo(ptr %ptrA, float %val, ptr %ptrB) {
221228 ret void
222229}
223230)IR" );
224- Function &LLVMF = *M->getFunction (" foo" );
225-
226- DominatorTree DT (LLVMF);
227- TargetLibraryInfoImpl TLII;
228- TargetLibraryInfo TLI (TLII);
229- DataLayout DL (M->getDataLayout ());
230- LoopInfo LI (DT);
231- AssumptionCache AC (LLVMF);
232- ScalarEvolution SE (LLVMF, TLI, AC, DT, LI);
233-
234231 sandboxir::Context Ctx (C);
235232 auto &F = *Ctx.createFunction (&LLVMF);
236233 auto &BB = *F.begin ();
0 commit comments