Skip to content

Commit a0c7ca8

Browse files
[BOLT] Use range-based for loops (NFC)
LLVM Coding Standards discourage for_each unless callable objects already exist.
1 parent 89df4e4 commit a0c7ca8

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4419,12 +4419,14 @@ void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
44194419
OS << "\n";
44204420

44214421
std::stack<BinaryLoop *> St;
4422-
for_each(*BLI, [&](BinaryLoop *L) { St.push(L); });
4422+
for (BinaryLoop *L : *BLI)
4423+
St.push(L);
44234424
while (!St.empty()) {
44244425
BinaryLoop *L = St.top();
44254426
St.pop();
44264427

4427-
for_each(*L, [&](BinaryLoop *Inner) { St.push(Inner); });
4428+
for (BinaryLoop *Inner : *L)
4429+
St.push(Inner);
44284430

44294431
if (!hasValidProfile())
44304432
continue;

bolt/lib/Core/DebugData.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,11 +1183,9 @@ void DebugAbbrevWriter::addUnitAbbreviations(DWARFUnit &Unit) {
11831183
// FIXME: if we had a full access to DWARFDebugAbbrev::AbbrDeclSets
11841184
// we wouldn't have to build our own sorted list for the quick lookup.
11851185
if (AbbrevSetOffsets.empty()) {
1186-
for_each(
1187-
*Unit.getContext().getDebugAbbrev(),
1188-
[&](const std::pair<uint64_t, DWARFAbbreviationDeclarationSet> &P) {
1189-
AbbrevSetOffsets.push_back(P.first);
1190-
});
1186+
for (const std::pair<const uint64_t, DWARFAbbreviationDeclarationSet>
1187+
&P : *Unit.getContext().getDebugAbbrev())
1188+
AbbrevSetOffsets.push_back(P.first);
11911189
sort(AbbrevSetOffsets);
11921190
}
11931191
auto It = upper_bound(AbbrevSetOffsets, StartOffset);

bolt/lib/Core/FunctionLayout.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ void FunctionLayout::eraseBasicBlocks(
151151
};
152152
const FragmentListType::iterator EmptyTailBegin =
153153
llvm::find_if_not(reverse(Fragments), IsEmpty).base();
154-
std::for_each(EmptyTailBegin, Fragments.end(),
155-
[](FunctionFragment *const FF) { delete FF; });
154+
for (FunctionFragment *const FF :
155+
llvm::make_range(EmptyTailBegin, Fragments.end()))
156+
delete FF;
156157
Fragments.erase(EmptyTailBegin, Fragments.end());
157158

158159
updateLayoutIndices();
@@ -208,8 +209,8 @@ void FunctionLayout::clear() {
208209
// be written to the output stream at its original file offset (see
209210
// `RewriteInstance::rewriteFile`). Hence, when the layout is cleared, retain
210211
// the main fragment, so that this information is not lost.
211-
std::for_each(Fragments.begin() + 1, Fragments.end(),
212-
[](FunctionFragment *const FF) { delete FF; });
212+
for (FunctionFragment *const FF : llvm::drop_begin(Fragments))
213+
delete FF;
213214
Fragments = FragmentListType{Fragments.front()};
214215
getMainFragment().Size = 0;
215216
}

bolt/lib/Passes/SplitFunctions.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ struct SplitProfile2 {
129129
}
130130

131131
template <typename It> void partition(const It Start, const It End) const {
132-
std::for_each(Start, End, [](BinaryBasicBlock *const BB) {
132+
for (BinaryBasicBlock *const BB : llvm::make_range(Start, End)) {
133133
assert(BB->canOutline() &&
134134
"Moving a block that is not outlineable to cold fragment");
135135
BB->setFragmentNum(FragmentNum::cold());
136-
});
136+
}
137137
}
138138
};
139139

@@ -155,9 +155,8 @@ struct SplitRandom2 {
155155
std::uniform_int_distribution<DiffT> Dist(MinimumSplit,
156156
NumOutlineableBlocks);
157157
const DiffT NumColdBlocks = Dist(*Gen);
158-
std::for_each(End - NumColdBlocks, End, [](BinaryBasicBlock *BB) {
158+
for (BinaryBasicBlock *BB : llvm::make_range(End - NumColdBlocks, End))
159159
BB->setFragmentNum(FragmentNum::cold());
160-
});
161160

162161
LLVM_DEBUG(dbgs() << formatv("BOLT-DEBUG: randomly chose last {0} (out of "
163162
"{1} possible) blocks to split\n",
@@ -216,11 +215,11 @@ struct SplitAll {
216215

217216
template <typename It> void partition(It Start, It End) const {
218217
unsigned Fragment = 1;
219-
std::for_each(Start, End, [&](BinaryBasicBlock *const BB) {
218+
for (BinaryBasicBlock *const BB : llvm::make_range(Start, End)) {
220219
assert(BB->canOutline() &&
221220
"Moving a block that is not outlineable to cold fragment");
222221
BB->setFragmentNum(FragmentNum(Fragment++));
223-
});
222+
}
224223
}
225224
};
226225
} // namespace

0 commit comments

Comments
 (0)