diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -490,6 +490,20 @@ set(LIBCXX_DEBUG_BUILD OFF) endif() +# PSTL Configuration =========================================================== +if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + get_target_property(LIBCXXABI_PSTL_INCLUDE_DIRS pstl::ParallelSTL INTERFACE_INCLUDE_DIRECTORIES) + list(POP_FRONT LIBCXXABI_PSTL_INCLUDE_DIRS LIBCXX_PSTL_SOURCE_DIR LIBCXX_PSTL_GENERATED_SOURCE_DIR) + + string(LENGTH ${LIBCXX_PSTL_SOURCE_DIR} length) + math(EXPR length "${length} - 19") + string(SUBSTRING ${LIBCXX_PSTL_SOURCE_DIR} 18 ${length} LIBCXX_PSTL_SOURCE_DIR) + + string(LENGTH ${LIBCXX_PSTL_GENERATED_SOURCE_DIR} length) + math(EXPR length "${length} - 19") + string(SUBSTRING ${LIBCXX_PSTL_GENERATED_SOURCE_DIR} 18 ${length} LIBCXX_PSTL_GENERATED_SOURCE_DIR) +endif() + #=============================================================================== # Setup Compiler Flags #=============================================================================== diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -801,6 +801,48 @@ wctype.h ) +set(pstl_files + __pstl_algorithm + __pstl_execution + __pstl_memory + __pstl_numeric + pstl/internal/omp/parallel_for_each.h + pstl/internal/omp/parallel_for.h + pstl/internal/omp/parallel_invoke.h + pstl/internal/omp/parallel_merge.h + pstl/internal/omp/parallel_reduce.h + pstl/internal/omp/parallel_scan.h + pstl/internal/omp/parallel_stable_partial_sort.h + pstl/internal/omp/parallel_stable_sort.h + pstl/internal/omp/parallel_transform_reduce.h + pstl/internal/omp/parallel_transform_scan.h + pstl/internal/omp/util.h + pstl/internal/algorithm_fwd.h + pstl/internal/algorithm_impl.h + pstl/internal/execution_defs.h + pstl/internal/execution_impl.h + pstl/internal/glue_algorithm_defs.h + pstl/internal/glue_algorithm_impl.h + pstl/internal/glue_execution_defs.h + pstl/internal/glue_memory_defs.h + pstl/internal/glue_memory_impl.h + pstl/internal/glue_numeric_defs.h + pstl/internal/glue_numeric_impl.h + pstl/internal/memory_impl.h + pstl/internal/numeric_fwd.h + pstl/internal/numeric_impl.h + pstl/internal/parallel_backend_omp.h + pstl/internal/parallel_backend_serial.h + pstl/internal/parallel_backend_tbb.h + pstl/internal/parallel_backend_utils.h + pstl/internal/parallel_backend.h + pstl/internal/parallel_impl.h + pstl/internal/pstl_config.h + pstl/internal/undef_macros.h + pstl/internal/unseq_backend_simd.h + pstl/internal/utils.h + ) + foreach(feature LIBCXX_ENABLE_FILESYSTEM LIBCXX_ENABLE_LOCALIZATION LIBCXX_ENABLE_THREADS LIBCXX_ENABLE_WIDE_CHARACTERS) if (NOT ${${feature}}) set(requires_${feature} "requires LIBCXX_CONFIGURED_WITHOUT_SUPPORT_FOR_THIS_HEADER") @@ -822,6 +864,27 @@ list(APPEND _all_includes "${dst}") endforeach() +if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + message(STATUS "Copying PSTL files") + foreach(f ${pstl_files}) + set(src ${LIBCXX_PSTL_SOURCE_DIR}/${f}) + set(dst ${LIBCXX_GENERATED_INCLUDE_DIR}/${f}) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying PSTL header ${f}") + list(APPEND _all_includes ${dst}) + endforeach() + + set(src ${LIBCXX_PSTL_GENERATED_SOURCE_DIR}/__pstl_config_site) + set(dst ${LIBCXX_GENERATED_INCLUDE_DIR}/__pstl_config_site) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying PSTL header ${f}") + list(APPEND _all_includes ${dst}) +endif() + add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes}) add_library(cxx-headers INTERFACE) diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -1913,7 +1913,9 @@ #endif #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 -# include <__pstl_algorithm> +// TODO: Remove this include once we fix transitive includes of +# include <__functional/not_fn.h> +# include <__pstl_algorithm> #endif #endif // _LIBCPP_ALGORITHM diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -532,7 +532,6 @@ #include #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# include # include # include #endif diff --git a/libcxx/test/libcxx/clang_tidy.sh.cpp b/libcxx/test/libcxx/clang_tidy.sh.cpp --- a/libcxx/test/libcxx/clang_tidy.sh.cpp +++ b/libcxx/test/libcxx/clang_tidy.sh.cpp @@ -8,6 +8,8 @@ // REQUIRES: has-clang-tidy +// XFAIL: with-pstl + // TODO: run clang-tidy with modules enabled once they are supported // RUN: clang-tidy %s --warnings-as-errors=* -header-filter=.* --config-file=%S/../../.clang-tidy -- -Wweak-vtables -Wno-unknown-warning-option %{compile_flags} -fno-modules // -Wno-unknown-warning-option tells clang-tidy to ignore '-W' command-line arguments that it doesn't know. diff --git a/libcxx/test/libcxx/min_max_macros.compile.pass.cpp b/libcxx/test/libcxx/min_max_macros.compile.pass.cpp --- a/libcxx/test/libcxx/min_max_macros.compile.pass.cpp +++ b/libcxx/test/libcxx/min_max_macros.compile.pass.cpp @@ -12,6 +12,8 @@ // The system-provided seems to be broken on AIX // XFAIL: LIBCXX-AIX-FIXME +// XFAIL: with-pstl + // Prevent from generating deprecated warnings for this test. #if defined(__DEPRECATED) # undef __DEPRECATED diff --git a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp --- a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp +++ b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp @@ -12,6 +12,8 @@ // The system-provided seems to be broken on AIX // XFAIL: LIBCXX-AIX-FIXME +// XFAIL: with-pstl + // Prevent from generating deprecated warnings for this test. #if defined(__DEPRECATED) # undef __DEPRECATED diff --git a/libcxx/test/libcxx/transitive_includes/expected.unordered_map b/libcxx/test/libcxx/transitive_includes/expected.unordered_map --- a/libcxx/test/libcxx/transitive_includes/expected.unordered_map +++ b/libcxx/test/libcxx/transitive_includes/expected.unordered_map @@ -1,4 +1,3 @@ -algorithm atomic bit chrono diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml --- a/libcxx/utils/ci/buildkite-pipeline.yml +++ b/libcxx/utils/ci/buildkite-pipeline.yml @@ -392,6 +392,19 @@ limit: 2 timeout_in_minutes: 120 + - label: "With PSTL support" + command: "libcxx/utils/ci/run-buildbot with-pstl" + artifact_paths: + - "**/test-results.xml" + agents: + queue: "libcxx-builders" + os: "linux" + retry: + automatic: + - exit_status: -1 # Agent was lost + limit: 2 + timeout_in_minutes: 120 + - label: "No transitive includes" command: "libcxx/utils/ci/run-buildbot generic-no-transitive-includes" artifact_paths: diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot --- a/libcxx/utils/ci/run-buildbot +++ b/libcxx/utils/ci/run-buildbot @@ -92,7 +92,7 @@ function generate-cmake() { generate-cmake-base \ - -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \ + -DLLVM_ENABLE_RUNTIMES="pstl;libcxx;libcxxabi;libunwind" \ -DLIBCXX_CXX_ABI=libcxxabi \ "${@}" } @@ -369,6 +369,15 @@ generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-abi-unstable.cmake" check-runtimes ;; +with-pstl) + clean + generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx20.cmake" \ + -DLIBCXX_TEST_CONFIG="llvm-libc++-with-pstl.cfg.in" \ + -DLIBUNWIND_TEST_CONFIG="llvm-libunwind-shared.cfg.in" \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE \ + -DLIBCXX_ENABLE_PARALLEL_ALGORITHMS=ON + check-runtimes +;; apple-system) clean diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -197,6 +197,7 @@ '_LIBCPP_HAS_NO_WIDE_CHARACTERS': 'no-wide-characters', '_LIBCPP_HAS_NO_UNICODE': 'libcpp-has-no-unicode', '_LIBCPP_ENABLE_DEBUG_MODE': 'libcpp-has-debug-mode', + '_LIBCPP_HAS_PARALLEL_ALGORITHMS': 'with-pstl', } for macro, feature in macros.items(): DEFAULT_FEATURES.append( diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -160,6 +160,9 @@ # Build the shared library. add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) +if (TARGET pstl::ParallelSTL) + target_link_libraries(cxxabi_shared_objects PUBLIC pstl::ParallelSTL) +endif() if (LIBCXXABI_USE_LLVM_UNWINDER) if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY) target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements @@ -235,6 +238,9 @@ # Build the static library. add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS}) +if (TARGET pstl::ParallelSTL) + target_link_libraries(cxxabi_static_objects PUBLIC pstl::ParallelSTL) +endif() if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY) target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements target_sources(cxxabi_static_objects PUBLIC $) diff --git a/pstl/include/pstl/internal/algorithm_impl.h b/pstl/include/pstl/internal/algorithm_impl.h --- a/pstl/include/pstl/internal/algorithm_impl.h +++ b/pstl/include/pstl/internal/algorithm_impl.h @@ -536,7 +536,7 @@ template _ForwardIterator -__pattern_find_if(_Tag __tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, +__pattern_find_if(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) noexcept { return __internal::__brick_find_if(__first, __last, __pred, typename _Tag::__is_vector{}); diff --git a/pstl/include/pstl/internal/undef_macros.h b/pstl/include/pstl/internal/undef_macros.h new file mode 100644 --- /dev/null +++ b/pstl/include/pstl/internal/undef_macros.h @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifdef min +# undef min +#endif + +#ifdef max +# undef max +#endif diff --git a/pstl/include/pstl/internal/utils.h b/pstl/include/pstl/internal/utils.h --- a/pstl/include/pstl/internal/utils.h +++ b/pstl/include/pstl/internal/utils.h @@ -24,6 +24,7 @@ auto __except_handler(_Fp __f) -> decltype(__f()) { +#if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L try { return __f(); @@ -36,6 +37,9 @@ { std::terminate(); // Good bye according to the standard [algorithms.parallel.exceptions] } +#else + return __f(); +#endif // defined(__cpp_exceptions) && __cpp_exceptions >= 199711L } template diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -15,7 +15,7 @@ # We order libraries to mirror roughly how they are layered, except that compiler-rt can depend # on libc++, so we put it after. -set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp") +set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;pstl;libcxxabi;libcxx;compiler-rt;openmp") set(LLVM_ALL_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc") set(LLVM_ENABLE_RUNTIMES "" CACHE STRING "Semicolon-separated list of runtimes to build (${LLVM_ALL_RUNTIMES}), or \"all\".")