[llvm] [llvm] Initialize SmallVector with ranges (NFC) (PR #100948)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 17:43:54 PDT 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/100948
>From 1192c4f76f54fe50901af599b8d868dc3e6dab8f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 28 Jul 2024 14:03:06 -0700
Subject: [PATCH 1/2] [llvm] Initialize SmallVector with ranges (NFC)
---
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 8 ++------
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 4 +---
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 4 +---
llvm/lib/IR/BasicBlock.cpp | 4 +---
llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp | 4 +---
llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp | 4 +---
llvm/lib/Transforms/Utils/ValueMapper.cpp | 5 ++---
7 files changed, 9 insertions(+), 24 deletions(-)
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));
>From e8a58ef53e931071d046e5189886248f6d1725da Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 28 Jul 2024 17:43:29 -0700
Subject: [PATCH 2/2] Fix formatting.
---
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 1216dfa3ba7df..0d7a51bfe7375 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -260,7 +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(OwnedModules.added());
+ SmallVector<Module *, 16> ModsToAdd(OwnedModules.added());
for (auto *M : ModsToAdd)
generateCodeForModule(M);
More information about the llvm-commits
mailing list