[llvm] [VPlan] Migrate VPBuilder to VPInsertPt fully (NFC) (PR #209764)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 04:26:46 PDT 2026


================
@@ -117,87 +154,44 @@ class VPBuilder {
 
 public:
   VPlan &getPlan() const {
-    assert(getInsertBlock() && "Insert block must be set");
-    return *getInsertBlock()->getPlan();
+    assert(InsertPt && "Insert block must be set");
+    return *InsertPt.getBlock()->getPlan();
   }
 
   VPBuilder() = default;
-  VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); }
-  VPBuilder(VPRecipeBase *InsertPt) { setInsertPoint(InsertPt); }
-  VPBuilder(VPBasicBlock *TheBB, VPBasicBlock::iterator IP) {
-    setInsertPoint(TheBB, IP);
-  }
-
-  /// Clear the insertion point: created instructions will not be inserted into
-  /// a block.
-  void clearInsertionPoint() {
-    BB = nullptr;
-    InsertPt = VPBasicBlock::iterator();
-  }
+  VPBuilder(const VPInsertPoint &IP) : InsertPt(IP) {}
+  VPBuilder(VPBasicBlock *TheBB, VPBasicBlock::iterator IP)
+      : InsertPt(TheBB, IP) {}
 
-  VPBasicBlock *getInsertBlock() const { return BB; }
-  VPBasicBlock::iterator getInsertPoint() const { return InsertPt; }
+  /// Get the recipe at the current point.
+  VPRecipeBase *getRecipe() const { return InsertPt; }
 
   /// Create a VPBuilder to insert after \p R.
   static VPBuilder getToInsertAfter(VPRecipeBase *R) {
-    VPBuilder B;
-    B.setInsertPoint(R->getParent(), std::next(R->getIterator()));
-    return B;
+    return {R->getParent(), std::next(R->getIterator())};
   }
 
-  /// InsertPoint - A saved insertion point.
-  class VPInsertPoint {
-    VPBasicBlock *Block = nullptr;
-    VPBasicBlock::iterator Point;
-
-  public:
-    /// Creates a new insertion point which doesn't point to anything.
-    VPInsertPoint() = default;
-
-    /// Creates a new insertion point at the given location.
-    VPInsertPoint(VPBasicBlock *InsertBlock, VPBasicBlock::iterator InsertPoint)
-        : Block(InsertBlock), Point(InsertPoint) {}
-
-    /// Returns true if this insert point is set.
-    bool isSet() const { return Block != nullptr; }
-
-    VPBasicBlock *getBlock() const { return Block; }
-    VPBasicBlock::iterator getPoint() const { return Point; }
-  };
-
   /// Sets the current insert point to a previously-saved location.
   void restoreIP(VPInsertPoint IP) {
-    if (IP.isSet())
-      setInsertPoint(IP.getBlock(), IP.getPoint());
+    if (IP)
+      setInsertPoint(IP);
     else
-      clearInsertionPoint();
-  }
-
-  /// This specifies that created VPInstructions should be appended to the end
-  /// of the specified block.
-  void setInsertPoint(VPBasicBlock *TheBB) {
-    assert(TheBB && "Attempting to set a null insert point");
-    BB = TheBB;
-    InsertPt = BB->end();
+      InsertPt.clear();
   }
 
-  /// This specifies that created instructions should be inserted at the
-  /// specified point.
-  void setInsertPoint(VPBasicBlock *TheBB, VPBasicBlock::iterator IP) {
-    BB = TheBB;
+  /// Set the current insert point.
+  void setInsertPoint(const VPInsertPoint &IP) {
+    assert(IP && "Attempting to set a null insert point");
     InsertPt = IP;
   }
-
-  /// This specifies that created instructions should be inserted at the
-  /// specified point.
-  void setInsertPoint(VPRecipeBase *IP) {
-    BB = IP->getParent();
-    InsertPt = IP->getIterator();
+  void setInsertPoint(VPBasicBlock *TheBB, VPBasicBlock::iterator IP) {
+    assert(TheBB && "Attempting to set a null insert point");
+    InsertPt = VPInsertPoint(TheBB, IP);
----------------
fhahn wrote:

do we still need this overload going forward, given that we can construct an insert point from BB & IP?

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


More information about the llvm-commits mailing list