diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index a49a0177c736..21016f84d48a 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -4190,45 +4190,14 @@ struct CastInfo : public ForwardToPointerCast> {}; -/// Casting from (const) VPRecipeBase -> (const) VPIRMetadata is supported for -/// all recipe types implementing VPIRMetadata. Used by isa<> & co. -namespace detail { -template -static inline auto castToVPIRMetadata(RecipeBasePtrTy R) -> DstTy { - switch (R->getVPRecipeID()) { - case VPRecipeBase::VPInstructionSC: - return cast(R); - case VPRecipeBase::VPWidenSC: - return cast(R); - case VPRecipeBase::VPWidenCastSC: - return cast(R); - case VPRecipeBase::VPWidenIntrinsicSC: - return cast(R); - case VPRecipeBase::VPWidenCallSC: - return cast(R); - case VPRecipeBase::VPReplicateSC: - return cast(R); - case VPRecipeBase::VPInterleaveSC: - case VPRecipeBase::VPInterleaveEVLSC: - return cast(R); - case VPRecipeBase::VPWidenLoadSC: - case VPRecipeBase::VPWidenLoadEVLSC: - case VPRecipeBase::VPWidenStoreSC: - case VPRecipeBase::VPWidenStoreEVLSC: - return cast(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 -struct CastInfoVPIRMetadata : public CastIsPossible { - 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 + : public DefaultDoCastIfPossible> { + /// Used by isa. + static inline bool isPossible(VPRecipeBase *R) { + // NOTE: Each recipe inheriting from VPIRMetadata must be listed here. return isa { R); } - using RetTy = DstTy *; - - /// doCast is used by cast<>. - static inline RetTy doCast(SrcTy R) { - return detail::castToVPIRMetadata(R); + /// Used by cast. + static inline VPIRMetadata *doCast(VPRecipeBase *R) { + switch (R->getVPRecipeID()) { + case VPRecipeBase::VPInstructionSC: + return cast(R); + case VPRecipeBase::VPWidenSC: + return cast(R); + case VPRecipeBase::VPWidenCastSC: + return cast(R); + case VPRecipeBase::VPWidenIntrinsicSC: + return cast(R); + case VPRecipeBase::VPWidenCallSC: + return cast(R); + case VPRecipeBase::VPReplicateSC: + return cast(R); + case VPRecipeBase::VPInterleaveSC: + case VPRecipeBase::VPInterleaveEVLSC: + return cast(R); + case VPRecipeBase::VPWidenLoadSC: + case VPRecipeBase::VPWidenLoadEVLSC: + case VPRecipeBase::VPWidenStoreSC: + case VPRecipeBase::VPWidenStoreEVLSC: + return cast(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 - : CastInfoVPIRMetadata {}; + template <> struct CastInfo - : CastInfoVPIRMetadata {}; + : public ConstStrippingForwardingCast< + VPIRMetadata, const VPRecipeBase *, + CastInfo> {}; +template <> +struct CastInfo + : public ForwardToPointerCast> {}; /// 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