[BOLT] Use range-based for loops (NFC)

LLVM Coding Standards discourage for_each unless callable objects
already exist.
This commit is contained in:
Kazu Hirata 2022-09-03 11:17:32 -07:00
parent 89df4e4825
commit a0c7ca8ad4
4 changed files with 17 additions and 17 deletions

View File

@ -4419,12 +4419,14 @@ void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
OS << "\n";
std::stack<BinaryLoop *> St;
for_each(*BLI, [&](BinaryLoop *L) { St.push(L); });
for (BinaryLoop *L : *BLI)
St.push(L);
while (!St.empty()) {
BinaryLoop *L = St.top();
St.pop();
for_each(*L, [&](BinaryLoop *Inner) { St.push(Inner); });
for (BinaryLoop *Inner : *L)
St.push(Inner);
if (!hasValidProfile())
continue;

View File

@ -1183,11 +1183,9 @@ void DebugAbbrevWriter::addUnitAbbreviations(DWARFUnit &Unit) {
// FIXME: if we had a full access to DWARFDebugAbbrev::AbbrDeclSets
// we wouldn't have to build our own sorted list for the quick lookup.
if (AbbrevSetOffsets.empty()) {
for_each(
*Unit.getContext().getDebugAbbrev(),
[&](const std::pair<uint64_t, DWARFAbbreviationDeclarationSet> &P) {
AbbrevSetOffsets.push_back(P.first);
});
for (const std::pair<const uint64_t, DWARFAbbreviationDeclarationSet>
&P : *Unit.getContext().getDebugAbbrev())
AbbrevSetOffsets.push_back(P.first);
sort(AbbrevSetOffsets);
}
auto It = upper_bound(AbbrevSetOffsets, StartOffset);

View File

@ -151,8 +151,9 @@ void FunctionLayout::eraseBasicBlocks(
};
const FragmentListType::iterator EmptyTailBegin =
llvm::find_if_not(reverse(Fragments), IsEmpty).base();
std::for_each(EmptyTailBegin, Fragments.end(),
[](FunctionFragment *const FF) { delete FF; });
for (FunctionFragment *const FF :
llvm::make_range(EmptyTailBegin, Fragments.end()))
delete FF;
Fragments.erase(EmptyTailBegin, Fragments.end());
updateLayoutIndices();
@ -208,8 +209,8 @@ void FunctionLayout::clear() {
// be written to the output stream at its original file offset (see
// `RewriteInstance::rewriteFile`). Hence, when the layout is cleared, retain
// the main fragment, so that this information is not lost.
std::for_each(Fragments.begin() + 1, Fragments.end(),
[](FunctionFragment *const FF) { delete FF; });
for (FunctionFragment *const FF : llvm::drop_begin(Fragments))
delete FF;
Fragments = FragmentListType{Fragments.front()};
getMainFragment().Size = 0;
}

View File

@ -129,11 +129,11 @@ struct SplitProfile2 {
}
template <typename It> void partition(const It Start, const It End) const {
std::for_each(Start, End, [](BinaryBasicBlock *const BB) {
for (BinaryBasicBlock *const BB : llvm::make_range(Start, End)) {
assert(BB->canOutline() &&
"Moving a block that is not outlineable to cold fragment");
BB->setFragmentNum(FragmentNum::cold());
});
}
}
};
@ -155,9 +155,8 @@ struct SplitRandom2 {
std::uniform_int_distribution<DiffT> Dist(MinimumSplit,
NumOutlineableBlocks);
const DiffT NumColdBlocks = Dist(*Gen);
std::for_each(End - NumColdBlocks, End, [](BinaryBasicBlock *BB) {
for (BinaryBasicBlock *BB : llvm::make_range(End - NumColdBlocks, End))
BB->setFragmentNum(FragmentNum::cold());
});
LLVM_DEBUG(dbgs() << formatv("BOLT-DEBUG: randomly chose last {0} (out of "
"{1} possible) blocks to split\n",
@ -216,11 +215,11 @@ struct SplitAll {
template <typename It> void partition(It Start, It End) const {
unsigned Fragment = 1;
std::for_each(Start, End, [&](BinaryBasicBlock *const BB) {
for (BinaryBasicBlock *const BB : llvm::make_range(Start, End)) {
assert(BB->canOutline() &&
"Moving a block that is not outlineable to cold fragment");
BB->setFragmentNum(FragmentNum(Fragment++));
});
}
}
};
} // namespace