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

via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 03:52:53 PDT 2025


================
@@ -1166,6 +1166,29 @@ class VPIRInstruction : public VPRecipeBase {
   void extractLastLaneOfFirstOperand(VPBuilder &Builder);
 };
 
+/// Helper type to provide functions to access incoming values and blocks for
+/// phi-like recipes.
+class VPPhiAccessors {
+protected:
+  /// Return a VPRecipeBase* to the current object.
+  virtual const VPRecipeBase *getAsRecipe() const = 0;
+
+public:
+  virtual ~VPPhiAccessors() = default;
+
+  /// Returns the incoming VPValue with index \p Idx.
+  VPValue *getIncomingValue(unsigned Idx) const {
+    return getAsRecipe()->getOperand(Idx);
+  }
+
+  /// Returns the incoming block with index \p Idx.
+  const VPBasicBlock *getIncomingBlock(unsigned Idx) const;
+
+  unsigned getNumIncomingValues() const {
----------------
ayalz wrote:

```suggestion
  /// Returns the number of incoming values, also number of incoming blocks.
  unsigned getNumIncoming() const {
```
its both Values and Blocks?

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


More information about the llvm-commits mailing list