diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp --- a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp +++ b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "IncludeFixerContext.h" -#include +#include "llvm/ADT/STLExtras.h" namespace clang { namespace include_fixer { @@ -84,11 +84,11 @@ // QuerySymbolInfos may contain replicated elements. Because CorrectTypo // callback doesn't always work as we expected. In somecases, it will be // triggered at the same position or unidentified symbol multiple times. - std::sort(QuerySymbolInfos.begin(), QuerySymbolInfos.end(), - [&](const QuerySymbolInfo &A, const QuerySymbolInfo &B) { - return std::make_pair(A.Range.getOffset(), A.Range.getLength()) < - std::make_pair(B.Range.getOffset(), B.Range.getLength()); - }); + llvm::sort(QuerySymbolInfos, + [&](const QuerySymbolInfo &A, const QuerySymbolInfo &B) { + return std::make_pair(A.Range.getOffset(), A.Range.getLength()) < + std::make_pair(B.Range.getOffset(), B.Range.getLength()); + }); QuerySymbolInfos.erase( std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(), [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) { diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp --- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp +++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp @@ -21,8 +21,8 @@ #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" #include "clang/Tooling/Refactoring.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" -#include #include namespace clang { @@ -206,8 +206,7 @@ return NewFieldsPositions[LHS->getMember()->getFieldIndex()] < NewFieldsPositions[RHS->getMember()->getFieldIndex()]; }; - std::sort(std::begin(NewWrittenInitializersOrder), - std::end(NewWrittenInitializersOrder), ByFieldNewPosition); + llvm::sort(NewWrittenInitializersOrder, ByFieldNewPosition); assert(OldWrittenInitializersOrder.size() == NewWrittenInitializersOrder.size()); for (unsigned i = 0, e = NewWrittenInitializersOrder.size(); i < e; ++i) diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -14,6 +14,7 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Analysis/CFG.h" #include "clang/Lex/Lexer.h" +#include "llvm/ADT/STLExtras.h" #include "../utils/ExprSequence.h" @@ -228,10 +229,9 @@ } // Sort the uses by their occurrence in the source code. - std::sort(Uses->begin(), Uses->end(), - [](const DeclRefExpr *D1, const DeclRefExpr *D2) { - return D1->getExprLoc() < D2->getExprLoc(); - }); + llvm::sort(*Uses, [](const DeclRefExpr *D1, const DeclRefExpr *D2) { + return D1->getExprLoc() < D2->getExprLoc(); + }); } bool isStandardSmartPointer(const ValueDecl *VD) { diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/STLExtras.h" #include @@ -125,20 +126,20 @@ // Sort the includes. We first sort by priority, then lexicographically. for (unsigned BI = 0, BE = Blocks.size() - 1; BI != BE; ++BI) - std::sort(IncludeIndices.begin() + Blocks[BI], - IncludeIndices.begin() + Blocks[BI + 1], - [&FileDirectives](unsigned LHSI, unsigned RHSI) { - IncludeDirective &LHS = FileDirectives[LHSI]; - IncludeDirective &RHS = FileDirectives[RHSI]; - - int PriorityLHS = - getPriority(LHS.Filename, LHS.IsAngled, LHS.IsMainModule); - int PriorityRHS = - getPriority(RHS.Filename, RHS.IsAngled, RHS.IsMainModule); - - return std::tie(PriorityLHS, LHS.Filename) < - std::tie(PriorityRHS, RHS.Filename); - }); + llvm::sort(IncludeIndices.begin() + Blocks[BI], + IncludeIndices.begin() + Blocks[BI + 1], + [&FileDirectives](unsigned LHSI, unsigned RHSI) { + IncludeDirective &LHS = FileDirectives[LHSI]; + IncludeDirective &RHS = FileDirectives[RHSI]; + + int PriorityLHS = getPriority(LHS.Filename, LHS.IsAngled, + LHS.IsMainModule); + int PriorityRHS = getPriority(RHS.Filename, RHS.IsAngled, + RHS.IsMainModule); + + return std::tie(PriorityLHS, LHS.Filename) < + std::tie(PriorityRHS, RHS.Filename); + }); // Emit a warning for each block and fixits for all changes within that // block. diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp --- a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp +++ b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp @@ -5,13 +5,13 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// + +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include - using namespace llvm; int main(int argc, char *argv[]) { @@ -54,7 +54,7 @@ Entries.emplace_back(CodePoint, To); } - std::sort(Entries.begin(), Entries.end()); + llvm::sort(Entries); unsigned LargestValue = std::max_element(Entries.begin(), Entries.end(), diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp @@ -9,8 +9,8 @@ #include "InconsistentDeclarationParameterNameCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "llvm/ADT/STLExtras.h" -#include #include using namespace clang::ast_matchers; @@ -158,12 +158,12 @@ // Sort in order of appearance in translation unit to generate clear // diagnostics. - std::sort(InconsistentDeclarations.begin(), InconsistentDeclarations.end(), - [&SM](const InconsistentDeclarationInfo &Info1, - const InconsistentDeclarationInfo &Info2) { - return SM.isBeforeInTranslationUnit(Info1.DeclarationLocation, - Info2.DeclarationLocation); - }); + llvm::sort(InconsistentDeclarations, + [&SM](const InconsistentDeclarationInfo &Info1, + const InconsistentDeclarationInfo &Info2) { + return SM.isBeforeInTranslationUnit(Info1.DeclarationLocation, + Info2.DeclarationLocation); + }); return InconsistentDeclarations; } diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -35,6 +35,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" @@ -475,7 +476,7 @@ Sem.LookupVisibleDecls(S, LookupKind, Collector, /*IncludeGlobalScope=*/false, /*LoadExternal=*/false); - std::sort(Scopes.begin(), Scopes.end()); + llvm::sort(Scopes); Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end()); return Scopes; } diff --git a/clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp b/clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp --- a/clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp +++ b/clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp @@ -10,6 +10,7 @@ #include "clang-pseudo/grammar/LRGraph.h" #include "clang-pseudo/grammar/LRTable.h" #include "clang/Basic/TokenKinds.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" #include @@ -60,8 +61,8 @@ continue; Table.Reduces.insert(Table.Reduces.end(), It->second.begin(), It->second.end()); - std::sort(Table.Reduces.begin() + Table.ReduceOffset.back(), - Table.Reduces.end()); + llvm::sort(Table.Reduces.begin() + Table.ReduceOffset.back(), + Table.Reduces.end()); } Table.ReduceOffset.push_back(Table.Reduces.size()); diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -35,7 +35,7 @@ #include "llvm/IR/Type.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include // std::sort +#include using namespace clang; using namespace CodeGen; diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -12,6 +12,7 @@ #include "clang/Tooling/Transformer/RangeSelector.h" #include "clang/Tooling/Transformer/RewriteRule.h" #include "clang/Tooling/Transformer/Stencil.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "gmock/gmock.h" @@ -1617,10 +1618,9 @@ "clang-tool", std::make_shared(), {{"input.h", Header}})); - std::sort(Changes.begin(), Changes.end(), - [](const AtomicChange &L, const AtomicChange &R) { - return L.getFilePath() < R.getFilePath(); - }); + llvm::sort(Changes, [](const AtomicChange &L, const AtomicChange &R) { + return L.getFilePath() < R.getFilePath(); + }); ASSERT_EQ(Changes[0].getFilePath(), "./input.h"); EXPECT_THAT(Changes[0].getInsertedHeaders(), IsEmpty()); diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -13,6 +13,7 @@ #include "Symbols.h" #include "Writer.h" #include "llvm/ADT/Twine.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" #include "llvm/Object/COFF.h" #include "llvm/Support/Debug.h" @@ -815,7 +816,7 @@ size_t cnt = 0; for (const ChunkAndOffset &co : syms) begin[cnt++] = co.inputChunk->getRVA() + co.offset; - std::sort(begin, begin + cnt); + llvm::sort(begin, begin + cnt); assert(std::unique(begin, begin + cnt) == begin + cnt && "RVA tables should be de-duplicated"); } diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp --- a/lld/COFF/DLL.cpp +++ b/lld/COFF/DLL.cpp @@ -21,6 +21,7 @@ #include "COFFLinkerContext.h" #include "Chunks.h" #include "SymbolTable.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Object/COFF.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Path.h" @@ -150,10 +151,9 @@ for (auto &kv : m) { // Sort symbols by name for each group. std::vector &syms = kv.second; - std::sort(syms.begin(), syms.end(), - [](DefinedImportData *a, DefinedImportData *b) { - return a->getName() < b->getName(); - }); + llvm::sort(syms, [](DefinedImportData *a, DefinedImportData *b) { + return a->getName() < b->getName(); + }); v.push_back(std::move(syms)); } return v; diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -18,6 +18,7 @@ #include "lld/Common/ErrorHandler.h" #include "lld/Common/Memory.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/COFF.h" #include "llvm/Object/COFF.h" @@ -694,10 +695,9 @@ config->exports = std::move(v); // Sort by name. - std::sort(config->exports.begin(), config->exports.end(), - [](const Export &a, const Export &b) { - return a.exportName < b.exportName; - }); + llvm::sort(config->exports, [](const Export &a, const Export &b) { + return a.exportName < b.exportName; + }); } void assignExportOrdinals() { diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -29,6 +29,7 @@ #include "lld/Common/DWARF.h" #include "lld/Common/Strings.h" #include "lld/Common/Version.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/StringExtras.h" #include "llvm/BinaryFormat/Dwarf.h" @@ -1703,7 +1704,7 @@ parallelSort(relocs.begin(), nonRelative, [&](auto &a, auto &b) { return a.r_offset < b.r_offset; }); // Non-relative relocations are few, so don't bother with parallelSort. - std::sort(nonRelative, relocs.end(), [&](auto &a, auto &b) { + llvm::sort(nonRelative, relocs.end(), [&](auto &a, auto &b) { return std::tie(a.r_sym, a.r_offset) < std::tie(b.r_sym, b.r_offset); }); } @@ -2039,7 +2040,7 @@ std::unique_ptr offsets(new uint64_t[relocs.size()]); for (auto it : llvm::enumerate(relocs)) offsets[it.index()] = it.value().getOffset(); - std::sort(offsets.get(), offsets.get() + relocs.size()); + llvm::sort(offsets.get(), offsets.get() + relocs.size()); // For each leading relocation, find following ones that can be folded // as a bitmap and fold them. diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -802,7 +802,7 @@ // - by function, then // - by isa // and then sort by the original/current ID. Since the IDs are guaranteed to - // be unique, the result of std::sort will be deterministic. There's no need + // be unique, the result of llvm::sort will be deterministic. There's no need // for std::stable_sort. llvm::sort(Order, [this](MDIndex LHS, MDIndex RHS) { return std::make_tuple(LHS.F, getMetadataTypeOrder(LHS.get(MDs)), LHS.ID) < diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -3709,10 +3709,9 @@ for (auto &PHI : CreatedPHIs) SortedPHIs.push_back(PHI); - std::sort( - SortedPHIs.begin(), SortedPHIs.end(), [&](LDVSSAPhi *A, LDVSSAPhi *B) { - return BBToOrder[&A->getParent()->BB] < BBToOrder[&B->getParent()->BB]; - }); + llvm::sort(SortedPHIs, [&](LDVSSAPhi *A, LDVSSAPhi *B) { + return BBToOrder[&A->getParent()->BB] < BBToOrder[&B->getParent()->BB]; + }); for (auto &PHI : SortedPHIs) { ValueIDNum ThisBlockValueNum = diff --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp --- a/llvm/lib/MC/MCPseudoProbe.cpp +++ b/llvm/lib/MC/MCPseudoProbe.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCPseudoProbe.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" @@ -519,7 +520,7 @@ std::vector Addresses; for (auto Entry : Address2ProbesMap) Addresses.push_back(Entry.first); - std::sort(Addresses.begin(), Addresses.end()); + llvm::sort(Addresses); for (auto K : Addresses) { OS << "Address:\t"; OS << K; diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp --- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp @@ -13,6 +13,7 @@ #include "DXILBitcodeWriter.h" #include "DXILValueEnumerator.h" #include "PointerTypeAnalysis.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/Bitcode/BitcodeCommon.h" #include "llvm/Bitcode/BitcodeReader.h" @@ -2580,10 +2581,9 @@ SortedTable.push_back(VI.second->getValueName()); } // The keys are unique, so there shouldn't be stability issues. - std::sort(SortedTable.begin(), SortedTable.end(), - [](const ValueName *A, const ValueName *B) { - return A->first() < B->first(); - }); + llvm::sort(SortedTable, [](const ValueName *A, const ValueName *B) { + return A->first() < B->first(); + }); for (const ValueName *SI : SortedTable) { auto &Name = *SI; diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp --- a/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp @@ -809,7 +809,7 @@ // - by function, then // - by isa // and then sort by the original/current ID. Since the IDs are guaranteed to - // be unique, the result of std::sort will be deterministic. There's no need + // be unique, the result of llvm::sort will be deterministic. There's no need // for std::stable_sort. llvm::sort(Order, [this](MDIndex LHS, MDIndex RHS) { return std::make_tuple(LHS.F, getMetadataTypeOrder(LHS.get(MDs)), LHS.ID) < diff --git a/llvm/lib/Target/XCore/XCoreFrameLowering.cpp b/llvm/lib/Target/XCore/XCoreFrameLowering.cpp --- a/llvm/lib/Target/XCore/XCoreFrameLowering.cpp +++ b/llvm/lib/Target/XCore/XCoreFrameLowering.cpp @@ -27,7 +27,7 @@ #include "llvm/IR/Function.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Target/TargetOptions.h" -#include // std::sort +#include using namespace llvm; diff --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp --- a/llvm/unittests/ADT/SmallSetTest.cpp +++ b/llvm/unittests/ADT/SmallSetTest.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/STLExtras.h" #include "gtest/gtest.h" #include @@ -78,7 +79,7 @@ std::vector V(s1.begin(), s1.end()); // Make sure the elements are in the expected order. - std::sort(V.begin(), V.end()); + llvm::sort(V); for (int i = 0; i < 3; i++) EXPECT_EQ(i, V[i]); @@ -89,7 +90,7 @@ V.assign(s1.begin(), s1.end()); // Make sure the elements are in the expected order. - std::sort(V.begin(), V.end()); + llvm::sort(V); for (int i = 0; i < 6; i++) EXPECT_EQ(i, V[i]); } @@ -104,7 +105,7 @@ s1.insert("str 1"); std::vector V(s1.begin(), s1.end()); - std::sort(V.begin(), V.end()); + llvm::sort(V); EXPECT_EQ(2u, s1.size()); EXPECT_EQ("str 1", V[0]); EXPECT_EQ("str 2", V[1]); @@ -115,7 +116,7 @@ V.assign(s1.begin(), s1.end()); // Make sure the elements are in the expected order. - std::sort(V.begin(), V.end()); + llvm::sort(V); EXPECT_EQ(4u, s1.size()); EXPECT_EQ("str 0", V[0]); EXPECT_EQ("str 1", V[1]); diff --git a/llvm/unittests/MIR/MachineMetadata.cpp b/llvm/unittests/MIR/MachineMetadata.cpp --- a/llvm/unittests/MIR/MachineMetadata.cpp +++ b/llvm/unittests/MIR/MachineMetadata.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/MIRParser/MIRParser.h" #include "llvm/CodeGen/MIRPrinter.h" #include "llvm/CodeGen/MachineFunction.h" @@ -271,8 +272,8 @@ for (auto &MD : MDList) Collected.push_back(MD.second); - std::sort(Generated.begin(), Generated.end()); - std::sort(Collected.begin(), Collected.end()); + llvm::sort(Generated); + llvm::sort(Collected); EXPECT_EQ(Collected, Generated); // FileCheck the output from MIR printer. @@ -421,8 +422,8 @@ for (auto &MD : MDList) Collected.push_back(MD.second); - std::sort(Generated.begin(), Generated.end()); - std::sort(Collected.begin(), Collected.end()); + llvm::sort(Generated); + llvm::sort(Collected); EXPECT_EQ(Collected, Generated); // FileCheck the output from MIR printer. @@ -520,8 +521,8 @@ for (auto &MD : MDList) Collected.push_back(MD.second); - std::sort(Generated.begin(), Generated.end()); - std::sort(Collected.begin(), Collected.end()); + llvm::sort(Generated); + llvm::sort(Collected); EXPECT_EQ(Collected, Generated); // FileCheck the output from MIR printer. diff --git a/llvm/unittests/Support/AlignmentTest.cpp b/llvm/unittests/Support/AlignmentTest.cpp --- a/llvm/unittests/Support/AlignmentTest.cpp +++ b/llvm/unittests/Support/AlignmentTest.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Alignment.h" +#include "llvm/ADT/STLExtras.h" #include "gtest/gtest.h" #include @@ -179,7 +180,7 @@ TEST(AlignmentTest, AlignComparisons) { std::vector ValidAlignments = getValidAlignments(); - std::sort(ValidAlignments.begin(), ValidAlignments.end()); + llvm::sort(ValidAlignments); for (size_t I = 1; I < ValidAlignments.size(); ++I) { assert(I >= 1); const Align A(ValidAlignments[I - 1]); diff --git a/llvm/utils/TableGen/DXILEmitter.cpp b/llvm/utils/TableGen/DXILEmitter.cpp --- a/llvm/utils/TableGen/DXILEmitter.cpp +++ b/llvm/utils/TableGen/DXILEmitter.cpp @@ -122,15 +122,14 @@ static void emitDXILEnums(std::vector &DXILOps, raw_ostream &OS) { // Sort by Category + OpName. - std::sort(DXILOps.begin(), DXILOps.end(), - [](DXILOperationData &A, DXILOperationData &B) { - // Group by Category first. - if (A.Category == B.Category) - // Inside same Category, order by OpName. - return A.DXILOp < B.DXILOp; - else - return A.Category < B.Category; - }); + llvm::sort(DXILOps, [](DXILOperationData &A, DXILOperationData &B) { + // Group by Category first. + if (A.Category == B.Category) + // Inside same Category, order by OpName. + return A.DXILOp < B.DXILOp; + else + return A.Category < B.Category; + }); OS << "// Enumeration for operations specified by DXIL\n"; OS << "enum class OpCode : unsigned {\n"; @@ -160,20 +159,19 @@ std::make_pair(It.getKey().str(), buildCategoryStr(It.second))); } // Sort by Category + ClassName. - std::sort(ClassVec.begin(), ClassVec.end(), - [](std::pair &A, - std::pair &B) { - StringRef ClassA = A.first; - StringRef CategoryA = A.second; - StringRef ClassB = B.first; - StringRef CategoryB = B.second; - // Group by Category first. - if (CategoryA == CategoryB) - // Inside same Category, order by ClassName. - return ClassA < ClassB; - else - return CategoryA < CategoryB; - }); + llvm::sort(ClassVec, [](std::pair &A, + std::pair &B) { + StringRef ClassA = A.first; + StringRef CategoryA = A.second; + StringRef ClassB = B.first; + StringRef CategoryB = B.second; + // Group by Category first. + if (CategoryA == CategoryB) + // Inside same Category, order by ClassName. + return ClassA < ClassB; + else + return CategoryA < CategoryB; + }); OS << "// Groups for DXIL operations with equivalent function templates\n"; OS << "enum class OpCodeClass : unsigned {\n"; @@ -266,10 +264,9 @@ static void emitDXILOperationTable(std::vector &DXILOps, raw_ostream &OS) { // Sort by DXILOpID. - std::sort(DXILOps.begin(), DXILOps.end(), - [](DXILOperationData &A, DXILOperationData &B) { - return A.DXILOpID < B.DXILOpID; - }); + llvm::sort(DXILOps, [](DXILOperationData &A, DXILOperationData &B) { + return A.DXILOpID < B.DXILOpID; + }); // Collect Names. SequenceToOffsetTable OpClassStrings; diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp --- a/llvm/utils/TableGen/DirectiveEmitter.cpp +++ b/llvm/utils/TableGen/DirectiveEmitter.cpp @@ -681,7 +681,7 @@ std::vector Clauses = DirLang.getClauses(); // Sort clauses in reverse alphabetical order so with clauses with same // beginning, the longer option is tried before. - std::sort(Clauses.begin(), Clauses.end(), compareClauseName); + llvm::sort(Clauses, compareClauseName); IfDefScope Scope("GEN_FLANG_CLAUSES_PARSER", OS); OS << "\n"; unsigned index = 0; diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp --- a/llvm/utils/TableGen/SearchableTableEmitter.cpp +++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp @@ -15,6 +15,7 @@ #include "CodeGenIntrinsics.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -650,8 +651,9 @@ SearchIndex Idx; std::copy(Table.Fields.begin(), Table.Fields.end(), std::back_inserter(Idx.Fields)); - std::sort(Table.Entries.begin(), Table.Entries.end(), - [&](Record *LHS, Record *RHS) { return compareBy(LHS, RHS, Idx); }); + llvm::sort(Table.Entries, [&](Record *LHS, Record *RHS) { + return compareBy(LHS, RHS, Idx); + }); } void SearchableTableEmitter::run(raw_ostream &OS) { diff --git a/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp b/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp --- a/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp +++ b/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp @@ -121,8 +121,9 @@ std::pair> serialize() { std::set Names = this->getNameFragments(); std::vector Sorted(Names.begin(), Names.end()); - std::sort(Sorted.begin(), Sorted.end(), - [](const auto &a, const auto &b) { return a.size() > b.size(); }); + llvm::sort(Sorted, [](const auto &a, const auto &b) { + return a.size() > b.size(); + }); std::string Dict(Letters.begin(), Letters.end()); Dict.reserve(50000); for (const std::string &Name : Sorted) { diff --git a/mlir/lib/Analysis/Liveness.cpp b/mlir/lib/Analysis/Liveness.cpp --- a/mlir/lib/Analysis/Liveness.cpp +++ b/mlir/lib/Analysis/Liveness.cpp @@ -15,6 +15,7 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/Region.h" #include "mlir/IR/Value.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/raw_ostream.h" @@ -288,10 +289,9 @@ auto printValueRefs = [&](const ValueSetT &values) { std::vector orderedValues(values.begin(), values.end()); - std::sort(orderedValues.begin(), orderedValues.end(), - [&](Value left, Value right) { - return valueIds[left] < valueIds[right]; - }); + llvm::sort(orderedValues, [&](Value left, Value right) { + return valueIds[left] < valueIds[right]; + }); for (Value value : orderedValues) printValueRef(value); }; @@ -317,10 +317,9 @@ printValueRef(result); os << ":"; auto liveOperations = resolveLiveness(result); - std::sort(liveOperations.begin(), liveOperations.end(), - [&](Operation *left, Operation *right) { - return operationIds[left] < operationIds[right]; - }); + llvm::sort(liveOperations, [&](Operation *left, Operation *right) { + return operationIds[left] < operationIds[right]; + }); for (Operation *operation : liveOperations) { os << "\n// "; operation->print(os); diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp --- a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp @@ -26,6 +26,7 @@ #include "mlir/Transforms/Passes.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -683,7 +684,7 @@ srcIdCandidates.push_back(srcNode->id); } - std::sort(srcIdCandidates.begin(), srcIdCandidates.end()); + llvm::sort(srcIdCandidates); srcIdCandidates.erase( std::unique(srcIdCandidates.begin(), srcIdCandidates.end()), srcIdCandidates.end()); diff --git a/mlir/lib/Dialect/SCF/Utils/Utils.cpp b/mlir/lib/Dialect/SCF/Utils/Utils.cpp --- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp +++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp @@ -673,7 +673,7 @@ // Presort combined dimensions. auto sortedDimensions = llvm::to_vector<3>(combinedDimensions); for (auto &dims : sortedDimensions) - std::sort(dims.begin(), dims.end()); + llvm::sort(dims); // Normalize ParallelOp's iteration pattern. SmallVector normalizedLowerBounds, normalizedSteps, diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -1073,7 +1073,7 @@ // Constructing the simplified semi-affine sum of product/division/mod // expression from the flattened form in the desired sorted order of indices // of the various individual product/division/mod expressions. - std::sort(indices.begin(), indices.end()); + llvm::sort(indices); for (const std::pair index : indices) { assert(indexToExprMap.lookup(index) && "cannot find key in `indexToExprMap` map");