[llvm] [IR] Use range-based for loops (NFC) (PR #97950)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 7 16:58:17 PDT 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/97950
>From 7ee9f4c50e04ca16e1d3b8c024c95e01202562ac Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 7 Jul 2024 06:18:09 -0700
Subject: [PATCH 1/2] [IR] Use range-based for loops (NFC)
---
llvm/lib/IR/AsmWriter.cpp | 4 ++--
llvm/lib/IR/Module.cpp | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
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;
>From 0ca4db8143e6d8307d4d1b98104b26415ffbf8e0 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 7 Jul 2024 16:57:53 -0700
Subject: [PATCH 2/2] Fix formatting.
---
llvm/lib/IR/Module.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 4eb2ca9bc3d11..c966c53d09baf 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -387,7 +387,7 @@ void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
Metadata *Val) {
NamedMDNode *ModFlags = getOrInsertModuleFlagsMetadata();
// Replace the flag if it already exists.
- for (MDNode *Flag : ModFlags->operands()) {
+ for (MDNode *Flag : ModFlags->operands()) {
ModFlagBehavior MFB;
MDString *K = nullptr;
Metadata *V = nullptr;
More information about the llvm-commits
mailing list