[libc-commits] [libc] 61c9052 - [libc] Add LIBC_INLINE_VAR for inline variables

Caslyn Tonelli via libc-commits libc-commits at lists.llvm.org
Fri Jun 16 08:46:44 PDT 2023


Author: Alex Brachet
Date: 2023-06-16T15:46:32Z
New Revision: 61c9052cec10a80f9a48d2da9e443629089c9a88

URL: https://github.com/llvm/llvm-project/commit/61c9052cec10a80f9a48d2da9e443629089c9a88
DIFF: https://github.com/llvm/llvm-project/commit/61c9052cec10a80f9a48d2da9e443629089c9a88.diff

LOG: [libc] Add LIBC_INLINE_VAR for inline variables

These are the only variables I could find that use LIBC_INLINE. Note, these are namespace scoped constexpr so local linkage is implied. inline is useful here to silence clang's unused-const-variable variable. For Fuchsia, the distinction between LIBC_INLINE and LIBC_INLINE_VAR is helpful because we define LIBC_INLINE as `[[gnu::always_inline]] inline` when building with gcc. This isn't meaningful on variables.

Alternatively, we could make these variables simply constexpr and also add `[[maybe_unused]]`

Reviewed By: sivachandra, mcgrathr

Differential Revision: https://reviews.llvm.org/D152951

Added: 
    

Modified: 
    libc/docs/dev/code_style.rst
    libc/src/__support/macros/attributes.h
    libc/src/string/memory_utils/op_x86.h

Removed: 
    


################################################################################
diff  --git a/libc/docs/dev/code_style.rst b/libc/docs/dev/code_style.rst
index edbd0ef75438c..f237fc17220f5 100644
--- a/libc/docs/dev/code_style.rst
+++ b/libc/docs/dev/code_style.rst
@@ -45,18 +45,23 @@ We define two kinds of macros: **code defined** and **build defined** macros.
      specific operations. e.g., ``LIBC_INLINE``, ``LIBC_NO_LOOP_UNROLL``,
      ``LIBC_LIKELY``, ``LIBC_INLINE_ASM``.
 
-Inline functions defined in header files
+Inline functions and variables defined in header files
 ========================================
 
-When defining functions inline in header files, we follow certain rules:
+When defining functions and variables inline in header files, we follow certain
+rules:
 
 #. The functions should not be given file-static linkage. There can be class
    static methods defined inline however.
-#. Instead of using the ``inline`` keyword, they should be tagged with the
-   ``LIBC_INLINE`` macro defined in ``src/__support/common.h``. For example:
+#. Instead of using the ``inline`` keyword, functions should be tagged with the
+   ``LIBC_INLINE`` macro and variables should be tagged with the
+   ``LIBC_INLINE_VAR`` macro defined in ``src/__support/macros/attributes.h``.
+   For example:
 
    .. code-block:: c++
 
+     LIBC_INLINE_VAR constexpr bool foo = true;
+
      LIBC_INLINE ReturnType function_defined_inline(ArgType arg) {
        ...
      }

diff  --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index 38b6b7f97617c..0c8a37b34e66a 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -20,6 +20,7 @@
 #include "properties/architectures.h"
 
 #define LIBC_INLINE inline
+#define LIBC_INLINE_VAR inline
 #define LIBC_INLINE_ASM __asm__ __volatile__
 #define LIBC_UNUSED __attribute__((unused))
 

diff  --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index a0c8d3aba4e80..58e7eaf908ac3 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -40,13 +40,12 @@
 namespace __llvm_libc::x86 {
 
 // A set of constants to check compile time features.
-LIBC_INLINE static constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
-LIBC_INLINE static constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
-LIBC_INLINE static constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
-LIBC_INLINE static constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
-LIBC_INLINE static constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
-LIBC_INLINE static constexpr bool kAvx512BW =
-    LLVM_LIBC_IS_DEFINED(__AVX512BW__);
+LIBC_INLINE_VAR constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
+LIBC_INLINE_VAR constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
+LIBC_INLINE_VAR constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
+LIBC_INLINE_VAR constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
+LIBC_INLINE_VAR constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
+LIBC_INLINE_VAR constexpr bool kAvx512BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);
 
 ///////////////////////////////////////////////////////////////////////////////
 // Memcpy repmovsb implementation


        


More information about the libc-commits mailing list