Skip to content

Commit b2a9ea4

Browse files
committed
[libc] Apply no-builtin everywhere, remove unnecessary flags
Note, this is a re-submission of D125894 with `features = ["-header_modules"]` added to the main BUILD.bazel file. 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/D126773
1 parent f951a6b commit b2a9ea4

File tree

4 files changed

+11
-44
lines changed

4 files changed

+11
-44
lines changed

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY")
33
function(_get_common_compile_options output_var)
44
set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
55
if(NOT ${LIBC_TARGET_OS} STREQUAL "windows")
6-
set(compile_options ${compile_options} -fpie -ffreestanding)
6+
set(compile_options ${compile_options} -fpie -ffreestanding -fno-builtin)
77
endif()
88
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
99
list(APPEND compile_options "-fno-exceptions")

libc/src/string/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ function(add_implementation name impl_name)
279279
${ARGN})
280280

281281
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
282-
list(APPEND ADD_IMPL_MLLVM_COMPILE_OPTIONS "-combiner-global-alias-analysis")
283282
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
284283
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
285284
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
@@ -309,9 +308,6 @@ function(add_bcmp bcmp_name)
309308
DEPENDS
310309
.memory_utils.memory_utils
311310
libc.include.string
312-
COMPILE_OPTIONS
313-
-fno-builtin-memcmp
314-
-fno-builtin-bcmp
315311
${ARGN}
316312
)
317313
endfunction()
@@ -339,8 +335,6 @@ function(add_bzero bzero_name)
339335
DEPENDS
340336
.memory_utils.memset_implementation
341337
libc.include.string
342-
COMPILE_OPTIONS
343-
-fno-builtin-bzero
344338
${ARGN}
345339
)
346340
endfunction()
@@ -368,8 +362,6 @@ function(add_memcmp memcmp_name)
368362
DEPENDS
369363
.memory_utils.memcmp_implementation
370364
libc.include.string
371-
COMPILE_OPTIONS
372-
-fno-builtin-memcmp
373365
${ARGN}
374366
)
375367
endfunction()
@@ -400,8 +392,6 @@ function(add_memcpy memcpy_name)
400392
DEPENDS
401393
.memory_utils.memcpy_implementation
402394
libc.include.string
403-
COMPILE_OPTIONS
404-
-fno-builtin-memcpy
405395
${ARGN}
406396
)
407397
endfunction()
@@ -434,8 +424,6 @@ function(add_memmove memmove_name)
434424
DEPENDS
435425
.memory_utils.memory_utils
436426
libc.include.string
437-
COMPILE_OPTIONS
438-
-fno-builtin
439427
${ARGN}
440428
)
441429
endfunction()
@@ -468,8 +456,6 @@ function(add_memset memset_name)
468456
DEPENDS
469457
.memory_utils.memset_implementation
470458
libc.include.string
471-
COMPILE_OPTIONS
472-
-fno-builtin-memset
473459
${ARGN}
474460
)
475461
endfunction()

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
99

1010
package(
1111
default_visibility = ["//visibility:public"],
12+
features = ["-header_modules"],
1213
licenses = ["notice"],
1314
)
1415

@@ -85,15 +86,21 @@ cc_library(
8586
hdrs = [
8687
"src/__support/CPP/UInt.h",
8788
],
88-
deps = [":libc_root","__support_cpp_array"],
89+
deps = [
90+
"__support_cpp_array",
91+
":libc_root",
92+
],
8993
)
9094

9195
cc_library(
9296
name = "__support_cpp_type_traits",
9397
hdrs = [
9498
"src/__support/CPP/TypeTraits.h",
9599
],
96-
deps = [":libc_root","__support_cpp_uint"],
100+
deps = [
101+
"__support_cpp_uint",
102+
":libc_root",
103+
],
97104
)
98105

99106
cc_library(
@@ -806,12 +813,6 @@ libc_function(
806813
name = "memcpy",
807814
srcs = ["src/string/memcpy.cpp"],
808815
hdrs = ["src/string/memcpy.h"],
809-
copts = [
810-
"-fno-builtin-memcpy",
811-
"-fno-builtin-memmove",
812-
"-mllvm -combiner-global-alias-analysis",
813-
"-mllvm --tail-merge-threshold=0",
814-
],
815816
features = no_sanitize_features,
816817
deps = [
817818
":__support_common",
@@ -823,10 +824,6 @@ libc_function(
823824
name = "memset",
824825
srcs = ["src/string/memset.cpp"],
825826
hdrs = ["src/string/memset.h"],
826-
copts = [
827-
"-fno-builtin-memset",
828-
"-mllvm -combiner-global-alias-analysis",
829-
],
830827
features = no_sanitize_features,
831828
deps = [
832829
":__support_common",
@@ -838,10 +835,6 @@ libc_function(
838835
name = "memmove",
839836
srcs = ["src/string/memmove.cpp"],
840837
hdrs = ["src/string/memmove.h"],
841-
copts = [
842-
"-fno-builtin-memmove",
843-
"-mllvm -combiner-global-alias-analysis",
844-
],
845838
features = no_sanitize_features,
846839
deps = [
847840
":__support_common",
@@ -855,10 +848,6 @@ libc_function(
855848
name = "memcmp",
856849
srcs = ["src/string/memcmp.cpp"],
857850
hdrs = ["src/string/memcmp.h"],
858-
copts = [
859-
"-fno-builtin-memcmp",
860-
"-mllvm -combiner-global-alias-analysis",
861-
],
862851
features = no_sanitize_features,
863852
deps = [
864853
":__support_common",
@@ -871,10 +860,6 @@ libc_function(
871860
name = "bcmp",
872861
srcs = ["src/string/bcmp.cpp"],
873862
hdrs = ["src/string/bcmp.h"],
874-
copts = [
875-
"-fno-builtin-bcmp",
876-
"-fno-builtin-memcmp",
877-
],
878863
features = no_sanitize_features,
879864
deps = [
880865
":__support_common",
@@ -886,11 +871,6 @@ libc_function(
886871
name = "bzero",
887872
srcs = ["src/string/bzero.cpp"],
888873
hdrs = ["src/string/bzero.h"],
889-
copts = [
890-
"-fno-builtin-bzero",
891-
"-fno-builtin-memset",
892-
"-mllvm -combiner-global-alias-analysis",
893-
],
894874
features = no_sanitize_features,
895875
deps = [
896876
":__support_common",

utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def libc_function(name, srcs, deps = None, copts = None, **kwargs):
3131
deps.append(LIBC_ROOT_TARGET)
3232
copts = copts or []
3333
copts.append("-O3")
34+
copts.append("-fno-builtin")
3435

3536
# We compile the code twice, the first target is suffixed with ".__internal__" and contains the
3637
# C++ functions in the "__llvm_libc" namespace. This allows us to test the function in the

0 commit comments

Comments
 (0)