diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 7cf1ce9202e9..623c3eb580d8 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -4419,12 +4419,14 @@ void BinaryFunction::printLoopInfo(raw_ostream &OS) const { OS << "\n"; std::stack 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; diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp index f0c59fb69523..d6f7dd175fd7 100644 --- a/bolt/lib/Core/DebugData.cpp +++ b/bolt/lib/Core/DebugData.cpp @@ -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 &P) { - AbbrevSetOffsets.push_back(P.first); - }); + for (const std::pair + &P : *Unit.getContext().getDebugAbbrev()) + AbbrevSetOffsets.push_back(P.first); sort(AbbrevSetOffsets); } auto It = upper_bound(AbbrevSetOffsets, StartOffset); diff --git a/bolt/lib/Core/FunctionLayout.cpp b/bolt/lib/Core/FunctionLayout.cpp index 2ccf82ce7270..37b07bd28f26 100644 --- a/bolt/lib/Core/FunctionLayout.cpp +++ b/bolt/lib/Core/FunctionLayout.cpp @@ -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; } diff --git a/bolt/lib/Passes/SplitFunctions.cpp b/bolt/lib/Passes/SplitFunctions.cpp index 4c7518585fcc..7b6a4507aba9 100644 --- a/bolt/lib/Passes/SplitFunctions.cpp +++ b/bolt/lib/Passes/SplitFunctions.cpp @@ -129,11 +129,11 @@ struct SplitProfile2 { } template 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 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 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