[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated 
https://github.com/llvm/llvm-project/pull/228476

>From f5972378b467bd5c2b97fa6a241969e28e074363 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 2 Oct 2026 16:19:26 +0200
Subject: [PATCH 1/2] [IRBuilder] Deprecate SetInsertPoint with redundant
 BasicBlock argument

Replace calls of `SetInsertPoint(BB, It)` with just `SetInsertPoint(It)`
and deprecate the method accepting the no longer needed BasicBlock
argument.
---
 clang/lib/CodeGen/CGBlocks.cpp|  2 +-
 clang/lib/CodeGen/CGGPUBuiltin.cpp|  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  7 ++-
 clang/lib/CodeGen/CGObjCMac.cpp   |  2 +-
 clang/lib/CodeGen/CGStmt.cpp  |  2 +-
 clang/lib/CodeGen/CodeGenABITypes.cpp |  2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |  2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 11 ++---
 .../Utils/ScalarEvolutionExpander.h   |  4 +-
 llvm/lib/Analysis/MemoryBuiltins.cpp  |  2 +-
 llvm/lib/CodeGen/AtomicExpandPass.cpp |  8 +--
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |  6 +--
 llvm/lib/CodeGen/ExpandIRInsts.cpp|  4 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 44 -
 llvm/lib/IR/Core.cpp  |  2 +-
 .../Target/AMDGPU/AMDGPUAtomicOptimizer.cpp   |  2 +-
 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp   | 14 +++---
 .../Target/ARM/MVELaneInterleavingPass.cpp|  2 +-
 llvm/lib/Target/ARM/MVETailPredication.cpp|  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  2 +-
 .../Hexagon/HexagonVectorLoopCarriedReuse.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp   |  2 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |  2 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  2 +-
 llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp |  4 +-
 llvm/lib/Transforms/Coroutines/CoroFrame.cpp  | 10 ++--
 llvm/lib/Transforms/IPO/Instrumentor.cpp  |  2 +-
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp |  3 +-
 .../InstCombine/InstCombineAndOrXor.cpp   |  2 +-
 .../InstCombine/InstCombineCalls.cpp  |  2 +-
 .../InstCombine/InstCombineCompares.cpp   |  4 +-
 .../Transforms/InstCombine/InstCombinePHI.cpp |  4 +-
 .../InstCombine/InstCombineSelect.cpp |  2 +-
 .../InstCombine/InstCombineVectorOps.cpp  |  2 +-
 llvm/lib/Transforms/Scalar/ExpandMemCmp.cpp   |  6 +--
 llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp |  2 +-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  |  6 +--
 .../lib/Transforms/Scalar/LoopPredication.cpp |  2 +-
 .../Scalar/LowerMatrixIntrinsics.cpp  |  6 +--
 .../Scalar/PartiallyInlineLibCalls.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  4 +-
 llvm/lib/Transforms/Scalar/SROA.cpp   |  5 +-
 .../Scalar/ScalarizeMaskedMemIntrin.cpp   | 16 +++---
 llvm/lib/Transforms/Scalar/Scalarizer.cpp |  4 +-
 .../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp |  4 +-
 .../Transforms/Utils/CallPromotionUtils.cpp   |  2 +-
 llvm/lib/Transforms/Utils/FlattenCFG.cpp  |  3 +-
 llvm/lib/Transforms/Utils/IntegerDivision.cpp |  2 +-
 llvm/lib/Transforms/Utils/LoopUtils.cpp   |  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   |  3 +-
 .../Utils/ScalarEvolutionExpander.cpp |  4 +-
 llvm/lib/Transforms/Utils/SimplifyIndVar.cpp  |  3 +-
 .../lib/Transforms/Utils/SimplifyLibCalls.cpp |  4 +-
 .../Vectorize/LoopIdiomVectorize.cpp  |  2 +-
 .../Transforms/Vectorize/SLPVectorizer.cpp| 49 +++
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  4 +-
 llvm/unittests/Analysis/MemorySSATest.cpp | 24 -
 .../Frontend/OpenMPIRBuilderTest.cpp  |  8 +--
 llvm/unittests/IR/DebugInfoTest.cpp   |  3 +-
 llvm/unittests/IR/IRBuilderTest.cpp   |  2 +-
 .../Transforms/Utils/SSAUpdaterBulkTest.cpp   |  2 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 13 +++--
 polly/lib/CodeGen/BlockGenerators.cpp | 26 +-
 polly/lib/CodeGen/CodeGeneration.cpp  | 11 ++---
 polly/lib/CodeGen/IslExprBuilder.cpp  |  6 +--
 polly/lib/CodeGen/IslNodeBuilder.cpp  | 24 +
 67 files changed, 192 insertions(+), 229 deletions(-)

diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index d653df2b6c8b9e..26c34925b7a651 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1588,7 +1588,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
 entry_ptr = entry_ptr->getNextNode()->getIterator();
   else
 entry_ptr = entry->end();
-  Builder.SetInsertPoint(entry, entry_ptr);
+  Builder.SetInsertPoint(entry_ptr);
 
   // Emit debug information for all the DeclRefExprs.
   // FIXME: also for 'this'
diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 47cac03b645325..5d397b5a0d9d92 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ 

[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Ramkumar Ramachandra via cfe-commits

https://github.com/artagnon approved this pull request.

LGTM, thanks.

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits




nikic wrote:

I think we'll want to keep the method. It's widely used (grep gives more than 
600 hits), and I don't think replacing it with 
`GetInsertPoint().getNodeParent()` would improve things.

As for the `BB` member, yes, we should drop it, but there is some preparatory 
work to do first.

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits


@@ -193,10 +193,7 @@ class IRBuilderBase {
   /// This specifies that created instructions should be inserted at the
   /// specified point.
   void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
-BB = TheBB;
-InsertPt = IP;
-if (IP != TheBB->end())
-  SetCurrentDebugLocation(IP->getStableDebugLoc());

nikic wrote:

This is done by the other overload being called (see the next method after 
this).

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits

https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated 
https://github.com/llvm/llvm-project/pull/228476

>From f5972378b467bd5c2b97fa6a241969e28e074363 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 2 Oct 2026 16:19:26 +0200
Subject: [PATCH 1/3] [IRBuilder] Deprecate SetInsertPoint with redundant
 BasicBlock argument

Replace calls of `SetInsertPoint(BB, It)` with just `SetInsertPoint(It)`
and deprecate the method accepting the no longer needed BasicBlock
argument.
---
 clang/lib/CodeGen/CGBlocks.cpp|  2 +-
 clang/lib/CodeGen/CGGPUBuiltin.cpp|  2 +-
 clang/lib/CodeGen/CGObjC.cpp  |  7 ++-
 clang/lib/CodeGen/CGObjCMac.cpp   |  2 +-
 clang/lib/CodeGen/CGStmt.cpp  |  2 +-
 clang/lib/CodeGen/CodeGenABITypes.cpp |  2 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |  2 +-
 llvm/include/llvm/IR/IRBuilder.h  | 11 ++---
 .../Utils/ScalarEvolutionExpander.h   |  4 +-
 llvm/lib/Analysis/MemoryBuiltins.cpp  |  2 +-
 llvm/lib/CodeGen/AtomicExpandPass.cpp |  8 +--
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |  6 +--
 llvm/lib/CodeGen/ExpandIRInsts.cpp|  4 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp|  2 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 44 -
 llvm/lib/IR/Core.cpp  |  2 +-
 .../Target/AMDGPU/AMDGPUAtomicOptimizer.cpp   |  2 +-
 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp   | 14 +++---
 .../Target/ARM/MVELaneInterleavingPass.cpp|  2 +-
 llvm/lib/Target/ARM/MVETailPredication.cpp|  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  2 +-
 .../Hexagon/HexagonVectorLoopCarriedReuse.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp   |  2 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |  2 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  2 +-
 llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp |  4 +-
 llvm/lib/Transforms/Coroutines/CoroFrame.cpp  | 10 ++--
 llvm/lib/Transforms/IPO/Instrumentor.cpp  |  2 +-
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp |  3 +-
 .../InstCombine/InstCombineAndOrXor.cpp   |  2 +-
 .../InstCombine/InstCombineCalls.cpp  |  2 +-
 .../InstCombine/InstCombineCompares.cpp   |  4 +-
 .../Transforms/InstCombine/InstCombinePHI.cpp |  4 +-
 .../InstCombine/InstCombineSelect.cpp |  2 +-
 .../InstCombine/InstCombineVectorOps.cpp  |  2 +-
 llvm/lib/Transforms/Scalar/ExpandMemCmp.cpp   |  6 +--
 llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp |  2 +-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  |  6 +--
 .../lib/Transforms/Scalar/LoopPredication.cpp |  2 +-
 .../Scalar/LowerMatrixIntrinsics.cpp  |  6 +--
 .../Scalar/PartiallyInlineLibCalls.cpp|  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  4 +-
 llvm/lib/Transforms/Scalar/SROA.cpp   |  5 +-
 .../Scalar/ScalarizeMaskedMemIntrin.cpp   | 16 +++---
 llvm/lib/Transforms/Scalar/Scalarizer.cpp |  4 +-
 .../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp |  4 +-
 .../Transforms/Utils/CallPromotionUtils.cpp   |  2 +-
 llvm/lib/Transforms/Utils/FlattenCFG.cpp  |  3 +-
 llvm/lib/Transforms/Utils/IntegerDivision.cpp |  2 +-
 llvm/lib/Transforms/Utils/LoopUtils.cpp   |  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   |  3 +-
 .../Utils/ScalarEvolutionExpander.cpp |  4 +-
 llvm/lib/Transforms/Utils/SimplifyIndVar.cpp  |  3 +-
 .../lib/Transforms/Utils/SimplifyLibCalls.cpp |  4 +-
 .../Vectorize/LoopIdiomVectorize.cpp  |  2 +-
 .../Transforms/Vectorize/SLPVectorizer.cpp| 49 +++
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |  4 +-
 llvm/unittests/Analysis/MemorySSATest.cpp | 24 -
 .../Frontend/OpenMPIRBuilderTest.cpp  |  8 +--
 llvm/unittests/IR/DebugInfoTest.cpp   |  3 +-
 llvm/unittests/IR/IRBuilderTest.cpp   |  2 +-
 .../Transforms/Utils/SSAUpdaterBulkTest.cpp   |  2 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  | 13 +++--
 polly/lib/CodeGen/BlockGenerators.cpp | 26 +-
 polly/lib/CodeGen/CodeGeneration.cpp  | 11 ++---
 polly/lib/CodeGen/IslExprBuilder.cpp  |  6 +--
 polly/lib/CodeGen/IslNodeBuilder.cpp  | 24 +
 67 files changed, 192 insertions(+), 229 deletions(-)

diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index d653df2b6c8b9e..26c34925b7a651 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1588,7 +1588,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
 entry_ptr = entry_ptr->getNextNode()->getIterator();
   else
 entry_ptr = entry->end();
-  Builder.SetInsertPoint(entry, entry_ptr);
+  Builder.SetInsertPoint(entry_ptr);
 
   // Emit debug information for all the DeclRefExprs.
   // FIXME: also for 'this'
diff --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 47cac03b645325..5d397b5a0d9d92 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ 

[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits

https://github.com/nikic auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Ramkumar Ramachandra via cfe-commits




artagnon wrote:

Sounds good, thanks for the explanation!

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Ramkumar Ramachandra via cfe-commits

https://github.com/artagnon edited 
https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits




nikic wrote:

They can in fact go out of sync, which I learned the hard way in 
https://github.com/llvm/llvm-project/pull/228117. I expect that dropping the 
separate BB member is going to run into similar complications as that PR.

I've left a TODO for dropping the member.

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Ramkumar Ramachandra via cfe-commits




artagnon wrote:

Okay, I was just worried about correctness issues from setting the insert-point 
to a different BB, but if this is not an issue, maybe just add a TODO or FIXME 
for this method and the BB member for future contributors?

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Ramkumar Ramachandra via cfe-commits

https://github.com/artagnon edited 
https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [polly] [IRBuilder] Use SetInsertPoint without redundant BasicBlock argument (PR #228476)

2026-10-03 Thread Nikita Popov via cfe-commits


@@ -193,10 +193,7 @@ class IRBuilderBase {
   /// This specifies that created instructions should be inserted at the
   /// specified point.
   void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {

nikic wrote:

The variant without BasicBlock already exists (the function below this). This 
one will get deprecated. I added a TODO to that effect.

https://github.com/llvm/llvm-project/pull/228476
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits