diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -16,6 +16,7 @@ #include "bolt/Utils/CommandLineOpts.h" #include "bolt/Utils/NameResolver.h" #include "bolt/Utils/Utils.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" @@ -1500,10 +1501,9 @@ std::vector BinaryContext::getSortedFunctions() { std::vector SortedFunctions(BinaryFunctions.size()); - llvm::transform(BinaryFunctions, SortedFunctions.begin(), - [](std::pair &BFI) { - return &BFI.second; - }); + llvm::transform(llvm::make_second_range(BinaryFunctions), + SortedFunctions.begin(), + [](BinaryFunction &BF) { return &BF; }); llvm::stable_sort(SortedFunctions, [](const BinaryFunction *A, const BinaryFunction *B) { @@ -1518,10 +1518,9 @@ std::vector BinaryContext::getAllBinaryFunctions() { std::vector AllFunctions; AllFunctions.reserve(BinaryFunctions.size() + InjectedBinaryFunctions.size()); - llvm::transform(BinaryFunctions, std::back_inserter(AllFunctions), - [](std::pair &BFI) { - return &BFI.second; - }); + llvm::transform(llvm::make_second_range(BinaryFunctions), + std::back_inserter(AllFunctions), + [](BinaryFunction &BF) { return &BF; }); llvm::copy(InjectedBinaryFunctions, std::back_inserter(AllFunctions)); return AllFunctions; diff --git a/bolt/lib/Passes/IndirectCallPromotion.cpp b/bolt/lib/Passes/IndirectCallPromotion.cpp --- a/bolt/lib/Passes/IndirectCallPromotion.cpp +++ b/bolt/lib/Passes/IndirectCallPromotion.cpp @@ -14,7 +14,9 @@ #include "bolt/Passes/BinaryFunctionCallGraph.h" #include "bolt/Passes/DataflowInfoManager.h" #include "bolt/Passes/Inliner.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/CommandLine.h" +#include #define DEBUG_TYPE "ICP" #define DEBUG_VERBOSE(Level, X) \ @@ -497,11 +499,8 @@ HotTarget.second = Index; } - llvm::transform( - HotTargetMap, std::back_inserter(HotTargets), - [](const std::pair> &A) { - return A.second; - }); + llvm::copy(llvm::make_second_range(HotTargetMap), + std::back_inserter(HotTargets)); // Sort with highest counts first. llvm::sort(reverse(HotTargets)); diff --git a/bolt/lib/Passes/ReorderFunctions.cpp b/bolt/lib/Passes/ReorderFunctions.cpp --- a/bolt/lib/Passes/ReorderFunctions.cpp +++ b/bolt/lib/Passes/ReorderFunctions.cpp @@ -294,10 +294,8 @@ { std::vector SortedFunctions(BFs.size()); uint32_t Index = 0; - llvm::transform(BFs, SortedFunctions.begin(), - [](std::pair &BFI) { - return &BFI.second; - }); + llvm::transform(llvm::make_second_range(BFs), SortedFunctions.begin(), + [](BinaryFunction &BF) { return &BF; }); llvm::stable_sort(SortedFunctions, [&](const BinaryFunction *A, const BinaryFunction *B) { if (A->isIgnored()) @@ -428,10 +426,8 @@ if (FuncsFile || LinkSectionsFile) { std::vector SortedFunctions(BFs.size()); - llvm::transform(BFs, SortedFunctions.begin(), - [](std::pair &BFI) { - return &BFI.second; - }); + llvm::transform(llvm::make_second_range(BFs), SortedFunctions.begin(), + [](BinaryFunction &BF) { return &BF; }); // Sort functions by index. llvm::stable_sort(SortedFunctions, 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 @@ -4450,8 +4450,7 @@ } std::vector SectionsOnly(OutputSections.size()); - llvm::transform(OutputSections, SectionsOnly.begin(), - [](auto &SectionInfo) { return SectionInfo.second; }); + llvm::copy(llvm::make_second_range(OutputSections), SectionsOnly.begin()); return SectionsOnly; } diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp --- a/bolt/tools/merge-fdata/merge-fdata.cpp +++ b/bolt/tools/merge-fdata/merge-fdata.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "bolt/Profile/ProfileYAMLMapping.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -398,9 +399,8 @@ BinaryProfile MergedProfile; MergedProfile.Header = MergedHeader; MergedProfile.Functions.resize(MergedBFs.size()); - llvm::transform( - MergedBFs, MergedProfile.Functions.begin(), - [](StringMapEntry &V) { return V.second; }); + llvm::copy(llvm::make_second_range(MergedBFs), + MergedProfile.Functions.begin()); // For consistency, sort functions by their IDs. llvm::sort(MergedProfile.Functions,