[libc-commits] [libc] 406b3f2 - [libc] Add an optimization macro header

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Thu Feb 9 05:35:59 PST 2023


Author: Guillaume Chatelet
Date: 2023-02-09T13:35:49Z
New Revision: 406b3f2cbbee764578184e19de42d3a0602883aa

URL: https://github.com/llvm/llvm-project/commit/406b3f2cbbee764578184e19de42d3a0602883aa
DIFF: https://github.com/llvm/llvm-project/commit/406b3f2cbbee764578184e19de42d3a0602883aa.diff

LOG: [libc] Add an optimization macro header

Added: 
    libc/src/__support/macros/optimization.h

Modified: 
    libc/src/__support/macros/CMakeLists.txt
    libc/src/__support/macros/attributes.h
    libc/src/__support/macros/properties/compiler.h
    libc/src/string/memory_utils/CMakeLists.txt
    libc/src/string/memory_utils/bcmp_implementations.h
    libc/src/string/memory_utils/memcmp_implementations.h
    libc/src/string/memory_utils/memcpy_implementations.h
    libc/src/string/memory_utils/memmove_implementations.h
    libc/src/string/memory_utils/memset_implementations.h
    libc/src/string/memory_utils/op_generic.h
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/macros/CMakeLists.txt b/libc/src/__support/macros/CMakeLists.txt
index 1b3728856676..7f6134682070 100644
--- a/libc/src/__support/macros/CMakeLists.txt
+++ b/libc/src/__support/macros/CMakeLists.txt
@@ -3,13 +3,21 @@ add_subdirectory(properties)
 add_header_library(
   attributes
   HDRS
-  attributes.h
+    attributes.h
+)
+
+add_header_library(
+  optimization
+  HDRS
+    optimization.h
+  DEPENDS
+    libc.src.__support.macros.properties.compiler
 )
 
 add_header_library(
   sanitizer
   HDRS
-  sanitizer.h
+    sanitizer.h
   DEPENDS
-  libc.src.__support.macros.properties.compiler
+    libc.src.__support.macros.properties.compiler
 )

diff  --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index 4f42954a71a7..7be34bd72303 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -5,6 +5,14 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+// This header file defines macros for declaring attributes for functions,
+// types, and variables.
+//
+// These macros are used within llvm-libc and allow the compiler to optimize,
+// where applicable, certain function calls.
+//
+// Most macros here are exposing GCC or Clang features, and are stubbed out for
+// other compilers.
 
 #ifndef LLVM_LIBC_SUPPORT_MACROS_ATTRIBUTES_H
 #define LLVM_LIBC_SUPPORT_MACROS_ATTRIBUTES_H

diff  --git a/libc/src/__support/macros/optimization.h b/libc/src/__support/macros/optimization.h
new file mode 100644
index 000000000000..2b5ee78cd7cb
--- /dev/null
+++ b/libc/src/__support/macros/optimization.h
@@ -0,0 +1,23 @@
+//===-- Portable optimization macros ----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// This header file defines portable macros for performance optimization.
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_MACROS_OPTIMIZATION_H
+#define LLVM_LIBC_SRC_SUPPORT_MACROS_OPTIMIZATION_H
+
+#include "src/__support/macros/properties/compiler.h"
+
+#if defined(LIBC_COMPILER_IS_CLANG)
+#define LIBC_LOOP_NOUNROLL _Pragma("nounroll")
+#elif defined(LIBC_COMPILER_IS_GCC)
+#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")
+#else
+#define LIBC_LOOP_NOUNROLL
+#endif
+
+#endif /* LLVM_LIBC_SRC_SUPPORT_MACROS_OPTIMIZATION_H */

diff  --git a/libc/src/__support/macros/properties/compiler.h b/libc/src/__support/macros/properties/compiler.h
index c95e62fa5275..9f26767618ae 100644
--- a/libc/src/__support/macros/properties/compiler.h
+++ b/libc/src/__support/macros/properties/compiler.h
@@ -23,7 +23,7 @@
 
 // Compiler builtin-detection.
 // clang.llvm.org/docs/LanguageExtensions.html#has-builtin
-#if defined(LIBC_COMPILER_IS_CLANG) ||                                       \
+#if defined(LIBC_COMPILER_IS_CLANG) ||                                         \
     (defined(LIBC_COMPILER_IS_GCC) && (__GNUC__ >= 10))
 #define LIBC_HAS_BUILTIN(BUILTIN) __has_builtin(BUILTIN)
 #else
@@ -38,12 +38,4 @@
 #define LIBC_HAS_FEATURE(FEATURE) 0
 #endif
 
-#if defined(LIBC_COMPILER_IS_CLANG)
-#define LIBC_LOOP_NOUNROLL _Pragma("nounroll")
-#elif defined(LIBC_COMPILER_IS_GCC)
-#define LIBC_LOOP_NOUNROLL _Pragma("GCC unroll 0")
-#else
-#define LIBC_LOOP_NOUNROLL
-#endif
-
 #endif // LLVM_LIBC_SUPPORT_MACROS_PROPERTIES_COMPILER_H

diff  --git a/libc/src/string/memory_utils/CMakeLists.txt b/libc/src/string/memory_utils/CMakeLists.txt
index 97d314d607ec..371b4010a4dc 100644
--- a/libc/src/string/memory_utils/CMakeLists.txt
+++ b/libc/src/string/memory_utils/CMakeLists.txt
@@ -15,10 +15,10 @@ add_header_library(
     utils.h
   DEPS
     libc.src.__support.common
-    libc.src.__support.macros.properties.compiler
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.cstddef
     libc.src.__support.CPP.type_traits
+    libc.src.__support.macros.optimization
 )
 
 add_header_library(

diff  --git a/libc/src/string/memory_utils/bcmp_implementations.h b/libc/src/string/memory_utils/bcmp_implementations.h
index 8c92d1696e66..8e3aa4dd497d 100644
--- a/libc/src/string/memory_utils/bcmp_implementations.h
+++ b/libc/src/string/memory_utils/bcmp_implementations.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BCMP_IMPLEMENTATIONS_H
 
 #include "src/__support/common.h"
+#include "src/__support/macros/optimization.h"
 #include "src/__support/macros/properties/architectures.h"
 #include "src/string/memory_utils/op_aarch64.h"
 #include "src/string/memory_utils/op_builtin.h"

diff  --git a/libc/src/string/memory_utils/memcmp_implementations.h b/libc/src/string/memory_utils/memcmp_implementations.h
index 8a24855fbf4d..71b165378243 100644
--- a/libc/src/string/memory_utils/memcmp_implementations.h
+++ b/libc/src/string/memory_utils/memcmp_implementations.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCMP_IMPLEMENTATIONS_H
 
 #include "src/__support/common.h"
+#include "src/__support/macros/optimization.h"
 #include "src/__support/macros/properties/architectures.h"
 #include "src/string/memory_utils/op_aarch64.h"
 #include "src/string/memory_utils/op_builtin.h"

diff  --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h
index f0fe43de0b9e..211a6fb9c19a 100644
--- a/libc/src/string/memory_utils/memcpy_implementations.h
+++ b/libc/src/string/memory_utils/memcpy_implementations.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY_IMPLEMENTATIONS_H
 
 #include "src/__support/common.h"
+#include "src/__support/macros/optimization.h"
 #include "src/__support/macros/properties/architectures.h"
 #include "src/string/memory_utils/op_aarch64.h"
 #include "src/string/memory_utils/op_builtin.h"

diff  --git a/libc/src/string/memory_utils/memmove_implementations.h b/libc/src/string/memory_utils/memmove_implementations.h
index 12b7623fbf20..2d920daf4708 100644
--- a/libc/src/string/memory_utils/memmove_implementations.h
+++ b/libc/src/string/memory_utils/memmove_implementations.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_IMPLEMENTATIONS_H
 
 #include "src/__support/common.h"
+#include "src/__support/macros/optimization.h"
 #include "src/string/memory_utils/op_aarch64.h"
 #include "src/string/memory_utils/op_builtin.h"
 #include "src/string/memory_utils/op_generic.h"

diff  --git a/libc/src/string/memory_utils/memset_implementations.h b/libc/src/string/memory_utils/memset_implementations.h
index 27e572a5a5f3..089d74996188 100644
--- a/libc/src/string/memory_utils/memset_implementations.h
+++ b/libc/src/string/memory_utils/memset_implementations.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H
 
 #include "src/__support/common.h"
+#include "src/__support/macros/optimization.h"
 #include "src/__support/macros/properties/architectures.h"
 #include "src/string/memory_utils/op_aarch64.h"
 #include "src/string/memory_utils/op_builtin.h"

diff  --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h
index 84beb679cf17..ae514f4cffa2 100644
--- a/libc/src/string/memory_utils/op_generic.h
+++ b/libc/src/string/memory_utils/op_generic.h
@@ -27,6 +27,7 @@
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
 #include "src/__support/endian.h"
+#include "src/__support/macros/optimization.h"
 #include "src/__support/macros/properties/compiler.h"
 #include "src/string/memory_utils/op_builtin.h"
 #include "src/string/memory_utils/utils.h"

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a63110be660c..2e9a95eb3a88 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -84,6 +84,15 @@ libc_support_library(
     deps = [":libc_root"],
 )
 
+libc_support_library(
+    name = "__support_macros_optimization",
+    hdrs = ["src/__support/macros/optimization.h"],
+    deps = [
+        ":__support_macros_properties_compiler",
+        ":libc_root",
+    ],
+)
+
 libc_support_library(
     name = "__support_macros_sanitizer",
     hdrs = ["src/__support/macros/sanitizer.h"],
@@ -1366,7 +1375,7 @@ libc_support_library(
         ":__support_cpp_cstddef",
         ":__support_cpp_type_traits",
         ":__support_macros_attributes",
-        ":__support_macros_properties_compiler",
+        ":__support_macros_optimization",
         ":libc_root",
     ],
 )


        


More information about the libc-commits mailing list