-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Transforms] Construct SmallVector with iterator ranges (NFC) #136259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_SmallVector_iter_range_llvm_Transforms
Apr 18, 2025
Merged
[Transforms] Construct SmallVector with iterator ranges (NFC) #136259
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_SmallVector_iter_range_llvm_Transforms
Apr 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136259.diff 9 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
index 3121659edadd8..e25f23107966d 100644
--- a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
+++ b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
@@ -604,9 +604,7 @@ ExpandVariadics::defineVariadicWrapper(Module &M, IRBuilder<> &Builder,
Builder.CreateIntrinsic(Intrinsic::vastart, {DL.getAllocaPtrType(Ctx)},
{VaListInstance});
- SmallVector<Value *> Args;
- for (Argument &A : F.args())
- Args.push_back(&A);
+ SmallVector<Value *> Args(llvm::make_pointer_range(F.args()));
Type *ParameterType = ABI->vaListParameterType(M);
if (ABI->vaListPassedInSSARegister())
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 31e057baee2bf..994ea2f8317fc 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1740,9 +1740,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
OptimizationRemarkEmitter &ORE) {
bool Changed = false;
DT.updateDFSNumbers();
- SmallVector<Value *> FunctionArgs;
- for (Value &Arg : F.args())
- FunctionArgs.push_back(&Arg);
+ SmallVector<Value *> FunctionArgs(llvm::make_pointer_range(F.args()));
ConstraintInfo Info(F.getDataLayout(), FunctionArgs);
State S(DT, LI, SE);
std::unique_ptr<Module> ReproducerModule(
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 3f04f7f57c54f..db97f7e1efcfd 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -599,9 +599,8 @@ bool IndVarSimplify::simplifyAndExtend(Loop *L,
L->getBlocks()[0]->getModule(), Intrinsic::experimental_guard);
bool HasGuards = GuardDecl && !GuardDecl->use_empty();
- SmallVector<PHINode *, 8> LoopPhis;
- for (PHINode &PN : L->getHeader()->phis())
- LoopPhis.push_back(&PN);
+ SmallVector<PHINode *, 8> LoopPhis(
+ llvm::make_pointer_range(L->getHeader()->phis()));
// Each round of simplification iterates through the SimplifyIVUsers worklist
// for all current phis, then determines whether any IVs can be
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 1dccba4cfa7b8..8c8effe2b013e 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1574,13 +1574,11 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader,
P.eraseFromParent();
}
- SmallVector<PHINode *, 8> LcssaInnerExit;
- for (PHINode &P : InnerExit->phis())
- LcssaInnerExit.push_back(&P);
+ SmallVector<PHINode *, 8> LcssaInnerExit(
+ llvm::make_pointer_range(InnerExit->phis()));
- SmallVector<PHINode *, 8> LcssaInnerLatch;
- for (PHINode &P : InnerLatch->phis())
- LcssaInnerLatch.push_back(&P);
+ SmallVector<PHINode *, 8> LcssaInnerLatch(
+ llvm::make_pointer_range(InnerLatch->phis()));
// Lcssa PHIs for values used outside the inner loop are in InnerExit.
// If a PHI node has users outside of InnerExit, it has a use outside the
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index 4524446e5947f..221094f170ac7 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -361,9 +361,8 @@ class ConstantTerminatorFoldingImpl {
for (BasicBlock *BB : DeadExitBlocks) {
// Eliminate all Phis and LandingPads from dead exits.
// TODO: Consider removing all instructions in this dead block.
- SmallVector<Instruction *, 4> DeadInstructions;
- for (auto &PN : BB->phis())
- DeadInstructions.push_back(&PN);
+ SmallVector<Instruction *, 4> DeadInstructions(
+ llvm::make_pointer_range(BB->phis()));
if (auto *LandingPad = dyn_cast<LandingPadInst>(BB->getFirstNonPHIIt()))
DeadInstructions.emplace_back(LandingPad);
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index b78270f6309ff..9ed8b06c22fde 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -165,9 +165,7 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,
MemorySSAUpdater *MSSAU) {
// Recursively deleting a PHI may cause multiple PHIs to be deleted
// or RAUW'd undef, so use an array of WeakTrackingVH for the PHIs to delete.
- SmallVector<WeakTrackingVH, 8> PHIs;
- for (PHINode &PN : BB->phis())
- PHIs.push_back(&PN);
+ SmallVector<WeakTrackingVH, 8> PHIs(llvm::make_pointer_range(BB->phis()));
bool Changed = false;
for (unsigned i = 0, e = PHIs.size(); i != e; ++i)
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 2b055020022be..18af0972bc36d 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -91,10 +91,7 @@ static bool isBlockValidForExtraction(const BasicBlock &BB,
// don't hoist code that uses another basicblock address, as it's likely to
// lead to unexpected behavior, like cross-function jumps
SmallPtrSet<User const *, 16> Visited;
- SmallVector<User const *, 16> ToVisit;
-
- for (Instruction const &Inst : BB)
- ToVisit.push_back(&Inst);
+ SmallVector<User const *, 16> ToVisit(llvm::make_pointer_range(BB));
while (!ToVisit.empty()) {
User const *Curr = ToVisit.pop_back_val();
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index e25ec6c3b2a58..31d8acb706997 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1715,9 +1715,8 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
const TargetTransformInfo *TTI) {
// Find integer phis in order of increasing width.
- SmallVector<PHINode*, 8> Phis;
- for (PHINode &PN : L->getHeader()->phis())
- Phis.push_back(&PN);
+ SmallVector<PHINode *, 8> Phis(
+ llvm::make_pointer_range(L->getHeader()->phis()));
if (TTI)
// Use stable_sort to preserve order of equivalent PHIs, so the order
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 87fcf7e5d9742..bfceee46a237c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8267,9 +8267,8 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
// The vec.epilog.iter.check block may contain Phi nodes from inductions or
// reductions which merge control-flow from the latch block and the middle
// block. Update the incoming values here and move the Phi into the preheader.
- SmallVector<PHINode *, 4> PhisInBlock;
- for (PHINode &Phi : VecEpilogueIterationCountCheck->phis())
- PhisInBlock.push_back(&Phi);
+ SmallVector<PHINode *, 4> PhisInBlock(
+ llvm::make_pointer_range(VecEpilogueIterationCountCheck->phis()));
for (PHINode *Phi : PhisInBlock) {
Phi->moveBefore(LoopVectorPreHeader->getFirstNonPHIIt());
|
kuhar
approved these changes
Apr 18, 2025
fhahn
reviewed
Apr 20, 2025
for (PHINode &Phi : VecEpilogueIterationCountCheck->phis()) | ||
PhisInBlock.push_back(&Phi); | ||
SmallVector<PHINode *, 4> PhisInBlock( | ||
llvm::make_pointer_range(VecEpilogueIterationCountCheck->phis())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llvm::
prefixes should not needed?
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.