[llvm] 357bbaa - [VPlan] Add VPRecipeBase::toVPUser helper (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 11:44:05 PDT 2020
Author: Florian Hahn
Date: 2020-10-04T19:43:27+01:00
New Revision: 357bbaab666b212c5bfb65df80e76aace5367eff
URL: https://github.com/llvm/llvm-project/commit/357bbaab666b212c5bfb65df80e76aace5367eff
DIFF: https://github.com/llvm/llvm-project/commit/357bbaab666b212c5bfb65df80e76aace5367eff.diff
LOG: [VPlan] Add VPRecipeBase::toVPUser helper (NFC).
This adds a helper to convert a VPRecipeBase pointer to a VPUser, for
recipes that inherit from VPUser. Once VPRecipeBase directly inherits
from VPUser this helper can be removed.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 95d5cfdcafba..cb5a43272e54 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -77,6 +77,30 @@ void VPRecipeBase::dump() const {
dbgs() << "\n";
}
+VPUser *VPRecipeBase::toVPUser() {
+ if (auto *U = dyn_cast<VPInstruction>(this))
+ return U;
+ if (auto *U = dyn_cast<VPWidenRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPWidenCallRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPWidenSelectRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPWidenGEPRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPBlendRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPInterleaveRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPReplicateRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPBranchOnMaskRecipe>(this))
+ return U;
+ if (auto *U = dyn_cast<VPWidenMemoryInstructionRecipe>(this))
+ return U;
+ return nullptr;
+}
+
// Get the top-most entry block of \p Start. This is the entry block of the
// containing VPlan. This function is templated to support both const and non-const blocks
template <typename T> static T *getPlanEntry(T *Start) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 416a79eacfa7..fae73fdc5782 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -676,10 +676,15 @@ class VPRecipeBase : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock> {
///
/// \returns an iterator pointing to the element after the erased one
iplist<VPRecipeBase>::iterator eraseFromParent();
+
+ /// Returns a pointer to a VPUser, if the recipe inherits from VPUser or
+ /// nullptr otherwise.
+ VPUser *toVPUser();
};
inline bool VPUser::classof(const VPRecipeBase *Recipe) {
- return Recipe->getVPRecipeID() == VPRecipeBase::VPWidenSC ||
+ return Recipe->getVPRecipeID() == VPRecipeBase::VPInstructionSC ||
+ Recipe->getVPRecipeID() == VPRecipeBase::VPWidenSC ||
Recipe->getVPRecipeID() == VPRecipeBase::VPWidenCallSC ||
Recipe->getVPRecipeID() == VPRecipeBase::VPWidenSelectSC ||
Recipe->getVPRecipeID() == VPRecipeBase::VPWidenGEPSC ||
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 926473af7d46..39727ca01d84 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -339,6 +339,16 @@ compound=true
}
}
+TEST(VPRecipeTest, CastVPInstructionToVPUser) {
+ VPValue Op1;
+ VPValue Op2;
+ VPInstruction Recipe(Instruction::Add, {&Op1, &Op2});
+ EXPECT_TRUE(isa<VPUser>(&Recipe));
+ VPRecipeBase *BaseR = &Recipe;
+ EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
+}
+
TEST(VPRecipeTest, CastVPWidenRecipeToVPUser) {
LLVMContext C;
@@ -354,6 +364,7 @@ TEST(VPRecipeTest, CastVPWidenRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&WidenR));
VPRecipeBase *WidenRBase = &WidenR;
EXPECT_TRUE(isa<VPUser>(WidenRBase));
+ EXPECT_EQ(&WidenR, WidenRBase->toVPUser());
delete AI;
}
@@ -372,6 +383,7 @@ TEST(VPRecipeTest, CastVPWidenCallRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
delete Call;
}
@@ -394,6 +406,7 @@ TEST(VPRecipeTest, CastVPWidenSelectRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&WidenSelectR));
VPRecipeBase *BaseR = &WidenSelectR;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&WidenSelectR, BaseR->toVPUser());
delete SelectI;
}
@@ -413,6 +426,7 @@ TEST(VPRecipeTest, CastVPWidenGEPRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
delete GEP;
}
@@ -442,6 +456,7 @@ TEST(VPRecipeTest, CastVPInterleaveRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
}
TEST(VPRecipeTest, CastVPReplicateRecipeToVPUser) {
@@ -468,6 +483,7 @@ TEST(VPRecipeTest, CastVPBranchOnMaskRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
}
TEST(VPRecipeTest, CastVPWidenMemoryInstructionRecipeToVPUser) {
@@ -483,6 +499,7 @@ TEST(VPRecipeTest, CastVPWidenMemoryInstructionRecipeToVPUser) {
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
+ EXPECT_EQ(&Recipe, BaseR->toVPUser());
delete Load;
}
More information about the llvm-commits
mailing list