diff options
author | Kazu Hirata <kazu@google.com> | 2024-01-31 23:54:05 -0800 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2024-01-31 23:54:05 -0800 |
commit | e8512786fedbfa6ddba70ceddc29d7122173ba5e (patch) | |
tree | 0f9417ca0f81b05e30067f7450fc4ae93147c5b8 | |
parent | 7ec996d4c5c30083b070be4898140440094e6b97 (diff) |
[IR] Use range-based for loops (NFC)
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Function.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/IR/ProfDataUtils.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 7 |
6 files changed, 14 insertions, 16 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 3c15784a0ed5..9a3f38c9f970 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1308,8 +1308,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) { ++mdnNext; // Recursively add any MDNodes referenced by operands. - for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) - if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i))) + for (const MDOperand &MDO : N->operands()) + if (const MDNode *Op = dyn_cast_or_null<MDNode>(MDO)) CreateMetadataSlot(Op); } diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index b90bbe71ac18..19d80eb9aec0 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5209,8 +5209,8 @@ static Metadata *upgradeLoopArgument(Metadata *MD) { SmallVector<Metadata *, 8> Ops; Ops.reserve(T->getNumOperands()); Ops.push_back(upgradeLoopTag(T->getContext(), OldTag->getString())); - for (unsigned I = 1, E = T->getNumOperands(); I != E; ++I) - Ops.push_back(T->getOperand(I)); + for (const MDOperand &MDO : llvm::drop_begin(T->operands())) + Ops.push_back(MDO); return MDTuple::get(T->getContext(), Ops); } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index d8c1b0d534f6..2cf88292b14e 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -400,8 +400,8 @@ static MDNode *updateLoopMetadataDebugLocationsImpl( // Save space for the self-referential LoopID. SmallVector<Metadata *, 4> MDs = {nullptr}; - for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) { - Metadata *MD = OrigLoopID->getOperand(i); + for (const MDOperand &MDO : llvm::drop_begin(OrigLoopID->operands())) { + Metadata *MD = MDO; if (!MD) MDs.push_back(nullptr); else if (Metadata *NewMD = Updater(MD)) diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 22e2455462bf..d3e2ae0dede4 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -1976,10 +1976,9 @@ DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const { if (MDNode *MD = getMetadata(LLVMContext::MD_prof)) if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) if (MDS->getString().equals("function_entry_count")) - for (unsigned i = 2; i < MD->getNumOperands(); i++) - R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i)) - ->getValue() - .getZExtValue()); + for (const MDOperand &MDO : llvm::drop_begin(MD->operands(), 2)) + R.insert( + mdconst::extract<ConstantInt>(MDO)->getValue().getZExtValue()); return R; } diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp index b1a10d0ce5a5..dcb057c1b25f 100644 --- a/llvm/lib/IR/ProfDataUtils.cpp +++ b/llvm/lib/IR/ProfDataUtils.cpp @@ -162,8 +162,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) { return false; if (ProfDataName->getString().equals("branch_weights")) { - for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) { - auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx)); + for (const MDOperand &MDO : llvm::drop_begin(ProfileData->operands())) { + auto *V = mdconst::dyn_extract<ConstantInt>(MDO); assert(V && "Malformed branch_weight in MD_prof node"); TotalVal += V->getValue().getZExtValue(); } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 91cf91fbc788..f4c1508e4b7d 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2917,8 +2917,8 @@ void Verifier::visitFunction(const Function &F) { VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); // The llvm.loop annotations also contain two DILocations. if (auto MD = I.getMetadata(LLVMContext::MD_loop)) - for (unsigned i = 1; i < MD->getNumOperands(); ++i) - VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i))); + for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) + VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MDO)); if (BrokenDebugInfo) return; } @@ -4717,8 +4717,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { Check(MD->getNumOperands() == 1 + ExpectedNumOperands, "Wrong number of operands", MD); } - for (unsigned i = 1; i < MD->getNumOperands(); ++i) { - auto &MDO = MD->getOperand(i); + for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) { Check(MDO, "second operand should not be null", MD); Check(mdconst::dyn_extract<ConstantInt>(MDO), "!prof brunch_weights operand is not a const int"); |