From 1647ff6e2753026f8a1e21c60d37b83602520b64 Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Mon, 13 Apr 2020 14:46:41 +0300 Subject: [PATCH] [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers. It can be used to avoid passing the begin and end of a range. This makes the code shorter and it is consistent with another wrappers we already have. Differential revision: https://reviews.llvm.org/D78016 --- .../clang/StaticAnalyzer/Core/AnalyzerOptions.h | 4 +-- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- clang/lib/CodeGen/CGObjCMac.cpp | 2 +- clang/lib/Format/Format.cpp | 3 +- clang/lib/Format/SortJavaScriptImports.cpp | 2 +- .../StaticAnalyzer/Frontend/CheckerRegistry.cpp | 3 +- clang/lib/Tooling/Syntax/Tokens.cpp | 15 ++++---- lld/wasm/InputFiles.cpp | 13 ++++--- llvm/include/llvm/ADT/CoalescingBitVector.h | 8 ++--- llvm/include/llvm/ADT/STLExtras.h | 12 +++++++ llvm/include/llvm/CodeGen/LiveInterval.h | 2 +- llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp | 2 +- llvm/lib/Analysis/LoopCacheAnalysis.cpp | 8 ++--- llvm/lib/Analysis/TargetLibraryInfo.cpp | 9 +++-- llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 6 ++-- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 3 +- llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp | 2 +- llvm/lib/Frontend/OpenMP/OMPContext.cpp | 4 +-- llvm/lib/IR/AsmWriter.cpp | 6 ++-- llvm/lib/IR/Attributes.cpp | 23 +++++++------ llvm/lib/MC/MCSubtargetInfo.cpp | 8 ++--- llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp | 3 +- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 3 +- llvm/lib/Target/Mips/MipsCCState.cpp | 6 ++-- llvm/lib/Target/X86/X86EvexToVex.cpp | 6 ++-- llvm/lib/Target/X86/X86ISelLowering.cpp | 8 ++--- llvm/lib/Target/X86/X86InstrFMA3Info.cpp | 7 ++-- llvm/lib/Target/X86/X86InstrFoldTables.cpp | 40 +++++++++------------- llvm/lib/Target/X86/X86IntrinsicsInfo.h | 6 ++-- llvm/lib/Transforms/IPO/CalledValuePropagation.cpp | 3 +- llvm/tools/llvm-exegesis/lib/Target.cpp | 4 +-- llvm/tools/llvm-objcopy/ELF/Object.cpp | 3 +- .../llvm-objcopy/MachO/MachOLayoutBuilder.cpp | 19 +++++----- llvm/unittests/ADT/SimpleIListTest.cpp | 26 +++++++------- llvm/unittests/Support/ParallelTest.cpp | 2 +- 35 files changed, 129 insertions(+), 144 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index ce16095..d2df24a 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -292,9 +292,7 @@ public: }; bool isUnknownAnalyzerConfig(StringRef Name) const { - - assert(std::is_sorted(AnalyzerConfigCmdFlags.begin(), - AnalyzerConfigCmdFlags.end())); + assert(llvm::is_sorted(AnalyzerConfigCmdFlags)); return !std::binary_search(AnalyzerConfigCmdFlags.begin(), AnalyzerConfigCmdFlags.end(), Name); diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index fb0c8b3..812fdc6 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -5352,7 +5352,7 @@ findARMVectorIntrinsicInMap(ArrayRef IntrinsicMap, #ifndef NDEBUG if (!MapProvenSorted) { - assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap))); + assert(llvm::is_sorted(IntrinsicMap)); MapProvenSorted = true; } #endif diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 31ab797..1d0379a 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -5451,7 +5451,7 @@ llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, // This isn't a stable sort, but our algorithm should handle it fine. llvm::array_pod_sort(IvarsInfo.begin(), IvarsInfo.end()); } else { - assert(std::is_sorted(IvarsInfo.begin(), IvarsInfo.end())); + assert(llvm::is_sorted(IvarsInfo)); } assert(IvarsInfo.back().Offset < InstanceEnd); diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4a5626d..9b65c79 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2049,8 +2049,7 @@ static void sortCppIncludes(const FormatStyle &Style, // enough as additional newlines might be added or removed across #include // blocks. This we handle below by generating the updated #imclude blocks and // comparing it to the original. - if (Indices.size() == Includes.size() && - std::is_sorted(Indices.begin(), Indices.end()) && + if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) && Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve) return; diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index 5be243f..db2b65b 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -144,7 +144,7 @@ public: llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { return References[LHSI] < References[RHSI]; }); - bool ReferencesInOrder = std::is_sorted(Indices.begin(), Indices.end()); + bool ReferencesInOrder = llvm::is_sorted(Indices); std::string ReferencesText; bool SymbolsInOrder = true; diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp index e558354..62ac1ed 100644 --- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp @@ -59,8 +59,7 @@ binaryFind(CheckerOrPackageInfoList &Collection, StringRef FullName) { using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type; using CheckerOrPackageFullNameLT = FullNameLT; - assert(std::is_sorted(Collection.begin(), Collection.end(), - CheckerOrPackageFullNameLT{}) && + assert(llvm::is_sorted(Collection, CheckerOrPackageFullNameLT{}) && "In order to efficiently gather checkers/packages, this function " "expects them to be already sorted!"); diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp index 1464d97..c6b9048 100644 --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -643,14 +643,13 @@ public: #ifndef NDEBUG for (auto &pair : Result.Files) { auto &mappings = pair.second.Mappings; - assert(std::is_sorted( - mappings.begin(), mappings.end(), - [](const TokenBuffer::Mapping &M1, const TokenBuffer::Mapping &M2) { - return M1.BeginSpelled < M2.BeginSpelled && - M1.EndSpelled < M2.EndSpelled && - M1.BeginExpanded < M2.BeginExpanded && - M1.EndExpanded < M2.EndExpanded; - })); + assert(llvm::is_sorted(mappings, [](const TokenBuffer::Mapping &M1, + const TokenBuffer::Mapping &M2) { + return M1.BeginSpelled < M2.BeginSpelled && + M1.EndSpelled < M2.EndSpelled && + M1.BeginExpanded < M2.BeginExpanded && + M1.EndExpanded < M2.EndExpanded; + })); } #endif diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 15a8587..4954e6d 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -223,14 +223,13 @@ static void setRelocs(const std::vector &chunks, return; ArrayRef relocs = section->Relocations; - assert(std::is_sorted(relocs.begin(), relocs.end(), - [](const WasmRelocation &r1, const WasmRelocation &r2) { - return r1.Offset < r2.Offset; - })); - assert(std::is_sorted( - chunks.begin(), chunks.end(), [](InputChunk *c1, InputChunk *c2) { - return c1->getInputSectionOffset() < c2->getInputSectionOffset(); + assert(llvm::is_sorted( + relocs, [](const WasmRelocation &r1, const WasmRelocation &r2) { + return r1.Offset < r2.Offset; })); + assert(llvm::is_sorted(chunks, [](InputChunk *c1, InputChunk *c2) { + return c1->getInputSectionOffset() < c2->getInputSectionOffset(); + })); auto relocsNext = relocs.begin(); auto relocsEnd = relocs.end(); diff --git a/llvm/include/llvm/ADT/CoalescingBitVector.h b/llvm/include/llvm/ADT/CoalescingBitVector.h index 8ef6f4f..6478574 100644 --- a/llvm/include/llvm/ADT/CoalescingBitVector.h +++ b/llvm/include/llvm/ADT/CoalescingBitVector.h @@ -384,10 +384,10 @@ private: for (IntervalMapOverlaps I(Intervals, Other.Intervals); I.valid(); ++I) Overlaps.emplace_back(I.start(), I.stop()); - assert(std::is_sorted(Overlaps.begin(), Overlaps.end(), - [](IntervalT LHS, IntervalT RHS) { - return LHS.second < RHS.first; - }) && + assert(llvm::is_sorted(Overlaps, + [](IntervalT LHS, IntervalT RHS) { + return LHS.second < RHS.first; + }) && "Overlaps must be sorted"); return !Overlaps.empty(); } diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index a6619ad..529219e 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1257,6 +1257,18 @@ bool is_contained(R &&Range, const E &Element) { return std::find(adl_begin(Range), adl_end(Range), Element) != adl_end(Range); } +/// Wrapper function around std::is_sorted to check if elements in a range \p R +/// are sorted with respect to a comparator \p C. +template bool is_sorted(R &&Range, Compare C) { + return std::is_sorted(adl_begin(Range), adl_end(Range), C); +} + +/// Wrapper function around std::is_sorted to check if elements in a range \p R +/// are sorted in non-descending order. +template bool is_sorted(R &&Range) { + return std::is_sorted(adl_begin(Range), adl_end(Range)); +} + /// Wrapper function around std::count to count the number of times an element /// \p Element occurs in the given range \p Range. template auto count(R &&Range, const E &Element) { diff --git a/llvm/include/llvm/CodeGen/LiveInterval.h b/llvm/include/llvm/CodeGen/LiveInterval.h index dfb104a..0764257 100644 --- a/llvm/include/llvm/CodeGen/LiveInterval.h +++ b/llvm/include/llvm/CodeGen/LiveInterval.h @@ -617,7 +617,7 @@ namespace llvm { /// subranges). Returns true if found at least one index. template bool findIndexesLiveAt(Range &&R, OutputIt O) const { - assert(std::is_sorted(R.begin(), R.end())); + assert(llvm::is_sorted(R)); auto Idx = R.begin(), EndIdx = R.end(); auto Seg = segments.begin(), EndSeg = segments.end(); bool Found = false; diff --git a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp index eb5c96e..179f063 100644 --- a/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp +++ b/llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp @@ -552,7 +552,7 @@ bool CFLAndersAAResult::FunctionInfo::mayAlias( return std::less()(LHS.Val, RHS.Val); }; #ifdef EXPENSIVE_CHECKS - assert(std::is_sorted(Itr->second.begin(), Itr->second.end(), Comparator)); + assert(llvm::is_sorted(Itr->second, Comparator)); #endif auto RangePair = std::equal_range(Itr->second.begin(), Itr->second.end(), OffsetValue{RHS, 0}, Comparator); diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp index c08a84e..6271bbf 100644 --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -64,10 +64,10 @@ static Loop *getInnerMostLoop(const LoopVectorTy &Loops) { return LastLoop; } - return (std::is_sorted(Loops.begin(), Loops.end(), - [](const Loop *L1, const Loop *L2) { - return L1->getLoopDepth() < L2->getLoopDepth(); - })) + return (llvm::is_sorted(Loops, + [](const Loop *L1, const Loop *L2) { + return L1->getLoopDepth() < L2->getLoopDepth(); + })) ? LastLoop : nullptr; } diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp index ffa6921..cae71d1 100644 --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -69,11 +69,10 @@ static bool hasBcmp(const Triple &TT) { static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef StandardNames) { // Verify that the StandardNames array is in alphabetical order. - assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), - [](StringRef LHS, StringRef RHS) { - return LHS < RHS; - }) && - "TargetLibraryInfoImpl function names must be sorted"); + assert( + llvm::is_sorted(StandardNames, + [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) && + "TargetLibraryInfoImpl function names must be sorted"); // Set IO unlocked variants as unavailable // Set them as available per system below diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 7419c46..8bdddc2 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -231,9 +231,9 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F, return LU->getOperandNo() > RU->getOperandNo(); }); - if (std::is_sorted( - List.begin(), List.end(), - [](const Entry &L, const Entry &R) { return L.second < R.second; })) + if (llvm::is_sorted(List, [](const Entry &L, const Entry &R) { + return L.second < R.second; + })) // Order is already correct. return; diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e75bf95..0624dfe 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2424,8 +2424,7 @@ void DebugLocEntry::finalize(const AsmPrinter &AP, assert(llvm::all_of(Values, [](DbgValueLoc P) { return P.isFragment(); }) && "all values are expected to be fragments"); - assert(std::is_sorted(Values.begin(), Values.end()) && - "fragments are expected to be sorted"); + assert(llvm::is_sorted(Values) && "fragments are expected to be sorted"); for (auto Fragment : Values) DwarfDebug::emitDebugLocValue(AP, BT, Fragment, DwarfExpr); diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp index 834a7ad..4fa9069 100644 --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -513,7 +513,7 @@ void MachineIRBuilder::buildSequence(Register Res, ArrayRef Ops, #ifndef NDEBUG assert(Ops.size() == Indices.size() && "incompatible args"); assert(!Ops.empty() && "invalid trivial sequence"); - assert(std::is_sorted(Indices.begin(), Indices.end()) && + assert(llvm::is_sorted(Indices) && "sequence offsets must be in ascending order"); assert(getMRI()->getType(Res).isValid() && "invalid operand type"); diff --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp b/llvm/lib/Frontend/OpenMP/OMPContext.cpp index ccb148c..c44e858 100644 --- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -91,8 +91,8 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple) { /// expected to be sorted. template static bool isSubset(ArrayRef C0, ArrayRef C1) { #ifdef EXPENSIVE_CHECKS - assert(std::is_sorted(C0.begin(), C0.end()) && - std::is_sorted(C1.begin(), C1.end()) && "Expected sorted arrays!"); + assert(llvm::is_sorted(C0) && llvm::is_sorted(C1) && + "Expected sorted arrays!"); #endif if (C0.size() > C1.size()) return false; diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 1b74533..ca01fe4 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -228,9 +228,9 @@ static void predictValueUseListOrderImpl(const Value *V, const Function *F, return LU->getOperandNo() > RU->getOperandNo(); }); - if (std::is_sorted( - List.begin(), List.end(), - [](const Entry &L, const Entry &R) { return L.second < R.second; })) + if (llvm::is_sorted(List, [](const Entry &L, const Entry &R) { + return L.second < R.second; + })) // Order is already correct. return; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index e237f6c..f7e4251 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1019,11 +1019,12 @@ AttributeList::get(LLVMContext &C, if (Attrs.empty()) return {}; - assert(std::is_sorted(Attrs.begin(), Attrs.end(), - [](const std::pair &LHS, - const std::pair &RHS) { - return LHS.first < RHS.first; - }) && "Misordered Attributes list!"); + assert(llvm::is_sorted(Attrs, + [](const std::pair &LHS, + const std::pair &RHS) { + return LHS.first < RHS.first; + }) && + "Misordered Attributes list!"); assert(llvm::none_of(Attrs, [](const std::pair &Pair) { return Pair.second.hasAttribute(Attribute::None); @@ -1055,11 +1056,11 @@ AttributeList::get(LLVMContext &C, if (Attrs.empty()) return {}; - assert(std::is_sorted(Attrs.begin(), Attrs.end(), - [](const std::pair &LHS, - const std::pair &RHS) { - return LHS.first < RHS.first; - }) && + assert(llvm::is_sorted(Attrs, + [](const std::pair &LHS, + const std::pair &RHS) { + return LHS.first < RHS.first; + }) && "Misordered Attributes list!"); assert(llvm::none_of(Attrs, [](const std::pair &Pair) { @@ -1228,7 +1229,7 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, AttributeList AttributeList::addParamAttribute(LLVMContext &C, ArrayRef ArgNos, Attribute A) const { - assert(std::is_sorted(ArgNos.begin(), ArgNos.end())); + assert(llvm::is_sorted(ArgNos)); SmallVector AttrSets(this->begin(), this->end()); unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex); diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index efe1e95..1c187d6 100644 --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/lib/MC/MCSubtargetInfo.cpp @@ -155,10 +155,8 @@ static FeatureBitset getFeatures(StringRef CPU, StringRef FS, if (ProcDesc.empty() || ProcFeatures.empty()) return FeatureBitset(); - assert(std::is_sorted(std::begin(ProcDesc), std::end(ProcDesc)) && - "CPU table is not sorted"); - assert(std::is_sorted(std::begin(ProcFeatures), std::end(ProcFeatures)) && - "CPU features table is not sorted"); + assert(llvm::is_sorted(ProcDesc) && "CPU table is not sorted"); + assert(llvm::is_sorted(ProcFeatures) && "CPU features table is not sorted"); // Resulting bits FeatureBitset Bits; @@ -290,7 +288,7 @@ bool MCSubtargetInfo::checkFeatures(StringRef FS) const { } const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const { - assert(std::is_sorted(ProcDesc.begin(), ProcDesc.end()) && + assert(llvm::is_sorted(ProcDesc) && "Processor machine model table is not sorted"); // Find entry diff --git a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp index 9e461c3..a122dac 100644 --- a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -417,8 +417,7 @@ static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) { // Make sure the table is sorted. static std::atomic TableChecked(false); if (!TableChecked.load(std::memory_order_relaxed)) { - assert(std::is_sorted(std::begin(NEONLdStTable), std::end(NEONLdStTable)) && - "NEONLdStTable is not sorted!"); + assert(llvm::is_sorted(NEONLdStTable) && "NEONLdStTable is not sorted!"); TableChecked.store(true, std::memory_order_relaxed); } #endif diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 9304d83..c3639b3 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -3619,8 +3619,7 @@ public: if (Kind == k_RegisterList && Regs.back().second == ARM::APSR) Kind = k_RegisterListWithAPSR; - assert(std::is_sorted(Regs.begin(), Regs.end()) && - "Register list must be sorted by encoding"); + assert(llvm::is_sorted(Regs) && "Register list must be sorted by encoding"); auto Op = std::make_unique(Kind); for (const auto &P : Regs) diff --git a/llvm/lib/Target/Mips/MipsCCState.cpp b/llvm/lib/Target/Mips/MipsCCState.cpp index ef48c85..fe3fe82 100644 --- a/llvm/lib/Target/Mips/MipsCCState.cpp +++ b/llvm/lib/Target/Mips/MipsCCState.cpp @@ -30,9 +30,9 @@ static bool isF128SoftLibCall(const char *CallSym) { // Check that LibCalls is sorted alphabetically. auto Comp = [](const char *S1, const char *S2) { return strcmp(S1, S2) < 0; }; - assert(std::is_sorted(std::begin(LibCalls), std::end(LibCalls), Comp)); - return std::binary_search(std::begin(LibCalls), std::end(LibCalls), - CallSym, Comp); + assert(llvm::is_sorted(LibCalls, Comp)); + return std::binary_search(std::begin(LibCalls), std::end(LibCalls), CallSym, + Comp); } /// This function returns true if Ty is fp128, {f128} or i128 which was diff --git a/llvm/lib/Target/X86/X86EvexToVex.cpp b/llvm/lib/Target/X86/X86EvexToVex.cpp index f1cf9b9..540ad98 100644 --- a/llvm/lib/Target/X86/X86EvexToVex.cpp +++ b/llvm/lib/Target/X86/X86EvexToVex.cpp @@ -237,11 +237,9 @@ bool EvexToVexInstPass::CompressEvexToVexImpl(MachineInstr &MI) const { // Make sure the tables are sorted. static std::atomic TableChecked(false); if (!TableChecked.load(std::memory_order_relaxed)) { - assert(std::is_sorted(std::begin(X86EvexToVex128CompressTable), - std::end(X86EvexToVex128CompressTable)) && + assert(llvm::is_sorted(X86EvexToVex128CompressTable) && "X86EvexToVex128CompressTable is not sorted!"); - assert(std::is_sorted(std::begin(X86EvexToVex256CompressTable), - std::end(X86EvexToVex256CompressTable)) && + assert(llvm::is_sorted(X86EvexToVex256CompressTable) && "X86EvexToVex256CompressTable is not sorted!"); TableChecked.store(true, std::memory_order_relaxed); } diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 4103201..47ef38a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -3383,10 +3383,10 @@ static ArrayRef get64BitArgumentXMMs(MachineFunction &MF, #ifndef NDEBUG static bool isSortedByValueNo(ArrayRef ArgLocs) { - return std::is_sorted(ArgLocs.begin(), ArgLocs.end(), - [](const CCValAssign &A, const CCValAssign &B) -> bool { - return A.getValNo() < B.getValNo(); - }); + return llvm::is_sorted( + ArgLocs, [](const CCValAssign &A, const CCValAssign &B) -> bool { + return A.getValNo() < B.getValNo(); + }); } #endif diff --git a/llvm/lib/Target/X86/X86InstrFMA3Info.cpp b/llvm/lib/Target/X86/X86InstrFMA3Info.cpp index 25bbddd..6d803e93 100644 --- a/llvm/lib/Target/X86/X86InstrFMA3Info.cpp +++ b/llvm/lib/Target/X86/X86InstrFMA3Info.cpp @@ -116,11 +116,8 @@ static void verifyTables() { #ifndef NDEBUG static std::atomic TableChecked(false); if (!TableChecked.load(std::memory_order_relaxed)) { - assert(std::is_sorted(std::begin(Groups), std::end(Groups)) && - std::is_sorted(std::begin(RoundGroups), std::end(RoundGroups)) && - std::is_sorted(std::begin(BroadcastGroups), - std::end(BroadcastGroups)) && - "FMA3 tables not sorted!"); + assert(llvm::is_sorted(Groups) && llvm::is_sorted(RoundGroups) && + llvm::is_sorted(BroadcastGroups) && "FMA3 tables not sorted!"); TableChecked.store(true, std::memory_order_relaxed); } #endif diff --git a/llvm/lib/Target/X86/X86InstrFoldTables.cpp b/llvm/lib/Target/X86/X86InstrFoldTables.cpp index 15745c1..11fbb37 100644 --- a/llvm/lib/Target/X86/X86InstrFoldTables.cpp +++ b/llvm/lib/Target/X86/X86InstrFoldTables.cpp @@ -5529,53 +5529,45 @@ lookupFoldTableImpl(ArrayRef Table, unsigned RegOp) { // Make sure the tables are sorted. static std::atomic FoldTablesChecked(false); if (!FoldTablesChecked.load(std::memory_order_relaxed)) { - assert(std::is_sorted(std::begin(MemoryFoldTable2Addr), - std::end(MemoryFoldTable2Addr)) && + assert(llvm::is_sorted(MemoryFoldTable2Addr) && std::adjacent_find(std::begin(MemoryFoldTable2Addr), std::end(MemoryFoldTable2Addr)) == - std::end(MemoryFoldTable2Addr) && + std::end(MemoryFoldTable2Addr) && "MemoryFoldTable2Addr is not sorted and unique!"); - assert(std::is_sorted(std::begin(MemoryFoldTable0), - std::end(MemoryFoldTable0)) && + assert(llvm::is_sorted(MemoryFoldTable0) && std::adjacent_find(std::begin(MemoryFoldTable0), std::end(MemoryFoldTable0)) == - std::end(MemoryFoldTable0) && + std::end(MemoryFoldTable0) && "MemoryFoldTable0 is not sorted and unique!"); - assert(std::is_sorted(std::begin(MemoryFoldTable1), - std::end(MemoryFoldTable1)) && + assert(llvm::is_sorted(MemoryFoldTable1) && std::adjacent_find(std::begin(MemoryFoldTable1), std::end(MemoryFoldTable1)) == - std::end(MemoryFoldTable1) && + std::end(MemoryFoldTable1) && "MemoryFoldTable1 is not sorted and unique!"); - assert(std::is_sorted(std::begin(MemoryFoldTable2), - std::end(MemoryFoldTable2)) && + assert(llvm::is_sorted(MemoryFoldTable2) && std::adjacent_find(std::begin(MemoryFoldTable2), std::end(MemoryFoldTable2)) == - std::end(MemoryFoldTable2) && + std::end(MemoryFoldTable2) && "MemoryFoldTable2 is not sorted and unique!"); - assert(std::is_sorted(std::begin(MemoryFoldTable3), - std::end(MemoryFoldTable3)) && + assert(llvm::is_sorted(MemoryFoldTable3) && std::adjacent_find(std::begin(MemoryFoldTable3), std::end(MemoryFoldTable3)) == - std::end(MemoryFoldTable3) && + std::end(MemoryFoldTable3) && "MemoryFoldTable3 is not sorted and unique!"); - assert(std::is_sorted(std::begin(MemoryFoldTable4), - std::end(MemoryFoldTable4)) && + assert(llvm::is_sorted(MemoryFoldTable4) && std::adjacent_find(std::begin(MemoryFoldTable4), std::end(MemoryFoldTable4)) == - std::end(MemoryFoldTable4) && + std::end(MemoryFoldTable4) && "MemoryFoldTable4 is not sorted and unique!"); - assert(std::is_sorted(std::begin(BroadcastFoldTable2), - std::end(BroadcastFoldTable2)) && + assert(llvm::is_sorted(BroadcastFoldTable2) && std::adjacent_find(std::begin(BroadcastFoldTable2), std::end(BroadcastFoldTable2)) == - std::end(BroadcastFoldTable2) && + std::end(BroadcastFoldTable2) && "BroadcastFoldTable2 is not sorted and unique!"); - assert(std::is_sorted(std::begin(BroadcastFoldTable3), - std::end(BroadcastFoldTable3)) && + assert(llvm::is_sorted(BroadcastFoldTable3) && std::adjacent_find(std::begin(BroadcastFoldTable3), std::end(BroadcastFoldTable3)) == - std::end(BroadcastFoldTable3) && + std::end(BroadcastFoldTable3) && "BroadcastFoldTable3 is not sorted and unique!"); FoldTablesChecked.store(true, std::memory_order_relaxed); } diff --git a/llvm/lib/Target/X86/X86IntrinsicsInfo.h b/llvm/lib/Target/X86/X86IntrinsicsInfo.h index 6dc4860..a3b4279 100644 --- a/llvm/lib/Target/X86/X86IntrinsicsInfo.h +++ b/llvm/lib/Target/X86/X86IntrinsicsInfo.h @@ -1155,10 +1155,8 @@ static const IntrinsicData* getIntrinsicWithoutChain(unsigned IntNo) { } static void verifyIntrinsicTables() { - assert(std::is_sorted(std::begin(IntrinsicsWithoutChain), - std::end(IntrinsicsWithoutChain)) && - std::is_sorted(std::begin(IntrinsicsWithChain), - std::end(IntrinsicsWithChain)) && + assert(llvm::is_sorted(IntrinsicsWithoutChain) && + llvm::is_sorted(IntrinsicsWithChain) && "Intrinsic data tables should be sorted by Intrinsic ID"); assert((std::adjacent_find(std::begin(IntrinsicsWithoutChain), std::end(IntrinsicsWithoutChain)) == diff --git a/llvm/lib/Transforms/IPO/CalledValuePropagation.cpp b/llvm/lib/Transforms/IPO/CalledValuePropagation.cpp index f28a399..8358cce 100644 --- a/llvm/lib/Transforms/IPO/CalledValuePropagation.cpp +++ b/llvm/lib/Transforms/IPO/CalledValuePropagation.cpp @@ -72,8 +72,7 @@ public: CVPLatticeVal(CVPLatticeStateTy LatticeState) : LatticeState(LatticeState) {} CVPLatticeVal(std::vector &&Functions) : LatticeState(FunctionSet), Functions(std::move(Functions)) { - assert(std::is_sorted(this->Functions.begin(), this->Functions.end(), - Compare())); + assert(llvm::is_sorted(this->Functions, Compare())); } /// Get a reference to the functions held by this lattice value. The number diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp index 7fb2231..4e0de93 100644 --- a/llvm/tools/llvm-exegesis/lib/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/Target.cpp @@ -107,8 +107,8 @@ const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr, 0u}; const PfmCountersInfo &ExegesisTarget::getPfmCounters(StringRef CpuName) const { - assert(std::is_sorted( - CpuPfmCounters.begin(), CpuPfmCounters.end(), + assert(llvm::is_sorted( + CpuPfmCounters, [](const CpuAndPfmCounters &LHS, const CpuAndPfmCounters &RHS) { return strcmp(LHS.CpuName, RHS.CpuName) < 0; }) && diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp index 14ac7bb..bc590fa 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -1902,8 +1902,7 @@ static void orderSegments(std::vector &Segments) { // returns an Offset one past the end of the last segment. static uint64_t layoutSegments(std::vector &Segments, uint64_t Offset) { - assert(std::is_sorted(std::begin(Segments), std::end(Segments), - compareSegmentsByOffset)); + assert(llvm::is_sorted(Segments, compareSegmentsByOffset)); // The only way a segment should move is if a section was between two // segments and that section was removed. If that section isn't in a segment // then it's acceptable, but not ideal, to simply move it to after the diff --git a/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp b/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp index fc45bf9..9ac02eb 100644 --- a/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp +++ b/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp @@ -61,15 +61,16 @@ void MachOLayoutBuilder::updateDySymTab(MachO::macho_load_command &MLC) { assert(MLC.load_command_data.cmd == MachO::LC_DYSYMTAB); // Make sure that nlist entries in the symbol table are sorted by the those // types. The order is: local < defined external < undefined external. - assert(std::is_sorted(O.SymTable.Symbols.begin(), O.SymTable.Symbols.end(), - [](const std::unique_ptr &A, - const std::unique_ptr &B) { - bool AL = A->isLocalSymbol(), BL = B->isLocalSymbol(); - if (AL != BL) - return AL; - return !AL && !A->isUndefinedSymbol() && - B->isUndefinedSymbol(); - }) && + assert(llvm::is_sorted(O.SymTable.Symbols, + [](const std::unique_ptr &A, + const std::unique_ptr &B) { + bool AL = A->isLocalSymbol(), + BL = B->isLocalSymbol(); + if (AL != BL) + return AL; + return !AL && !A->isUndefinedSymbol() && + B->isUndefinedSymbol(); + }) && "Symbols are not sorted by their types."); uint32_t NumLocalSymbols = 0; diff --git a/llvm/unittests/ADT/SimpleIListTest.cpp b/llvm/unittests/ADT/SimpleIListTest.cpp index 9b8ffac..238896e 100644 --- a/llvm/unittests/ADT/SimpleIListTest.cpp +++ b/llvm/unittests/ADT/SimpleIListTest.cpp @@ -436,8 +436,8 @@ TEST(SimpleIListTest, merge) { // Check setup. EXPECT_EQ(4u, L1.size()); EXPECT_EQ(6u, L2.size()); - EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end())); - EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end())); + EXPECT_TRUE(llvm::is_sorted(L1)); + EXPECT_TRUE(llvm::is_sorted(L2)); // Merge. auto &LHS = IsL1LHS ? L1 : L2; @@ -445,7 +445,7 @@ TEST(SimpleIListTest, merge) { LHS.merge(RHS); EXPECT_TRUE(RHS.empty()); EXPECT_FALSE(LHS.empty()); - EXPECT_TRUE(std::is_sorted(LHS.begin(), LHS.end())); + EXPECT_TRUE(llvm::is_sorted(LHS)); auto I = LHS.begin(); for (Node &N : Ns) EXPECT_EQ(&N, &*I++); @@ -473,8 +473,8 @@ TEST(SimpleIListTest, mergeIsStable) { // Check setup. EXPECT_EQ(3u, L1.size()); EXPECT_EQ(2u, L2.size()); - EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end(), makeFalse)); - EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end(), makeFalse)); + EXPECT_TRUE(llvm::is_sorted(L1, makeFalse)); + EXPECT_TRUE(llvm::is_sorted(L2, makeFalse)); }; // Merge. Should be stable. @@ -482,7 +482,7 @@ TEST(SimpleIListTest, mergeIsStable) { L1.merge(L2, makeFalse); EXPECT_TRUE(L2.empty()); EXPECT_FALSE(L1.empty()); - EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end(), makeFalse)); + EXPECT_TRUE(llvm::is_sorted(L1, makeFalse)); auto I = L1.begin(); EXPECT_EQ(&Ns[0], &*I++); EXPECT_EQ(&Ns[3], &*I++); @@ -497,7 +497,7 @@ TEST(SimpleIListTest, mergeIsStable) { L2.merge(L1, makeFalse); EXPECT_TRUE(L1.empty()); EXPECT_FALSE(L2.empty()); - EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end(), makeFalse)); + EXPECT_TRUE(llvm::is_sorted(L2, makeFalse)); I = L2.begin(); EXPECT_EQ(&Ns[1], &*I++); EXPECT_EQ(&Ns[2], &*I++); @@ -521,7 +521,7 @@ TEST(SimpleIListTest, mergeEmpty) { // Check setup. EXPECT_EQ(4u, L1.size()); EXPECT_TRUE(L2.empty()); - EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end())); + EXPECT_TRUE(llvm::is_sorted(L1)); // Merge. auto &LHS = IsL1LHS ? L1 : L2; @@ -529,7 +529,7 @@ TEST(SimpleIListTest, mergeEmpty) { LHS.merge(RHS); EXPECT_TRUE(RHS.empty()); EXPECT_FALSE(LHS.empty()); - EXPECT_TRUE(std::is_sorted(LHS.begin(), LHS.end())); + EXPECT_TRUE(llvm::is_sorted(LHS)); auto I = LHS.begin(); for (Node &N : Ns) EXPECT_EQ(&N, &*I++); @@ -554,11 +554,11 @@ TEST(SimpleIListTest, sort) { // Check setup. EXPECT_EQ(10u, L.size()); - EXPECT_FALSE(std::is_sorted(L.begin(), L.end())); + EXPECT_FALSE(llvm::is_sorted(L)); // Sort. L.sort(); - EXPECT_TRUE(std::is_sorted(L.begin(), L.end())); + EXPECT_TRUE(llvm::is_sorted(L)); auto I = L.begin(); for (Node &N : Ns) EXPECT_EQ(&N, &*I++); @@ -581,11 +581,11 @@ TEST(SimpleIListTest, sortIsStable) { // Check setup. EXPECT_EQ(10u, L.size()); - EXPECT_FALSE(std::is_sorted(L.begin(), L.end(), compare)); + EXPECT_FALSE(llvm::is_sorted(L, compare)); // Sort. L.sort(compare); - EXPECT_TRUE(std::is_sorted(L.begin(), L.end(), compare)); + EXPECT_TRUE(llvm::is_sorted(L, compare)); auto I = L.begin(); for (int O : {3, 4, 1, 2, 0}) EXPECT_EQ(&Ns[O], &*I++); diff --git a/llvm/unittests/Support/ParallelTest.cpp b/llvm/unittests/Support/ParallelTest.cpp index 63c7152..4bae89d 100644 --- a/llvm/unittests/Support/ParallelTest.cpp +++ b/llvm/unittests/Support/ParallelTest.cpp @@ -31,7 +31,7 @@ TEST(Parallel, sort) { i = dist(randEngine); sort(parallel::par, std::begin(array), std::end(array)); - ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array))); + ASSERT_TRUE(llvm::is_sorted(array)); } TEST(Parallel, parallel_for) { -- 2.7.4