[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:47 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 {
+      return Point == Block->end() ? nullptr : &*Point;
+    }
+    template <typename T> void insert(T &R) { return Block->insert(R, Point); }
----------------
fhahn wrote:

```suggestion
    VPBasicBlock *getBlock() const { return Block; }
    
    operator VPRecipeBase *() const {
      return Point == Block->end() ? nullptr : &*Point;
    }
    
    template <typename T> void insert(T &R) { return Block->insert(R, Point); }
```

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


More information about the llvm-commits mailing list