llvm.org GIT mirror llvm / 4ead3eb
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328943 91177308-0d34-0410-b5e6-96231b3b80d8 Mandeep Singh Grang 1 year, 5 months ago
15 changed file(s) with 103 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
6262 Entries.reserve(Symbols.getNumItems());
6363 for (const auto &Sym : make_range(Symbols.begin(), Symbols.end()))
6464 Entries.push_back(std::make_pair(Sym.getKey(), Sym.getValue()));
65 std::sort(
66 Entries.begin(), Entries.end(),
67 [](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
65 llvm::sort(Entries.begin(), Entries.end(),
66 [](const Entry &LHS, const Entry &RHS) {
67 return LHS.first < RHS.first;
68 });
6869 for (const auto &Sym : Entries) {
6970 if (Sym.second.ObjectAddress)
7071 OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));
10681068
10691069 // The object addresses where sorted, but again, the linked
10701070 // addresses might end up in a different order.
1071 std::sort(Ranges.begin(), Ranges.end());
1071 llvm::sort(Ranges.begin(), Ranges.end());
10721072
10731073 if (!Ranges.empty()) {
10741074 MS->SwitchSection(MC->getObjectFileInfo()->getDwarfARangesSection());
24062406 // the file, this allows us to just keep an index in the relocation
24072407 // array that we advance during our walk, rather than resorting to
24082408 // some associative container. See DwarfLinker::NextValidReloc.
2409 std::sort(ValidRelocs.begin(), ValidRelocs.end());
2409 llvm::sort(ValidRelocs.begin(), ValidRelocs.end());
24102410 return true;
24112411 }
24122412
3838 Result.reserve(Strings.size());
3939 for (const auto &E : Strings)
4040 Result.emplace_back(E);
41 std::sort(
41 llvm::sort(
4242 Result.begin(), Result.end(),
4343 [](const DwarfStringPoolEntryRef A, const DwarfStringPoolEntryRef B) {
4444 return A.getIndex() < B.getIndex();
521521 if (DyLibExists && !sys::fs::exists(path)) {
522522 Components =
523523 GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep);
524 std::sort(Components.begin(), Components.end());
524 llvm::sort(Components.begin(), Components.end());
525525 break;
526526 }
527527 }
4343
4444 // Sort elements by mask popcount, so that we prioritize resource units over
4545 // resource groups, and smaller groups over larger groups.
46 std::sort(Worklist.begin(), Worklist.end(),
47 [](const ResourcePlusCycles &A, const ResourcePlusCycles &B) {
48 unsigned popcntA = countPopulation(A.first);
49 unsigned popcntB = countPopulation(B.first);
50 if (popcntA < popcntB)
51 return true;
52 if (popcntA > popcntB)
53 return false;
54 return A.first < B.first;
55 });
46 llvm::sort(Worklist.begin(), Worklist.end(),
47 [](const ResourcePlusCycles &A, const ResourcePlusCycles &B) {
48 unsigned popcntA = countPopulation(A.first);
49 unsigned popcntB = countPopulation(B.first);
50 if (popcntA < popcntB)
51 return true;
52 if (popcntA > popcntB)
53 return false;
54 return A.first < B.first;
55 });
5656
5757 uint64_t UsedResourceUnits = 0;
5858
704704
705705 if (ReverseSort)
706706 Cmp = [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); };
707 std::sort(SymbolList.begin(), SymbolList.end(), Cmp);
707 llvm::sort(SymbolList.begin(), SymbolList.end(), Cmp);
708708 }
709709
710710 if (!PrintFileName) {
452452 Rels.push_back(Reloc);
453453
454454 // Sort relocations by address.
455 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
455 llvm::sort(Rels.begin(), Rels.end(), RelocAddressLess);
456456
457457 ArrayRef Contents;
458458 error(Obj->getSectionContents(Pdata, Contents));
69086908 BaseSegmentAddress);
69096909
69106910 // Sort the symbols by address, just in case they didn't come in that way.
6911 std::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
6911 llvm::sort(Symbols.begin(), Symbols.end(), SymbolSorter());
69126912
69136913 // Build a data in code table that is sorted on by the address of each entry.
69146914 uint64_t BaseAddress = 0;
13801380 }
13811381 }
13821382
1383 std::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end());
1384 std::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end());
1383 llvm::sort(DataMappingSymsAddr.begin(), DataMappingSymsAddr.end());
1384 llvm::sort(TextMappingSymsAddr.begin(), TextMappingSymsAddr.end());
13851385
13861386 if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
13871387 // AMDGPU disassembler uses symbolizer for printing labels
14061406 }
14071407
14081408 // Sort relocations by address.
1409 std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
1409 llvm::sort(Rels.begin(), Rels.end(), RelocAddressLess);
14101410
14111411 StringRef SegmentName = "";
14121412 if (const MachOObjectFile *MachO = dyn_cast(Obj)) {
875875
876876 std::vector SortedIDs(IS->name_ids().begin(),
877877 IS->name_ids().end());
878 std::sort(SortedIDs.begin(), SortedIDs.end());
878 llvm::sort(SortedIDs.begin(), SortedIDs.end());
879879 for (uint32_t I : SortedIDs) {
880880 auto ES = IS->getStringForID(I);
881881 llvm::SmallString<32> Str;
127127 }
128128
129129 if (Comp)
130 std::sort(Filtered.begin(), Filtered.end(), Comp);
130 llvm::sort(Filtered.begin(), Filtered.end(), Comp);
131131 return Filtered;
132132 }
133133
976976 std::vector> Funcs;
977977 while (auto Func = Functions->getNext())
978978 Funcs.push_back(std::move(Func));
979 std::sort(Funcs.begin(), Funcs.end(),
980 opts::pretty::compareFunctionSymbols);
979 llvm::sort(Funcs.begin(), Funcs.end(),
980 opts::pretty::compareFunctionSymbols);
981981 for (const auto &Func : Funcs) {
982982 Printer.NewLine();
983983 Dumper.start(*Func, FunctionDumper::PointerType::None);
995995 std::vector> Datas;
996996 while (auto Var = Vars->getNext())
997997 Datas.push_back(std::move(Var));
998 std::sort(Datas.begin(), Datas.end(),
999 opts::pretty::compareDataSymbols);
998 llvm::sort(Datas.begin(), Datas.end(),
999 opts::pretty::compareDataSymbols);
10001000 for (const auto &Var : Datas)
10011001 Dumper.start(*Var);
10021002 }
606606 RelocMap[Section].push_back(Reloc);
607607
608608 // Sort relocations by address.
609 std::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
610 relocAddressLess);
609 llvm::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
610 relocAddressLess);
611611 }
612612 }
613613
281281 // Sort the data according to user-provided flags.
282282 switch (AccountSortOutput) {
283283 case SortField::FUNCID:
284 std::sort(Results.begin(), Results.end(),
285 [](const TupleType &L, const TupleType &R) {
286 if (AccountSortOrder == SortDirection::ASCENDING)
287 return std::get<0>(L) < std::get<0>(R);
288 if (AccountSortOrder == SortDirection::DESCENDING)
289 return std::get<0>(L) > std::get<0>(R);
290 llvm_unreachable("Unknown sort direction");
291 });
284 llvm::sort(Results.begin(), Results.end(),
285 [](const TupleType &L, const TupleType &R) {
286 if (AccountSortOrder == SortDirection::ASCENDING)
287 return std::get<0>(L) < std::get<0>(R);
288 if (AccountSortOrder == SortDirection::DESCENDING)
289 return std::get<0>(L) > std::get<0>(R);
290 llvm_unreachable("Unknown sort direction");
291 });
292292 break;
293293 case SortField::COUNT:
294 std::sort(Results.begin(), Results.end(),
295 [](const TupleType &L, const TupleType &R) {
296 if (AccountSortOrder == SortDirection::ASCENDING)
297 return std::get<1>(L) < std::get<1>(R);
298 if (AccountSortOrder == SortDirection::DESCENDING)
299 return std::get<1>(L) > std::get<1>(R);
300 llvm_unreachable("Unknown sort direction");
301 });
294 llvm::sort(Results.begin(), Results.end(),
295 [](const TupleType &L, const TupleType &R) {
296 if (AccountSortOrder == SortDirection::ASCENDING)
297 return std::get<1>(L) < std::get<1>(R);
298 if (AccountSortOrder == SortDirection::DESCENDING)
299 return std::get<1>(L) > std::get<1>(R);
300 llvm_unreachable("Unknown sort direction");
301 });
302302 break;
303303 default:
304304 // Here we need to look into the ResultRow for the rest of the data that
305305 // we want to sort by.
306 std::sort(Results.begin(), Results.end(),
307 [&](const TupleType &L, const TupleType &R) {
308 auto &LR = std::get<2>(L);
309 auto &RR = std::get<2>(R);
310 switch (AccountSortOutput) {
311 case SortField::COUNT:
312 if (AccountSortOrder == SortDirection::ASCENDING)
313 return LR.Count < RR.Count;
314 if (AccountSortOrder == SortDirection::DESCENDING)
315 return LR.Count > RR.Count;
316 llvm_unreachable("Unknown sort direction");
317 case SortField::MIN:
318 if (AccountSortOrder == SortDirection::ASCENDING)
319 return LR.Min < RR.Min;
320 if (AccountSortOrder == SortDirection::DESCENDING)
321 return LR.Min > RR.Min;
322 llvm_unreachable("Unknown sort direction");
323 case SortField::MED:
324 if (AccountSortOrder == SortDirection::ASCENDING)
325 return LR.Median < RR.Median;
326 if (AccountSortOrder == SortDirection::DESCENDING)
327 return LR.Median > RR.Median;
328 llvm_unreachable("Unknown sort direction");
329 case SortField::PCT90:
330 if (AccountSortOrder == SortDirection::ASCENDING)
331 return LR.Pct90 < RR.Pct90;
332 if (AccountSortOrder == SortDirection::DESCENDING)
333 return LR.Pct90 > RR.Pct90;
334 llvm_unreachable("Unknown sort direction");
335 case SortField::PCT99:
336 if (AccountSortOrder == SortDirection::ASCENDING)
337 return LR.Pct99 < RR.Pct99;
338 if (AccountSortOrder == SortDirection::DESCENDING)
339 return LR.Pct99 > RR.Pct99;
340 llvm_unreachable("Unknown sort direction");
341 case SortField::MAX:
342 if (AccountSortOrder == SortDirection::ASCENDING)
343 return LR.Max < RR.Max;
344 if (AccountSortOrder == SortDirection::DESCENDING)
345 return LR.Max > RR.Max;
346 llvm_unreachable("Unknown sort direction");
347 case SortField::SUM:
348 if (AccountSortOrder == SortDirection::ASCENDING)
349 return LR.Sum < RR.Sum;
350 if (AccountSortOrder == SortDirection::DESCENDING)
351 return LR.Sum > RR.Sum;
352 llvm_unreachable("Unknown sort direction");
353 default:
354 llvm_unreachable("Unsupported sort order");
355 }
356 });
306 llvm::sort(Results.begin(), Results.end(),
307 [&](const TupleType &L, const TupleType &R) {
308 auto &LR = std::get<2>(L);
309 auto &RR = std::get<2>(R);
310 switch (AccountSortOutput) {
311 case SortField::COUNT:
312 if (AccountSortOrder == SortDirection::ASCENDING)
313 return LR.Count < RR.Count;
314 if (AccountSortOrder == SortDirection::DESCENDING)
315 return LR.Count > RR.Count;
316 llvm_unreachable("Unknown sort direction");
317 case SortField::MIN:
318 if (AccountSortOrder == SortDirection::ASCENDING)
319 return LR.Min < RR.Min;
320 if (AccountSortOrder == SortDirection::DESCENDING)
321 return LR.Min > RR.Min;
322 llvm_unreachable("Unknown sort direction");
323 case SortField::MED:
324 if (AccountSortOrder == SortDirection::ASCENDING)
325 return LR.Median < RR.Median;
326 if (AccountSortOrder == SortDirection::DESCENDING)
327 return LR.Median > RR.Median;
328 llvm_unreachable("Unknown sort direction");
329 case SortField::PCT90:
330 if (AccountSortOrder == SortDirection::ASCENDING)
331 return LR.Pct90 < RR.Pct90;
332 if (AccountSortOrder == SortDirection::DESCENDING)
333 return LR.Pct90 > RR.Pct90;
334 llvm_unreachable("Unknown sort direction");
335 case SortField::PCT99:
336 if (AccountSortOrder == SortDirection::ASCENDING)
337 return LR.Pct99 < RR.Pct99;
338 if (AccountSortOrder == SortDirection::DESCENDING)
339 return LR.Pct99 > RR.Pct99;
340 llvm_unreachable("Unknown sort direction");
341 case SortField::MAX:
342 if (AccountSortOrder == SortDirection::ASCENDING)
343 return LR.Max < RR.Max;
344 if (AccountSortOrder == SortDirection::DESCENDING)
345 return LR.Max > RR.Max;
346 llvm_unreachable("Unknown sort direction");
347 case SortField::SUM:
348 if (AccountSortOrder == SortDirection::ASCENDING)
349 return LR.Sum < RR.Sum;
350 if (AccountSortOrder == SortDirection::DESCENDING)
351 return LR.Sum > RR.Sum;
352 llvm_unreachable("Unknown sort direction");
353 default:
354 llvm_unreachable("Unsupported sort order");
355 }
356 });
357357 break;
358358 }
359359
416416 }
417417 }
418418
419 std::sort(WriteQueue.begin(), WriteQueue.end(),
420 [](const writeOperation &a, const writeOperation &b) {
421 return a.first < b.first;
422 });
419 llvm::sort(WriteQueue.begin(), WriteQueue.end(),
420 [](const writeOperation &a, const writeOperation &b) {
421 return a.first < b.first;
422 });
423423
424424 for (auto writeOp : WriteQueue) {
425425 ZeroToOffset(OS, writeOp.first);