[libc-commits] [libc] 94d6dd9 - [libc] Apply no-builtin everywhere, remove unnecessary flags
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Thu May 19 02:08:51 PDT 2022
Author: Guillaume Chatelet
Date: 2022-05-19T09:08:42Z
New Revision: 94d6dd90576637fa0eb2c40ca92320ad4c1a6942
URL: https://github.com/llvm/llvm-project/commit/94d6dd90576637fa0eb2c40ca92320ad4c1a6942
DIFF: https://github.com/llvm/llvm-project/commit/94d6dd90576637fa0eb2c40ca92320ad4c1a6942.diff
LOG: [libc] Apply no-builtin everywhere, remove unnecessary flags
Some functions like `stpncpy` are implemented in terms of `memset` but are not
currently using `-fno-builtin-memset`. This is somewhat hidden by the fact that
we use `-ffreestanding` globally and that `-ffreestanding` implies
`-fno-builtin` for Clang.
This patch also removes `-mllvm -combiner-global-alias-analysis` that is Clang
specific and that does not bring substantial gains on modern processors.
Also we keep `-mllvm --tail-merge-threshold=0` for aarch64 in CMakeLists.txt
but we omit it in the Bazel config. This is because Bazel consumes the source
files directly and so it can use PGO to take optimal decisions locally.
Differential Revision: https://reviews.llvm.org/D125894
Added:
Modified:
libc/cmake/modules/LLVMLibCObjectRules.cmake
libc/src/string/CMakeLists.txt
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
Removed:
################################################################################
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 8e2f489752a6..2544a648c8a5 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -3,7 +3,7 @@ set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY")
function(_get_common_compile_options output_var)
set(compile_options ${LLVM_CXX_STD_default} ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
if(NOT ${LIBC_TARGET_OS} STREQUAL "windows")
- set(compile_options ${compile_options} -fpie -ffreestanding)
+ set(compile_options ${compile_options} -fpie -ffreestanding -fno-builtin)
endif()
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fno-exceptions")
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index 8c404064a2a9..20b1b4c95c01 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -268,7 +268,6 @@ function(add_implementation name impl_name)
${ARGN})
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
- list(APPEND ADD_IMPL_MLLVM_COMPILE_OPTIONS "-combiner-global-alias-analysis")
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
@@ -298,9 +297,6 @@ function(add_bcmp bcmp_name)
DEPENDS
.memory_utils.memory_utils
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin-memcmp
- -fno-builtin-bcmp
${ARGN}
)
endfunction()
@@ -328,8 +324,6 @@ function(add_bzero bzero_name)
DEPENDS
.memory_utils.memset_implementation
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin-bzero
${ARGN}
)
endfunction()
@@ -357,8 +351,6 @@ function(add_memcmp memcmp_name)
DEPENDS
.memory_utils.memcmp_implementation
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin-memcmp
${ARGN}
)
endfunction()
@@ -389,8 +381,6 @@ function(add_memcpy memcpy_name)
DEPENDS
.memory_utils.memcpy_implementation
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin-memcpy
${ARGN}
)
endfunction()
@@ -423,8 +413,6 @@ function(add_memmove memmove_name)
DEPENDS
.memory_utils.memory_utils
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin
${ARGN}
)
endfunction()
@@ -457,8 +445,6 @@ function(add_memset memset_name)
DEPENDS
.memory_utils.memset_implementation
libc.include.string
- COMPILE_OPTIONS
- -fno-builtin-memset
${ARGN}
)
endfunction()
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 9c6c1bc8b4a5..df64defead8f 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -85,7 +85,10 @@ cc_library(
hdrs = [
"src/__support/CPP/UInt.h",
],
- deps = [":libc_root","__support_cpp_array"],
+ deps = [
+ "__support_cpp_array",
+ ":libc_root",
+ ],
)
cc_library(
@@ -93,7 +96,10 @@ cc_library(
hdrs = [
"src/__support/CPP/TypeTraits.h",
],
- deps = [":libc_root","__support_cpp_uint"],
+ deps = [
+ "__support_cpp_uint",
+ ":libc_root",
+ ],
)
cc_library(
@@ -805,12 +811,6 @@ libc_function(
name = "memcpy",
srcs = ["src/string/memcpy.cpp"],
hdrs = ["src/string/memcpy.h"],
- copts = [
- "-fno-builtin-memcpy",
- "-fno-builtin-memmove",
- "-mllvm -combiner-global-alias-analysis",
- "-mllvm --tail-merge-threshold=0",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
@@ -822,10 +822,6 @@ libc_function(
name = "memset",
srcs = ["src/string/memset.cpp"],
hdrs = ["src/string/memset.h"],
- copts = [
- "-fno-builtin-memset",
- "-mllvm -combiner-global-alias-analysis",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
@@ -837,10 +833,6 @@ libc_function(
name = "memmove",
srcs = ["src/string/memmove.cpp"],
hdrs = ["src/string/memmove.h"],
- copts = [
- "-fno-builtin-memmove",
- "-mllvm -combiner-global-alias-analysis",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
@@ -854,10 +846,6 @@ libc_function(
name = "memcmp",
srcs = ["src/string/memcmp.cpp"],
hdrs = ["src/string/memcmp.h"],
- copts = [
- "-fno-builtin-memcmp",
- "-mllvm -combiner-global-alias-analysis",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
@@ -870,10 +858,6 @@ libc_function(
name = "bcmp",
srcs = ["src/string/bcmp.cpp"],
hdrs = ["src/string/bcmp.h"],
- copts = [
- "-fno-builtin-bcmp",
- "-fno-builtin-memcmp",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
@@ -885,11 +869,6 @@ libc_function(
name = "bzero",
srcs = ["src/string/bzero.cpp"],
hdrs = ["src/string/bzero.h"],
- copts = [
- "-fno-builtin-bzero",
- "-fno-builtin-memset",
- "-mllvm -combiner-global-alias-analysis",
- ],
features = no_sanitize_features,
deps = [
":__support_common",
diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
index 8e86e8f8a994..8b4882d0c504 100644
--- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
@@ -31,6 +31,7 @@ def libc_function(name, srcs, deps = None, copts = None, **kwargs):
deps.append(LIBC_ROOT_TARGET)
copts = copts or []
copts.append("-O3")
+ copts.append("-fno-builtin")
# We compile the code twice, the first target is suffixed with ".__internal__" and contains the
# C++ functions in the "__llvm_libc" namespace. This allows us to test the function in the
More information about the libc-commits
mailing list