3 set(LLVM_LINK_COMPONENTS
8 #==============================================================================
9 # Add Unit Testing Support
10 #==============================================================================
12 function(add_libc_benchmark_unittest target_name)
13 if(NOT LLVM_INCLUDE_TESTS)
17 cmake_parse_arguments(
18 "LIBC_BENCHMARKS_UNITTEST"
19 "" # No optional arguments
20 "SUITE" # Single value arguments
21 "SRCS;DEPENDS" # Multi-value arguments
25 add_executable(${target_name}
27 ${LIBC_BENCHMARKS_UNITTEST_SRCS}
29 target_link_libraries(${target_name}
33 ${LIBC_BENCHMARKS_UNITTEST_DEPENDS}
35 llvm_update_compile_flags(${target_name})
40 COMMAND $<TARGET_FILE:${target_name}>
42 add_dependencies(libc-benchmark-util-tests ${target_name})
45 #==============================================================================
46 # Build Google Benchmark for libc
47 #==============================================================================
49 include(ExternalProject)
50 ExternalProject_Add(google-benchmark-libc
52 PREFIX google-benchmark-libc
53 SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark
54 INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-libc
56 -DBENCHMARK_ENABLE_EXCEPTIONS:BOOL=OFF
57 -DBENCHMARK_ENABLE_LTO:BOOL=OFF
58 -DBENCHMARK_ENABLE_TESTING:BOOL=OFF
59 -DBENCHMARK_ENABLE_WERROR:BOOL=${LLVM_ENABLE_WERROR}
60 -DBENCHMARK_FORCE_WERROR:BOOL=OFF
61 -DBENCHMARK_USE_LIBCXX:BOOL=OFF
62 -DCMAKE_BUILD_TYPE:STRING=Release
64 -DCMAKE_SYSTEM_NAME:STRING=${CMAKE_SYSTEM_NAME}
65 -DCMAKE_SYSTEM_PROCESSOR:STRING=${CMAKE_SYSTEM_PROCESSOR}
66 -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
67 -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
68 -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
69 -DCMAKE_FIND_ROOT_PATH:STRING=${CMAKE_FIND_ROOT_PATH}
71 -DBUILD_SHARED_LIBS:BOOL=OFF
72 -DCMAKE_EXE_LINKER_FLAGS:STRING=-static
74 -DCMAKE_CXX_STANDARD:STRING=14
75 -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
78 add_custom_target(libc-benchmark-util-tests)
81 add_library(libc-benchmark
88 target_include_directories(libc-benchmark
89 PUBLIC ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}
91 target_link_libraries(libc-benchmark
98 add_dependencies(libc-benchmark google-benchmark-libc)
99 llvm_update_compile_flags(libc-benchmark)
101 add_libc_benchmark_unittest(libc-benchmark-test
102 SRCS LibcBenchmarkTest.cpp
103 DEPENDS libc-benchmark
106 # libc-memory-benchmark
107 add_library(libc-memory-benchmark
110 LibcMemoryBenchmark.cpp
111 LibcMemoryBenchmark.h
112 LibcFunctionPrototypes.h
113 MemorySizeDistributions.cpp
114 MemorySizeDistributions.h
116 target_include_directories(libc-memory-benchmark
118 ${CMAKE_CURRENT_SOURCE_DIR}
120 target_link_libraries(libc-memory-benchmark
124 llvm_update_compile_flags(libc-memory-benchmark)
126 add_libc_benchmark_unittest(libc-memory-benchmark-test
127 SRCS LibcMemoryBenchmarkTest.cpp
128 DEPENDS libc-memory-benchmark
138 target_link_libraries(json PUBLIC libc-memory-benchmark)
139 llvm_update_compile_flags(json)
141 add_libc_benchmark_unittest(json-test
146 #==============================================================================
148 #==============================================================================
150 # Benchmark all implementations that can run on the target CPU.
151 function(add_libc_multi_impl_benchmark name)
152 get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations)
153 foreach(fq_config_name IN LISTS fq_implementations)
154 get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES)
155 cpu_supports(can_run "${required_cpu_features}")
157 set(benchmark_name ${fq_config_name}_benchmark)
158 add_executable(${benchmark_name}
160 LibcMemoryBenchmarkMain.cpp
162 get_target_property(entrypoint_object_file ${fq_config_name} "OBJECT_FILE_RAW")
163 target_link_libraries(${benchmark_name} PUBLIC json ${entrypoint_object_file})
164 string(TOUPPER ${name} name_upper)
165 target_compile_definitions(${benchmark_name} PRIVATE "-DLIBC_BENCHMARK_FUNCTION_${name_upper}=LIBC_NAMESPACE::${name}" "-DLIBC_BENCHMARK_FUNCTION_NAME=\"${fq_config_name}\"")
166 llvm_update_compile_flags(${benchmark_name})
168 message(STATUS "Skipping benchmark for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
173 add_libc_multi_impl_benchmark(bcmp)
174 add_libc_multi_impl_benchmark(bzero)
175 add_libc_multi_impl_benchmark(memcmp)
176 add_libc_multi_impl_benchmark(memcpy)
177 add_libc_multi_impl_benchmark(memmove)
178 add_libc_multi_impl_benchmark(memset)
180 #==============================================================================
181 # Google Benchmarking tool
182 #==============================================================================
184 # This target uses the Google Benchmark facility to report throughput for llvm
185 # libc memory functions compiled for the host machine. This is useful to
186 # continuously monitor the performance of the memory functions.
187 add_executable(libc.benchmarks.memory_functions.opt_host
189 LibcMemoryGoogleBenchmarkMain.cpp
190 LibcDefaultImplementations.cpp
192 target_link_libraries(libc.benchmarks.memory_functions.opt_host
194 libc-memory-benchmark
195 libc.src.string.memcmp_opt_host.__internal__
196 libc.src.string.bcmp_opt_host.__internal__
197 libc.src.string.memcpy_opt_host.__internal__
198 libc.src.string.memset_opt_host.__internal__
199 libc.src.string.bzero_opt_host.__internal__
200 libc.src.string.memmove_opt_host.__internal__
203 llvm_update_compile_flags(libc.benchmarks.memory_functions.opt_host)
205 add_subdirectory(automemcpy)