| 1 |
include(ExternalProject) |
| 2 |
include(CheckCXXCompilerFlag) |
| 3 |
|
| 4 |
#============================================================================== |
| 5 |
# Build Google Benchmark |
| 6 |
#============================================================================== |
| 7 |
|
| 8 |
set(CMAKE_FOLDER "${CMAKE_FOLDER}/Benchmarks") |
| 9 |
|
| 10 |
set(BENCHMARK_COMPILE_FLAGS |
| 11 |
-Wno-unused-command-line-argument |
| 12 |
-nostdinc++ |
| 13 |
-isystem "${LIBCXX_GENERATED_INCLUDE_DIR}" |
| 14 |
-L${LIBCXX_LIBRARY_DIR} |
| 15 |
-Wl,-rpath,${LIBCXX_LIBRARY_DIR} |
| 16 |
${SANITIZER_FLAGS} |
| 17 |
) |
| 18 |
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) |
| 19 |
list(APPEND BENCHMARK_COMPILE_FLAGS |
| 20 |
-isystem "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}") |
| 21 |
endif() |
| 22 |
if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH) |
| 23 |
list(APPEND BENCHMARK_COMPILE_FLAGS |
| 24 |
-L${LIBCXX_CXX_ABI_LIBRARY_PATH} |
| 25 |
-Wl,-rpath,${LIBCXX_CXX_ABI_LIBRARY_PATH}) |
| 26 |
endif() |
| 27 |
split_list(BENCHMARK_COMPILE_FLAGS) |
| 28 |
|
| 29 |
ExternalProject_Add(google-benchmark |
| 30 |
EXCLUDE_FROM_ALL ON |
| 31 |
DEPENDS cxx cxx-headers |
| 32 |
PREFIX google-benchmark |
| 33 |
SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark |
| 34 |
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark |
| 35 |
CMAKE_CACHE_ARGS |
| 36 |
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} |
| 37 |
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} |
| 38 |
-DCMAKE_BUILD_TYPE:STRING=RELEASE |
| 39 |
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> |
| 40 |
-DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_COMPILE_FLAGS} |
| 41 |
-DBENCHMARK_USE_LIBCXX:BOOL=ON |
| 42 |
-DBENCHMARK_ENABLE_TESTING:BOOL=OFF) |
| 43 |
|
| 44 |
#============================================================================== |
| 45 |
# Benchmark tests configuration |
| 46 |
#============================================================================== |
| 47 |
add_custom_target(cxx-benchmarks) |
| 48 |
set(BENCHMARK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 49 |
set(BENCHMARK_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark) |
| 50 |
|
| 51 |
add_library( cxx-benchmarks-flags INTERFACE) |
| 52 |
|
| 53 |
# TODO(cmake): remove. This is a workaround to prevent older versions of GCC |
| 54 |
# from failing the configure step because they don't support C++23. |
| 55 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13.0") |
| 56 |
return() |
| 57 |
endif() |
| 58 |
#TODO(cmake): remove the `add_compile_options`. Currently we have to explicitly |
| 59 |
# pass the `std:c++latest` flag on Windows to work around an issue where |
| 60 |
# requesting `cxx_std_23` results in an error -- somehow CMake fails to |
| 61 |
# translate the `c++23` flag into `c++latest`, and the highest numbered C++ |
| 62 |
# version that MSVC flags support is C++20. |
| 63 |
if (MSVC) |
| 64 |
add_compile_options(/std:c++latest) |
| 65 |
# ibm-clang does not recognize the cxx_std_23 flag, so use this as a temporary |
| 66 |
# workaround on AIX as well. |
| 67 |
elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX") |
| 68 |
add_compile_options(-std=c++23) |
| 69 |
else() |
| 70 |
target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23) |
| 71 |
endif() |
| 72 |
|
| 73 |
target_compile_options(cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++ |
| 74 |
${SANITIZER_FLAGS} -Wno-user-defined-literals -Wno-suggest-override) |
| 75 |
target_include_directories(cxx-benchmarks-flags INTERFACE "${LIBCXX_GENERATED_INCLUDE_DIR}" |
| 76 |
INTERFACE "${BENCHMARK_INSTALL_DIR}/include" |
| 77 |
INTERFACE "${LIBCXX_SOURCE_DIR}/test/support") |
| 78 |
target_link_options(cxx-benchmarks-flags INTERFACE -lm -nostdlib++ |
| 79 |
"-L${BENCHMARK_INSTALL_DIR}/lib" "-L${BENCHMARK_INSTALL_DIR}/lib64" |
| 80 |
${SANITIZER_FLAGS}) |
| 81 |
|
| 82 |
set(libcxx_benchmark_targets) |
| 83 |
|
| 84 |
function(add_benchmark_test name source_file) |
| 85 |
set(libcxx_target ${name}_libcxx) |
| 86 |
list(APPEND libcxx_benchmark_targets ${libcxx_target}) |
| 87 |
add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file}) |
| 88 |
target_link_libraries(${libcxx_target} PRIVATE cxx-benchmarks-flags) |
| 89 |
add_dependencies(${libcxx_target} cxx google-benchmark) |
| 90 |
add_dependencies(cxx-benchmarks ${libcxx_target}) |
| 91 |
if (LIBCXX_ENABLE_SHARED) |
| 92 |
target_link_libraries(${libcxx_target} PRIVATE cxx_shared) |
| 93 |
else() |
| 94 |
target_link_libraries(${libcxx_target} PRIVATE cxx_static) |
| 95 |
endif() |
| 96 |
target_link_libraries(${libcxx_target} PRIVATE cxx_experimental benchmark) |
| 97 |
if (LLVM_USE_SANITIZER) |
| 98 |
target_link_libraries(${libcxx_target} PRIVATE -ldl) |
| 99 |
endif() |
| 100 |
set_target_properties(${libcxx_target} |
| 101 |
PROPERTIES |
| 102 |
OUTPUT_NAME "${name}.bench.out" |
| 103 |
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" |
| 104 |
CXX_EXTENSIONS NO) |
| 105 |
cxx_link_system_libraries(${libcxx_target}) |
| 106 |
endfunction() |
| 107 |
|
| 108 |
|
| 109 |
#============================================================================== |
| 110 |
# Register Benchmark tests |
| 111 |
#============================================================================== |
| 112 |
set(BENCHMARK_TESTS |
| 113 |
algorithms.partition_point.bench.cpp |
| 114 |
algorithms/count.bench.cpp |
| 115 |
algorithms/equal.bench.cpp |
| 116 |
algorithms/find.bench.cpp |
| 117 |
algorithms/fill.bench.cpp |
| 118 |
algorithms/for_each.bench.cpp |
| 119 |
algorithms/lower_bound.bench.cpp |
| 120 |
algorithms/make_heap.bench.cpp |
| 121 |
algorithms/make_heap_then_sort_heap.bench.cpp |
| 122 |
algorithms/min.bench.cpp |
| 123 |
algorithms/minmax.bench.cpp |
| 124 |
algorithms/min_max_element.bench.cpp |
| 125 |
algorithms/mismatch.bench.cpp |
| 126 |
algorithms/pop_heap.bench.cpp |
| 127 |
algorithms/pstl.stable_sort.bench.cpp |
| 128 |
algorithms/push_heap.bench.cpp |
| 129 |
algorithms/ranges_contains.bench.cpp |
| 130 |
algorithms/ranges_ends_with.bench.cpp |
| 131 |
algorithms/ranges_make_heap.bench.cpp |
| 132 |
algorithms/ranges_make_heap_then_sort_heap.bench.cpp |
| 133 |
algorithms/ranges_pop_heap.bench.cpp |
| 134 |
algorithms/ranges_push_heap.bench.cpp |
| 135 |
algorithms/ranges_sort.bench.cpp |
| 136 |
algorithms/ranges_sort_heap.bench.cpp |
| 137 |
algorithms/ranges_stable_sort.bench.cpp |
| 138 |
algorithms/set_intersection.bench.cpp |
| 139 |
algorithms/sort.bench.cpp |
| 140 |
algorithms/sort_heap.bench.cpp |
| 141 |
algorithms/stable_sort.bench.cpp |
| 142 |
atomic_wait.bench.cpp |
| 143 |
atomic_wait_vs_mutex_lock.bench.cpp |
| 144 |
libcxxabi/dynamic_cast.bench.cpp |
| 145 |
libcxxabi/dynamic_cast_old_stress.bench.cpp |
| 146 |
allocation.bench.cpp |
| 147 |
deque.bench.cpp |
| 148 |
deque_iterator.bench.cpp |
| 149 |
exception_ptr.bench.cpp |
| 150 |
filesystem.bench.cpp |
| 151 |
format_to_n.bench.cpp |
| 152 |
format_to.bench.cpp |
| 153 |
format.bench.cpp |
| 154 |
formatted_size.bench.cpp |
| 155 |
formatter_float.bench.cpp |
| 156 |
formatter_int.bench.cpp |
| 157 |
function.bench.cpp |
| 158 |
join_view.bench.cpp |
| 159 |
lexicographical_compare_three_way.bench.cpp |
| 160 |
map.bench.cpp |
| 161 |
monotonic_buffer.bench.cpp |
| 162 |
numeric/gcd.bench.cpp |
| 163 |
ordered_set.bench.cpp |
| 164 |
shared_mutex_vs_mutex.bench.cpp |
| 165 |
stop_token.bench.cpp |
| 166 |
std_format_spec_string_unicode.bench.cpp |
| 167 |
std_format_spec_string_unicode_escape.bench.cpp |
| 168 |
string.bench.cpp |
| 169 |
stringstream.bench.cpp |
| 170 |
system_error.bench.cpp |
| 171 |
to_chars.bench.cpp |
| 172 |
unordered_set_operations.bench.cpp |
| 173 |
util_smartptr.bench.cpp |
| 174 |
variant_visit_1.bench.cpp |
| 175 |
variant_visit_2.bench.cpp |
| 176 |
variant_visit_3.bench.cpp |
| 177 |
vector_operations.bench.cpp |
| 178 |
) |
| 179 |
|
| 180 |
foreach(test_path ${BENCHMARK_TESTS}) |
| 181 |
get_filename_component(test_file "${test_path}" NAME) |
| 182 |
string(REPLACE ".bench.cpp" "" test_name "${test_file}") |
| 183 |
if (NOT DEFINED ${test_name}_REPORTED) |
| 184 |
message(STATUS "Adding Benchmark: ${test_file}") |
| 185 |
# Only report the adding of the benchmark once. |
| 186 |
set(${test_name}_REPORTED ON CACHE INTERNAL "") |
| 187 |
endif() |
| 188 |
add_benchmark_test(${test_name} ${test_path}) |
| 189 |
endforeach() |
| 190 |
|
| 191 |
if (LIBCXX_INCLUDE_TESTS) |
| 192 |
include(AddLLVM) |
| 193 |
|
| 194 |
configure_lit_site_cfg( |
| 195 |
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in |
| 196 |
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py) |
| 197 |
|
| 198 |
set(BENCHMARK_LIT_ARGS "--show-all --show-xfail --show-unsupported ${LIT_ARGS_DEFAULT}") |
| 199 |
|
| 200 |
add_lit_target(check-cxx-benchmarks |
| 201 |
"Running libcxx benchmarks tests" |
| 202 |
${CMAKE_CURRENT_BINARY_DIR} |
| 203 |
DEPENDS cxx-benchmarks cxx-test-depends |
| 204 |
ARGS ${BENCHMARK_LIT_ARGS}) |
| 205 |
endif() |