Skip to content

Commit 0a06eb9

Browse files
committed
[libc++] Take 2: Integrate the PSTL into libc++
Summary: This commit allows specifying LIBCXX_ENABLE_PARALLEL_ALGORITHMS when configuring libc++ in CMake. When that option is enabled, libc++ will assume that the PSTL can be found somewhere on the CMake module path, and it will provide the C++17 parallel algorithms based on the PSTL (that is assumed to be available). The commit also adds support for running the PSTL tests as part of the libc++ test suite. The first attempt to commit this failed because it exposed a bug in the tests for modules. Now that this has been fixed, it should be safe to commit this. Reviewers: EricWF Subscribers: mgorny, christof, jkorous, dexonsmith, libcxx-commits, mclow.lists, EricWF Tags: #libc Differential Revision: https://reviews.llvm.org/D60480 llvm-svn: 367903
1 parent 3de3324 commit 0a06eb9

File tree

17 files changed

+71
-1
lines changed

17 files changed

+71
-1
lines changed

libcxx/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ endif()
8080
option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library"
8181
${ENABLE_FILESYSTEM_DEFAULT})
8282
option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
83+
option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF)
8384

8485
# Benchmark options -----------------------------------------------------------
8586
option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON)
@@ -745,6 +746,7 @@ config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
745746
config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
746747
config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
747748
config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
749+
config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS)
748750

749751
if (LIBCXX_ABI_DEFINES)
750752
set(abi_defines)

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(files
6262
deque
6363
errno.h
6464
exception
65+
execution
6566
experimental/__config
6667
experimental/__memory
6768
experimental/algorithm

libcxx/include/__config_site.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#cmakedefine _LIBCPP_NO_VCRUNTIME
3030
#cmakedefine01 _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
3131
#cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@
32+
#cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS
3233

3334
@_LIBCPP_ABI_DEFINES@
3435

libcxx/include/algorithm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5678,4 +5678,8 @@ _LIBCPP_END_NAMESPACE_STD
56785678

56795679
_LIBCPP_POP_MACROS
56805680

5681+
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
5682+
# include <pstl/internal/glue_algorithm_impl.h>
5683+
#endif
5684+
56815685
#endif // _LIBCPP_ALGORITHM

libcxx/include/execution

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// -*- C++ -*-
2+
//===------------------------- execution ---------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP_EXECUTION
11+
#define _LIBCPP_EXECUTION
12+
13+
#include <__config>
14+
15+
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
16+
# include <pstl/internal/glue_execution_defs.h>
17+
#endif
18+
19+
#endif // _LIBCPP_EXECUTION

libcxx/include/memory

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5590,4 +5590,8 @@ _LIBCPP_END_NAMESPACE_STD
55905590

55915591
_LIBCPP_POP_MACROS
55925592

5593+
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
5594+
# include <pstl/internal/glue_memory_impl.h>
5595+
#endif
5596+
55935597
#endif // _LIBCPP_MEMORY

libcxx/include/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ module std [system] {
275275
header "exception"
276276
export *
277277
}
278+
module execution {
279+
header "execution"
280+
export *
281+
}
278282
module filesystem {
279283
header "filesystem"
280284
export *

libcxx/include/numeric

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,4 +586,8 @@ _LIBCPP_END_NAMESPACE_STD
586586

587587
_LIBCPP_POP_MACROS
588588

589+
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
590+
# include <pstl/internal/glue_numeric_impl.h>
591+
#endif
592+
589593
#endif // _LIBCPP_NUMERIC

libcxx/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ function(cxx_link_system_libraries target)
196196
endif()
197197
endfunction()
198198

199+
if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS AND NOT TARGET pstl::ParallelSTL)
200+
message(FATAL_ERROR "Could not find ParallelSTL")
201+
endif()
202+
199203
function(cxx_set_common_defines name)
200204
if(LIBCXX_CXX_ABI_HEADER_TARGET)
201205
add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET})
@@ -222,6 +226,10 @@ function(cxx_set_common_defines name)
222226
# in printf, scanf.
223227
_CRT_STDIO_ISO_WIDE_SPECIFIERS)
224228
endif()
229+
230+
if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
231+
target_link_libraries(${name} PUBLIC pstl::ParallelSTL)
232+
endif()
225233
endfunction()
226234

227235
split_list(LIBCXX_COMPILE_FLAGS)

libcxx/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
4040
pythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
4141
pythonize_bool(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
4242
pythonize_bool(LIBCXX_DEBUG_BUILD)
43+
pythonize_bool(LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
4344

4445
# By default, for non-standalone builds, libcxx and libcxxabi share a library
4546
# directory.

0 commit comments

Comments
 (0)