[llvm] e851278 - [IR] Use range-based for loops (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 23:54:14 PST 2024


Author: Kazu Hirata
Date: 2024-01-31T23:54:05-08:00
New Revision: e8512786fedbfa6ddba70ceddc29d7122173ba5e

URL: https://github.com/llvm/llvm-project/commit/e8512786fedbfa6ddba70ceddc29d7122173ba5e
DIFF: https://github.com/llvm/llvm-project/commit/e8512786fedbfa6ddba70ceddc29d7122173ba5e.diff

LOG: [IR] Use range-based for loops (NFC)

Added: 
    

Modified: 
    llvm/lib/IR/AsmWriter.cpp
    llvm/lib/IR/AutoUpgrade.cpp
    llvm/lib/IR/DebugInfo.cpp
    llvm/lib/IR/Function.cpp
    llvm/lib/IR/ProfDataUtils.cpp
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 3c15784a0ed5e..9a3f38c9f9708 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 b90bbe71ac189..19d80eb9aec0b 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 d8c1b0d534f61..2cf88292b14ed 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 22e2455462bf4..d3e2ae0dede45 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 b1a10d0ce5a52..dcb057c1b25fd 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 91cf91fbc788b..f4c1508e4b7dd 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");


        


More information about the llvm-commits mailing list