[llvm] [VPlan] Cleanup and generalize VPPhiAccessors CastInfo (NFC) (PR #190027)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 04:46:02 PDT 2026
================
@@ -4151,50 +4151,42 @@ class LLVM_ABI_FOR_TEST VPScalarIVStepsRecipe : public VPRecipeWithIRFlags {
#endif
};
-/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
-/// types implementing VPPhiAccessors. Used by isa<> & co.
-template <> struct CastIsPossible<VPPhiAccessors, const VPRecipeBase *> {
- static inline bool isPossible(const VPRecipeBase *f) {
+/// Support casting from VPRecipeBase -> VPPhiAccessors.
+template <>
+struct CastInfo<VPPhiAccessors, VPRecipeBase *>
+ : DefaultDoCastIfPossible<VPPhiAccessors *, VPRecipeBase *,
+ CastInfo<VPPhiAccessors, VPRecipeBase *>> {
+ /// Used by isa.
+ static inline bool isPossible(VPRecipeBase *R) {
// TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
- return isa<VPIRPhi, VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPhi>(f);
- }
-};
-/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
-/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
-template <typename SrcTy>
-struct CastInfoVPPhiAccessors : public CastIsPossible<VPPhiAccessors, SrcTy> {
-
- using Self = CastInfo<VPPhiAccessors, SrcTy>;
-
- /// doCast is used by cast<>.
- static inline VPPhiAccessors *doCast(SrcTy R) {
- return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
- switch (R->getVPRecipeID()) {
- case VPRecipeBase::VPInstructionSC:
- return cast<VPPhi>(R);
- case VPRecipeBase::VPIRInstructionSC:
- return cast<VPIRPhi>(R);
- case VPRecipeBase::VPWidenPHISC:
- return cast<VPWidenPHIRecipe>(R);
- default:
- return cast<VPHeaderPHIRecipe>(R);
- }
- }());
+ return isa<VPPhi, VPIRPhi, VPWidenPHIRecipe, VPHeaderPHIRecipe>(R);
}
-
- /// doCastIfPossible is used by dyn_cast<>.
- static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
- if (!Self::isPossible(f))
- return nullptr;
- return doCast(f);
+ /// Used by cast.
----------------
fhahn wrote:
nit
```suggestion
/// Used by cast.
```
https://github.com/llvm/llvm-project/pull/190027
More information about the llvm-commits
mailing list