aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-07-07 06:34:18 +0900
committerGitHub <noreply@github.com>2024-07-07 06:34:18 +0900
commit40c12648c6c0a39efce294e3fa763fd6c8ed4005 (patch)
treee542140c5175fac95735ffde1288c6a084b67ebe
parent9abb574f9a68b1c0c32f49745f9dad8e1a7db1f9 (diff)
downloadllvm-40c12648c6c0a39efce294e3fa763fd6c8ed4005.zip
llvm-40c12648c6c0a39efce294e3fa763fd6c8ed4005.tar.gz
llvm-40c12648c6c0a39efce294e3fa763fd6c8ed4005.tar.bz2
[Bitcode] Use range-based for loops (NFC) (#97776)
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp4
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp4
-rw-r--r--llvm/lib/Bitcode/Writer/ValueEnumerator.cpp21
3 files changed, 14 insertions, 15 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 05c9697..f56b2b3 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1988,8 +1988,8 @@ Error BitcodeReader::parseAttributeBlock() {
Attrs.clear();
break;
case bitc::PARAMATTR_CODE_ENTRY: // ENTRY: [attrgrp0, attrgrp1, ...]
- for (unsigned i = 0, e = Record.size(); i != e; ++i)
- Attrs.push_back(MAttributeGroups[Record[i]]);
+ for (uint64_t Val : Record)
+ Attrs.push_back(MAttributeGroups[Val]);
MAttributes.push_back(AttributeList::get(Context, Attrs));
Attrs.clear();
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 9102f3a..7d7b224 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -549,8 +549,8 @@ class MetadataLoader::MetadataLoaderImpl {
/// DISubprogram's retainedNodes.
void upgradeCULocals() {
if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu")) {
- for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
- auto *CU = dyn_cast<DICompileUnit>(CUNodes->getOperand(I));
+ for (MDNode *N : CUNodes->operands()) {
+ auto *CU = dyn_cast<DICompileUnit>(N);
if (!CU)
continue;
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 631f31c..9f735f7 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -620,8 +620,8 @@ void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
}
void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
- for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
- EnumerateMetadata(nullptr, MD->getOperand(i));
+ for (const MDNode *N : MD->operands())
+ EnumerateMetadata(nullptr, N);
}
unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const {
@@ -931,10 +931,9 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
// itself. This makes it more likely that we can avoid forward references
// in the reader. We know that there can be no cycles in the constants
// graph that don't go through a global variable.
- for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
- I != E; ++I)
- if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
- EnumerateValue(*I);
+ for (const Use &U : C->operands())
+ if (!isa<BasicBlock>(U)) // Don't enumerate BB operand to BlockAddress.
+ EnumerateValue(U);
if (auto *CE = dyn_cast<ConstantExpr>(C)) {
if (CE->getOpcode() == Instruction::ShuffleVector)
EnumerateValue(CE->getShuffleMaskForBitcode());
@@ -1144,12 +1143,12 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
}
// Add all of the function-local metadata.
- for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i) {
+ for (const LocalAsMetadata *Local : FnLocalMDVector) {
// At this point, every local values have been incorporated, we shouldn't
// have a metadata operand that references a value that hasn't been seen.
- assert(ValueMap.count(FnLocalMDVector[i]->getValue()) &&
+ assert(ValueMap.count(Local->getValue()) &&
"Missing value for metadata operand");
- EnumerateFunctionLocalMetadata(F, FnLocalMDVector[i]);
+ EnumerateFunctionLocalMetadata(F, Local);
}
// DIArgList entries must come after function-local metadata, as it is not
// possible to forward-reference them.
@@ -1159,8 +1158,8 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
void ValueEnumerator::purgeFunction() {
/// Remove purged values from the ValueMap.
- for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
- ValueMap.erase(Values[i].first);
+ for (const auto &V : llvm::drop_begin(Values, NumModuleValues))
+ ValueMap.erase(V.first);
for (const Metadata *MD : llvm::drop_begin(MDs, NumModuleMDs))
MetadataMap.erase(MD);
for (const BasicBlock *BB : BasicBlocks)