Skip to content

Commit b2ba531

Browse files
[Transforms] Construct SmallVector with iterator ranges (NFC) (#136259)
1 parent 58774f1 commit b2ba531

File tree

9 files changed

+16
-31
lines changed

9 files changed

+16
-31
lines changed

llvm/lib/Transforms/IPO/ExpandVariadics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,7 @@ ExpandVariadics::defineVariadicWrapper(Module &M, IRBuilder<> &Builder,
604604
Builder.CreateIntrinsic(Intrinsic::vastart, {DL.getAllocaPtrType(Ctx)},
605605
{VaListInstance});
606606

607-
SmallVector<Value *> Args;
608-
for (Argument &A : F.args())
609-
Args.push_back(&A);
607+
SmallVector<Value *> Args(llvm::make_pointer_range(F.args()));
610608

611609
Type *ParameterType = ABI->vaListParameterType(M);
612610
if (ABI->vaListPassedInSSARegister())

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,9 +1738,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
17381738
OptimizationRemarkEmitter &ORE) {
17391739
bool Changed = false;
17401740
DT.updateDFSNumbers();
1741-
SmallVector<Value *> FunctionArgs;
1742-
for (Value &Arg : F.args())
1743-
FunctionArgs.push_back(&Arg);
1741+
SmallVector<Value *> FunctionArgs(llvm::make_pointer_range(F.args()));
17441742
ConstraintInfo Info(F.getDataLayout(), FunctionArgs);
17451743
State S(DT, LI, SE);
17461744
std::unique_ptr<Module> ReproducerModule(

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,8 @@ bool IndVarSimplify::simplifyAndExtend(Loop *L,
599599
L->getBlocks()[0]->getModule(), Intrinsic::experimental_guard);
600600
bool HasGuards = GuardDecl && !GuardDecl->use_empty();
601601

602-
SmallVector<PHINode *, 8> LoopPhis;
603-
for (PHINode &PN : L->getHeader()->phis())
604-
LoopPhis.push_back(&PN);
602+
SmallVector<PHINode *, 8> LoopPhis(
603+
llvm::make_pointer_range(L->getHeader()->phis()));
605604

606605
// Each round of simplification iterates through the SimplifyIVUsers worklist
607606
// for all current phis, then determines whether any IVs can be

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,11 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader,
15741574
P.eraseFromParent();
15751575
}
15761576

1577-
SmallVector<PHINode *, 8> LcssaInnerExit;
1578-
for (PHINode &P : InnerExit->phis())
1579-
LcssaInnerExit.push_back(&P);
1577+
SmallVector<PHINode *, 8> LcssaInnerExit(
1578+
llvm::make_pointer_range(InnerExit->phis()));
15801579

1581-
SmallVector<PHINode *, 8> LcssaInnerLatch;
1582-
for (PHINode &P : InnerLatch->phis())
1583-
LcssaInnerLatch.push_back(&P);
1580+
SmallVector<PHINode *, 8> LcssaInnerLatch(
1581+
llvm::make_pointer_range(InnerLatch->phis()));
15841582

15851583
// Lcssa PHIs for values used outside the inner loop are in InnerExit.
15861584
// If a PHI node has users outside of InnerExit, it has a use outside the

llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ class ConstantTerminatorFoldingImpl {
361361
for (BasicBlock *BB : DeadExitBlocks) {
362362
// Eliminate all Phis and LandingPads from dead exits.
363363
// TODO: Consider removing all instructions in this dead block.
364-
SmallVector<Instruction *, 4> DeadInstructions;
365-
for (auto &PN : BB->phis())
366-
DeadInstructions.push_back(&PN);
364+
SmallVector<Instruction *, 4> DeadInstructions(
365+
llvm::make_pointer_range(BB->phis()));
367366

368367
if (auto *LandingPad = dyn_cast<LandingPadInst>(BB->getFirstNonPHIIt()))
369368
DeadInstructions.emplace_back(LandingPad);

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,
165165
MemorySSAUpdater *MSSAU) {
166166
// Recursively deleting a PHI may cause multiple PHIs to be deleted
167167
// or RAUW'd undef, so use an array of WeakTrackingVH for the PHIs to delete.
168-
SmallVector<WeakTrackingVH, 8> PHIs;
169-
for (PHINode &PN : BB->phis())
170-
PHIs.push_back(&PN);
168+
SmallVector<WeakTrackingVH, 8> PHIs(llvm::make_pointer_range(BB->phis()));
171169

172170
bool Changed = false;
173171
for (unsigned i = 0, e = PHIs.size(); i != e; ++i)

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ static bool isBlockValidForExtraction(const BasicBlock &BB,
9191
// don't hoist code that uses another basicblock address, as it's likely to
9292
// lead to unexpected behavior, like cross-function jumps
9393
SmallPtrSet<User const *, 16> Visited;
94-
SmallVector<User const *, 16> ToVisit;
95-
96-
for (Instruction const &Inst : BB)
97-
ToVisit.push_back(&Inst);
94+
SmallVector<User const *, 16> ToVisit(llvm::make_pointer_range(BB));
9895

9996
while (!ToVisit.empty()) {
10097
User const *Curr = ToVisit.pop_back_val();

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,9 +1715,8 @@ SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
17151715
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
17161716
const TargetTransformInfo *TTI) {
17171717
// Find integer phis in order of increasing width.
1718-
SmallVector<PHINode*, 8> Phis;
1719-
for (PHINode &PN : L->getHeader()->phis())
1720-
Phis.push_back(&PN);
1718+
SmallVector<PHINode *, 8> Phis(
1719+
llvm::make_pointer_range(L->getHeader()->phis()));
17211720

17221721
if (TTI)
17231722
// Use stable_sort to preserve order of equivalent PHIs, so the order

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8267,9 +8267,8 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
82678267
// The vec.epilog.iter.check block may contain Phi nodes from inductions or
82688268
// reductions which merge control-flow from the latch block and the middle
82698269
// block. Update the incoming values here and move the Phi into the preheader.
8270-
SmallVector<PHINode *, 4> PhisInBlock;
8271-
for (PHINode &Phi : VecEpilogueIterationCountCheck->phis())
8272-
PhisInBlock.push_back(&Phi);
8270+
SmallVector<PHINode *, 4> PhisInBlock(
8271+
llvm::make_pointer_range(VecEpilogueIterationCountCheck->phis()));
82738272

82748273
for (PHINode *Phi : PhisInBlock) {
82758274
Phi->moveBefore(LoopVectorPreHeader->getFirstNonPHIIt());

0 commit comments

Comments
 (0)