diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f32bb151..37a1e3fc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ endif() option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of the main libc++ library" ${ENABLE_FILESYSTEM_DEFAULT}) option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) +option(LIBCXX_ENABLE_PARALLEL_ALGORITHMS "Enable the parallel algorithms library. This requires the PSTL to be available." OFF) # Benchmark options ----------------------------------------------------------- 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) config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) +config_define_if(LIBCXX_ENABLE_PARALLEL_ALGORITHMS _LIBCPP_HAS_PARALLEL_ALGORITHMS) if (LIBCXX_ABI_DEFINES) set(abi_defines) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7cbf82caa..e12068a1a 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -62,6 +62,7 @@ set(files deque errno.h exception + execution experimental/__config experimental/__memory experimental/algorithm diff --git a/include/__config_site.in b/include/__config_site.in index ffbd372ed..1ccc158c6 100644 --- a/include/__config_site.in +++ b/include/__config_site.in @@ -29,6 +29,7 @@ #cmakedefine _LIBCPP_NO_VCRUNTIME #cmakedefine01 _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT #cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ +#cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS @_LIBCPP_ABI_DEFINES@ diff --git a/include/algorithm b/include/algorithm index 0d7862675..ac780af63 100644 --- a/include/algorithm +++ b/include/algorithm @@ -5678,4 +5678,8 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +# include +#endif + #endif // _LIBCPP_ALGORITHM diff --git a/include/execution b/include/execution new file mode 100644 index 000000000..c12615b77 --- /dev/null +++ b/include/execution @@ -0,0 +1,19 @@ +// -*- C++ -*- +//===------------------------- execution ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXECUTION +#define _LIBCPP_EXECUTION + +#include <__config> + +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +# include +#endif + +#endif // _LIBCPP_EXECUTION diff --git a/include/memory b/include/memory index d9222b3ad..ff500f830 100644 --- a/include/memory +++ b/include/memory @@ -5590,4 +5590,8 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +# include +#endif + #endif // _LIBCPP_MEMORY diff --git a/include/module.modulemap b/include/module.modulemap index bbfe90ed5..31d39ddf7 100644 --- a/include/module.modulemap +++ b/include/module.modulemap @@ -275,6 +275,10 @@ module std [system] { header "exception" export * } + module execution { + header "execution" + export * + } module filesystem { header "filesystem" export * diff --git a/include/numeric b/include/numeric index 2118704d5..f5ac1410f 100644 --- a/include/numeric +++ b/include/numeric @@ -586,4 +586,8 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +# include +#endif + #endif // _LIBCPP_NUMERIC diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31cd24333..352791e8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -196,6 +196,10 @@ function(cxx_link_system_libraries target) endif() endfunction() +if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS AND NOT TARGET pstl::ParallelSTL) + message(FATAL_ERROR "Could not find ParallelSTL") +endif() + function(cxx_set_common_defines name) if(LIBCXX_CXX_ABI_HEADER_TARGET) add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) @@ -222,6 +226,10 @@ function(cxx_set_common_defines name) # in printf, scanf. _CRT_STDIO_ISO_WIDE_SPECIFIERS) endif() + + if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + target_link_libraries(${name} PUBLIC pstl::ParallelSTL) + endif() endfunction() split_list(LIBCXX_COMPILE_FLAGS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 408ab6266..8a2114faf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,6 +40,7 @@ pythonize_bool(LIBCXX_HAS_ATOMIC_LIB) pythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB) pythonize_bool(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) pythonize_bool(LIBCXX_DEBUG_BUILD) +pythonize_bool(LIBCXX_ENABLE_PARALLEL_ALGORITHMS) # By default, for non-standalone builds, libcxx and libcxxabi share a library # directory. diff --git a/test/libcxx/double_include.sh.cpp b/test/libcxx/double_include.sh.cpp index 2ee444af5..5a1ee32f9 100644 --- a/test/libcxx/double_include.sh.cpp +++ b/test/libcxx/double_include.sh.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index ed9a71105..b5b390dc4 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -33,6 +33,7 @@ config.use_libatomic = @LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@ config.debug_build = @LIBCXX_DEBUG_BUILD@ config.libcxxabi_shared = @LIBCXXABI_ENABLE_SHARED@ config.cxx_ext_threads = @LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY@ +config.pstl_root = "@ParallelSTL_SOURCE_DIR@" if @LIBCXX_ENABLE_PARALLEL_ALGORITHMS@ else None # Let the main config do the real work. config.loaded_site_config = True diff --git a/test/std/pstl b/test/std/pstl new file mode 120000 index 000000000..27a2822d9 --- /dev/null +++ b/test/std/pstl @@ -0,0 +1 @@ +../../../pstl/test/std \ No newline at end of file diff --git a/utils/libcxx/test/config.py b/utils/libcxx/test/config.py index 82951b765..09ba9cf80 100644 --- a/utils/libcxx/test/config.py +++ b/utils/libcxx/test/config.py @@ -581,6 +581,13 @@ class Configuration(object): support_path = os.path.join(self.libcxx_src_root, 'test/support') self.cxx.compile_flags += ['-I' + support_path] + # Add includes for the PSTL headers + pstl_root = self.get_lit_conf('pstl_root') + if pstl_root is not None: + self.cxx.compile_flags += ['-I' + os.path.join(pstl_root, 'include')] + self.cxx.compile_flags += ['-I' + os.path.join(pstl_root, 'test')] + self.config.available_features.add('parallel-algorithms') + # FIXME(EricWF): variant_size.pass.cpp requires a slightly larger # template depth with older Clang versions. self.cxx.addFlagIfSupported('-ftemplate-depth=270')