Skip to content

Commit cc88413

Browse files
committed
[VPlan] Support isa/dyn_cast from VPRecipeBase to VPIRMetadata (NFC).
Implement CastInfo from VPRecipeBase to VPIRMetadata to support isa/dyn_Cast. This is similar to CastInfoVPPhiAccessors, supporting dyn_cast by down-casting to the concrete recipe types inheriting from VPIRMetadata. Can be used for more generalized VPIRMetadata printing following llvm#165825.
1 parent e5d9644 commit cc88413

File tree

1 file changed

+70
-0
lines changed
  • llvm/lib/Transforms/Vectorize

1 file changed

+70
-0
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,6 +3815,76 @@ template <>
38153815
struct CastInfo<VPPhiAccessors, const VPRecipeBase *>
38163816
: CastInfoVPPhiAccessors<const VPRecipeBase *> {};
38173817

3818+
/// Casting from VPRecipeBase -> VPIRMetadata is supported for all recipe types
3819+
/// implementing VPIRMetadata. Used by isa<> & co.
3820+
template <> struct CastIsPossible<VPIRMetadata, const VPRecipeBase *> {
3821+
static inline bool isPossible(const VPRecipeBase *R) {
3822+
return isa<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
3823+
VPWidenIntrinsicRecipe, VPWidenCallRecipe, VPWidenSelectRecipe,
3824+
VPReplicateRecipe, VPInterleaveRecipe, VPInterleaveEVLRecipe,
3825+
VPWidenLoadRecipe, VPWidenLoadEVLRecipe, VPWidenStoreRecipe,
3826+
VPWidenStoreEVLRecipe>(R);
3827+
}
3828+
};
3829+
3830+
/// Support casting from VPRecipeBase -> VPIRMetadata, by down-casting to the
3831+
/// recipe types implementing VPIRMetadata. Used by cast<>, dyn_cast<> & co.
3832+
template <typename SrcTy>
3833+
struct CastInfoVPIRMetadata : public CastIsPossible<VPIRMetadata, SrcTy> {
3834+
3835+
using Self = CastInfo<VPIRMetadata, SrcTy>;
3836+
3837+
/// doCast is used by cast<>.
3838+
static inline VPIRMetadata *doCast(SrcTy R) {
3839+
return const_cast<VPIRMetadata *>([R]() -> const VPIRMetadata * {
3840+
switch (R->getVPDefID()) {
3841+
case VPDef::VPInstructionSC:
3842+
return cast<VPInstruction>(R);
3843+
case VPDef::VPWidenSC:
3844+
return cast<VPWidenRecipe>(R);
3845+
case VPDef::VPWidenCastSC:
3846+
return cast<VPWidenCastRecipe>(R);
3847+
case VPDef::VPWidenIntrinsicSC:
3848+
return cast<VPWidenIntrinsicRecipe>(R);
3849+
case VPDef::VPWidenCallSC:
3850+
return cast<VPWidenCallRecipe>(R);
3851+
case VPDef::VPWidenSelectSC:
3852+
return cast<VPWidenSelectRecipe>(R);
3853+
case VPDef::VPReplicateSC:
3854+
return cast<VPReplicateRecipe>(R);
3855+
case VPDef::VPInterleaveSC:
3856+
return cast<VPInterleaveRecipe>(R);
3857+
case VPDef::VPInterleaveEVLSC:
3858+
return cast<VPInterleaveEVLRecipe>(R);
3859+
case VPDef::VPWidenLoadSC:
3860+
return cast<VPWidenLoadRecipe>(R);
3861+
case VPDef::VPWidenLoadEVLSC:
3862+
return cast<VPWidenLoadEVLRecipe>(R);
3863+
case VPDef::VPWidenStoreSC:
3864+
return cast<VPWidenStoreRecipe>(R);
3865+
case VPDef::VPWidenStoreEVLSC:
3866+
return cast<VPWidenStoreEVLRecipe>(R);
3867+
default:
3868+
llvm_unreachable("invalid recipe for VPIRMetadata cast");
3869+
}
3870+
}());
3871+
}
3872+
3873+
/// doCastIfPossible is used by dyn_cast<>.
3874+
static inline VPIRMetadata *doCastIfPossible(SrcTy f) {
3875+
if (!Self::isPossible(f))
3876+
return nullptr;
3877+
return doCast(f);
3878+
}
3879+
};
3880+
3881+
template <>
3882+
struct CastInfo<VPIRMetadata, VPRecipeBase *>
3883+
: CastInfoVPIRMetadata<VPRecipeBase *> {};
3884+
template <>
3885+
struct CastInfo<VPIRMetadata, const VPRecipeBase *>
3886+
: CastInfoVPIRMetadata<const VPRecipeBase *> {};
3887+
38183888
/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
38193889
/// holds a sequence of zero or more VPRecipe's each representing a sequence of
38203890
/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.

0 commit comments

Comments
 (0)