[llvm] [VPlan] Add helper to define CastInfo for casting to VP mixins (NFC) (PR #197494)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 01:28:22 PDT 2026
================
@@ -4044,34 +4044,32 @@ class LLVM_ABI_FOR_TEST VPScalarIVStepsRecipe : public VPRecipeWithIRFlags {
#endif
};
+/// CastInfo helper for casting from a recipe superclass (e.g. VPRecipeBase,
+/// VPUser) to a mixin class that is not part of the VPRecipeBase class
+/// hierarchy (e.g. VPPhiAccessors, VPIRMetadata).
+namespace vpdetail {
+template <class VPMixin, class From, class... RecipeTys>
+struct VPMixinCast
+ : public DefaultDoCastIfPossible<VPMixin *, From *,
+ VPMixinCast<VPMixin, From, RecipeTys...>> {
+ static_assert((std::is_base_of_v<VPMixin, RecipeTys> && ...),
+ "Each type in RecipeTys must derive from VPMixin");
+ static bool isPossible(From *R) { return isa<RecipeTys...>(R); }
+ static VPMixin *doCast(From *R) {
+ VPMixin *Out = nullptr;
+ (void)((Out = dyn_cast<RecipeTys>(R)) || ...);
----------------
fhahn wrote:
The `dyn_casts` are from `VPRecipeBase*` to concrete recipe types, which go through a different path (recipe `classof` implementations)
https://github.com/llvm/llvm-project/pull/197494
More information about the llvm-commits
mailing list