hanchenye-llvm-project/libcxx/include
Eric Fiselier 78153b3a97 Optimize operator=(const basic_string&) for tail call.
Patch by Martijn Vels (mvels@google.com)
Reviewed as https://reviews.llvm.org/D68276

This is a non trivial win for externally templated assignment operator.

x86 without tail call (current libc++)

0000000000000000 <std::string::operator=(std::string const&)>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   53                      push   %rbx
   5:   50                      push   %rax
   6:   48 89 fb                mov    %rdi,%rbx
   9:   48 39 f7                cmp    %rsi,%rdi
   c:   74 17                   je     25 <std::string::operator=(std::string const&)+0x25>
   e:   0f b6 56 17             movzbl 0x17(%rsi),%edx
  12:   84 d2                   test   %dl,%dl
  14:   79 07                   jns    1d <std::string::operator=(std::string const&)+0x1d>
  16:   48 8b 56 08             mov    0x8(%rsi),%rdx
  1a:   48 8b 36                mov    (%rsi),%rsi
  1d:   48 89 df                mov    %rbx,%rdi
  20:   e8 00 00 00 00          callq  25 <std::string::operator=(std::string const&)+0x25>
  25:   48 89 d8                mov    %rbx,%rax
  28:   48 83 c4 08             add    $0x8,%rsp
  2c:   5b                      pop    %rbx
  2d:   5d                      pop    %rbp
  2e:   c3                      retq

After:

0000000000000000 <std::string::operator=(std::string const&)>:
   0:   48 39 f7                cmp    %rsi,%rdi
   3:   74 14                   je     19 <std::string::operator=(std::string const&)+0x19>
   5:   0f b6 56 17             movzbl 0x17(%rsi),%edx
   9:   84 d2                   test   %dl,%dl
   b:   79 07                   jns    14 <std::string::operator=(std::string const&)+0x14>
   d:   48 8b 56 08             mov    0x8(%rsi),%rdx
  11:   48 8b 36                mov    (%rsi),%rsi
  14:   e9 00 00 00 00          jmpq   19 <std::string::operator=(std::string const&)+0x19>
  19:   48 89 f8                mov    %rdi,%rax
  1c:   c3                      retq

Benchmark (pending per https://reviews.llvm.org/D67667)

```
BM_StringAssignStr_Empty_Opaque                     6.23ns ± 0%             5.19ns ± 0%  -16.70%          (p=0.016 n=5+4)
BM_StringAssignStr_Empty_Transparent                5.86ns ± 0%             5.14ns ± 0%  -12.24%          (p=0.008 n=5+5)
BM_StringAssignStr_Small_Opaque                     8.79ns ± 1%             7.69ns ± 0%  -12.53%          (p=0.008 n=5+5)
BM_StringAssignStr_Small_Transparent                9.44ns ± 0%             8.00ns ± 0%  -15.26%          (p=0.008 n=5+5)
BM_StringAssignStr_Large_Opaque                     25.2ns ± 0%             24.3ns ± 0%   -3.50%          (p=0.008 n=5+5)
BM_StringAssignStr_Large_Transparent                23.6ns ± 0%             22.5ns ± 0%   -4.76%          (p=0.008 n=5+5)
BM_StringAssignStr_Huge_Opaque                       319ns ± 5%              317ns ± 5%     ~             (p=0.690 n=5+5)
BM_StringAssignStr_Huge_Transparent                  319ns ± 5%              317ns ± 5%     ~             (p=0.421 n=5+5)
BM_StringAssignAsciiz_Empty_Opaque                  7.41ns ± 0%             7.77ns ± 0%   +4.89%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Empty_Transparent             7.54ns ± 3%             7.30ns ± 0%   -3.24%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Small_Opaque                  9.87ns ± 0%            10.24ns ± 1%   +3.76%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Small_Transparent             10.4ns ± 1%              9.8ns ± 2%   -5.78%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Large_Opaque                  30.1ns ± 0%             30.1ns ± 0%     ~             (p=0.167 n=5+5)
BM_StringAssignAsciiz_Large_Transparent             27.1ns ± 0%             27.4ns ± 0%   +0.92%          (p=0.016 n=4+5)
BM_StringAssignAsciiz_Huge_Opaque                    383ns ± 4%              382ns ± 4%     ~             (p=0.548 n=5+5)
BM_StringAssignAsciiz_Huge_Transparent               375ns ± 0%              380ns ± 0%   +1.37%          (p=0.029 n=4+4)
BM_StringAssignAsciizMix_Opaque                     14.0ns ± 0%             14.0ns ± 0%     ~             (p=0.881 n=5+5)
BM_StringAssignAsciizMix_Transparent                13.7ns ± 1%             13.8ns ± 0%     ~             (p=0.056 n=5+5)
```

llvm-svn: 374137
2019-10-09 03:07:02 +00:00
..
experimental [libcxx] Do not implicitly #include assert.h 2019-09-26 11:12:29 +00:00
ext Change default bucket count in hash_set/hash_map. 2019-08-01 19:48:29 +00:00
support [libc++] Remove empty header xlocale/xlocale.h 2019-03-11 15:41:51 +00:00
CMakeLists.txt [libc++] Take 2: Integrate the PSTL into libc++ 2019-08-05 18:29:14 +00:00
__bit_reference Reorganize the 'bit' header to make most of the facilities available for internal use pre-C++20. NFC for external users 2019-07-12 01:01:55 +00:00
__bsd_locale_defaults.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__bsd_locale_fallbacks.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__config Revert "Revert "Implement std::condition_variable via pthread_cond_clockwait() where available"" 2019-09-18 18:13:32 +00:00
__config_site.in [libc++] Take 2: Integrate the PSTL into libc++ 2019-08-05 18:29:14 +00:00
__debug Remove exception throwing debug mode handler support. 2019-03-18 21:50:12 +00:00
__errc Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__functional_03 Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__functional_base [libc++] Take 2: Implement LWG 2510 2019-09-26 14:51:10 +00:00
__functional_base_03 Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__hash_table Reorganize the 'bit' header to make most of the facilities available for internal use pre-C++20. NFC for external users 2019-07-12 01:01:55 +00:00
__libcpp_version Bump the trunk version to 10.0.0svn 2019-07-18 11:51:05 +00:00
__locale [libcxx] Fix build breakage on mips 2019-08-20 10:19:55 +00:00
__mutex_base [libc++] Take 2: Implement LWG 2510 2019-09-26 14:51:10 +00:00
__node_handle Avoid name conflict with kernel headers 2019-04-24 09:43:44 +00:00
__nullptr Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__split_buffer Improve codegen for deque. 2019-08-12 07:51:05 +00:00
__sso_allocator Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__std_stream Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
__string Add debug check for null pointers passed to <string_view> 2019-09-14 19:55:28 +00:00
__threading_support [libcxx] Only declare contents of threading API when 2019-08-21 15:38:24 +00:00
__tree Fix memory leak in set and map. 2019-07-11 23:13:38 +00:00
__tuple Refactor default constructor SFINAE in pair and tuple. 2019-09-30 20:55:30 +00:00
__undef_macros Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
algorithm Add a missing _VSTD:: before a call to merge. Fixes PR43034. Checked the rest of 'algorithm' looking for unqualified calls. Didn't find any. 2019-08-20 22:23:35 +00:00
any [NFC][libc++] Remove stray semi-colon after function definition 2019-06-19 16:33:28 +00:00
array [libc++] Declare std::tuple_element as struct instead of class 2019-04-01 16:39:34 +00:00
atomic [libc++] Use __extension__ in a portable manner 2019-09-04 12:44:19 +00:00
bit Implement most of P1612R1: Relocate endian. Moves the std::endian functionality from 'type-traits' to 'bit'. No other change. The reason that this is 'partial' is that P1621 also recommends a feature-test macro, but I don't have the value for that one yet. In a month or so, I'll add that 2019-07-23 04:20:19 +00:00
bitset Ensure bitset's string constructor doesn't poison the overload set. 2019-07-01 19:59:34 +00:00
cassert Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
ccomplex Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cctype Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cerrno Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cfenv Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cfloat Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
charconv [libc++] Fix build with gcc 4.8 2019-06-13 22:27:24 +00:00
chrono Revert "Extension: Mark the default constructor of chrono::duration as conditionally noexcept"; this breaks the gcc5 bot for C++11 2019-09-23 06:16:41 +00:00
cinttypes Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ciso646 Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
climits Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
clocale Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cmath [libc++] Harden usage of static_assert against C++03 2019-10-01 12:12:21 +00:00
codecvt Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
compare Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
complex [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
complex.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
condition_variable Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
csetjmp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
csignal Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstdarg Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstdbool Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstddef Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstdint Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstdio Remove ::gets for FreeBSD 13 and later 2019-09-07 22:18:20 +00:00
cstdlib Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cstring Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ctgmath Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
ctime Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
ctype.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cwchar Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cwctype Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
deque Improve codegen for deque. 2019-08-12 07:51:05 +00:00
errno.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
exception Make move and forward work in C++03. 2019-06-21 15:20:55 +00:00
execution [pstl][libc++] Provide uglified header names for interface headers 2019-08-06 21:11:24 +00:00
fenv.h Mark fenv.h as a system header before the #include_next directive 2019-03-29 16:03:57 +00:00
filesystem [libc++] Always build with -fvisibility=hidden 2019-08-13 15:02:53 +00:00
float.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
forward_list Make forward_list::remove/remove_if/unique all return void before C++20; undoes that bit of D58332. Thanks to Mikhail Maltsev for pointing this out 2019-07-08 03:45:28 +00:00
fstream Open fstream files in O_CLOEXEC mode when possible. 2019-09-16 19:26:41 +00:00
functional Revert "Suppress -Wctad-maybe-unsupported on types w/o deduction guides." 2019-08-04 07:13:43 +00:00
future Assume __is_final, __is_base_of, and friends. 2019-06-21 13:56:13 +00:00
initializer_list [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
inttypes.h AIX system headers need stdint.h and inttypes.h to be re-enterable 2019-06-20 15:36:32 +00:00
iomanip [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
ios [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
iosfwd Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
iostream Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
istream [libc++] Implement LWG 3199 2019-08-20 18:21:06 +00:00
iterator Revert "Suppress -Wctad-maybe-unsupported on types w/o deduction guides." 2019-08-04 07:13:43 +00:00
limits Fix -Wdouble-promotion warnings. 2019-07-01 16:13:31 +00:00
limits.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
list Make forward_list::remove/remove_if/unique all return void before C++20; undoes that bit of D58332. Thanks to Mikhail Maltsev for pointing this out 2019-07-08 03:45:28 +00:00
locale [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
locale.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
map [libc++] Use _EnableIf instead of std::enable_if in deduction guides for map and set 2019-07-19 17:13:39 +00:00
math.h [libc++] Move __clamp_to_integral to <cmath>, and harden against min()/max() macros 2019-09-04 13:35:03 +00:00
memory [libc++] Remove C++03 variadics in shared_ptr (v2) 2019-10-07 21:41:15 +00:00
module.modulemap [libc++] Take 2: Integrate the PSTL into libc++ 2019-08-05 18:29:14 +00:00
mutex [libc++] Take 2: Implement LWG 2510 2019-09-26 14:51:10 +00:00
new [libc++] Take 2: Implement LWG 2510 2019-09-26 14:51:10 +00:00
numeric [pstl][libc++] Provide uglified header names for interface headers 2019-08-06 21:11:24 +00:00
optional Add a missing '__uncvref_t' to the SFINAE constraints for optional's assignment operator. Fixes PR38638. Thanks to Jonathan Wakely for the report 2019-06-27 18:40:55 +00:00
ostream Add forward declaration of operator<< in <string_view> as required. 2019-09-25 18:56:54 +00:00
queue [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
random [libc++] Explicitly cast in generate_canonical 2019-08-20 15:39:20 +00:00
ratio Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
regex Add a missing default parameter to regex::assign. This is LWG3296; reviewed as https://reviews.llvm.org/D67944 2019-09-25 16:40:30 +00:00
scoped_allocator Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
set [libc++] Use _EnableIf instead of std::enable_if in deduction guides for map and set 2019-07-19 17:13:39 +00:00
setjmp.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
shared_mutex Revert "Suppress -Wctad-maybe-unsupported on types w/o deduction guides." 2019-08-04 07:13:43 +00:00
span [libc++] Declare std::tuple_element as struct instead of class 2019-04-01 16:39:34 +00:00
sstream add a test and a couple minor bug fixes for the implicit-signed-integer-truncation sanitizer. This is PR#40566 2019-02-01 21:59:27 +00:00
stack [NFC][libcxx] Remove trailing whitespace 2019-05-29 16:01:36 +00:00
stdbool.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
stddef.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
stdexcept Fix ABI compatibility of `<stdexcept>` with VCRuntime. 2019-03-06 20:31:57 +00:00
stdint.h AIX system headers need stdint.h and inttypes.h to be re-enterable 2019-06-20 15:36:32 +00:00
stdio.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
stdlib.h Fix implementation of ::abs and std::abs LWG 2192. 2019-04-23 18:01:58 +00:00
streambuf Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
string Optimize operator=(const basic_string&) for tail call. 2019-10-09 03:07:02 +00:00
string.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
string_view Add forward declaration of operator<< in <string_view> as required. 2019-09-25 18:56:54 +00:00
strstream Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
system_error Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
tgmath.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
thread Rework recursive_timed_mutex so that it uses __thread_id instead of using the lower-level __libcpp_thread_id. This is prep for fixing PR42918. Reviewed as https://reviews.llvm.org/D65895 2019-08-14 16:21:27 +00:00
tuple Refactor default constructor SFINAE in pair and tuple. 2019-09-30 20:55:30 +00:00
type_traits [libc++] Take 2: Implement LWG 2510 2019-09-26 14:51:10 +00:00
typeindex Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
typeinfo Fix build breakage on 32-bit machines 2019-05-29 02:38:19 +00:00
unordered_map Add contains method to associative containers. This patch implements P0458R2, adding contains to map, multimap, unordered_map, unordered_multimap, set, multiset, unordered_set, and unordered_multiset. 2019-07-16 03:21:01 +00:00
unordered_set Add contains method to associative containers. This patch implements P0458R2, adding contains to map, multimap, unordered_map, unordered_multimap, set, multiset, unordered_set, and unordered_multiset. 2019-07-16 03:21:01 +00:00
utility Refactor default constructor SFINAE in pair and tuple. 2019-09-30 20:55:30 +00:00
valarray Remove incorrect explicit instantiation declarations for valarray 2019-04-25 21:31:58 +00:00
variant Improve compile time of variant. 2019-07-14 21:29:39 +00:00
vector Recommit r370502: Make `vector` unconditionally move elements when 2019-09-13 16:09:33 +00:00
version P0722R3: Implement library support for destroying delete 2019-05-23 23:46:44 +00:00
wchar.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
wctype.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00