Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / src / algorithm.cpp
blobaf9d60a8e271e84f56fe4a2f1f2e8cbc7af5d958
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <algorithm>
10 #include <bit>
12 _LIBCPP_BEGIN_NAMESPACE_STD
14 template <class Comp, class RandomAccessIterator>
15 void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {
16 auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));
18 // Only use bitset partitioning for arithmetic types. We should also check
19 // that the default comparator is in use so that we are sure that there are no
20 // branches in the comparator.
21 std::__introsort<_ClassicAlgPolicy,
22 ranges::less,
23 RandomAccessIterator,
24 __use_branchless_sort<ranges::less, RandomAccessIterator>::value>(
25 first, last, ranges::less{}, depth_limit);
28 // clang-format off
29 template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
30 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
31 template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
32 #endif
33 template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
34 template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
35 template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
36 template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
37 template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
38 template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
39 template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
40 template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
41 template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
42 template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
43 template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
44 template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
45 template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
46 // clang-format on
48 _LIBCPP_END_NAMESPACE_STD