[VPlan] Cleanup and generalize VPIRMetadata CastInfo (NFC) (#190162)
Similar to b0230f59 ([VPlan] Cleanup and generalize VPPhiAccessors CastInfo, #190027).
This commit is contained in:
parent
e6bb6d906a
commit
d0e265f20d
@ -4190,45 +4190,14 @@ struct CastInfo<VPPhiAccessors, VPRecipeBase>
|
||||
: public ForwardToPointerCast<VPPhiAccessors, VPRecipeBase *,
|
||||
CastInfo<VPPhiAccessors, 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,
|
||||
@ -4236,26 +4205,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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user