Skip to content

Commit 40c1264

Browse files
[Bitcode] Use range-based for loops (NFC) (#97776)
1 parent 9abb574 commit 40c1264

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,8 @@ Error BitcodeReader::parseAttributeBlock() {
19881988
Attrs.clear();
19891989
break;
19901990
case bitc::PARAMATTR_CODE_ENTRY: // ENTRY: [attrgrp0, attrgrp1, ...]
1991-
for (unsigned i = 0, e = Record.size(); i != e; ++i)
1992-
Attrs.push_back(MAttributeGroups[Record[i]]);
1991+
for (uint64_t Val : Record)
1992+
Attrs.push_back(MAttributeGroups[Val]);
19931993

19941994
MAttributes.push_back(AttributeList::get(Context, Attrs));
19951995
Attrs.clear();

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ class MetadataLoader::MetadataLoaderImpl {
549549
/// DISubprogram's retainedNodes.
550550
void upgradeCULocals() {
551551
if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu")) {
552-
for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
553-
auto *CU = dyn_cast<DICompileUnit>(CUNodes->getOperand(I));
552+
for (MDNode *N : CUNodes->operands()) {
553+
auto *CU = dyn_cast<DICompileUnit>(N);
554554
if (!CU)
555555
continue;
556556

llvm/lib/Bitcode/Writer/ValueEnumerator.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ void ValueEnumerator::EnumerateNamedMetadata(const Module &M) {
620620
}
621621

622622
void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
623-
for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
624-
EnumerateMetadata(nullptr, MD->getOperand(i));
623+
for (const MDNode *N : MD->operands())
624+
EnumerateMetadata(nullptr, N);
625625
}
626626

627627
unsigned ValueEnumerator::getMetadataFunctionID(const Function *F) const {
@@ -931,10 +931,9 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
931931
// itself. This makes it more likely that we can avoid forward references
932932
// in the reader. We know that there can be no cycles in the constants
933933
// graph that don't go through a global variable.
934-
for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
935-
I != E; ++I)
936-
if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
937-
EnumerateValue(*I);
934+
for (const Use &U : C->operands())
935+
if (!isa<BasicBlock>(U)) // Don't enumerate BB operand to BlockAddress.
936+
EnumerateValue(U);
938937
if (auto *CE = dyn_cast<ConstantExpr>(C)) {
939938
if (CE->getOpcode() == Instruction::ShuffleVector)
940939
EnumerateValue(CE->getShuffleMaskForBitcode());
@@ -1144,12 +1143,12 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
11441143
}
11451144

11461145
// Add all of the function-local metadata.
1147-
for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i) {
1146+
for (const LocalAsMetadata *Local : FnLocalMDVector) {
11481147
// At this point, every local values have been incorporated, we shouldn't
11491148
// have a metadata operand that references a value that hasn't been seen.
1150-
assert(ValueMap.count(FnLocalMDVector[i]->getValue()) &&
1149+
assert(ValueMap.count(Local->getValue()) &&
11511150
"Missing value for metadata operand");
1152-
EnumerateFunctionLocalMetadata(F, FnLocalMDVector[i]);
1151+
EnumerateFunctionLocalMetadata(F, Local);
11531152
}
11541153
// DIArgList entries must come after function-local metadata, as it is not
11551154
// possible to forward-reference them.
@@ -1159,8 +1158,8 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
11591158

11601159
void ValueEnumerator::purgeFunction() {
11611160
/// Remove purged values from the ValueMap.
1162-
for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
1163-
ValueMap.erase(Values[i].first);
1161+
for (const auto &V : llvm::drop_begin(Values, NumModuleValues))
1162+
ValueMap.erase(V.first);
11641163
for (const Metadata *MD : llvm::drop_begin(MDs, NumModuleMDs))
11651164
MetadataMap.erase(MD);
11661165
for (const BasicBlock *BB : BasicBlocks)

0 commit comments

Comments
 (0)