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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 04:43:25 PDT 2026


================
@@ -97,13 +97,50 @@ void reportVectorization(OptimizationRemarkEmitter *ORE, Loop *TheLoop,
 
 /// VPlan-based builder utility analogous to IRBuilder.
 class VPBuilder {
-  VPBasicBlock *BB = nullptr;
-  VPBasicBlock::iterator InsertPt = VPBasicBlock::iterator();
+public:
+  /// 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 to insert at \p Point in \p Block.
+    VPInsertPoint(VPBasicBlock *Block, VPBasicBlock::iterator Point)
+        : Block(Block), Point(Point) {}
+
+    /// Creates a new insertion point to insert before \p R.
+    VPInsertPoint(VPRecipeBase *R)
+        : Block(R->getParent()), Point(R->getIterator()) {}
+
+    /// Creates a new insertion point to insert at the end of \p Block.
+    VPInsertPoint(VPBasicBlock *Block) : Block(Block), Point(Block->end()) {}
+
+    /// Returns true if this insert point is set.
+    operator bool() const { return Block; }
+
+    /// Clears Block and Point.
+    void clear() {
+      Block = nullptr;
+      Point = {};
+    }
+
+    VPBasicBlock *getBlock() const { return Block; }
+    operator VPRecipeBase *() const {
----------------
artagnon wrote:

Ah, but we'd have to introduce getPoint to get access to the point or make Point public, both of which I wanted to avoid?

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


More information about the llvm-commits mailing list