From 125ea20d55c554fbe14eb1f6cff7d44a720a51f5 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 13 Jan 2021 19:14:42 -0800 Subject: [PATCH] [llvm] Use llvm::stable_sort (NFC) --- llvm/lib/CodeGen/SafeStackLayout.cpp | 8 +++---- .../Hexagon/MCTargetDesc/HexagonShuffler.cpp | 5 ++--- llvm/lib/Transforms/IPO/IROutliner.cpp | 2 +- llvm/lib/Transforms/Scalar/SROA.cpp | 2 +- llvm/utils/TableGen/DAGISelEmitter.cpp | 3 +-- llvm/utils/TableGen/GlobalISelEmitter.cpp | 25 +++++++++------------ llvm/utils/TableGen/RegisterInfoEmitter.cpp | 3 +-- llvm/utils/TableGen/SearchableTableEmitter.cpp | 26 ++++++++++------------ 8 files changed, 33 insertions(+), 41 deletions(-) diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp index f333e50..5bd4f4d 100644 --- a/llvm/lib/CodeGen/SafeStackLayout.cpp +++ b/llvm/lib/CodeGen/SafeStackLayout.cpp @@ -140,10 +140,10 @@ void StackLayout::computeLayout() { // Sort objects by size (largest first) to reduce fragmentation. if (StackObjects.size() > 2) - std::stable_sort(StackObjects.begin() + 1, StackObjects.end(), - [](const StackObject &a, const StackObject &b) { - return a.Size > b.Size; - }); + llvm::stable_sort(drop_begin(StackObjects, 1), + [](const StackObject &a, const StackObject &b) { + return a.Size > b.Size; + }); for (auto &Obj : StackObjects) layoutObject(Obj); diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp index 2788b86..8a44ba3 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp @@ -326,7 +326,7 @@ bool HexagonShuffler::ValidResourceUsage(HexagonPacketSummary const &Summary) { } // Verify the CVI slot subscriptions. - std::stable_sort(begin(), end(), HexagonInstr::lessCVI); + llvm::stable_sort(*this, HexagonInstr::lessCVI); // create vector of hvx instructions to check HVXInstsT hvxInsts; hvxInsts.clear(); @@ -609,8 +609,7 @@ llvm::Optional HexagonShuffler::tryAuction(HexagonPacketSummary const &Summary) const { HexagonPacket PacketResult = Packet; HexagonUnitAuction AuctionCore(Summary.ReservedSlotMask); - std::stable_sort(PacketResult.begin(), PacketResult.end(), - HexagonInstr::lessCore); + llvm::stable_sort(PacketResult, HexagonInstr::lessCore); const bool ValidSlots = llvm::all_of(insts(PacketResult), [&AuctionCore](HexagonInstr const &I) { diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index da9ac99..281b182 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -554,7 +554,7 @@ static void getCodeExtractorArguments( // Sort the GVNs, since we now have constants included in the \ref InputGVNs // we need to make sure they are in a deterministic order. - stable_sort(InputGVNs.begin(), InputGVNs.end()); + stable_sort(InputGVNs); } /// Look over the inputs and map each input argument to an argument in the diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 0805cb5..1a0180a 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -1076,7 +1076,7 @@ AllocaSlices::AllocaSlices(const DataLayout &DL, AllocaInst &AI) // Sort the uses. This arranges for the offsets to be in ascending order, // and the sizes to be in descending order. - std::stable_sort(Slices.begin(), Slices.end()); + llvm::stable_sort(Slices); } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) diff --git a/llvm/utils/TableGen/DAGISelEmitter.cpp b/llvm/utils/TableGen/DAGISelEmitter.cpp index 1652281..32ed0bf 100644 --- a/llvm/utils/TableGen/DAGISelEmitter.cpp +++ b/llvm/utils/TableGen/DAGISelEmitter.cpp @@ -159,8 +159,7 @@ void DAGISelEmitter::run(raw_ostream &OS) { // We want to process the matches in order of minimal cost. Sort the patterns // so the least cost one is at the start. - std::stable_sort(Patterns.begin(), Patterns.end(), - PatternSortingPredicate(CGP)); + llvm::stable_sort(Patterns, PatternSortingPredicate(CGP)); // Convert each variant of each pattern into a Matcher. Records.startTimer("Convert to matchers"); diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index e18de6e..a303753 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -5480,15 +5480,13 @@ GlobalISelEmitter::buildMatchTable(MutableArrayRef Rules, OpcodeOrder[Opcode] = CurrentOrdering++; } - std::stable_sort(InputRules.begin(), InputRules.end(), - [&OpcodeOrder](const Matcher *A, const Matcher *B) { - auto *L = static_cast(A); - auto *R = static_cast(B); - return std::make_tuple(OpcodeOrder[L->getOpcode()], - L->getNumOperands()) < - std::make_tuple(OpcodeOrder[R->getOpcode()], - R->getNumOperands()); - }); + llvm::stable_sort(InputRules, [&OpcodeOrder](const Matcher *A, + const Matcher *B) { + auto *L = static_cast(A); + auto *R = static_cast(B); + return std::make_tuple(OpcodeOrder[L->getOpcode()], L->getNumOperands()) < + std::make_tuple(OpcodeOrder[R->getOpcode()], R->getNumOperands()); + }); for (Matcher *Rule : InputRules) Rule->optimize(); @@ -6088,11 +6086,10 @@ void SwitchMatcher::finalize() { if (empty()) return; - std::stable_sort(Matchers.begin(), Matchers.end(), - [](const Matcher *L, const Matcher *R) { - return L->getFirstCondition().getValue() < - R->getFirstCondition().getValue(); - }); + llvm::stable_sort(Matchers, [](const Matcher *L, const Matcher *R) { + return L->getFirstCondition().getValue() < + R->getFirstCondition().getValue(); + }); Condition = Matchers[0]->popFirstCondition(); for (unsigned I = 1, E = Values.size(); I < E; ++I) Matchers[I]->popFirstCondition(); diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp index 69e9bc6..dce7594 100644 --- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp +++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp @@ -359,8 +359,7 @@ using DwarfRegNumsVecTy = std::vector; static void finalizeDwarfRegNumsKeys(DwarfRegNumsVecTy &DwarfRegNums) { // Sort and unique to get a map-like vector. We want the last assignment to // match previous behaviour. - std::stable_sort(DwarfRegNums.begin(), DwarfRegNums.end(), - on_first()); + llvm::stable_sort(DwarfRegNums, on_first()); // Warn about duplicate assignments. const Record *LastSeenReg = nullptr; for (const auto &X : DwarfRegNums) { diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp index 2e86b13..912d43b 100644 --- a/llvm/utils/TableGen/SearchableTableEmitter.cpp +++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp @@ -338,11 +338,10 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table, for (unsigned i = 0; i < Table.Entries.size(); ++i) Entries.emplace_back(Table.Entries[i], i); - std::stable_sort(Entries.begin(), Entries.end(), - [&](const std::pair &LHS, - const std::pair &RHS) { - return compareBy(LHS.first, RHS.first, Index); - }); + llvm::stable_sort(Entries, [&](const std::pair &LHS, + const std::pair &RHS) { + return compareBy(LHS.first, RHS.first, Index); + }); IndexRowsStorage.reserve(Entries.size()); for (const auto &Entry : Entries) { @@ -610,11 +609,11 @@ void SearchableTableEmitter::collectEnumEntries( } if (ValueField.empty()) { - std::stable_sort(Enum.Entries.begin(), Enum.Entries.end(), - [](const std::unique_ptr &LHS, - const std::unique_ptr &RHS) { - return LHS->first < RHS->first; - }); + llvm::stable_sort(Enum.Entries, + [](const std::unique_ptr &LHS, + const std::unique_ptr &RHS) { + return LHS->first < RHS->first; + }); for (size_t i = 0; i < Enum.Entries.size(); ++i) Enum.Entries[i]->second = i; @@ -739,10 +738,9 @@ void SearchableTableEmitter::run(raw_ostream &OS) { TableRec->getValueAsListOfStrings("PrimaryKey"), TableRec->getValueAsBit("PrimaryKeyEarlyOut")); - std::stable_sort(Table->Entries.begin(), Table->Entries.end(), - [&](Record *LHS, Record *RHS) { - return compareBy(LHS, RHS, *Table->PrimaryKey); - }); + llvm::stable_sort(Table->Entries, [&](Record *LHS, Record *RHS) { + return compareBy(LHS, RHS, *Table->PrimaryKey); + }); } TableMap.insert(std::make_pair(TableRec, Table.get())); -- 2.7.4