[llvm] r285534 - [SCEV] Reduce boilerplate in unit tests
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 30 20:32:39 PDT 2016
Author: sanjoy
Date: Sun Oct 30 22:32:39 2016
New Revision: 285534
URL: http://llvm.org/viewvc/llvm-project?rev=285534&view=rev
Log:
[SCEV] Reduce boilerplate in unit tests
Modified:
llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp
Modified: llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp?rev=285534&r1=285533&r2=285534&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp Sun Oct 30 22:32:39 2016
@@ -386,7 +386,6 @@ TEST_F(ScalarEvolutionsTest, Commutative
" ret void "
"} "
" "
- " "
"define void @f_3() { "
" %x = load i32, i32* @var_0"
" %y = load i32, i32* @var_1"
@@ -398,14 +397,19 @@ TEST_F(ScalarEvolutionsTest, Commutative
assert(M && "Could not parse module?");
assert(!verifyModule(*M) && "Must have been well formed!");
- {
- auto *F = M->getFunction("f_1");
- ASSERT_NE(F, nullptr);
-
- auto *IV0 = getInstructionByName(*F, "iv0");
- auto *IV0Inc = getInstructionByName(*F, "iv0.inc");
+ auto RunWithFunctionAndSE =
+ [&](StringRef FuncName,
+ function_ref<void(Function &F, ScalarEvolution& SE)> Test) {
+ auto *F = M->getFunction(FuncName);
+ ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
+ ScalarEvolution SE = buildSE(*F);
+ Test(*F, SE);
+ };
+
+ RunWithFunctionAndSE("f_1", [&](Function &F, ScalarEvolution &SE) {
+ auto *IV0 = getInstructionByName(F, "iv0");
+ auto *IV0Inc = getInstructionByName(F, "iv0.inc");
- ScalarEvolution SE = buildSE(*F);
auto *FirstExprForIV0 = SE.getSCEV(IV0);
auto *FirstExprForIV0Inc = SE.getSCEV(IV0Inc);
auto *SecondExprForIV0 = SE.getSCEV(IV0);
@@ -413,29 +417,24 @@ TEST_F(ScalarEvolutionsTest, Commutative
EXPECT_TRUE(isa<SCEVAddRecExpr>(FirstExprForIV0));
EXPECT_TRUE(isa<SCEVAddRecExpr>(FirstExprForIV0Inc));
EXPECT_TRUE(isa<SCEVAddRecExpr>(SecondExprForIV0));
- }
-
- {
- auto *F = M->getFunction("f_2");
- ASSERT_NE(F, nullptr);
-
- ScalarEvolution SE = buildSE(*F);
+ });
- auto *LoadArg0 = SE.getSCEV(getInstructionByName(*F, "x"));
- auto *LoadArg1 = SE.getSCEV(getInstructionByName(*F, "y"));
- auto *LoadArg2 = SE.getSCEV(getInstructionByName(*F, "z"));
+ RunWithFunctionAndSE("f_2", [&](Function &F, ScalarEvolution &SE) {
+ auto *LoadArg0 = SE.getSCEV(getInstructionByName(F, "x"));
+ auto *LoadArg1 = SE.getSCEV(getInstructionByName(F, "y"));
+ auto *LoadArg2 = SE.getSCEV(getInstructionByName(F, "z"));
auto *MulA = SE.getMulExpr(LoadArg0, LoadArg1);
auto *MulB = SE.getMulExpr(LoadArg1, LoadArg0);
EXPECT_EQ(MulA, MulB);
- SmallVector<const SCEV *, 3> Ops0 = { LoadArg0, LoadArg1, LoadArg2 };
- SmallVector<const SCEV *, 3> Ops1 = { LoadArg0, LoadArg2, LoadArg1 };
- SmallVector<const SCEV *, 3> Ops2 = { LoadArg1, LoadArg0, LoadArg2 };
- SmallVector<const SCEV *, 3> Ops3 = { LoadArg1, LoadArg2, LoadArg0 };
- SmallVector<const SCEV *, 3> Ops4 = { LoadArg2, LoadArg1, LoadArg0 };
- SmallVector<const SCEV *, 3> Ops5 = { LoadArg2, LoadArg0, LoadArg1 };
+ SmallVector<const SCEV *, 3> Ops0 = {LoadArg0, LoadArg1, LoadArg2};
+ SmallVector<const SCEV *, 3> Ops1 = {LoadArg0, LoadArg2, LoadArg1};
+ SmallVector<const SCEV *, 3> Ops2 = {LoadArg1, LoadArg0, LoadArg2};
+ SmallVector<const SCEV *, 3> Ops3 = {LoadArg1, LoadArg2, LoadArg0};
+ SmallVector<const SCEV *, 3> Ops4 = {LoadArg2, LoadArg1, LoadArg0};
+ SmallVector<const SCEV *, 3> Ops5 = {LoadArg2, LoadArg0, LoadArg1};
auto *Mul0 = SE.getMulExpr(Ops0);
auto *Mul1 = SE.getMulExpr(Ops1);
@@ -449,21 +448,17 @@ TEST_F(ScalarEvolutionsTest, Commutative
EXPECT_EQ(Mul2, Mul3);
EXPECT_EQ(Mul3, Mul4);
EXPECT_EQ(Mul4, Mul5);
- }
+ });
- {
- auto *F = M->getFunction("f_3");
- ASSERT_NE(F, nullptr);
-
- ScalarEvolution SE = buildSE(*F);
- auto *LoadArg0 = SE.getSCEV(getInstructionByName(*F, "x"));
- auto *LoadArg1 = SE.getSCEV(getInstructionByName(*F, "y"));
+ RunWithFunctionAndSE("f_3", [&](Function &F, ScalarEvolution &SE) {
+ auto *LoadArg0 = SE.getSCEV(getInstructionByName(F, "x"));
+ auto *LoadArg1 = SE.getSCEV(getInstructionByName(F, "y"));
auto *MulA = SE.getMulExpr(LoadArg0, LoadArg1);
auto *MulB = SE.getMulExpr(LoadArg1, LoadArg0);
EXPECT_EQ(MulA, MulB) << "MulA = " << *MulA << ", MulB = " << *MulB;
- }
+ });
}
} // end anonymous namespace
More information about the llvm-commits
mailing list