[llvm] [IR] Use range-based for loops (NFC) (PR #97950)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 06:43:26 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/97950.diff


2 Files Affected:

- (modified) llvm/lib/IR/AsmWriter.cpp (+2-2) 
- (modified) llvm/lib/IR/Module.cpp (+1-2) 


``````````diff
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 0bf8be9ac55f9..6599730590de6 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1021,8 +1021,8 @@ void SlotTracker::processModule() {
 
   // Add metadata used by named metadata.
   for (const NamedMDNode &NMD : TheModule->named_metadata()) {
-    for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
-      CreateMetadataSlot(NMD.getOperand(i));
+    for (const MDNode *N : NMD.operands())
+      CreateMetadataSlot(N);
   }
 
   for (const Function &F : *TheModule) {
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 16c79442f82fe..4eb2ca9bc3d11 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -387,8 +387,7 @@ void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                            Metadata *Val) {
   NamedMDNode *ModFlags = getOrInsertModuleFlagsMetadata();
   // Replace the flag if it already exists.
-  for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) {
-    MDNode *Flag = ModFlags->getOperand(I);
+  for (MDNode *Flag : ModFlags->operands())  {
     ModFlagBehavior MFB;
     MDString *K = nullptr;
     Metadata *V = nullptr;

``````````

</details>


https://github.com/llvm/llvm-project/pull/97950


More information about the llvm-commits mailing list