[llvm] [VPlan] Cleanup and generalize VPIRMetadata CastInfo (NFC) (PR #190162)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 05:31:26 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/190162
None
>From 05251c342b126ffbf918f46544c6aca3b41976f2 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Thu, 2 Apr 2026 13:17:16 +0100
Subject: [PATCH] [VPlan] Cleanup and generalize VPIRMetadata CastInfo (NFC)
---
llvm/lib/Transforms/Vectorize/VPlan.h | 98 ++++++++++++---------------
1 file changed, 44 insertions(+), 54 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index ab47d927942db..a0e8ac95c0b30 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4196,45 +4196,14 @@ template <>
struct CastInfo<VPPhiAccessors, const VPRecipeBase *>
: CastInfoVPPhiAccessors<const VPRecipeBase *> {};
-/// Casting from (const) VPRecipeBase -> (const) VPIRMetadata is supported for
-/// all recipe types implementing VPIRMetadata. Used by isa<> & co.
-namespace detail {
-template <typename DstTy, typename RecipeBasePtrTy>
-static inline auto castToVPIRMetadata(RecipeBasePtrTy R) -> DstTy {
- switch (R->getVPRecipeID()) {
- case VPRecipeBase::VPInstructionSC:
- return cast<VPInstruction>(R);
- case VPRecipeBase::VPWidenSC:
- return cast<VPWidenRecipe>(R);
- case VPRecipeBase::VPWidenCastSC:
- return cast<VPWidenCastRecipe>(R);
- case VPRecipeBase::VPWidenIntrinsicSC:
- return cast<VPWidenIntrinsicRecipe>(R);
- case VPRecipeBase::VPWidenCallSC:
- return cast<VPWidenCallRecipe>(R);
- case VPRecipeBase::VPReplicateSC:
- return cast<VPReplicateRecipe>(R);
- case VPRecipeBase::VPInterleaveSC:
- case VPRecipeBase::VPInterleaveEVLSC:
- return cast<VPInterleaveBase>(R);
- case VPRecipeBase::VPWidenLoadSC:
- case VPRecipeBase::VPWidenLoadEVLSC:
- case VPRecipeBase::VPWidenStoreSC:
- case VPRecipeBase::VPWidenStoreEVLSC:
- return cast<VPWidenMemoryRecipe>(R);
- default:
- llvm_unreachable("invalid recipe for VPIRMetadata cast");
- }
-}
-} // namespace detail
-
-/// Support casting from VPRecipeBase -> VPIRMetadata, by down-casting to the
-/// recipe types implementing VPIRMetadata. Used by cast<>, dyn_cast<> & co.
-template <typename DstTy, typename SrcTy>
-struct CastInfoVPIRMetadata : public CastIsPossible<DstTy, SrcTy> {
- static inline bool isPossible(SrcTy R) {
- // NOTE: Each recipe inheriting from VPIRMetadata must be listed here and
- // also handled in castToVPIRMetadata.
+/// Support casting from VPRecipeBase -> VPIRMetadata.
+template <>
+struct CastInfo<VPIRMetadata, VPRecipeBase *>
+ : public DefaultDoCastIfPossible<VPIRMetadata *, VPRecipeBase *,
+ CastInfo<VPIRMetadata, VPRecipeBase *>> {
+ /// Used by isa.
+ static inline bool isPossible(VPRecipeBase *R) {
+ // NOTE: Each recipe inheriting from VPIRMetadata must be listed here.
return isa<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
VPWidenIntrinsicRecipe, VPWidenCallRecipe, VPReplicateRecipe,
VPInterleaveRecipe, VPInterleaveEVLRecipe, VPWidenLoadRecipe,
@@ -4242,26 +4211,47 @@ struct CastInfoVPIRMetadata : public CastIsPossible<DstTy, SrcTy> {
R);
}
- using RetTy = DstTy *;
-
- /// doCast is used by cast<>.
- static inline RetTy doCast(SrcTy R) {
- return detail::castToVPIRMetadata<RetTy, SrcTy>(R);
+ /// Used by cast.
+ static inline VPIRMetadata *doCast(VPRecipeBase *R) {
+ switch (R->getVPRecipeID()) {
+ case VPRecipeBase::VPInstructionSC:
+ return cast<VPInstruction>(R);
+ case VPRecipeBase::VPWidenSC:
+ return cast<VPWidenRecipe>(R);
+ case VPRecipeBase::VPWidenCastSC:
+ return cast<VPWidenCastRecipe>(R);
+ case VPRecipeBase::VPWidenIntrinsicSC:
+ return cast<VPWidenIntrinsicRecipe>(R);
+ case VPRecipeBase::VPWidenCallSC:
+ return cast<VPWidenCallRecipe>(R);
+ case VPRecipeBase::VPReplicateSC:
+ return cast<VPReplicateRecipe>(R);
+ case VPRecipeBase::VPInterleaveSC:
+ case VPRecipeBase::VPInterleaveEVLSC:
+ return cast<VPInterleaveBase>(R);
+ case VPRecipeBase::VPWidenLoadSC:
+ case VPRecipeBase::VPWidenLoadEVLSC:
+ case VPRecipeBase::VPWidenStoreSC:
+ case VPRecipeBase::VPWidenStoreEVLSC:
+ return cast<VPWidenMemoryRecipe>(R);
+ default:
+ llvm_unreachable("Illegal recipe for VPIRMetadata cast");
+ }
}
- /// doCastIfPossible is used by dyn_cast<>.
- static inline RetTy doCastIfPossible(SrcTy R) {
- if (!isPossible(R))
- return nullptr;
- return doCast(R);
- }
+ /// Used by inherited doCastIfPossible to dyn_cast.
+ static inline VPIRMetadata *castFailed() { return nullptr; }
};
-template <>
-struct CastInfo<VPIRMetadata, VPRecipeBase *>
- : CastInfoVPIRMetadata<VPIRMetadata, VPRecipeBase *> {};
+
template <>
struct CastInfo<VPIRMetadata, const VPRecipeBase *>
- : CastInfoVPIRMetadata<const VPIRMetadata, const VPRecipeBase *> {};
+ : public ConstStrippingForwardingCast<
+ VPIRMetadata, const VPRecipeBase *,
+ CastInfo<VPIRMetadata, VPRecipeBase *>> {};
+template <>
+struct CastInfo<VPIRMetadata, VPRecipeBase>
+ : public ForwardToPointerCast<VPIRMetadata, VPRecipeBase *,
+ CastInfo<VPIRMetadata, VPRecipeBase *>> {};
/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
/// holds a sequence of zero or more VPRecipe's each representing a sequence of
More information about the llvm-commits
mailing list