Skip to content

Commit e851278

Browse files
[IR] Use range-based for loops (NFC)
1 parent 7ec996d commit e851278

File tree

6 files changed

+14
-16
lines changed

6 files changed

+14
-16
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
13081308
++mdnNext;
13091309

13101310
// Recursively add any MDNodes referenced by operands.
1311-
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
1312-
if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i)))
1311+
for (const MDOperand &MDO : N->operands())
1312+
if (const MDNode *Op = dyn_cast_or_null<MDNode>(MDO))
13131313
CreateMetadataSlot(Op);
13141314
}
13151315

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,8 +5209,8 @@ static Metadata *upgradeLoopArgument(Metadata *MD) {
52095209
SmallVector<Metadata *, 8> Ops;
52105210
Ops.reserve(T->getNumOperands());
52115211
Ops.push_back(upgradeLoopTag(T->getContext(), OldTag->getString()));
5212-
for (unsigned I = 1, E = T->getNumOperands(); I != E; ++I)
5213-
Ops.push_back(T->getOperand(I));
5212+
for (const MDOperand &MDO : llvm::drop_begin(T->operands()))
5213+
Ops.push_back(MDO);
52145214

52155215
return MDTuple::get(T->getContext(), Ops);
52165216
}

llvm/lib/IR/DebugInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ static MDNode *updateLoopMetadataDebugLocationsImpl(
400400
// Save space for the self-referential LoopID.
401401
SmallVector<Metadata *, 4> MDs = {nullptr};
402402

403-
for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) {
404-
Metadata *MD = OrigLoopID->getOperand(i);
403+
for (const MDOperand &MDO : llvm::drop_begin(OrigLoopID->operands())) {
404+
Metadata *MD = MDO;
405405
if (!MD)
406406
MDs.push_back(nullptr);
407407
else if (Metadata *NewMD = Updater(MD))

llvm/lib/IR/Function.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,9 @@ DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {
19761976
if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
19771977
if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
19781978
if (MDS->getString().equals("function_entry_count"))
1979-
for (unsigned i = 2; i < MD->getNumOperands(); i++)
1980-
R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
1981-
->getValue()
1982-
.getZExtValue());
1979+
for (const MDOperand &MDO : llvm::drop_begin(MD->operands(), 2))
1980+
R.insert(
1981+
mdconst::extract<ConstantInt>(MDO)->getValue().getZExtValue());
19831982
return R;
19841983
}
19851984

llvm/lib/IR/ProfDataUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) {
162162
return false;
163163

164164
if (ProfDataName->getString().equals("branch_weights")) {
165-
for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) {
166-
auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx));
165+
for (const MDOperand &MDO : llvm::drop_begin(ProfileData->operands())) {
166+
auto *V = mdconst::dyn_extract<ConstantInt>(MDO);
167167
assert(V && "Malformed branch_weight in MD_prof node");
168168
TotalVal += V->getValue().getZExtValue();
169169
}

llvm/lib/IR/Verifier.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,8 +2917,8 @@ void Verifier::visitFunction(const Function &F) {
29172917
VisitDebugLoc(I, I.getDebugLoc().getAsMDNode());
29182918
// The llvm.loop annotations also contain two DILocations.
29192919
if (auto MD = I.getMetadata(LLVMContext::MD_loop))
2920-
for (unsigned i = 1; i < MD->getNumOperands(); ++i)
2921-
VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i)));
2920+
for (const MDOperand &MDO : llvm::drop_begin(MD->operands()))
2921+
VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MDO));
29222922
if (BrokenDebugInfo)
29232923
return;
29242924
}
@@ -4717,8 +4717,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
47174717
Check(MD->getNumOperands() == 1 + ExpectedNumOperands,
47184718
"Wrong number of operands", MD);
47194719
}
4720-
for (unsigned i = 1; i < MD->getNumOperands(); ++i) {
4721-
auto &MDO = MD->getOperand(i);
4720+
for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) {
47224721
Check(MDO, "second operand should not be null", MD);
47234722
Check(mdconst::dyn_extract<ConstantInt>(MDO),
47244723
"!prof brunch_weights operand is not a const int");

0 commit comments

Comments
 (0)