[llvm] r328943 - [tools] Change std::sort to llvm::sort in response to r327219
Mandeep Singh Grang via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 1 14:24:53 PDT 2018
Author: mgrang
Date: Sun Apr 1 14:24:53 2018
New Revision: 328943
URL: http://llvm.org/viewvc/llvm-project?rev=328943&view=rev
Log:
[tools] Change std::sort to llvm::sort in response to r327219
Summary:
r327219 added wrappers to std::sort which randomly shuffle the container before sorting.
This will help in uncovering non-determinism caused due to undefined sorting
order of objects having the same key.
To make use of that infrastructure we need to invoke llvm::sort instead of std::sort.
Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort.
Refer the comments section in D44363 for a list of all the required patches.
Reviewers: JDevlieghere, zturner, echristo, dberris, friss
Reviewed By: echristo
Subscribers: gbedwell, llvm-commits
Differential Revision: https://reviews.llvm.org/D45141
Modified:
llvm/trunk/tools/dsymutil/DebugMap.cpp
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp
llvm/trunk/tools/llvm-config/llvm-config.cpp
llvm/trunk/tools/llvm-mca/InstrBuilder.cpp
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-objdump/MachODump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp
llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp
llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/tools/llvm-xray/xray-account.cc
llvm/trunk/tools/yaml2obj/yaml2macho.cpp
Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Sun Apr 1 14:24:53 2018
@@ -63,9 +63,10 @@ void DebugMapObject::print(raw_ostream &
Entries.reserve(Symbols.getNumItems());
for (const auto &Sym : make_range(Symbols.begin(), Symbols.end()))
Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue()));
- std::sort(
- Entries.begin(), Entries.end(),
- [](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
+ llvm::sort(Entries.begin(), Entries.end(),
+ [](const Entry &LHS, const Entry &RHS) {
+ return LHS.first < RHS.first;
+ });
for (const auto &Sym : Entries) {
if (Sym.second.ObjectAddress)
OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sun Apr 1 14:24:53 2018
@@ -1069,7 +1069,7 @@ void DwarfStreamer::emitUnitRangesEntrie
// The object addresses where sorted, but again, the linked
// addresses might end up in a different order.
- std::sort(Ranges.begin(), Ranges.end());
+ llvm::sort(Ranges.begin(), Ranges.end());
if (!Ranges.empty()) {
MS->SwitchSection(MC->getObjectFileInfo()->getDwarfARangesSection());
@@ -2407,7 +2407,7 @@ bool DwarfLinker::RelocationManager::fin
// the file, this allows us to just keep an index in the relocation
// array that we advance during our walk, rather than resorting to
// some associative container. See DwarfLinker::NextValidReloc.
- std::sort(ValidRelocs.begin(), ValidRelocs.end());
+ llvm::sort(ValidRelocs.begin(), ValidRelocs.end());
return true;
}
Modified: llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp (original)
+++ llvm/trunk/tools/dsymutil/NonRelocatableStringpool.cpp Sun Apr 1 14:24:53 2018
@@ -39,7 +39,7 @@ NonRelocatableStringpool::getEntries() c
Result.reserve(Strings.size());
for (const auto &E : Strings)
Result.emplace_back(E);
- std::sort(
+ llvm::sort(
Result.begin(), Result.end(),
[](const DwarfStringPoolEntryRef A, const DwarfStringPoolEntryRef B) {
return A.getIndex() < B.getIndex();
Modified: llvm/trunk/tools/llvm-config/llvm-config.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/llvm-config.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-config/llvm-config.cpp (original)
+++ llvm/trunk/tools/llvm-config/llvm-config.cpp Sun Apr 1 14:24:53 2018
@@ -522,7 +522,7 @@ int main(int argc, char **argv) {
if (DyLibExists && !sys::fs::exists(path)) {
Components =
GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep);
- std::sort(Components.begin(), Components.end());
+ llvm::sort(Components.begin(), Components.end());
break;
}
}
Modified: llvm/trunk/tools/llvm-mca/InstrBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/InstrBuilder.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/InstrBuilder.cpp (original)
+++ llvm/trunk/tools/llvm-mca/InstrBuilder.cpp Sun Apr 1 14:24:53 2018
@@ -44,16 +44,16 @@ static void initializeUsedResources(Inst
// Sort elements by mask popcount, so that we prioritize resource units over
// resource groups, and smaller groups over larger groups.
- std::sort(Worklist.begin(), Worklist.end(),
- [](const ResourcePlusCycles &A, const ResourcePlusCycles &B) {
- unsigned popcntA = countPopulation(A.first);
- unsigned popcntB = countPopulation(B.first);
- if (popcntA < popcntB)
- return true;
- if (popcntA > popcntB)
- return false;
- return A.first < B.first;
- });
+ llvm::sort(Worklist.begin(), Worklist.end(),
+ [](const ResourcePlusCycles &A, const ResourcePlusCycles &B) {
+ unsigned popcntA = countPopulation(A.first);
+ unsigned popcntB = countPopulation(B.first);
+ if (popcntA < popcntB)
+ return true;
+ if (popcntA > popcntB)
+ return false;
+ return A.first < B.first;
+ });
uint64_t UsedResourceUnits = 0;
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Sun Apr 1 14:24:53 2018
@@ -705,7 +705,7 @@ static void sortAndPrintSymbolList(Symbo
if (ReverseSort)
Cmp = [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); };
- std::sort(SymbolList.begin(), SymbolList.end(), Cmp);
+ llvm::sort(SymbolList.begin(), SymbolList.end(), Cmp);
}
if (!PrintFileName) {
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Sun Apr 1 14:24:53 2018
@@ -453,7 +453,7 @@ static bool getPDataSection(const COFFOb
Rels.push_back(Reloc);
// Sort relocations by address.
- std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
+ llvm::sort(Rels.begin(), Rels.end(), RelocAddressLess);
ArrayRef<uint8_t> Contents;
error(Obj->getSectionContents(Pdata, Contents));
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Sun Apr 1 14:24:53 2018
@@ -6909,7 +6909,7 @@ static void DisassembleMachO(StringRef F
BaseSegmentAddress);
// Sort the symbols by address, just in case they didn't come in that way.
- std::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
+ llvm::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
// Build a data in code table that is sorted on by the address of each entry.
uint64_t BaseAddress = 0;
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Sun Apr 1 14:24:53 2018
@@ -1381,8 +1381,8 @@ static void DisassembleObject(const Obje
}
}
- std::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end());
- std::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end());
+ llvm::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end());
+ llvm::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end());
if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
// AMDGPU disassembler uses symbolizer for printing labels
@@ -1407,7 +1407,7 @@ static void DisassembleObject(const Obje
}
// Sort relocations by address.
- std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
+ llvm::sort(Rels.begin(), Rels.end(), RelocAddressLess);
StringRef SegmentName = "";
if (const MachOObjectFile *MachO = dyn_cast<const MachOObjectFile>(Obj)) {
Modified: llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp Sun Apr 1 14:24:53 2018
@@ -876,7 +876,7 @@ Error DumpOutputStyle::dumpStringTableFr
std::vector<uint32_t> SortedIDs(IS->name_ids().begin(),
IS->name_ids().end());
- std::sort(SortedIDs.begin(), SortedIDs.end());
+ llvm::sort(SortedIDs.begin(), SortedIDs.end());
for (uint32_t I : SortedIDs) {
auto ES = IS->getStringForID(I);
llvm::SmallString<32> Str;
Modified: llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/PrettyTypeDumper.cpp Sun Apr 1 14:24:53 2018
@@ -128,7 +128,7 @@ filterAndSortClassDefs(LinePrinter &Prin
}
if (Comp)
- std::sort(Filtered.begin(), Filtered.end(), Comp);
+ llvm::sort(Filtered.begin(), Filtered.end(), Comp);
return Filtered;
}
Modified: llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp Sun Apr 1 14:24:53 2018
@@ -977,8 +977,8 @@ static void dumpPretty(StringRef Path) {
std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
while (auto Func = Functions->getNext())
Funcs.push_back(std::move(Func));
- std::sort(Funcs.begin(), Funcs.end(),
- opts::pretty::compareFunctionSymbols);
+ llvm::sort(Funcs.begin(), Funcs.end(),
+ opts::pretty::compareFunctionSymbols);
for (const auto &Func : Funcs) {
Printer.NewLine();
Dumper.start(*Func, FunctionDumper::PointerType::None);
@@ -996,8 +996,8 @@ static void dumpPretty(StringRef Path) {
std::vector<std::unique_ptr<PDBSymbolData>> Datas;
while (auto Var = Vars->getNext())
Datas.push_back(std::move(Var));
- std::sort(Datas.begin(), Datas.end(),
- opts::pretty::compareDataSymbols);
+ llvm::sort(Datas.begin(), Datas.end(),
+ opts::pretty::compareDataSymbols);
for (const auto &Var : Datas)
Dumper.start(*Var);
}
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Sun Apr 1 14:24:53 2018
@@ -607,8 +607,8 @@ void COFFDumper::cacheRelocations() {
RelocMap[Section].push_back(Reloc);
// Sort relocations by address.
- std::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
- relocAddressLess);
+ llvm::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
+ relocAddressLess);
}
}
Modified: llvm/trunk/tools/llvm-xray/xray-account.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-account.cc?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-account.cc (original)
+++ llvm/trunk/tools/llvm-xray/xray-account.cc Sun Apr 1 14:24:53 2018
@@ -282,79 +282,79 @@ void LatencyAccountant::exportStats(cons
// Sort the data according to user-provided flags.
switch (AccountSortOutput) {
case SortField::FUNCID:
- std::sort(Results.begin(), Results.end(),
- [](const TupleType &L, const TupleType &R) {
- if (AccountSortOrder == SortDirection::ASCENDING)
- return std::get<0>(L) < std::get<0>(R);
- if (AccountSortOrder == SortDirection::DESCENDING)
- return std::get<0>(L) > std::get<0>(R);
- llvm_unreachable("Unknown sort direction");
- });
+ llvm::sort(Results.begin(), Results.end(),
+ [](const TupleType &L, const TupleType &R) {
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return std::get<0>(L) < std::get<0>(R);
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return std::get<0>(L) > std::get<0>(R);
+ llvm_unreachable("Unknown sort direction");
+ });
break;
case SortField::COUNT:
- std::sort(Results.begin(), Results.end(),
- [](const TupleType &L, const TupleType &R) {
- if (AccountSortOrder == SortDirection::ASCENDING)
- return std::get<1>(L) < std::get<1>(R);
- if (AccountSortOrder == SortDirection::DESCENDING)
- return std::get<1>(L) > std::get<1>(R);
- llvm_unreachable("Unknown sort direction");
- });
+ llvm::sort(Results.begin(), Results.end(),
+ [](const TupleType &L, const TupleType &R) {
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return std::get<1>(L) < std::get<1>(R);
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return std::get<1>(L) > std::get<1>(R);
+ llvm_unreachable("Unknown sort direction");
+ });
break;
default:
// Here we need to look into the ResultRow for the rest of the data that
// we want to sort by.
- std::sort(Results.begin(), Results.end(),
- [&](const TupleType &L, const TupleType &R) {
- auto &LR = std::get<2>(L);
- auto &RR = std::get<2>(R);
- switch (AccountSortOutput) {
- case SortField::COUNT:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Count < RR.Count;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Count > RR.Count;
- llvm_unreachable("Unknown sort direction");
- case SortField::MIN:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Min < RR.Min;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Min > RR.Min;
- llvm_unreachable("Unknown sort direction");
- case SortField::MED:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Median < RR.Median;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Median > RR.Median;
- llvm_unreachable("Unknown sort direction");
- case SortField::PCT90:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Pct90 < RR.Pct90;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Pct90 > RR.Pct90;
- llvm_unreachable("Unknown sort direction");
- case SortField::PCT99:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Pct99 < RR.Pct99;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Pct99 > RR.Pct99;
- llvm_unreachable("Unknown sort direction");
- case SortField::MAX:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Max < RR.Max;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Max > RR.Max;
- llvm_unreachable("Unknown sort direction");
- case SortField::SUM:
- if (AccountSortOrder == SortDirection::ASCENDING)
- return LR.Sum < RR.Sum;
- if (AccountSortOrder == SortDirection::DESCENDING)
- return LR.Sum > RR.Sum;
- llvm_unreachable("Unknown sort direction");
- default:
- llvm_unreachable("Unsupported sort order");
- }
- });
+ llvm::sort(Results.begin(), Results.end(),
+ [&](const TupleType &L, const TupleType &R) {
+ auto &LR = std::get<2>(L);
+ auto &RR = std::get<2>(R);
+ switch (AccountSortOutput) {
+ case SortField::COUNT:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Count < RR.Count;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Count > RR.Count;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MIN:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Min < RR.Min;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Min > RR.Min;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MED:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Median < RR.Median;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Median > RR.Median;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::PCT90:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Pct90 < RR.Pct90;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Pct90 > RR.Pct90;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::PCT99:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Pct99 < RR.Pct99;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Pct99 > RR.Pct99;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MAX:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Max < RR.Max;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Max > RR.Max;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::SUM:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Sum < RR.Sum;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Sum > RR.Sum;
+ llvm_unreachable("Unknown sort direction");
+ default:
+ llvm_unreachable("Unsupported sort order");
+ }
+ });
break;
}
Modified: llvm/trunk/tools/yaml2obj/yaml2macho.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2macho.cpp?rev=328943&r1=328942&r2=328943&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2macho.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2macho.cpp Sun Apr 1 14:24:53 2018
@@ -417,10 +417,10 @@ Error MachOWriter::writeLinkEditData(raw
}
}
- std::sort(WriteQueue.begin(), WriteQueue.end(),
- [](const writeOperation &a, const writeOperation &b) {
- return a.first < b.first;
- });
+ llvm::sort(WriteQueue.begin(), WriteQueue.end(),
+ [](const writeOperation &a, const writeOperation &b) {
+ return a.first < b.first;
+ });
for (auto writeOp : WriteQueue) {
ZeroToOffset(OS, writeOp.first);
More information about the llvm-commits
mailing list