[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-24 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse closed 
https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-24 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse updated 
https://github.com/llvm/llvm-project/pull/123737

>From 36f969cc26363da7a6a109538d27af2c1d4f59f8 Mon Sep 17 00:00:00 2001
From: Jeremy Morse 
Date: Fri, 17 Jan 2025 17:49:05 +
Subject: [PATCH 1/3] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at
 many call-sites

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use
getFirstNonPHIIt, which returns an iterator. All these call sites are
where it's obviously safe to fetch the iterator then dereference it. A
follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
getFirstNonPHI, but not before adding concise documentation of what
considerations are needed (very few).
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/MicrosoftCXXABI.cpp |  2 +-
 llvm/include/llvm/IR/BasicBlock.h |  2 +-
 .../llvm/Transforms/Utils/Instrumentation.h   |  5 ++
 llvm/lib/Analysis/Loads.cpp   |  2 +-
 llvm/lib/Analysis/LoopNestAnalysis.cpp|  2 +-
 llvm/lib/Analysis/MustExecute.cpp |  2 +-
 llvm/lib/Analysis/ValueTracking.cpp   |  2 +-
 llvm/lib/CodeGen/AsmPrinter/WinException.cpp  |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  6 +-
 llvm/lib/CodeGen/GlobalMerge.cpp  |  2 +-
 llvm/lib/CodeGen/MachineFunction.cpp  |  3 +-
 llvm/lib/CodeGen/SelectOptimize.cpp   |  2 +-
 .../SelectionDAG/FunctionLoweringInfo.cpp |  6 +-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  4 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  9 ++-
 llvm/lib/CodeGen/WasmEHPrepare.cpp| 10 ++--
 llvm/lib/CodeGen/WinEHPrepare.cpp | 58 ++-
 llvm/lib/IR/EHPersonalities.cpp   |  2 +-
 llvm/lib/IR/Instructions.cpp  |  2 +-
 llvm/lib/IR/Verifier.cpp  | 20 +++
 llvm/lib/Target/BPF/BPFAdjustOpt.cpp  |  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  3 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp |  6 +-
 .../Coroutines/MaterializationUtils.cpp   |  6 +-
 llvm/lib/Transforms/IPO/IROutliner.cpp|  2 +-
 llvm/lib/Transforms/IPO/PartialInlining.cpp   |  2 +-
 .../Instrumentation/AddressSanitizer.cpp  |  6 +-
 .../Instrumentation/MemorySanitizer.cpp   |  5 +-
 .../NumericalStabilitySanitizer.cpp   |  4 +-
 .../Instrumentation/PGOInstrumentation.cpp|  6 +-
 .../Instrumentation/PGOMemOPSizeOpt.cpp   |  2 +-
 .../Instrumentation/ThreadSanitizer.cpp   |  8 ++-
 llvm/lib/Transforms/ObjCARC/ObjCARC.cpp   |  4 +-
 .../Transforms/ObjCARC/ObjCARCContract.cpp|  2 +-
 llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp   |  3 +-
 llvm/lib/Transforms/Scalar/GVN.cpp|  3 +-
 llvm/lib/Transforms/Scalar/GVNSink.cpp|  2 +-
 llvm/lib/Transforms/Scalar/LICM.cpp   |  7 ++-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  | 12 ++--
 .../lib/Transforms/Scalar/LoopInterchange.cpp | 17 +++---
 .../lib/Transforms/Scalar/LoopSimplifyCFG.cpp |  2 +-
 llvm/lib/Transforms/Scalar/SCCP.cpp   |  2 +-
 .../Transforms/Utils/BreakCriticalEdges.cpp   |  6 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  6 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  | 47 +++
 llvm/lib/Transforms/Utils/Local.cpp   |  6 +-
 llvm/lib/Transforms/Utils/LoopSimplify.cpp|  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   | 13 +++--
 llvm/lib/Transforms/Utils/MoveAutoInit.cpp|  2 +-
 llvm/lib/Transforms/Utils/SSAUpdater.cpp  |  5 +-
 .../Transforms/Vectorize/LoopVectorize.cpp|  6 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |  7 +--
 .../llvm-reduce/deltas/ReduceBasicBlocks.cpp  |  2 +-
 llvm/unittests/Analysis/MemorySSATest.cpp |  2 +-
 .../Analysis/ProfileSummaryInfoTest.cpp   | 10 ++--
 .../Frontend/OpenMPIRBuilderTest.cpp  | 16 ++---
 llvm/unittests/IR/DebugInfoTest.cpp   | 10 ++--
 llvm/unittests/IR/InstructionsTest.cpp|  4 +-
 llvm/unittests/Transforms/Scalar/LICMTest.cpp |  4 +-
 polly/lib/CodeGen/BlockGenerators.cpp |  8 +--
 polly/lib/CodeGen/LoopGenerators.cpp  |  2 +-
 .../lib/Transform/MaximalStaticExpansion.cpp  |  4 +-
 64 files changed, 224 insertions(+), 200 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 5dc1686e7914c1..5a395c924333e7 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1251,11 +1251,12 @@ void CodeGenFunction:

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-24 Thread Jeremy Morse via cfe-commits

jmorse wrote:

>  Regarding the direction of the patch, it seems a little unfortunate to 
> completely remove getFirstNonPHI() - sometimes we want the instruction and 
> sometimes we want the iterator, and forcing all of them to go through 
> getFirstNonPHIIt() may increase the chances that the iterator and instruction 
> are viewed as interchangeable and lead to people using 
> &*BB->getFirstNonPHIIt() as an insertion point. 

Indeed, this is the sharp end of RemoveDIs, we can't force all behaviours to be 
correct by using the type system, we have to accept some scope for 
misbehaviour. All things considered, I think having the type system bark at you 
beats relying on people to get it right each time. There's also some scope for 
static-analysis and dynamic instrumentation if we end up needing to scan for 
errors / risky behaviours.

(Pushing up rebased version then merging)

https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-24 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse updated 
https://github.com/llvm/llvm-project/pull/123737

>From f88945b08138e01601121bcdf4dd4893bed21a90 Mon Sep 17 00:00:00 2001
From: Jeremy Morse 
Date: Fri, 17 Jan 2025 17:49:05 +
Subject: [PATCH 1/3] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at
 many call-sites

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use
getFirstNonPHIIt, which returns an iterator. All these call sites are
where it's obviously safe to fetch the iterator then dereference it. A
follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
getFirstNonPHI, but not before adding concise documentation of what
considerations are needed (very few).
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/MicrosoftCXXABI.cpp |  2 +-
 llvm/include/llvm/IR/BasicBlock.h |  2 +-
 .../llvm/Transforms/Utils/Instrumentation.h   |  5 ++
 llvm/lib/Analysis/Loads.cpp   |  2 +-
 llvm/lib/Analysis/LoopNestAnalysis.cpp|  2 +-
 llvm/lib/Analysis/MustExecute.cpp |  2 +-
 llvm/lib/Analysis/ValueTracking.cpp   |  2 +-
 llvm/lib/CodeGen/AsmPrinter/WinException.cpp  |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  6 +-
 llvm/lib/CodeGen/GlobalMerge.cpp  |  2 +-
 llvm/lib/CodeGen/MachineFunction.cpp  |  3 +-
 llvm/lib/CodeGen/SelectOptimize.cpp   |  2 +-
 .../SelectionDAG/FunctionLoweringInfo.cpp |  6 +-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  4 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  9 ++-
 llvm/lib/CodeGen/WasmEHPrepare.cpp| 10 ++--
 llvm/lib/CodeGen/WinEHPrepare.cpp | 58 ++-
 llvm/lib/IR/EHPersonalities.cpp   |  2 +-
 llvm/lib/IR/Instructions.cpp  |  2 +-
 llvm/lib/IR/Verifier.cpp  | 20 +++
 llvm/lib/Target/BPF/BPFAdjustOpt.cpp  |  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  3 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp |  6 +-
 .../Coroutines/MaterializationUtils.cpp   |  6 +-
 llvm/lib/Transforms/IPO/IROutliner.cpp|  2 +-
 llvm/lib/Transforms/IPO/PartialInlining.cpp   |  2 +-
 .../Instrumentation/AddressSanitizer.cpp  |  6 +-
 .../Instrumentation/MemorySanitizer.cpp   |  5 +-
 .../NumericalStabilitySanitizer.cpp   |  4 +-
 .../Instrumentation/PGOInstrumentation.cpp|  6 +-
 .../Instrumentation/PGOMemOPSizeOpt.cpp   |  2 +-
 .../Instrumentation/ThreadSanitizer.cpp   |  8 ++-
 llvm/lib/Transforms/ObjCARC/ObjCARC.cpp   |  4 +-
 .../Transforms/ObjCARC/ObjCARCContract.cpp|  2 +-
 llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp   |  3 +-
 llvm/lib/Transforms/Scalar/GVN.cpp|  3 +-
 llvm/lib/Transforms/Scalar/GVNSink.cpp|  2 +-
 llvm/lib/Transforms/Scalar/LICM.cpp   |  7 ++-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  | 12 ++--
 .../lib/Transforms/Scalar/LoopInterchange.cpp | 17 +++---
 .../lib/Transforms/Scalar/LoopSimplifyCFG.cpp |  2 +-
 llvm/lib/Transforms/Scalar/SCCP.cpp   |  2 +-
 .../Transforms/Utils/BreakCriticalEdges.cpp   |  6 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  6 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  | 47 +++
 llvm/lib/Transforms/Utils/Local.cpp   |  6 +-
 llvm/lib/Transforms/Utils/LoopSimplify.cpp|  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   | 13 +++--
 llvm/lib/Transforms/Utils/MoveAutoInit.cpp|  2 +-
 llvm/lib/Transforms/Utils/SSAUpdater.cpp  |  5 +-
 .../Transforms/Vectorize/LoopVectorize.cpp|  6 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |  7 +--
 .../llvm-reduce/deltas/ReduceBasicBlocks.cpp  |  2 +-
 llvm/unittests/Analysis/MemorySSATest.cpp |  2 +-
 .../Analysis/ProfileSummaryInfoTest.cpp   | 10 ++--
 .../Frontend/OpenMPIRBuilderTest.cpp  | 16 ++---
 llvm/unittests/IR/DebugInfoTest.cpp   | 10 ++--
 llvm/unittests/IR/InstructionsTest.cpp|  4 +-
 llvm/unittests/Transforms/Scalar/LICMTest.cpp |  4 +-
 polly/lib/CodeGen/BlockGenerators.cpp |  8 +--
 polly/lib/CodeGen/LoopGenerators.cpp  |  2 +-
 .../lib/Transform/MaximalStaticExpansion.cpp  |  4 +-
 64 files changed, 224 insertions(+), 200 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index e7dd5fb01ebede..75f6f6c44e1fd9 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1251,11 +1251,12 @@ void CodeGenFunction:

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-24 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse updated 
https://github.com/llvm/llvm-project/pull/123737

>From f88945b08138e01601121bcdf4dd4893bed21a90 Mon Sep 17 00:00:00 2001
From: Jeremy Morse 
Date: Fri, 17 Jan 2025 17:49:05 +
Subject: [PATCH 1/2] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at
 many call-sites

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use
getFirstNonPHIIt, which returns an iterator. All these call sites are
where it's obviously safe to fetch the iterator then dereference it. A
follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
getFirstNonPHI, but not before adding concise documentation of what
considerations are needed (very few).
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/MicrosoftCXXABI.cpp |  2 +-
 llvm/include/llvm/IR/BasicBlock.h |  2 +-
 .../llvm/Transforms/Utils/Instrumentation.h   |  5 ++
 llvm/lib/Analysis/Loads.cpp   |  2 +-
 llvm/lib/Analysis/LoopNestAnalysis.cpp|  2 +-
 llvm/lib/Analysis/MustExecute.cpp |  2 +-
 llvm/lib/Analysis/ValueTracking.cpp   |  2 +-
 llvm/lib/CodeGen/AsmPrinter/WinException.cpp  |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  6 +-
 llvm/lib/CodeGen/GlobalMerge.cpp  |  2 +-
 llvm/lib/CodeGen/MachineFunction.cpp  |  3 +-
 llvm/lib/CodeGen/SelectOptimize.cpp   |  2 +-
 .../SelectionDAG/FunctionLoweringInfo.cpp |  6 +-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  4 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  9 ++-
 llvm/lib/CodeGen/WasmEHPrepare.cpp| 10 ++--
 llvm/lib/CodeGen/WinEHPrepare.cpp | 58 ++-
 llvm/lib/IR/EHPersonalities.cpp   |  2 +-
 llvm/lib/IR/Instructions.cpp  |  2 +-
 llvm/lib/IR/Verifier.cpp  | 20 +++
 llvm/lib/Target/BPF/BPFAdjustOpt.cpp  |  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  3 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp |  6 +-
 .../Coroutines/MaterializationUtils.cpp   |  6 +-
 llvm/lib/Transforms/IPO/IROutliner.cpp|  2 +-
 llvm/lib/Transforms/IPO/PartialInlining.cpp   |  2 +-
 .../Instrumentation/AddressSanitizer.cpp  |  6 +-
 .../Instrumentation/MemorySanitizer.cpp   |  5 +-
 .../NumericalStabilitySanitizer.cpp   |  4 +-
 .../Instrumentation/PGOInstrumentation.cpp|  6 +-
 .../Instrumentation/PGOMemOPSizeOpt.cpp   |  2 +-
 .../Instrumentation/ThreadSanitizer.cpp   |  8 ++-
 llvm/lib/Transforms/ObjCARC/ObjCARC.cpp   |  4 +-
 .../Transforms/ObjCARC/ObjCARCContract.cpp|  2 +-
 llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp   |  3 +-
 llvm/lib/Transforms/Scalar/GVN.cpp|  3 +-
 llvm/lib/Transforms/Scalar/GVNSink.cpp|  2 +-
 llvm/lib/Transforms/Scalar/LICM.cpp   |  7 ++-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  | 12 ++--
 .../lib/Transforms/Scalar/LoopInterchange.cpp | 17 +++---
 .../lib/Transforms/Scalar/LoopSimplifyCFG.cpp |  2 +-
 llvm/lib/Transforms/Scalar/SCCP.cpp   |  2 +-
 .../Transforms/Utils/BreakCriticalEdges.cpp   |  6 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  6 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  | 47 +++
 llvm/lib/Transforms/Utils/Local.cpp   |  6 +-
 llvm/lib/Transforms/Utils/LoopSimplify.cpp|  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   | 13 +++--
 llvm/lib/Transforms/Utils/MoveAutoInit.cpp|  2 +-
 llvm/lib/Transforms/Utils/SSAUpdater.cpp  |  5 +-
 .../Transforms/Vectorize/LoopVectorize.cpp|  6 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   |  7 +--
 .../llvm-reduce/deltas/ReduceBasicBlocks.cpp  |  2 +-
 llvm/unittests/Analysis/MemorySSATest.cpp |  2 +-
 .../Analysis/ProfileSummaryInfoTest.cpp   | 10 ++--
 .../Frontend/OpenMPIRBuilderTest.cpp  | 16 ++---
 llvm/unittests/IR/DebugInfoTest.cpp   | 10 ++--
 llvm/unittests/IR/InstructionsTest.cpp|  4 +-
 llvm/unittests/Transforms/Scalar/LICMTest.cpp |  4 +-
 polly/lib/CodeGen/BlockGenerators.cpp |  8 +--
 polly/lib/CodeGen/LoopGenerators.cpp  |  2 +-
 .../lib/Transform/MaximalStaticExpansion.cpp  |  4 +-
 64 files changed, 224 insertions(+), 200 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index e7dd5fb01ebede..75f6f6c44e1fd9 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1251,11 +1251,12 @@ void CodeGenFunction:

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-23 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-23 Thread Stephen Tozer via cfe-commits


@@ -173,8 +173,9 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
 
   // Set the DebugLoc of the inserted PHI, if available.
   DebugLoc DL;
-  if (const Instruction *I = BB->getFirstNonPHI())
-  DL = I->getDebugLoc();
+  BasicBlock::iterator It = BB->getFirstNonPHIIt();
+  if (It != BB->end())
+DL = It->getDebugLoc();

SLTozer wrote:

Possible alternative, YMMV:
```suggestion
  if (BasicBlock::iterator It = BB->getFirstNonPHIIt(); It != BB->end())
DL = It->getDebugLoc();
```

https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-23 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-23 Thread Stephen Tozer via cfe-commits

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

Code changes LGTM. Regarding the direction of the patch, it seems a little 
unfortunate to completely remove `getFirstNonPHI()` - sometimes we want the 
instruction and sometimes we want the iterator, and forcing all of them to go 
through `getFirstNonPHIIt()` _may_ increase the chances that the iterator and 
instruction are viewed as interchangeable and lead to people using 
`&*BB->getFirstNonPHIIt()` as an insertion point. I think the chance of this is 
substantially less likely than using the wrong iterator the current state of 
affairs, however!

https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-23 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer edited 
https://github.com/llvm/llvm-project/pull/123737
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-21 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 1297c1125f9c284e0cc0f2bf50d4b7ba519f7309 
f88945b08138e01601121bcdf4dd4893bed21a90 --extensions cpp,h -- 
clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp 
llvm/include/llvm/IR/BasicBlock.h 
llvm/include/llvm/Transforms/Utils/Instrumentation.h 
llvm/lib/Analysis/Loads.cpp llvm/lib/Analysis/LoopNestAnalysis.cpp 
llvm/lib/Analysis/MustExecute.cpp llvm/lib/Analysis/ValueTracking.cpp 
llvm/lib/CodeGen/AsmPrinter/WinException.cpp 
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/GlobalMerge.cpp 
llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectOptimize.cpp 
llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp 
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp 
llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp 
llvm/lib/CodeGen/WasmEHPrepare.cpp llvm/lib/CodeGen/WinEHPrepare.cpp 
llvm/lib/IR/EHPersonalities.cpp llvm/lib/IR/Instructions.cpp 
llvm/lib/IR/Verifier.cpp llvm/lib/Target/BPF/BPFAdjustOpt.cpp 
llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp 
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp 
llvm/lib/Target/X86/X86WinEHState.cpp 
llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp 
llvm/lib/Transforms/IPO/IROutliner.cpp 
llvm/lib/Transforms/IPO/PartialInlining.cpp 
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp 
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp 
llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp 
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp 
llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp 
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp 
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp 
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp 
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp llvm/lib/Transforms/Scalar/GVN.cpp 
llvm/lib/Transforms/Scalar/GVNSink.cpp llvm/lib/Transforms/Scalar/LICM.cpp 
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp 
llvm/lib/Transforms/Scalar/LoopInterchange.cpp 
llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp 
llvm/lib/Transforms/Scalar/SCCP.cpp 
llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp 
llvm/lib/Transforms/Utils/CodeExtractor.cpp 
llvm/lib/Transforms/Utils/InlineFunction.cpp 
llvm/lib/Transforms/Utils/Local.cpp llvm/lib/Transforms/Utils/LoopSimplify.cpp 
llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp 
llvm/lib/Transforms/Utils/MoveAutoInit.cpp 
llvm/lib/Transforms/Utils/SSAUpdater.cpp 
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
llvm/lib/Transforms/Vectorize/VPlan.cpp 
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp 
llvm/unittests/Analysis/MemorySSATest.cpp 
llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp 
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp 
llvm/unittests/IR/DebugInfoTest.cpp llvm/unittests/IR/InstructionsTest.cpp 
llvm/unittests/Transforms/Scalar/LICMTest.cpp 
polly/lib/CodeGen/BlockGenerators.cpp polly/lib/CodeGen/LoopGenerators.cpp 
polly/lib/Transform/MaximalStaticExpansion.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
index 3f410002f4..4131f71bb5 100644
--- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
@@ -760,9 +760,7 @@ void NumericalStabilitySanitizer::createShadowArguments(
   }))
 return;
 
-  IRBuilder<> Builder(
-  &F.getEntryBlock(),
-  F.getEntryBlock().getFirstNonPHIIt());
+  IRBuilder<> Builder(&F.getEntryBlock(), 
F.getEntryBlock().getFirstNonPHIIt());
   // The function has shadow args if the shadow args tag matches the function
   // address.
   Value *HasShadowArgs = Builder.CreateICmpEQ(
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index c3d094a325..7deaac5e59 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -479,9 +479,8 @@ static bool isTsanAtomic(const Instruction *I) {
 }
 
 void ThreadSanitizer::InsertRuntimeIgnores(Function &F) {
-  InstrumentationIRBuilder IRB(
-  &F.getEntryBlock(),
-  F.getEntryBlock().getFirstNonPHIIt());
+  InstrumentationIRBuilder IRB(&F.getEntryBlock(),
+   F.getEntryBlock().getFirstNonPHIIt());
   IRB.CreateCall(TsanIgnoreBegin);
   EscapeEnumerator EE(F, "tsan_ignore_cleanup", ClHandleCxxExceptions);
   while (IRBuilder<> *AtExit = EE.Next()) {
@@ -571,9 +570,8 @@ bool ThreadSanitizer::sanitizeFunction(Function &F,
 
   // Instrument function entry/exit points if there were instrumented accesses.
   if ((Res || HasCalls) && ClInstrumentFuncEntr

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-21 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-webassembly

Author: Jeremy Morse (jmorse)


Changes

(NB: this will fail CI as it composes with #123583, but I'm not gluing 
them together or it'll be too hard to review).

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a 
debug-info bit that's needed when getFirstNonPHI and similar feed into 
instruction insertion positions. Call-sites where that's necessary were updated 
a year ago; but to ensure some type safety however, we'd like to have all calls 
to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use 
getFirstNonPHIIt, which returns an iterator. All these call sites are where 
it's obviously safe to fetch the iterator then dereference it. A follow-up 
patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, 
but not before adding concise documentation of what considerations are needed 
(very few).

---

Patch is 88.59 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123737.diff


64 Files Affected:

- (modified) clang/lib/CodeGen/CGException.cpp (+4-3) 
- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+1-1) 
- (modified) llvm/include/llvm/IR/BasicBlock.h (+1-1) 
- (modified) llvm/include/llvm/Transforms/Utils/Instrumentation.h (+5) 
- (modified) llvm/lib/Analysis/Loads.cpp (+1-1) 
- (modified) llvm/lib/Analysis/LoopNestAnalysis.cpp (+1-1) 
- (modified) llvm/lib/Analysis/MustExecute.cpp (+1-1) 
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/AsmPrinter/WinException.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+2-1) 
- (modified) llvm/lib/CodeGen/SelectOptimize.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (+4-5) 
- (modified) llvm/lib/CodeGen/WasmEHPrepare.cpp (+5-5) 
- (modified) llvm/lib/CodeGen/WinEHPrepare.cpp (+30-28) 
- (modified) llvm/lib/IR/EHPersonalities.cpp (+1-1) 
- (modified) llvm/lib/IR/Instructions.cpp (+1-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+10-10) 
- (modified) llvm/lib/Target/BPF/BPFAdjustOpt.cpp (+1-1) 
- (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+1-2) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp 
(+2-2) 
- (modified) llvm/lib/Target/X86/X86WinEHState.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp (+3-3) 
- (modified) llvm/lib/Transforms/IPO/IROutliner.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/PartialInlining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+3-2) 
- (modified) 
llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+3-1) 
- (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (+6-2) 
- (modified) llvm/lib/Transforms/ObjCARC/ObjCARC.cpp (+2-2) 
- (modified) llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp (+1-1) 
- (modified) llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp (+2-1) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+2-1) 
- (modified) llvm/lib/Transforms/Scalar/GVNSink.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+4-3) 
- (modified) llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (+6-6) 
- (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+9-8) 
- (modified) llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SCCP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+24-23) 
- (modified) llvm/lib/Transforms/Utils/Local.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/LoopSimplify.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp (+9-4) 
- (modified) llvm/lib/Transforms/Utils/MoveAutoInit.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SSAUpdater.cpp (+3-2) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.cpp (+3-4) 
- (modified) llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp (+1-1) 
- (modified) llvm/unittests/Analysis/MemorySSATest.cpp (+1-1) 
- (modified) llvm/unittests/Analysis/ProfileSummaryInfoTest.cpp (+5-5) 
- (modified) llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp (+8-8) 
- (modified) llvm/unitte

[clang] [llvm] [polly] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (PR #123737)

2025-01-21 Thread Jeremy Morse via cfe-commits

https://github.com/jmorse created 
https://github.com/llvm/llvm-project/pull/123737

(NB: this will fail CI as it composes with #123583, but I'm not gluing them 
together or it'll be too hard to review).

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a 
debug-info bit that's needed when getFirstNonPHI and similar feed into 
instruction insertion positions. Call-sites where that's necessary were updated 
a year ago; but to ensure some type safety however, we'd like to have all calls 
to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use 
getFirstNonPHIIt, which returns an iterator. All these call sites are where 
it's obviously safe to fetch the iterator then dereference it. A follow-up 
patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, 
but not before adding concise documentation of what considerations are needed 
(very few).

>From f88945b08138e01601121bcdf4dd4893bed21a90 Mon Sep 17 00:00:00 2001
From: Jeremy Morse 
Date: Fri, 17 Jan 2025 17:49:05 +
Subject: [PATCH] [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many
 call-sites

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use
getFirstNonPHIIt, which returns an iterator. All these call sites are
where it's obviously safe to fetch the iterator then dereference it. A
follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
getFirstNonPHI, but not before adding concise documentation of what
considerations are needed (very few).
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/MicrosoftCXXABI.cpp |  2 +-
 llvm/include/llvm/IR/BasicBlock.h |  2 +-
 .../llvm/Transforms/Utils/Instrumentation.h   |  5 ++
 llvm/lib/Analysis/Loads.cpp   |  2 +-
 llvm/lib/Analysis/LoopNestAnalysis.cpp|  2 +-
 llvm/lib/Analysis/MustExecute.cpp |  2 +-
 llvm/lib/Analysis/ValueTracking.cpp   |  2 +-
 llvm/lib/CodeGen/AsmPrinter/WinException.cpp  |  4 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  6 +-
 llvm/lib/CodeGen/GlobalMerge.cpp  |  2 +-
 llvm/lib/CodeGen/MachineFunction.cpp  |  3 +-
 llvm/lib/CodeGen/SelectOptimize.cpp   |  2 +-
 .../SelectionDAG/FunctionLoweringInfo.cpp |  6 +-
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  4 +-
 .../CodeGen/SelectionDAG/SelectionDAGISel.cpp |  9 ++-
 llvm/lib/CodeGen/WasmEHPrepare.cpp| 10 ++--
 llvm/lib/CodeGen/WinEHPrepare.cpp | 58 ++-
 llvm/lib/IR/EHPersonalities.cpp   |  2 +-
 llvm/lib/IR/Instructions.cpp  |  2 +-
 llvm/lib/IR/Verifier.cpp  | 20 +++
 llvm/lib/Target/BPF/BPFAdjustOpt.cpp  |  2 +-
 .../Hexagon/HexagonLoopIdiomRecognition.cpp   |  3 +-
 .../WebAssemblyLowerEmscriptenEHSjLj.cpp  |  4 +-
 llvm/lib/Target/X86/X86WinEHState.cpp |  6 +-
 .../Coroutines/MaterializationUtils.cpp   |  6 +-
 llvm/lib/Transforms/IPO/IROutliner.cpp|  2 +-
 llvm/lib/Transforms/IPO/PartialInlining.cpp   |  2 +-
 .../Instrumentation/AddressSanitizer.cpp  |  6 +-
 .../Instrumentation/MemorySanitizer.cpp   |  5 +-
 .../NumericalStabilitySanitizer.cpp   |  4 +-
 .../Instrumentation/PGOInstrumentation.cpp|  6 +-
 .../Instrumentation/PGOMemOPSizeOpt.cpp   |  2 +-
 .../Instrumentation/ThreadSanitizer.cpp   |  8 ++-
 llvm/lib/Transforms/ObjCARC/ObjCARC.cpp   |  4 +-
 .../Transforms/ObjCARC/ObjCARCContract.cpp|  2 +-
 llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp   |  3 +-
 llvm/lib/Transforms/Scalar/GVN.cpp|  3 +-
 llvm/lib/Transforms/Scalar/GVNSink.cpp|  2 +-
 llvm/lib/Transforms/Scalar/LICM.cpp   |  7 ++-
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  | 12 ++--
 .../lib/Transforms/Scalar/LoopInterchange.cpp | 17 +++---
 .../lib/Transforms/Scalar/LoopSimplifyCFG.cpp |  2 +-
 llvm/lib/Transforms/Scalar/SCCP.cpp   |  2 +-
 .../Transforms/Utils/BreakCriticalEdges.cpp   |  6 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  6 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  | 47 +++
 llvm/lib/Transforms/Utils/Local.cpp   |  6 +-
 llvm/lib/Transforms/Utils/LoopSimplify.cpp|  2 +-
 .../Transforms/Utils/LowerMemIntrinsics.cpp   | 13 +++--
 llvm/lib/Transforms/Utils/MoveAutoInit.cpp|  2 +-
 llvm/lib/Transforms/Utils/SSAUpdater.cpp  |  5 +-
 .../Transforms/Vectorize/LoopVectorize.cpp|  6 +-