Skip to content

Commit 58774f1

Browse files
[CodeGen] Construct SmallVector with iterator ranges (NFC) (#136258)
1 parent 5ad32fa commit 58774f1

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,8 @@ bool CodeGenPrepare::eliminateFallThrough(Function &F, DominatorTree *DT) {
834834
// Scan all of the blocks in the function, except for the entry block.
835835
// Use a temporary array to avoid iterator being invalidated when
836836
// deleting blocks.
837-
SmallVector<WeakTrackingVH, 16> Blocks;
838-
for (auto &Block : llvm::drop_begin(F))
839-
Blocks.push_back(&Block);
837+
SmallVector<WeakTrackingVH, 16> Blocks(
838+
llvm::make_pointer_range(llvm::drop_begin(F)));
840839

841840
SmallSet<WeakTrackingVH, 16> Preds;
842841
for (auto &Block : Blocks) {

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,8 @@ void CombinerHelper::applyCombineExtendingLoads(
867867

868868
// Rewrite all the uses to fix up the types.
869869
auto &LoadValue = MI.getOperand(0);
870-
SmallVector<MachineOperand *, 4> Uses;
871-
for (auto &UseMO : MRI.use_operands(LoadValue.getReg()))
872-
Uses.push_back(&UseMO);
870+
SmallVector<MachineOperand *, 4> Uses(
871+
llvm::make_pointer_range(MRI.use_operands(LoadValue.getReg())));
873872

874873
for (auto *UseMO : Uses) {
875874
MachineInstr *UseMI = UseMO->getParent();

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,9 +2442,8 @@ static const DIExpression *computeExprForSpill(
24422442
static const DIExpression *computeExprForSpill(const MachineInstr &MI,
24432443
Register SpillReg) {
24442444
assert(MI.hasDebugOperandForReg(SpillReg) && "Spill Reg is not used in MI.");
2445-
SmallVector<const MachineOperand *> SpillOperands;
2446-
for (const MachineOperand &Op : MI.getDebugOperandsForReg(SpillReg))
2447-
SpillOperands.push_back(&Op);
2445+
SmallVector<const MachineOperand *> SpillOperands(
2446+
llvm::make_pointer_range(MI.getDebugOperandsForReg(SpillReg)));
24482447
return computeExprForSpill(MI, SpillOperands);
24492448
}
24502449

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,9 +1733,8 @@ void RegAllocFastImpl::handleDebugValue(MachineInstr &MI) {
17331733
// See if this virtual register has already been allocated to a physical
17341734
// register or spilled to a stack slot.
17351735
LiveRegMap::iterator LRI = findLiveVirtReg(Reg);
1736-
SmallVector<MachineOperand *> DbgOps;
1737-
for (MachineOperand &Op : MI.getDebugOperandsForReg(Reg))
1738-
DbgOps.push_back(&Op);
1736+
SmallVector<MachineOperand *> DbgOps(
1737+
llvm::make_pointer_range(MI.getDebugOperandsForReg(Reg)));
17391738

17401739
if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
17411740
// Update every use of Reg within MI.

llvm/lib/CodeGen/RegisterUsageInfo.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ PhysicalRegisterUsageInfo::getRegUsageInfo(const Function &FP) {
7272
void PhysicalRegisterUsageInfo::print(raw_ostream &OS, const Module *M) const {
7373
using FuncPtrRegMaskPair = std::pair<const Function *, std::vector<uint32_t>>;
7474

75-
SmallVector<const FuncPtrRegMaskPair *, 64> FPRMPairVector;
76-
7775
// Create a vector of pointer to RegMasks entries
78-
for (const auto &RegMask : RegMasks)
79-
FPRMPairVector.push_back(&RegMask);
76+
SmallVector<const FuncPtrRegMaskPair *, 64> FPRMPairVector(
77+
llvm::make_pointer_range(RegMasks));
8078

8179
// sort the vector to print analysis in alphabatic order of function name.
8280
llvm::sort(

0 commit comments

Comments
 (0)