diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h --- a/bolt/include/bolt/Core/DebugData.h +++ b/bolt/include/bolt/Core/DebugData.h @@ -1049,12 +1049,9 @@ assert(&Unit.getContext() == &Context && "cannot update attribute from a different DWARF context"); std::lock_guard Lock(WriterMutex); - bool AlreadyAdded = false; - for (AbbrevEntry &E : NewAbbrevEntries[&Unit][Abbrev]) - if (E.Attr == AttrTag) { - AlreadyAdded = true; - break; - } + bool AlreadyAdded = + llvm::any_of(NewAbbrevEntries[&Unit][Abbrev], + [&](AbbrevEntry &E) { return E.Attr == AttrTag; }); if (AlreadyAdded) return; diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1824,13 +1824,9 @@ // If this block contains an epilogue code and has an indirect branch, // then most likely it's a tail call. Otherwise, we cannot tell for sure // what it is and conservatively reject the function's CFG. - bool IsEpilogue = false; - for (const MCInst &Instr : BB) { - if (BC.MIB->isLeave(Instr) || BC.MIB->isPop(Instr)) { - IsEpilogue = true; - break; - } - } + bool IsEpilogue = llvm::any_of(BB, [&](const MCInst &Instr) { + return BC.MIB->isLeave(Instr) || BC.MIB->isPop(Instr); + }); if (IsEpilogue) { BC.MIB->convertJmpToTailCall(Instr); BB.removeAllSuccessors(); diff --git a/bolt/lib/Passes/FrameAnalysis.cpp b/bolt/lib/Passes/FrameAnalysis.cpp --- a/bolt/lib/Passes/FrameAnalysis.cpp +++ b/bolt/lib/Passes/FrameAnalysis.cpp @@ -56,20 +56,11 @@ FrameOptFunctionNamesFile = ""; } - bool IsValid = true; - if (!FrameOptFunctionNames.empty()) { - IsValid = false; - for (std::string &Name : FrameOptFunctionNames) { - if (Function.hasName(Name)) { - IsValid = true; - break; - } - } - } - if (!IsValid) - return false; - - return IsValid; + if (FrameOptFunctionNames.empty()) + return true; + return llvm::any_of(FrameOptFunctionNames, [&](std::string &Name) { + return Function.hasName(Name); + }); } } // namespace opts diff --git a/bolt/lib/Passes/PatchEntries.cpp b/bolt/lib/Passes/PatchEntries.cpp --- a/bolt/lib/Passes/PatchEntries.cpp +++ b/bolt/lib/Passes/PatchEntries.cpp @@ -13,6 +13,7 @@ #include "bolt/Passes/PatchEntries.h" #include "bolt/Utils/NameResolver.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" namespace opts { @@ -34,14 +35,11 @@ if (!opts::ForcePatch) { // Mark the binary for patching if we did not create external references // for original code in any of functions we are not going to emit. - bool NeedsPatching = false; - for (auto &BFI : BC.getBinaryFunctions()) { - BinaryFunction &Function = BFI.second; - if (!BC.shouldEmit(Function) && !Function.hasExternalRefRelocations()) { - NeedsPatching = true; - break; - } - } + bool NeedsPatching = llvm::any_of( + llvm::make_second_range(BC.getBinaryFunctions()), + [&](BinaryFunction &BF) { + return !BC.shouldEmit(BF) && !BF.hasExternalRefRelocations(); + }); if (!NeedsPatching) return; diff --git a/bolt/lib/Passes/ReorderData.cpp b/bolt/lib/Passes/ReorderData.cpp --- a/bolt/lib/Passes/ReorderData.cpp +++ b/bolt/lib/Passes/ReorderData.cpp @@ -108,13 +108,9 @@ bool IsValid = true; if (!opts::ReorderSymbols.empty()) { - IsValid = false; - for (const std::string &Name : opts::ReorderSymbols) { - if (BD->hasName(Name)) { - IsValid = true; - break; - } - } + IsValid = llvm::any_of(opts::ReorderSymbols, [&](const std::string &Name) { + return BD->hasName(Name); + }); } if (!IsValid) diff --git a/bolt/lib/Passes/ShrinkWrapping.cpp b/bolt/lib/Passes/ShrinkWrapping.cpp --- a/bolt/lib/Passes/ShrinkWrapping.cpp +++ b/bolt/lib/Passes/ShrinkWrapping.cpp @@ -1810,14 +1810,10 @@ BBIterTy ShrinkWrapping::processInsertionsList( BBIterTy InsertionPoint, BinaryBasicBlock *CurBB, std::vector &TodoList, int64_t SPVal, int64_t FPVal) { - bool HasInsertions = false; - for (WorklistItem &Item : TodoList) { - if (Item.Action == WorklistItem::Erase || - Item.Action == WorklistItem::ChangeToAdjustment) - continue; - HasInsertions = true; - break; - } + bool HasInsertions = llvm::any_of(TodoList, [&](WorklistItem &Item) { + return Item.Action == WorklistItem::InsertLoadOrStore || + Item.Action == WorklistItem::InsertPushOrPop; + }); if (!HasInsertions) return InsertionPoint; diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -18,6 +18,7 @@ #include "bolt/Profile/Heatmap.h" #include "bolt/Utils/CommandLineOpts.h" #include "bolt/Utils/Utils.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -2022,19 +2023,16 @@ MMapInfo &MMapInfo = I->second; if (BC->HasFixedLoadAddress && MMapInfo.MMapAddress) { // Check that the binary mapping matches one of the segments. - bool MatchFound = false; - for (auto &KV : BC->SegmentMapInfo) { - SegmentInfo &SegInfo = KV.second; - // The mapping is page-aligned and hence the MMapAddress could be - // different from the segment start address. We cannot know the page - // size of the mapping, but we know it should not exceed the segment - // alignment value. Hence we are performing an approximate check. - if (SegInfo.Address >= MMapInfo.MMapAddress && - SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment) { - MatchFound = true; - break; - } - } + bool MatchFound = llvm::any_of( + llvm::make_second_range(BC->SegmentMapInfo), + [&](SegmentInfo &SegInfo) { + // The mapping is page-aligned and hence the MMapAddress could be + // different from the segment start address. We cannot know the page + // size of the mapping, but we know it should not exceed the segment + // alignment value. Hence we are performing an approximate check. + return SegInfo.Address >= MMapInfo.MMapAddress && + SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment; + }); if (!MatchFound) { errs() << "PERF2BOLT-WARNING: ignoring mapping of " << NameToUse << " at 0x" << Twine::utohexstr(MMapInfo.MMapAddress) << '\n'; diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -31,6 +31,7 @@ #include "bolt/Utils/CommandLineOpts.h" #include "bolt/Utils/Utils.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" @@ -2500,15 +2501,12 @@ BC->getBinaryFunctionAtAddress(Address + 1)) { // Do an extra check that the function was referenced previously. // It's a linear search, but it should rarely happen. - bool Found = false; - for (const auto &RelKV : ContainingBF->Relocations) { - const Relocation &Rel = RelKV.second; - if (Rel.Symbol == RogueBF->getSymbol() && - !Relocation::isPCRelative(Rel.Type)) { - Found = true; - break; - } - } + bool Found = + llvm::any_of(llvm::make_second_range(ContainingBF->Relocations), + [&](const Relocation &Rel) { + return Rel.Symbol == RogueBF->getSymbol() && + !Relocation::isPCRelative(Rel.Type); + }); if (Found) { errs() << "BOLT-WARNING: detected possible compiler de-virtualization "