[libc-commits] [libc] 64671db - [libc] Remove unnecessary call in memfunction dispatchers (#75800)

via libc-commits libc-commits at lists.llvm.org
Tue Dec 19 04:57:48 PST 2023


Author: Guillaume Chatelet
Date: 2023-12-19T13:57:44+01:00
New Revision: 64671dbebcd12c2e8e87dac48b382f98b2f15568

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

LOG: [libc] Remove unnecessary call in memfunction dispatchers (#75800)

Before this patch the compiler could generate unnecessary calls to the
selected implementation.
https://clang.llvm.org/docs/AttributeReference.html#flatten

Added: 
    

Modified: 
    libc/src/string/memory_utils/inline_bcmp.h
    libc/src/string/memory_utils/inline_bzero.h
    libc/src/string/memory_utils/inline_memcmp.h
    libc/src/string/memory_utils/inline_memcpy.h
    libc/src/string/memory_utils/inline_memmove.h

Removed: 
    


################################################################################
diff  --git a/libc/src/string/memory_utils/inline_bcmp.h b/libc/src/string/memory_utils/inline_bcmp.h
index b1c981d859e022..69aa2acf75be47 100644
--- a/libc/src/string/memory_utils/inline_bcmp.h
+++ b/libc/src/string/memory_utils/inline_bcmp.h
@@ -32,7 +32,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LIBC_INLINE int inline_bcmp(const void *p1, const void *p2, size_t count) {
+[[gnu::flatten]] LIBC_INLINE int inline_bcmp(const void *p1, const void *p2,
+                                             size_t count) {
   return static_cast<int>(LIBC_SRC_STRING_MEMORY_UTILS_BCMP(
       reinterpret_cast<CPtr>(p1), reinterpret_cast<CPtr>(p2), count));
 }

diff  --git a/libc/src/string/memory_utils/inline_bzero.h b/libc/src/string/memory_utils/inline_bzero.h
index ed83cab68b2fd1..d760baca9d0f4d 100644
--- a/libc/src/string/memory_utils/inline_bzero.h
+++ b/libc/src/string/memory_utils/inline_bzero.h
@@ -16,11 +16,11 @@
 
 namespace LIBC_NAMESPACE {
 
-LIBC_INLINE static void inline_bzero(Ptr dst, size_t count) {
+[[gnu::flatten]] LIBC_INLINE static void inline_bzero(Ptr dst, size_t count) {
   inline_memset(dst, 0, count);
 }
 
-LIBC_INLINE static void inline_bzero(void *dst, size_t count) {
+[[gnu::flatten]] LIBC_INLINE static void inline_bzero(void *dst, size_t count) {
   inline_bzero(reinterpret_cast<Ptr>(dst), count);
 }
 

diff  --git a/libc/src/string/memory_utils/inline_memcmp.h b/libc/src/string/memory_utils/inline_memcmp.h
index d88d43691daee8..1fdc13973c6462 100644
--- a/libc/src/string/memory_utils/inline_memcmp.h
+++ b/libc/src/string/memory_utils/inline_memcmp.h
@@ -33,7 +33,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LIBC_INLINE int inline_memcmp(const void *p1, const void *p2, size_t count) {
+[[gnu::flatten]] LIBC_INLINE int inline_memcmp(const void *p1, const void *p2,
+                                               size_t count) {
   return static_cast<int>(LIBC_SRC_STRING_MEMORY_UTILS_MEMCMP(
       reinterpret_cast<CPtr>(p1), reinterpret_cast<CPtr>(p2), count));
 }

diff  --git a/libc/src/string/memory_utils/inline_memcpy.h b/libc/src/string/memory_utils/inline_memcpy.h
index a92bf4ddf881d5..c88fd55eff645f 100644
--- a/libc/src/string/memory_utils/inline_memcpy.h
+++ b/libc/src/string/memory_utils/inline_memcpy.h
@@ -40,8 +40,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LIBC_INLINE void inline_memcpy(void *__restrict dst, const void *__restrict src,
-                               size_t count) {
+[[gnu::flatten]] LIBC_INLINE void
+inline_memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
   LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY(reinterpret_cast<Ptr>(dst),
                                       reinterpret_cast<CPtr>(src), count);
 }

diff  --git a/libc/src/string/memory_utils/inline_memmove.h b/libc/src/string/memory_utils/inline_memmove.h
index 30c2c3ddbf1bb7..3cbc3e0b0a528d 100644
--- a/libc/src/string/memory_utils/inline_memmove.h
+++ b/libc/src/string/memory_utils/inline_memmove.h
@@ -49,14 +49,14 @@ LIBC_INLINE constexpr bool inline_memmove_no_small_size(void *, const void *,
   return false;
 }
 
-LIBC_INLINE bool inline_memmove_small_size(void *dst, const void *src,
-                                           size_t count) {
+[[gnu::flatten]] LIBC_INLINE bool
+inline_memmove_small_size(void *dst, const void *src, size_t count) {
   return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE(
       reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count);
 }
 
-LIBC_INLINE void inline_memmove_follow_up(void *dst, const void *src,
-                                          size_t count) {
+[[gnu::flatten]] LIBC_INLINE void
+inline_memmove_follow_up(void *dst, const void *src, size_t count) {
   LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP(
       reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count);
 }


        


More information about the libc-commits mailing list