[llvm] [llvm] Initialize SmallVector with ranges (NFC) (PR #100948)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 14:45:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/100948.diff
7 Files Affected:
- (modified) llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp (+2-6)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+1-3)
- (modified) llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp (+1-3)
- (modified) llvm/lib/IR/BasicBlock.cpp (+1-3)
- (modified) llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp (+1-3)
- (modified) llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp (+1-3)
- (modified) llvm/lib/Transforms/Utils/ValueMapper.cpp (+2-3)
``````````diff
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 0a6ce6a135817..20d5b2602df12 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -2426,9 +2426,7 @@ bool InstrRefBasedLDV::mlocJoin(
// as its predecessors. If a PHI is placed, test to see whether it's now a
// redundant PHI that we can eliminate.
- SmallVector<const MachineBasicBlock *, 8> BlockOrders;
- for (auto *Pred : MBB.predecessors())
- BlockOrders.push_back(Pred);
+ SmallVector<const MachineBasicBlock *, 8> BlockOrders(MBB.predecessors());
// Visit predecessors in RPOT order.
auto Cmp = [&](const MachineBasicBlock *A, const MachineBasicBlock *B) {
@@ -3268,9 +3266,7 @@ void InstrRefBasedLDV::buildVLocValueMap(
bool InLocsChanged =
vlocJoin(*MBB, LiveOutIdx, BlocksToExplore, *LiveIn);
- SmallVector<const MachineBasicBlock *, 8> Preds;
- for (const auto *Pred : MBB->predecessors())
- Preds.push_back(Pred);
+ SmallVector<const MachineBasicBlock *, 8> Preds(MBB->predecessors());
// If this block's live-in value is a VPHI, try to pick a machine-value
// for it. This makes the machine-value available and propagated
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c554c0f5b6fd7..9f5e6466309e9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1246,9 +1246,7 @@ void SelectionDAGBuilder::visitDbgInfo(const Instruction &I) {
SmallVector<Value *> Values(It->Values.location_ops());
if (!handleDebugValue(Values, Var, It->Expr, It->DL, SDNodeOrder,
It->Values.hasArgList())) {
- SmallVector<Value *, 4> Vals;
- for (Value *V : It->Values.location_ops())
- Vals.push_back(V);
+ SmallVector<Value *, 4> Vals(It->Values.location_ops());
addDanglingDebugInfo(Vals,
FnVarLocs->getDILocalVariable(It->VariableID),
It->Expr, Vals.size() > 1, It->DL, SDNodeOrder);
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 869b383dd064f..1216dfa3ba7df 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -260,9 +260,7 @@ void MCJIT::finalizeObject() {
// Generate code for module is going to move objects out of the 'added' list,
// so we need to copy that out before using it:
- SmallVector<Module*, 16> ModsToAdd;
- for (auto *M : OwnedModules.added())
- ModsToAdd.push_back(M);
+ SmallVector<Module*, 16> ModsToAdd(OwnedModules.added());
for (auto *M : ModsToAdd)
generateCodeForModule(M);
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index bf19934da047c..d9a6b6ba3791c 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -626,9 +626,7 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
// to reflect that the incoming branches will be from the New block and not
// from predecessors of the 'this' block.
// Save predecessors to separate vector before modifying them.
- SmallVector<BasicBlock *, 4> Predecessors;
- for (BasicBlock *Pred : predecessors(this))
- Predecessors.push_back(Pred);
+ SmallVector<BasicBlock *, 4> Predecessors(predecessors(this));
for (BasicBlock *Pred : Predecessors) {
Instruction *TI = Pred->getTerminator();
TI->replaceSuccessorWith(this, New);
diff --git a/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp b/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp
index 00931b1f63b29..e43437d00e91d 100644
--- a/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp
+++ b/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp
@@ -123,9 +123,7 @@ bool PPCGenScalarMASSEntries::runOnModule(Module &M) {
// The call to createScalarMASSCall() invalidates the iterator over users
// upon replacing the users. Precomputing the current list of users allows
// us to replace all the call sites.
- SmallVector<User *, 4> TheUsers;
- for (auto *User : Func.users())
- TheUsers.push_back(User);
+ SmallVector<User *, 4> TheUsers(Func.users());
for (auto *User : TheUsers)
if (auto *CI = dyn_cast_or_null<CallInst>(User)) {
diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index 4371b821eae63..d2268f0a30a25 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -149,9 +149,7 @@ class DFAJumpThreading {
unfoldSelectInstrs(DominatorTree *DT,
const SmallVector<SelectInstToUnfold, 4> &SelectInsts) {
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
- SmallVector<SelectInstToUnfold, 4> Stack;
- for (SelectInstToUnfold SIToUnfold : SelectInsts)
- Stack.push_back(SIToUnfold);
+ SmallVector<SelectInstToUnfold, 4> Stack(SelectInsts);
while (!Stack.empty()) {
SelectInstToUnfold SIToUnfold = Stack.pop_back_val();
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 1696e9c726735..5af56b01cb69c 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -565,9 +565,8 @@ void Mapper::remapDbgRecord(DbgRecord &DR) {
}
// Find Value operands and remap those.
- SmallVector<Value *, 4> Vals, NewVals;
- for (Value *Val : V.location_ops())
- Vals.push_back(Val);
+ SmallVector<Value *, 4> Vals(V.location_ops());
+ SmallVector<Value *, 4> NewVals;
for (Value *Val : Vals)
NewVals.push_back(mapValue(Val));
``````````
</details>
https://github.com/llvm/llvm-project/pull/100948
More information about the llvm-commits
mailing list