Skip to content

Commit 01eeefd

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Id47ac9d82f16650c6f21b161d8908ad1da958081
2 parents 486c900 + 6cc8d54 commit 01eeefd

File tree

34 files changed

+462
-227
lines changed

34 files changed

+462
-227
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4613,7 +4613,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
46134613
return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
46144614
spaceRequiredBeforeParens(Right);
46154615
}
4616-
if (!Left.Previous || Left.Previous->isNot(tok::period)) {
4616+
if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
46174617
if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
46184618
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
46194619
spaceRequiredBeforeParens(Right);

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11475,6 +11475,11 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
1147511475
"void new (link p);\n"
1147611476
"void delete (link p);");
1147711477

11478+
verifyFormat("{ p->delete(); }\n"
11479+
"{ p->new(); }",
11480+
"{ p->delete (); }\n"
11481+
"{ p->new (); }");
11482+
1147811483
FormatStyle AfterPlacementOperator = getLLVMStyle();
1147911484
AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
1148011485
EXPECT_TRUE(

libc/src/stdio/baremetal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ add_entrypoint_object(
44
remove.cpp
55
HDRS
66
../remove.h
7+
DEPENDS
8+
libc.include.stdio
79
)

libc/src/stdio/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_entrypoint_object(
66
../remove.h
77
DEPENDS
88
libc.include.fcntl
9+
libc.include.stdio
910
libc.include.unistd
1011
libc.include.sys_syscall
1112
libc.src.__support.OSUtil.osutil

libcxx/benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ set(BENCHMARK_TESTS
176176
algorithms/count.bench.cpp
177177
algorithms/equal.bench.cpp
178178
algorithms/find.bench.cpp
179+
algorithms/fill.bench.cpp
179180
algorithms/for_each.bench.cpp
180181
algorithms/lower_bound.bench.cpp
181182
algorithms/make_heap.bench.cpp
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
//===----------------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <benchmark/benchmark.h>
11+
#include <vector>
12+
13+
static void bm_fill_n(benchmark::State& state) {
14+
std::vector<bool> vec1(state.range());
15+
for (auto _ : state) {
16+
benchmark::DoNotOptimize(vec1);
17+
benchmark::DoNotOptimize(std::fill_n(vec1.begin(), vec1.size(), false));
18+
}
19+
}
20+
BENCHMARK(bm_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20);
21+
22+
static void bm_ranges_fill_n(benchmark::State& state) {
23+
std::vector<bool> vec1(state.range());
24+
for (auto _ : state) {
25+
benchmark::DoNotOptimize(vec1);
26+
benchmark::DoNotOptimize(std::ranges::fill_n(vec1.begin(), vec1.size(), false));
27+
}
28+
}
29+
BENCHMARK(bm_ranges_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20);
30+
31+
static void bm_fill(benchmark::State& state) {
32+
std::vector<bool> vec1(state.range());
33+
for (auto _ : state) {
34+
benchmark::DoNotOptimize(vec1);
35+
std::fill(vec1.begin(), vec1.end(), false);
36+
}
37+
}
38+
BENCHMARK(bm_fill)->DenseRange(1, 8)->Range(16, 1 << 20);
39+
40+
static void bm_ranges_fill(benchmark::State& state) {
41+
std::vector<bool> vec1(state.range());
42+
for (auto _ : state) {
43+
benchmark::DoNotOptimize(vec1);
44+
benchmark::DoNotOptimize(std::ranges::fill(vec1, false));
45+
}
46+
}
47+
BENCHMARK(bm_ranges_fill)->DenseRange(1, 8)->Range(16, 1 << 20);
48+
49+
BENCHMARK_MAIN();

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Improvements and New Features
4949
-----------------------------
5050

5151
- The performance of growing ``std::vector`` has been improved for trivially relocatable types.
52+
- The performance of ``ranges::fill`` and ``ranges::fill_n`` has been improved for ``vector<bool>::iterator``\s,
53+
resulting in a performance increase of up to 1400x.
5254

5355
Deprecations and Removals
5456
-------------------------

libcxx/include/__algorithm/fill_n.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,74 @@
99
#ifndef _LIBCPP___ALGORITHM_FILL_N_H
1010
#define _LIBCPP___ALGORITHM_FILL_N_H
1111

12+
#include <__algorithm/min.h>
1213
#include <__config>
14+
#include <__fwd/bit_reference.h>
1315
#include <__iterator/iterator_traits.h>
16+
#include <__memory/pointer_traits.h>
1417
#include <__utility/convert_to_integral.h>
1518

1619
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1720
# pragma GCC system_header
1821
#endif
1922

23+
_LIBCPP_PUSH_MACROS
24+
#include <__undef_macros>
25+
2026
_LIBCPP_BEGIN_NAMESPACE_STD
2127

2228
// fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
2329

30+
template <class _OutputIterator, class _Size, class _Tp>
31+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
32+
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value);
33+
34+
template <bool _FillVal, class _Cp>
35+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
36+
__fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
37+
using _It = __bit_iterator<_Cp, false>;
38+
using __storage_type = typename _It::__storage_type;
39+
40+
const int __bits_per_word = _It::__bits_per_word;
41+
// do first partial word
42+
if (__first.__ctz_ != 0) {
43+
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
44+
__storage_type __dn = std::min(__clz_f, __n);
45+
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
46+
if (_FillVal)
47+
*__first.__seg_ |= __m;
48+
else
49+
*__first.__seg_ &= ~__m;
50+
__n -= __dn;
51+
++__first.__seg_;
52+
}
53+
// do middle whole words
54+
__storage_type __nw = __n / __bits_per_word;
55+
std::__fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
56+
__n -= __nw * __bits_per_word;
57+
// do last partial word
58+
if (__n > 0) {
59+
__first.__seg_ += __nw;
60+
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
61+
if (_FillVal)
62+
*__first.__seg_ |= __m;
63+
else
64+
*__first.__seg_ &= ~__m;
65+
}
66+
}
67+
68+
template <class _Cp, class _Size>
69+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_iterator<_Cp, false>
70+
__fill_n(__bit_iterator<_Cp, false> __first, _Size __n, const bool& __value) {
71+
if (__n > 0) {
72+
if (__value)
73+
std::__fill_n_bool<true>(__first, __n);
74+
else
75+
std::__fill_n_bool<false>(__first, __n);
76+
}
77+
return __first + __n;
78+
}
79+
2480
template <class _OutputIterator, class _Size, class _Tp>
2581
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
2682
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
@@ -37,4 +93,6 @@ fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
3793

3894
_LIBCPP_END_NAMESPACE_STD
3995

96+
_LIBCPP_POP_MACROS
97+
4098
#endif // _LIBCPP___ALGORITHM_FILL_N_H

libcxx/include/__bit_reference

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -171,61 +171,6 @@ private:
171171
__bit_const_reference& operator=(const __bit_const_reference&) = delete;
172172
};
173173

174-
// fill_n
175-
176-
template <bool _FillVal, class _Cp>
177-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
178-
__fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) {
179-
using _It = __bit_iterator<_Cp, false>;
180-
using __storage_type = typename _It::__storage_type;
181-
182-
const int __bits_per_word = _It::__bits_per_word;
183-
// do first partial word
184-
if (__first.__ctz_ != 0) {
185-
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
186-
__storage_type __dn = std::min(__clz_f, __n);
187-
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
188-
if (_FillVal)
189-
*__first.__seg_ |= __m;
190-
else
191-
*__first.__seg_ &= ~__m;
192-
__n -= __dn;
193-
++__first.__seg_;
194-
}
195-
// do middle whole words
196-
__storage_type __nw = __n / __bits_per_word;
197-
std::fill_n(std::__to_address(__first.__seg_), __nw, _FillVal ? static_cast<__storage_type>(-1) : 0);
198-
__n -= __nw * __bits_per_word;
199-
// do last partial word
200-
if (__n > 0) {
201-
__first.__seg_ += __nw;
202-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
203-
if (_FillVal)
204-
*__first.__seg_ |= __m;
205-
else
206-
*__first.__seg_ &= ~__m;
207-
}
208-
}
209-
210-
template <class _Cp>
211-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
212-
fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value) {
213-
if (__n > 0) {
214-
if (__value)
215-
std::__fill_n<true>(__first, __n);
216-
else
217-
std::__fill_n<false>(__first, __n);
218-
}
219-
}
220-
221-
// fill
222-
223-
template <class _Cp>
224-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
225-
fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value) {
226-
std::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value);
227-
}
228-
229174
// copy
230175

231176
template <class _Cp, bool _IsConst>
@@ -1007,8 +952,10 @@ private:
1007952
friend class __bit_iterator<_Cp, true>;
1008953
template <class _Dp>
1009954
friend struct __bit_array;
955+
1010956
template <bool _FillVal, class _Dp>
1011-
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend void __fill_n(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
957+
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend void
958+
__fill_n_bool(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
1012959

1013960
template <class _Dp, bool _IC>
1014961
_LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_aligned(

libcxx/include/__functional/function.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
768768
{
769769
}
770770

771-
virtual __base<_Rp(_ArgTypes...)>* __clone() const {
771+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual __base<_Rp(_ArgTypes...)>* __clone() const {
772772
_LIBCPP_ASSERT_INTERNAL(
773773
false,
774774
"Block pointers are just pointers, so they should always fit into "
@@ -777,34 +777,40 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base
777777
return nullptr;
778778
}
779779

780-
virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { ::new ((void*)__p) __func(__f_); }
780+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
781+
::new ((void*)__p) __func(__f_);
782+
}
781783

782-
virtual void destroy() _NOEXCEPT {
784+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT {
783785
# ifndef _LIBCPP_HAS_OBJC_ARC
784786
if (__f_)
785787
_Block_release(__f_);
786788
# endif
787789
__f_ = 0;
788790
}
789791

790-
virtual void destroy_deallocate() _NOEXCEPT {
792+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate() _NOEXCEPT {
791793
_LIBCPP_ASSERT_INTERNAL(
792794
false,
793795
"Block pointers are just pointers, so they should always fit into "
794796
"std::function's small buffer optimization. This function should "
795797
"never be invoked.");
796798
}
797799

798-
virtual _Rp operator()(_ArgTypes&&... __arg) { return std::__invoke(__f_, std::forward<_ArgTypes>(__arg)...); }
800+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual _Rp operator()(_ArgTypes&&... __arg) {
801+
return std::__invoke(__f_, std::forward<_ArgTypes>(__arg)...);
802+
}
799803

800804
# ifndef _LIBCPP_HAS_NO_RTTI
801-
virtual const void* target(type_info const& __ti) const _NOEXCEPT {
805+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(type_info const& __ti) const _NOEXCEPT {
802806
if (__ti == typeid(__func::__block_type))
803807
return &__f_;
804808
return (const void*)nullptr;
805809
}
806810

807-
virtual const std::type_info& target_type() const _NOEXCEPT { return typeid(__func::__block_type); }
811+
_LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT {
812+
return typeid(__func::__block_type);
813+
}
808814
# endif // _LIBCPP_HAS_NO_RTTI
809815
};
810816

0 commit comments

Comments
 (0)