[libc-commits] [PATCH] D152951: [libc] Add LIBC_INLINE_VAR for inline variables

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG61c9052cec10: [libc] Add LIBC_INLINE_VAR for inline variables (authored by abrachet, committed by Caslyn).

Changed prior to commit:
  https://reviews.llvm.org/D152951?vs=531465&id=532174#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152951/new/

https://reviews.llvm.org/D152951

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


Index: libc/src/string/memory_utils/op_x86.h
===================================================================
--- libc/src/string/memory_utils/op_x86.h
+++ 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
Index: libc/src/__support/macros/attributes.h
===================================================================
--- libc/src/__support/macros/attributes.h
+++ 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))
 
Index: libc/docs/dev/code_style.rst
===================================================================
--- libc/docs/dev/code_style.rst
+++ libc/docs/dev/code_style.rst
@@ -45,18 +45,23 @@
      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) {
        ...
      }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152951.532174.patch
Type: text/x-patch
Size: 3055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230616/e40844a4/attachment.bin>


More information about the libc-commits mailing list