Skip to content

Commit

Permalink
[Bitcode] Use range-based for loops (NFC) (llvm#97776)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Jul 6, 2024
1 parent 9abb574 commit 40c1264
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 10 additions & 11 deletions llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 40c1264

Please sign in to comment.