Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm] Use llvm::sort (NFC) #96434

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2231,11 +2231,10 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares(
// order of fragment size - there should be no duplicates.
for (auto &Pair : FragmentMap) {
SmallVector<DebugVariable, 8> &Frags = Pair.second;
std::sort(Frags.begin(), Frags.end(),
[](const DebugVariable &Next, const DebugVariable &Elmt) {
return Elmt.getFragmentOrDefault().SizeInBits >
Next.getFragmentOrDefault().SizeInBits;
});
llvm::sort(Frags, [](const DebugVariable &Next, const DebugVariable &Elmt) {
return Elmt.getFragmentOrDefault().SizeInBits >
Next.getFragmentOrDefault().SizeInBits;
});
// Check for duplicates.
assert(std::adjacent_find(Frags.begin(), Frags.end()) == Frags.end());
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,9 @@ void extractInstructionFeatures(
// frequency vector, mapping each instruction to its associated MBB.

// Start off by sorting the segments based on the beginning slot index.
std::sort(
LRPosInfo.begin(), LRPosInfo.end(),
[](LRStartEndInfo A, LRStartEndInfo B) { return A.Begin < B.Begin; });
llvm::sort(LRPosInfo, [](LRStartEndInfo A, LRStartEndInfo B) {
return A.Begin < B.Begin;
});
size_t InstructionIndex = 0;
size_t CurrentSegmentIndex = 0;
SlotIndex CurrentIndex = LRPosInfo[0].Begin;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DWARFLinker/Parallel/ArrayList.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ template <typename T, size_t ItemsGroupSize = 512> class ArrayList {
forEach([&](T &Item) { SortedItems.push_back(Item); });

if (SortedItems.size()) {
std::sort(SortedItems.begin(), SortedItems.end(), Comparator);
llvm::sort(SortedItems, Comparator);

size_t SortedItemIdx = 0;
forEach([&](T &Item) { Item = SortedItems[SortedItemIdx++]; });
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,9 @@ void JITDylib::dump(raw_ostream &OS) {
std::vector<std::pair<SymbolStringPtr, SymbolTableEntry *>> SymbolsSorted;
for (auto &KV : Symbols)
SymbolsSorted.emplace_back(KV.first, &KV.second);
std::sort(SymbolsSorted.begin(), SymbolsSorted.end(),
[](const auto &L, const auto &R) { return *L.first < *R.first; });
llvm::sort(SymbolsSorted, [](const auto &L, const auto &R) {
return *L.first < *R.first;
});

for (auto &KV : SymbolsSorted) {
OS << " \"" << *KV.first << "\": ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void preserveDWARFSection(LinkGraph &G, Section &Sec) {
static SmallVector<char, 0> getSectionData(Section &Sec) {
SmallVector<char, 0> SecData;
SmallVector<Block *, 8> SecBlocks(Sec.blocks().begin(), Sec.blocks().end());
std::sort(SecBlocks.begin(), SecBlocks.end(), [](Block *LHS, Block *RHS) {
llvm::sort(SecBlocks, [](Block *LHS, Block *RHS) {
return LHS->getAddress() < RHS->getAddress();
});
// Convert back to what object file would have, one blob of section content
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ RawInstrProfReader<IntPtrT>::getTemporalProfTraces(
return TemporalProfTraces;
}
// Sort functions by their timestamps to build the trace.
std::sort(TemporalProfTimestamps.begin(), TemporalProfTimestamps.end());
llvm::sort(TemporalProfTimestamps);
TemporalProfTraceTy Trace;
if (Weight)
Trace.Weight = *Weight;
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,9 @@ void PipelineSolver::populateReadyList(
}

if (UseCostHeur) {
std::sort(ReadyList.begin(), ReadyList.end(),
[](std::pair<int, int> A, std::pair<int, int> B) {
return A.second < B.second;
});
llvm::sort(ReadyList, [](std::pair<int, int> A, std::pair<int, int> B) {
kazutakahirata marked this conversation as resolved.
Show resolved Hide resolved
return A.second < B.second;
});
}

assert(ReadyList.size() == CurrSU.second.size());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6886,8 +6886,8 @@ bool ARMPipelinerLoopInfo::tooMuchRegisterPressure(SwingSchedulerDAG &SSD,
++Stage) {
std::deque<SUnit *> Instrs =
SMS.getInstructions(Cycle + Stage * SMS.getInitiationInterval());
std::sort(Instrs.begin(), Instrs.end(),
[](SUnit *A, SUnit *B) { return A->NodeNum > B->NodeNum; });
llvm::sort(Instrs,
[](SUnit *A, SUnit *B) { return A->NodeNum > B->NodeNum; });
for (SUnit *SU : Instrs)
ProposedSchedule.push_back(SU);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVVMReflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static bool runNVVMReflect(Function &F, unsigned SmVersion) {

// Removing via isInstructionTriviallyDead may add duplicates to the ToRemove
// array. Filter out the duplicates before starting to erase from parent.
std::sort(ToRemove.begin(), ToRemove.end());
llvm::sort(ToRemove);
auto NewLastIter = llvm::unique(ToRemove);
ToRemove.erase(NewLastIter, ToRemove.end());

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool PPCMergeStringPool::mergeModuleStringPool(Module &M) {
return false;

// Sort the global constants to make access more efficient.
std::sort(MergeableStrings.begin(), MergeableStrings.end(), CompareConstants);
llvm::sort(MergeableStrings, CompareConstants);

SmallVector<Constant *> ConstantsInStruct;
for (GlobalVariable *GV : MergeableStrings)
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextNode::print(
// Make a copy of the computed context ids that we can sort for stability.
auto ContextIds = getContextIds();
std::vector<uint32_t> SortedIds(ContextIds.begin(), ContextIds.end());
std::sort(SortedIds.begin(), SortedIds.end());
llvm::sort(SortedIds);
for (auto Id : SortedIds)
OS << " " << Id;
OS << "\n";
Expand Down Expand Up @@ -2238,7 +2238,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextEdge::print(
<< " AllocTypes: " << getAllocTypeString(AllocTypes);
OS << " ContextIds:";
std::vector<uint32_t> SortedIds(ContextIds.begin(), ContextIds.end());
std::sort(SortedIds.begin(), SortedIds.end());
llvm::sort(SortedIds);
for (auto Id : SortedIds)
OS << " " << Id;
}
Expand Down Expand Up @@ -2380,7 +2380,7 @@ struct DOTGraphTraits<const CallsiteContextGraph<DerivedCCG, FuncTy, CallTy> *>
std::string IdString = "ContextIds:";
if (ContextIds.size() < 100) {
std::vector<uint32_t> SortedIds(ContextIds.begin(), ContextIds.end());
std::sort(SortedIds.begin(), SortedIds.end());
llvm::sort(SortedIds);
for (auto Id : SortedIds)
IdString += (" " + Twine(Id)).str();
} else {
Expand Down
33 changes: 15 additions & 18 deletions llvm/lib/Transforms/Utils/CodeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,15 @@ class ExtTSPImpl {
}

// Sorting chains by density in the decreasing order.
std::sort(SortedChains.begin(), SortedChains.end(),
[&](const ChainT *L, const ChainT *R) {
// Place the entry point at the beginning of the order.
if (L->isEntry() != R->isEntry())
return L->isEntry();

// Compare by density and break ties by chain identifiers.
return std::make_tuple(-L->density(), L->Id) <
std::make_tuple(-R->density(), R->Id);
});
llvm::sort(SortedChains, [&](const ChainT *L, const ChainT *R) {
// Place the entry point at the beginning of the order.
if (L->isEntry() != R->isEntry())
return L->isEntry();

// Compare by density and break ties by chain identifiers.
return std::make_tuple(-L->density(), L->Id) <
std::make_tuple(-R->density(), R->Id);
});

// Collect the nodes in the order specified by their chains.
std::vector<uint64_t> Order;
Expand Down Expand Up @@ -1355,14 +1354,12 @@ class CDSortImpl {
}

// Sort chains by density in the decreasing order.
std::sort(SortedChains.begin(), SortedChains.end(),
[&](const ChainT *L, const ChainT *R) {
const double DL = ChainDensity[L];
const double DR = ChainDensity[R];
// Compare by density and break ties by chain identifiers.
return std::make_tuple(-DL, L->Id) <
std::make_tuple(-DR, R->Id);
});
llvm::sort(SortedChains, [&](const ChainT *L, const ChainT *R) {
const double DL = ChainDensity[L];
const double DR = ChainDensity[R];
// Compare by density and break ties by chain identifiers.
return std::make_tuple(-DL, L->Id) < std::make_tuple(-DR, R->Id);
});

// Collect the nodes in the order specified by their chains.
std::vector<uint64_t> Order;
Expand Down
7 changes: 3 additions & 4 deletions llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,9 @@ Error Session::FileInfo::registerMultiStubEntry(
Sym.getTargetFlags());

// Let's keep stubs ordered by ascending address.
std::sort(Entry.begin(), Entry.end(),
[](const MemoryRegionInfo &L, const MemoryRegionInfo &R) {
return L.getTargetAddress() < R.getTargetAddress();
});
llvm::sort(Entry, [](const MemoryRegionInfo &L, const MemoryRegionInfo &R) {
return L.getTargetAddress() < R.getTargetAddress();
});

return Error::success();
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/ARMTargetDefEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
const auto MarchB = B->getValueAsString("MArchName");
return MarchA.compare(MarchB) < 0; // A lexographically less than B
};
std::sort(SortedExtensions.begin(), SortedExtensions.end(), Alphabetical);
llvm::sort(SortedExtensions, Alphabetical);

// The ARMProcFamilyEnum values are initialised by SubtargetFeature defs
// which set the ARMProcFamily field. We can generate the enum from these defs
Expand Down
3 changes: 1 addition & 2 deletions llvm/utils/TableGen/ExegesisEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
ValidationCounter->getValueAsDef("EventType")->getName(),
getPfmCounterId(ValidationCounter->getValueAsString("Counter"))});
}
std::sort(ValidationCounters.begin(), ValidationCounters.end(),
EventNumberLess);
llvm::sort(ValidationCounters, EventNumberLess);
OS << "\nstatic const std::pair<ValidationEvent, const char*> " << Target
<< Def.getName() << "ValidationCounters[] = {\n";
for (const ValidationCounterInfo &VCI : ValidationCounters) {
Expand Down
Loading