[Mlir-commits] [llvm] [mlir] [IRBuilder] Remove insertion block (PR #234245)

Antonio Frighetto llvmlistbot at llvm.org
Thu Oct 22 01:22:56 PDT 2026


================
@@ -171,42 +168,39 @@ class IRBuilderBase {
 
   /// Clear the insertion point: created instructions will not be
   /// inserted into a block.
-  void ClearInsertionPoint() {
-    BB = nullptr;
-    InsertPt = BasicBlock::iterator();
-  }
+  void ClearInsertionPoint() { InsertPt = BasicBlock::iterator(); }
 
-  BasicBlock *GetInsertBlock() const { return BB; }
+  BasicBlock *GetInsertBlock() const {
+    return InsertPt.isValid() ? InsertPt.getNodeParent() : nullptr;
+  }
   BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
   LLVMContext &getContext() const { return Context; }
 
   /// Get data layout. Requires that an insertion point is set and connected
   /// to a module.
   const DataLayout &getDataLayout() const {
-    assert(BB && "Must have insertion point to get data layout");
-    return BB->getDataLayout();
+    assert(InsertPt.isValid() &&
+           "Must have insertion point to get data layout");
+    return InsertPt.getNodeParent()->getDataLayout();
   }
 
   /// Get the module. Requires that an insertion point is set and connected
   /// to a module.
   Module *getModule() const {
-    assert(BB && "Must have insertion point to get module");
-    return BB->getModule();
+    assert(InsertPt.isValid() && "Must have insertion point to get module");
+    return InsertPt.getNodeParent()->getModule();
   }
 
   /// This specifies that created instructions should be appended to the
   /// end of the specified block.
-  void SetInsertPoint(BasicBlock *TheBB) {
-    BB = TheBB;
-    InsertPt = BB->end();
-  }
+  void SetInsertPoint(BasicBlock *TheBB) { InsertPt = TheBB->end(); }
 
   /// This specifies that created instructions should be inserted before
   /// the specified instruction.
   void SetInsertPoint(Instruction *I) {
-    BB = I->getParent();
     InsertPt = I->getIterator();
-    assert(InsertPt != BB->end() && "Can't read debug loc from end()");
+    assert(InsertPt != I->getParent()->end() &&
+           "Can't read debug loc from end()");
----------------
antoniofrighetto wrote:

I don't think that would be particularly useful as isValid() would test `&*I` to be non-null (so isValid() would return false only if `I` were nullptr, and, in that case, I->getIterator() would already trigger a null deref). If anything, might make sense anticipate the assert.

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


More information about the Mlir-commits mailing list