[llvm] aba4303 - Use llvm::sort instead of std::sort where possible

Dmitri Gribenko via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 23 06:19:11 PDT 2022


Author: Dmitri Gribenko
Date: 2022-07-23T15:19:05+02:00
New Revision: aba43035bdf89c08409f0efccaf5408165abed9e

URL: https://github.com/llvm/llvm-project/commit/aba43035bdf89c08409f0efccaf5408165abed9e
DIFF: https://github.com/llvm/llvm-project/commit/aba43035bdf89c08409f0efccaf5408165abed9e.diff

LOG: Use llvm::sort instead of std::sort where possible

llvm::sort is beneficial even when we use the iterator-based overload,
since it can optionally shuffle the elements (to detect
non-determinism). However llvm::sort is not usable everywhere, for
example, in compiler-rt.

Reviewed By: nhaehnle

Differential Revision: https://reviews.llvm.org/D130406

Added: 
    

Modified: 
    clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
    clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
    clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
    clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
    clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
    clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
    clang-tools-extra/clangd/IncludeFixer.cpp
    clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
    clang/lib/CodeGen/TargetInfo.cpp
    clang/unittests/Tooling/TransformerTest.cpp
    lld/COFF/Chunks.cpp
    lld/COFF/DLL.cpp
    lld/COFF/DriverUtils.cpp
    lld/ELF/SyntheticSections.cpp
    llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
    llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
    llvm/lib/MC/MCPseudoProbe.cpp
    llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
    llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp
    llvm/lib/Target/XCore/XCoreFrameLowering.cpp
    llvm/unittests/ADT/SmallSetTest.cpp
    llvm/unittests/MIR/MachineMetadata.cpp
    llvm/unittests/Support/AlignmentTest.cpp
    llvm/utils/TableGen/DXILEmitter.cpp
    llvm/utils/TableGen/DirectiveEmitter.cpp
    llvm/utils/TableGen/SearchableTableEmitter.cpp
    llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
    mlir/lib/Analysis/Liveness.cpp
    mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
    mlir/lib/Dialect/SCF/Utils/Utils.cpp
    mlir/lib/IR/AffineExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
index 073cee478512d..f6f8404204ba0 100644
--- 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 <algorithm>
+#include "llvm/ADT/STLExtras.h"
 
 namespace clang {
 namespace include_fixer {
@@ -84,11 +84,11 @@ IncludeFixerContext::IncludeFixerContext(
   // 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
index d179e6cb7c75b..346437e20322e 100644
--- 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 <algorithm>
 #include <string>
 
 namespace clang {
@@ -206,8 +206,7 @@ static void reorderFieldsInConstructor(
     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
index c67efa341f629..d2a0dd66d3239 100644
--- 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 @@ void UseAfterMoveFinder::getUsesAndReinits(
   }
 
   // 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
index 948bf16dd5e2c..f701bd182683c 100644
--- 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 <map>
 
@@ -125,20 +126,20 @@ void IncludeOrderPPCallbacks::EndOfMainFile() {
 
     // 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
index f14675c58271d..9fd718c270e59 100644
--- 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 <algorithm>
-
 using namespace llvm;
 
 int main(int argc, char *argv[]) {
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
 
     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
index 2ef0150cccca4..c43c2b5a0560c 100644
--- 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 <algorithm>
 #include <functional>
 
 using namespace clang::ast_matchers;
@@ -158,12 +158,12 @@ findInconsistentDeclarations(const FunctionDecl *OriginalDeclaration,
 
   // 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
index a057c438d7a93..fff82a46fc9ce 100644
--- 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 @@ collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
   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
index 3d6d440dd4ab0..387e1c54ee99b 100644
--- 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 <cstdint>
 
@@ -60,8 +61,8 @@ LRTable LRTable::Builder::build() && {
       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
index fc0952e68a667..d1ee61eab9d66 100644
--- 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 <algorithm> // std::sort
+#include <algorithm>
 
 using namespace clang;
 using namespace CodeGen;

diff  --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp
index 9bc372b97d807..73672820e1ddc 100644
--- 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 @@ TEST_F(TransformerTest, MultipleFiles) {
       "clang-tool", std::make_shared<PCHContainerOperations>(),
       {{"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
index 6cabb22d98cf2..3cdbd6c0337b7 100644
--- 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 @@ void RVATableChunk::writeTo(uint8_t *buf) const {
   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
index bfa2a6910e2b7..42a5a41f87ae2 100644
--- 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 @@ binImports(const std::vector<DefinedImportData *> &imports) {
   for (auto &kv : m) {
     // Sort symbols by name for each group.
     std::vector<DefinedImportData *> &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
index dbfbec16b1405..29a2d01658391 100644
--- 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 @@ void fixupExports() {
   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
index b8a2ebeefce93..acd1ed30076aa 100644
--- 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 @@ void RelocationBaseSection::computeRels() {
     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 @@ template <class ELFT> bool RelrSection<ELFT>::updateAllocSize() {
   std::unique_ptr<uint64_t[]> 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
index 727ec2e02cc2f..998f629aaa4ea 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -802,7 +802,7 @@ void ValueEnumerator::organizeMetadata() {
   //   - by function, then
   //   - by isa<MDString>
   // 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
index 2be488cbf9170..ef49d3888f2ba 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -3709,10 +3709,9 @@ Optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl(
   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
index 5277ce87bee0a..fdf8bbbe0a4d7 100644
--- 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 @@ void MCPseudoProbeDecoder::printProbesForAllAddresses(raw_ostream &OS) {
   std::vector<uint64_t> 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
index 3e09270a66d0c..8694336136209 100644
--- 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 @@ void DXILBitcodeWriter::writeFunctionLevelValueSymbolTable(
     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
index 08944ee3f1fef..e2a41515de389 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp
@@ -809,7 +809,7 @@ void ValueEnumerator::organizeMetadata() {
   //   - by function, then
   //   - by isa<MDString>
   // 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
index 19ebcb3ea3e88..2fb06e29bf3b5 100644
--- 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 <algorithm> // std::sort
+#include <algorithm>
 
 using namespace llvm;
 

diff  --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp
index 26cab828c784d..0b7400942e3cf 100644
--- 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 <string>
 
@@ -78,7 +79,7 @@ TEST(SmallSetTest, IteratorInt) {
 
   std::vector<int> 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 @@ TEST(SmallSetTest, IteratorInt) {
 
   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 @@ TEST(SmallSetTest, IteratorString) {
   s1.insert("str 1");
 
   std::vector<std::string> 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 @@ TEST(SmallSetTest, IteratorString) {
 
   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
index 95f42b4d16782..39d10dddb764e 100644
--- 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 @@ body:             |
   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 @@ body:             |
   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 @@ body:             |
   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
index 4fa16fa335a37..bc28b55b4089a 100644
--- 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 <vector>
@@ -179,7 +180,7 @@ TEST(AlignmentTest, offsetToAlignment) {
 
 TEST(AlignmentTest, AlignComparisons) {
   std::vector<uint64_t> 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
index fd58e798b445e..b9c563c62bbec 100644
--- a/llvm/utils/TableGen/DXILEmitter.cpp
+++ b/llvm/utils/TableGen/DXILEmitter.cpp
@@ -122,15 +122,14 @@ static std::string buildCategoryStr(StringSet<> &Cetegorys) {
 static void emitDXILEnums(std::vector<DXILOperationData> &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 @@ static void emitDXILEnums(std::vector<DXILOperationData> &DXILOps,
         std::make_pair(It.getKey().str(), buildCategoryStr(It.second)));
   }
   // Sort by Category + ClassName.
-  std::sort(ClassVec.begin(), ClassVec.end(),
-            [](std::pair<std::string, std::string> &A,
-               std::pair<std::string, std::string> &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<std::string, std::string> &A,
+                          std::pair<std::string, std::string> &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 std::string getDXILOpClassName(StringRef DXILOpClass) {
 static void emitDXILOperationTable(std::vector<DXILOperationData> &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<std::string> OpClassStrings;

diff  --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index be35baf4e809f..f32fbe3e25cd1 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -681,7 +681,7 @@ void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
   std::vector<Record *> 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
index ea849807de031..327c53e93a41b 100644
--- 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 @@ void SearchableTableEmitter::collectTableEntries(
   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
index 7b0e3b0472417..69ed865656509 100644
--- a/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
+++ b/llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
@@ -121,8 +121,9 @@ class Trie {
   std::pair<std::string, std::vector<uint8_t>> serialize() {
     std::set<std::string> Names = this->getNameFragments();
     std::vector<std::string> 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
index b3773295a9a02..7c04bb4ade79e 100644
--- 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 @@ void Liveness::print(raw_ostream &os) const {
 
   auto printValueRefs = [&](const ValueSetT &values) {
     std::vector<Value> 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 @@ void Liveness::print(raw_ostream &os) const {
         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
index 2ac860bc410a2..487cd322a7ec7 100644
--- 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 @@ static void getProducerCandidates(unsigned dstId, MemRefDependenceGraph *mdg,
       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
index 74bd106f919fc..7569476cb7cd1 100644
--- a/mlir/lib/Dialect/SCF/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/SCF/Utils/Utils.cpp
@@ -673,7 +673,7 @@ void mlir::collapseParallelLoops(
   // 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<Value, 3> normalizedLowerBounds, normalizedSteps,

diff  --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp
index 4b553d8e3a9a5..b4a593f72f61d 100644
--- a/mlir/lib/IR/AffineExpr.cpp
+++ b/mlir/lib/IR/AffineExpr.cpp
@@ -1073,7 +1073,7 @@ static AffineExpr getSemiAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
   // 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<unsigned, unsigned> index : indices) {
     assert(indexToExprMap.lookup(index) &&
            "cannot find key in `indexToExprMap` map");


        


More information about the llvm-commits mailing list