[clang] [llvm] [NFC][DebugInfo] Use iterators for instruction insertion in more places (PR #124291)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 07:30:38 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff c546b5317c518987a5f45dd4c4d25321a955c758 8bafca72573c7ba5e7b7711c5168e0609571661f --extensions h,cpp -- clang/lib/CodeGen/CodeGenFunction.h llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h llvm/lib/CodeGen/CodeGenPrepare.cpp llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp llvm/lib/Transforms/Coroutines/CoroSplit.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp llvm/lib/Transforms/Utils/BasicBlockUtils.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 4c717af0e5..1bc1e0bb87 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -539,7 +539,7 @@ inline void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore,
/// that \p End is assumed > 0, and thus not checked on entry) at \p
/// SplitBefore. Returns the first insert point in the loop body, and the
/// PHINode for the induction variable (i.e. "i" above).
-std::pair<Instruction*, Value*>
+std::pair<Instruction *, Value *>
SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBefore);
/// Utility function for performing a given action on each lane of a vector
@@ -550,9 +550,9 @@ SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBefore);
/// IRBuilder whose insert point is correctly set for instantiating the
/// given index, and a value which is (at runtime) the index to access.
/// This index *may* be a constant.
-void SplitBlockAndInsertForEachLane(ElementCount EC, Type *IndexTy,
- BasicBlock::iterator InsertBefore,
- std::function<void(IRBuilderBase&, Value*)> Func);
+void SplitBlockAndInsertForEachLane(
+ ElementCount EC, Type *IndexTy, BasicBlock::iterator InsertBefore,
+ std::function<void(IRBuilderBase &, Value *)> Func);
/// Utility function for performing a given action on each lane of a vector
/// with \p EVL effective length. EVL is assumed > 0. To simplify porting legacy
diff --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
index 27f22758d2..62b2839295 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
@@ -342,7 +342,8 @@ private:
MoveList createLoadGroups(const AddrList &Group) const;
MoveList createStoreGroups(const AddrList &Group) const;
bool moveTogether(MoveGroup &Move) const;
- template <typename T> InstMap cloneBefore(BasicBlock::iterator To, T &&Insts) const;
+ template <typename T>
+ InstMap cloneBefore(BasicBlock::iterator To, T &&Insts) const;
void realignLoadGroup(IRBuilderBase &Builder, const ByteSpan &VSpan,
int ScLen, Value *AlignVal, Value *AlignAddr) const;
@@ -1076,7 +1077,8 @@ auto AlignVectors::moveTogether(MoveGroup &Move) const -> bool {
}
template <typename T>
-auto AlignVectors::cloneBefore(BasicBlock::iterator To, T &&Insts) const -> InstMap {
+auto AlignVectors::cloneBefore(BasicBlock::iterator To, T &&Insts) const
+ -> InstMap {
InstMap Map;
for (Instruction *I : Insts) {
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index da387c5276..2630ae19da 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1276,8 +1276,8 @@ static bool hasCallsBetween(Instruction *Save, Instruction *ResumeOrDestroy) {
return true;
// Any calls from begging of the block up to ResumeOrDestroy?
- if (hasCallsInBlockBetween({ResumeOrDestroyBB->getFirstNonPHIIt(),
- ResumeOrDestroyIt}))
+ if (hasCallsInBlockBetween(
+ {ResumeOrDestroyBB->getFirstNonPHIIt(), ResumeOrDestroyIt}))
return true;
// Any calls in all of the blocks between SaveBB and ResumeOrDestroyBB?
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 0aa0cbcfc4..e39c42dcbb 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1661,37 +1661,40 @@ void AddressSanitizer::instrumentMaskedLoadOrStore(
if (Stride)
Stride = IB.CreateZExtOrTrunc(Stride, IntptrTy);
- SplitBlockAndInsertForEachLane(EVL, LoopInsertBefore->getIterator(),
- [&](IRBuilderBase &IRB, Value *Index) {
- Value *MaskElem = IRB.CreateExtractElement(Mask, Index);
- if (auto *MaskElemC = dyn_cast<ConstantInt>(MaskElem)) {
- if (MaskElemC->isZero())
- // No check
- return;
- // Unconditional check
- } else {
- // Conditional check
- Instruction *ThenTerm = SplitBlockAndInsertIfThen(
- MaskElem, &*IRB.GetInsertPoint(), false);
- IRB.SetInsertPoint(ThenTerm);
- }
+ SplitBlockAndInsertForEachLane(
+ EVL, LoopInsertBefore->getIterator(),
+ [&](IRBuilderBase &IRB, Value *Index) {
+ Value *MaskElem = IRB.CreateExtractElement(Mask, Index);
+ if (auto *MaskElemC = dyn_cast<ConstantInt>(MaskElem)) {
+ if (MaskElemC->isZero())
+ // No check
+ return;
+ // Unconditional check
+ } else {
+ // Conditional check
+ Instruction *ThenTerm = SplitBlockAndInsertIfThen(
+ MaskElem, &*IRB.GetInsertPoint(), false);
+ IRB.SetInsertPoint(ThenTerm);
+ }
- Value *InstrumentedAddress;
- if (isa<VectorType>(Addr->getType())) {
- assert(
- cast<VectorType>(Addr->getType())->getElementType()->isPointerTy() &&
- "Expected vector of pointer.");
- InstrumentedAddress = IRB.CreateExtractElement(Addr, Index);
- } else if (Stride) {
- Index = IRB.CreateMul(Index, Stride);
- InstrumentedAddress = IRB.CreatePtrAdd(Addr, Index);
- } else {
- InstrumentedAddress = IRB.CreateGEP(VTy, Addr, {Zero, Index});
- }
- doInstrumentAddress(Pass, I, &*IRB.GetInsertPoint(), InstrumentedAddress,
- Alignment, Granularity, ElemTypeSize, IsWrite,
- SizeArgument, UseCalls, Exp, RTCI);
- });
+ Value *InstrumentedAddress;
+ if (isa<VectorType>(Addr->getType())) {
+ assert(cast<VectorType>(Addr->getType())
+ ->getElementType()
+ ->isPointerTy() &&
+ "Expected vector of pointer.");
+ InstrumentedAddress = IRB.CreateExtractElement(Addr, Index);
+ } else if (Stride) {
+ Index = IRB.CreateMul(Index, Stride);
+ InstrumentedAddress = IRB.CreatePtrAdd(Addr, Index);
+ } else {
+ InstrumentedAddress = IRB.CreateGEP(VTy, Addr, {Zero, Index});
+ }
+ doInstrumentAddress(Pass, I, &*IRB.GetInsertPoint(),
+ InstrumentedAddress, Alignment, Granularity,
+ ElemTypeSize, IsWrite, SizeArgument, UseCalls, Exp,
+ RTCI);
+ });
}
void AddressSanitizer::instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 91aef98468..5d191c27b5 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1728,8 +1728,9 @@ void llvm::SplitBlockAndInsertIfThenElse(
}
}
-std::pair<Instruction*, Value*>
-llvm::SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBefore) {
+std::pair<Instruction *, Value *>
+llvm::SplitBlockAndInsertSimpleForLoop(Value *End,
+ BasicBlock::iterator SplitBefore) {
BasicBlock *LoopPred = SplitBefore->getParent();
BasicBlock *LoopBody = SplitBlock(SplitBefore->getParent(), SplitBefore);
BasicBlock *LoopExit = SplitBlock(SplitBefore->getParent(), SplitBefore);
@@ -1755,9 +1756,9 @@ llvm::SplitBlockAndInsertSimpleForLoop(Value *End, BasicBlock::iterator SplitBef
return std::make_pair(&*LoopBody->getFirstNonPHIIt(), IV);
}
-void llvm::SplitBlockAndInsertForEachLane(ElementCount EC,
- Type *IndexTy, BasicBlock::iterator InsertBefore,
- std::function<void(IRBuilderBase&, Value*)> Func) {
+void llvm::SplitBlockAndInsertForEachLane(
+ ElementCount EC, Type *IndexTy, BasicBlock::iterator InsertBefore,
+ std::function<void(IRBuilderBase &, Value *)> Func) {
IRBuilder<> IRB(InsertBefore->getParent(), InsertBefore);
``````````
</details>
https://github.com/llvm/llvm-project/pull/124291
More information about the llvm-commits
mailing list