Skip to content

Commit 81955da

Browse files
authored
[libc++] Remove special handling of the native C++ library in benchmarks (#98529)
There were some ad-hoc settings that allowed running the benchmarks against the native C++ Standard Library. While this ability is very useful, it was done before the test suite was quite independent of libc++ itself. Instead, it is better to streamline running the benchmarks on the native standard library by using a custom Lit configuration like we do with the test suite. A follow-up patch will rework the integration of benchmarks with the Lit configuration used for the test suite so that we can reuse the same mechanism for both, making it easy to benchmark the native standard library. It will also make benchmarks way more user-friendly to run since we will be able to run them like we run individual tests, which is a pain point right now.
1 parent 963e25a commit 81955da

File tree

6 files changed

+28
-123
lines changed

6 files changed

+28
-123
lines changed

libcxx/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,6 @@ set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01)
159159
set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING
160160
"Arguments to pass when running the benchmarks using check-cxx-benchmarks")
161161

162-
set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING
163-
"Build the benchmarks against the specified native STL.
164-
The value must be one of libc++/libstdc++")
165-
set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING
166-
"Use alternate GCC toolchain when building the native benchmarks")
167-
168-
if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
169-
if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++"
170-
OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++"))
171-
message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: "
172-
"'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'")
173-
endif()
174-
endif()
175-
176162
option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS})
177163
set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
178164
"Define suffix of library directory name (32/64)")

libcxx/benchmarks/CMakeLists.txt

Lines changed: 19 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ include(ExternalProject)
22
include(CheckCXXCompilerFlag)
33

44
#==============================================================================
5-
# Build Google Benchmark for libc++
5+
# Build Google Benchmark
66
#==============================================================================
77

88
set(CMAKE_FOLDER "${CMAKE_FOLDER}/Benchmarks")
99

10-
set(BENCHMARK_LIBCXX_COMPILE_FLAGS
10+
set(BENCHMARK_COMPILE_FLAGS
1111
-Wno-unused-command-line-argument
1212
-nostdinc++
1313
-isystem "${LIBCXX_GENERATED_INCLUDE_DIR}"
@@ -16,64 +16,37 @@ set(BENCHMARK_LIBCXX_COMPILE_FLAGS
1616
${SANITIZER_FLAGS}
1717
)
1818
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
19-
list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS
19+
list(APPEND BENCHMARK_COMPILE_FLAGS
2020
-isystem "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
2121
endif()
2222
if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
23-
list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS
23+
list(APPEND BENCHMARK_COMPILE_FLAGS
2424
-L${LIBCXX_CXX_ABI_LIBRARY_PATH}
2525
-Wl,-rpath,${LIBCXX_CXX_ABI_LIBRARY_PATH})
2626
endif()
27-
split_list(BENCHMARK_LIBCXX_COMPILE_FLAGS)
27+
split_list(BENCHMARK_COMPILE_FLAGS)
2828

29-
ExternalProject_Add(google-benchmark-libcxx
29+
ExternalProject_Add(google-benchmark
3030
EXCLUDE_FROM_ALL ON
3131
DEPENDS cxx cxx-headers
32-
PREFIX benchmark-libcxx
32+
PREFIX google-benchmark
3333
SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark
34-
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx
34+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark
3535
CMAKE_CACHE_ARGS
3636
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
3737
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
3838
-DCMAKE_BUILD_TYPE:STRING=RELEASE
3939
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
40-
-DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_LIBCXX_COMPILE_FLAGS}
40+
-DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_COMPILE_FLAGS}
4141
-DBENCHMARK_USE_LIBCXX:BOOL=ON
4242
-DBENCHMARK_ENABLE_TESTING:BOOL=OFF)
4343

44-
#==============================================================================
45-
# Build Google Benchmark for the native stdlib
46-
#==============================================================================
47-
set(BENCHMARK_NATIVE_TARGET_FLAGS)
48-
if (LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN)
49-
set(BENCHMARK_NATIVE_TARGET_FLAGS
50-
--gcc-toolchain=${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN})
51-
endif()
52-
split_list(BENCHMARK_NATIVE_TARGET_FLAGS)
53-
54-
if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
55-
ExternalProject_Add(google-benchmark-native
56-
EXCLUDE_FROM_ALL ON
57-
PREFIX benchmark-native
58-
SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark
59-
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native
60-
CMAKE_CACHE_ARGS
61-
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
62-
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
63-
-DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_NATIVE_TARGET_FLAGS}
64-
-DCMAKE_BUILD_TYPE:STRING=RELEASE
65-
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
66-
-DBENCHMARK_ENABLE_TESTING:BOOL=OFF)
67-
endif()
68-
69-
7044
#==============================================================================
7145
# Benchmark tests configuration
7246
#==============================================================================
7347
add_custom_target(cxx-benchmarks)
7448
set(BENCHMARK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
75-
set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx)
76-
set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native)
49+
set(BENCHMARK_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark)
7750

7851
add_library( cxx-benchmarks-flags INTERFACE)
7952

@@ -97,41 +70,23 @@ else()
9770
target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23)
9871
endif()
9972

100-
target_compile_options( cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++)
73+
target_compile_options(cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++
74+
${SANITIZER_FLAGS} -Wno-user-defined-literals -Wno-suggest-override)
10175
target_include_directories(cxx-benchmarks-flags INTERFACE "${LIBCXX_GENERATED_INCLUDE_DIR}"
102-
INTERFACE "${BENCHMARK_LIBCXX_INSTALL}/include"
76+
INTERFACE "${BENCHMARK_INSTALL_DIR}/include"
10377
INTERFACE "${LIBCXX_SOURCE_DIR}/test/support")
104-
105-
add_library( cxx-benchmarks-flags-native INTERFACE)
106-
target_link_libraries( cxx-benchmarks-flags-native INTERFACE cxx-benchmarks-flags)
107-
target_compile_options(cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS})
108-
target_link_options( cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS} "-L${BENCHMARK_NATIVE_INSTALL}/lib")
109-
if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")
110-
find_library(LIBSTDCXX_FILESYSTEM_TEST stdc++fs
111-
PATHS ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN}
112-
PATH_SUFFIXES lib lib64
113-
DOC "The libstdc++ filesystem library used by the benchmarks"
114-
)
115-
if (LIBSTDCXX_FILESYSTEM_TEST)
116-
target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lstdc++fs)
117-
endif()
118-
else()
119-
target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lc++fs -lc++experimental)
120-
endif()
121-
122-
add_library( cxx-benchmarks-flags-libcxx INTERFACE)
123-
target_link_libraries( cxx-benchmarks-flags-libcxx INTERFACE cxx-benchmarks-flags)
124-
target_compile_options(cxx-benchmarks-flags-libcxx INTERFACE ${SANITIZER_FLAGS} -Wno-user-defined-literals -Wno-suggest-override)
125-
target_link_options( cxx-benchmarks-flags-libcxx INTERFACE -lm -nostdlib++ "-L${BENCHMARK_LIBCXX_INSTALL}/lib" "-L${BENCHMARK_LIBCXX_INSTALL}/lib64" ${SANITIZER_FLAGS})
78+
target_link_options(cxx-benchmarks-flags INTERFACE -lm -nostdlib++
79+
"-L${BENCHMARK_INSTALL_DIR}/lib" "-L${BENCHMARK_INSTALL_DIR}/lib64"
80+
${SANITIZER_FLAGS})
12681

12782
set(libcxx_benchmark_targets)
12883

12984
function(add_benchmark_test name source_file)
13085
set(libcxx_target ${name}_libcxx)
13186
list(APPEND libcxx_benchmark_targets ${libcxx_target})
13287
add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file})
133-
target_link_libraries(${libcxx_target} PRIVATE cxx-benchmarks-flags-libcxx)
134-
add_dependencies(${libcxx_target} cxx google-benchmark-libcxx)
88+
target_link_libraries(${libcxx_target} PRIVATE cxx-benchmarks-flags)
89+
add_dependencies(${libcxx_target} cxx google-benchmark)
13590
add_dependencies(cxx-benchmarks ${libcxx_target})
13691
if (LIBCXX_ENABLE_SHARED)
13792
target_link_libraries(${libcxx_target} PRIVATE cxx_shared)
@@ -144,27 +99,10 @@ function(add_benchmark_test name source_file)
14499
endif()
145100
set_target_properties(${libcxx_target}
146101
PROPERTIES
147-
OUTPUT_NAME "${name}.libcxx.out"
102+
OUTPUT_NAME "${name}.bench.out"
148103
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}"
149104
CXX_EXTENSIONS NO)
150105
cxx_link_system_libraries(${libcxx_target})
151-
if (LIBCXX_BENCHMARK_NATIVE_STDLIB)
152-
set(native_target ${name}_native)
153-
add_executable(${native_target} EXCLUDE_FROM_ALL ${source_file})
154-
target_link_libraries(${native_target} PRIVATE cxx-benchmarks-flags-native)
155-
add_dependencies(${native_target} google-benchmark-native
156-
google-benchmark-libcxx)
157-
target_link_libraries(${native_target} PRIVATE -lbenchmark)
158-
if (LIBCXX_HAS_PTHREAD_LIB)
159-
target_link_libraries(${native_target} PRIVATE -pthread)
160-
endif()
161-
add_dependencies(cxx-benchmarks ${native_target})
162-
set_target_properties(${native_target}
163-
PROPERTIES
164-
OUTPUT_NAME "${name}.native.out"
165-
RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}"
166-
CXX_EXTENSIONS NO)
167-
endif()
168106
endfunction()
169107

170108

libcxx/benchmarks/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
config.test_source_root = config.test_exec_root
2020

2121
config.test_format = GoogleBenchmark(
22-
test_sub_dirs=".", test_suffix=".libcxx.out", benchmark_args=config.benchmark_args
22+
test_sub_dirs=".", test_suffix=".bench.out", benchmark_args=config.benchmark_args
2323
)

libcxx/docs/BuildingLibcxx.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,6 @@ libc++ Feature Options
399399
since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to
400400
get accurate measurements.
401401

402-
.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
403-
404-
**Default**:: ``""``
405-
406-
**Values**:: ``libc++``, ``libstdc++``
407-
408-
Build the libc++ benchmark tests and Google Benchmark library against the
409-
specified standard library on the platform. On Linux this can be used to
410-
compare libc++ to libstdc++ by building the benchmark tests against both
411-
standard libraries.
412-
413-
.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
414-
415-
Use the specified GCC toolchain and standard library when building the native
416-
stdlib benchmark tests.
417-
418402
.. option:: LIBCXX_ASSERTION_HANDLER_FILE:PATH
419403

420404
**Default**:: ``"${CMAKE_CURRENT_SOURCE_DIR}/vendor/llvm/default_assertion_handler.in"``

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ Build System Changes
178178
to automatically detect the presence of ``clang-tidy`` and the required ``Clang`` libraries.
179179

180180
- The CMake options ``LIBCXX_INSTALL_MODULES`` now defaults to ``ON``.
181+
182+
- The CMake options ``LIBCXX_BENCHMARK_NATIVE_STDLIB`` and ``LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN`` have
183+
been removed. To benchmark the native standard library, configure the test suite against the native
184+
standard library directly instead.

libcxx/docs/TestingLibcxx.rst

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Test Filenames`_ when determining the names for new test files.
351351
- Same as ``FOO.pass.cpp``, but for Objective-C++.
352352

353353
* - ``FOO.compile.pass.cpp``
354-
- Checks whether the C++ code in the file compiles successfully. In general, prefer ``compile`` tests over ``verify`` tests,
354+
- Checks whether the C++ code in the file compiles successfully. In general, prefer ``compile`` tests over ``verify`` tests,
355355
subject to the specific recommendations, below, for when to write ``verify`` tests.
356356
* - ``FOO.compile.pass.mm``
357357
- Same as ``FOO.compile.pass.cpp``, but for Objective-C++.
@@ -447,19 +447,12 @@ An example build would look like:
447447

448448
.. code-block:: bash
449449
450-
$ cd build
451-
$ ninja cxx-benchmarks
450+
$ ninja -C build cxx-benchmarks
452451
453452
This will build all of the benchmarks under ``<libcxx-src>/benchmarks`` to be
454453
built against the just-built libc++. The compiled tests are output into
455454
``build/projects/libcxx/benchmarks``.
456455

457-
The benchmarks can also be built against the platforms native standard library
458-
using the ``-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON`` CMake option. This
459-
is useful for comparing the performance of libc++ to other standard libraries.
460-
The compiled benchmarks are named ``<test>.libcxx.out`` if they test libc++ and
461-
``<test>.native.out`` otherwise.
462-
463456
Also See:
464457

465458
* :ref:`Building Libc++ <build instructions>`
@@ -476,8 +469,8 @@ For example:
476469
.. code-block:: bash
477470
478471
$ cd build/projects/libcxx/benchmarks
479-
$ ./algorithms.libcxx.out # Runs all the benchmarks
480-
$ ./algorithms.libcxx.out --benchmark_filter=BM_Sort.* # Only runs the sort benchmarks
472+
$ ./algorithms.bench.out # Runs all the benchmarks
473+
$ ./algorithms.bench.out --benchmark_filter=BM_Sort.* # Only runs the sort benchmarks
481474
482475
For more information about running benchmarks see `Google Benchmark`_.
483476

0 commit comments

Comments
 (0)