Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@

using namespace llvm;

struct SeedBundleTest : public testing::Test {
// We need several LLVM data structures to collect seeds from llvm-ir, but they
// have to be constructed as only after parsing the asm string, and most are
// never referred to again. Constructing them as member variables is awkward,
// because gUnit doesn't support custom constructors, so we can't pass the asm
// string as part of test construction. They would have to go in a sub-object
// created after parsing.

#define createLLVMF(FName, AsmString) \
parseIR(C, AsmString); \
Function &LLVMF = *M->getFunction(FName); \
DominatorTree DT(LLVMF); \
TargetLibraryInfoImpl TLII; \
TargetLibraryInfo TLI(TLII); \
DataLayout DL(M->getDataLayout()); \
LoopInfo LI(DT); \
AssumptionCache AC(LLVMF); \
ScalarEvolution SE(LLVMF, TLI, AC, DT, LI);

struct SeedCollectorTest : public testing::Test {
LLVMContext C;
std::unique_ptr<Module> M;

Expand All @@ -49,8 +67,8 @@ class SeedBundleForTest : public sandboxir::SeedBundle {
}
};

TEST_F(SeedBundleTest, SeedBundle) {
parseIR(C, R"IR(
TEST_F(SeedCollectorTest, SeedBundle) {
createLLVMF("foo", R"IR(
define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
bb:
%add0 = fadd float %v0, %v0
Expand All @@ -64,10 +82,8 @@ define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
ret void
}
)IR");
Function &LLVMF = *M->getFunction("foo");
sandboxir::Context Ctx(C);
auto &F = *Ctx.createFunction(&LLVMF);
DataLayout DL(M->getDataLayout());
auto *BB = &*F.begin();
auto It = BB->begin();
auto *I0 = &*It++;
Expand Down Expand Up @@ -145,8 +161,8 @@ define void @foo(float %v0, i32 %i0, i16 %i1, i8 %i2) {
EXPECT_EQ(Slice4.size(), 0u);
}

TEST_F(SeedBundleTest, MemSeedBundle) {
parseIR(C, R"IR(
TEST_F(SeedCollectorTest, MemSeedBundle) {
createLLVMF("foo", R"IR(
define void @foo(ptr %ptrA, float %val, ptr %ptr) {
bb:
%gep0 = getelementptr float, ptr %ptr, i32 0
Expand All @@ -166,15 +182,6 @@ define void @foo(ptr %ptrA, float %val, ptr %ptr) {
ret void
}
)IR");
Function &LLVMF = *M->getFunction("foo");

DominatorTree DT(LLVMF);
TargetLibraryInfoImpl TLII;
TargetLibraryInfo TLI(TLII);
DataLayout DL(M->getDataLayout());
LoopInfo LI(DT);
AssumptionCache AC(LLVMF);
ScalarEvolution SE(LLVMF, TLI, AC, DT, LI);

sandboxir::Context Ctx(C);
auto &F = *Ctx.createFunction(&LLVMF);
Expand Down Expand Up @@ -206,8 +213,8 @@ define void @foo(ptr %ptrA, float %val, ptr %ptr) {
EXPECT_THAT(LB, testing::ElementsAre(L0, L1, L2, L3));
}

TEST_F(SeedBundleTest, Container) {
parseIR(C, R"IR(
TEST_F(SeedCollectorTest, Container) {
createLLVMF("foo", R"IR(
define void @foo(ptr %ptrA, float %val, ptr %ptrB) {
bb:
%gepA0 = getelementptr float, ptr %ptrA, i32 0
Expand All @@ -221,16 +228,6 @@ define void @foo(ptr %ptrA, float %val, ptr %ptrB) {
ret void
}
)IR");
Function &LLVMF = *M->getFunction("foo");

DominatorTree DT(LLVMF);
TargetLibraryInfoImpl TLII;
TargetLibraryInfo TLI(TLII);
DataLayout DL(M->getDataLayout());
LoopInfo LI(DT);
AssumptionCache AC(LLVMF);
ScalarEvolution SE(LLVMF, TLI, AC, DT, LI);

sandboxir::Context Ctx(C);
auto &F = *Ctx.createFunction(&LLVMF);
auto &BB = *F.begin();
Expand Down
Loading