[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)
----------------
fhahn wrote:
can this just be `InsertPt = IP;`, removing the need for `clear`?
https://github.com/llvm/llvm-project/pull/209764
More information about the llvm-commits
mailing list