[llvm] [VPlan] Add VPPhiAccessors to provide interface for phi recipes (NFC) (PR #129388)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 03:01:50 PDT 2025


================
@@ -1166,6 +1166,30 @@ class VPIRInstruction : public VPRecipeBase {
   void extractLastLaneOfFirstOperand(VPBuilder &Builder);
 };
 
+/// Helper type to provide functions to access incoming values and blocks for
+/// phi-like recipes. RecipeTy must be a sub-class of VPRecipeBase.
+template <typename RecipeTy> class VPPhiAccessors {
+  /// Return a VPRecipeBase* to the current object.
+  const VPRecipeBase *getAsRecipe() const {
+    return static_cast<const RecipeTy *>(this);
----------------
fhahn wrote:

The use case enabled by getting rid of the template argument is supporting `dyn_cast` from `VPRecipeBase` -> `VPPhiAccessors`, as used in https://github.com/llvm/llvm-project/pull/124838 ( https://github.com/llvm/llvm-project/pull/124838/files#diff-a69094b5fcfce6b2bf9e957e2ac7011e5492e81c885129506c90874375e621fbR210) by implementing `CastInfo<VPPhiAccessors, const VPRecipeBase *>`

https://github.com/llvm/llvm-project/pull/129388


More information about the llvm-commits mailing list