diff --git a/libcxx/cmake/caches/With-pstl.cmake b/libcxx/cmake/caches/With-pstl.cmake new file mode 100644 --- /dev/null +++ b/libcxx/cmake/caches/With-pstl.cmake @@ -0,0 +1,3 @@ +set(LIBCXX_TEST_PARAMS "std=c++17" CACHE STRING "") +set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "") +set(LIBCXX_ENABLE_PARALLEL_ALGORITHMS ON CACHE BOOL "") diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -1908,6 +1908,8 @@ #endif #if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 +// TODO: Remove this include once we fix transitive includes of +# include <__functional/not_fn.h> # include <__pstl_algorithm> #endif diff --git a/libcxx/test/libcxx/clang_query.sh.cpp b/libcxx/test/libcxx/clang_query.sh.cpp --- a/libcxx/test/libcxx/clang_query.sh.cpp +++ b/libcxx/test/libcxx/clang_query.sh.cpp @@ -13,6 +13,8 @@ // The attributes hide_from_abi_of_visible.query relies on aren't applied on windows. // XFAIL: windows +// XFAIL: with-pstl + // RUN: clang-query -f %S/clang_query/hide_from_abi_or_visible.query %s --use-color -- -Wno-unknown-warning-option %{compile_flags} -fno-modules > %t.output // RUN: cat %t.output // RUN: cat %t.output | wc -l | grep -Fxq 1 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 @@ -11,6 +11,8 @@ // The GCC compiler flags are not always compatible with clang-tidy. // UNSUPPORTED: gcc +// XFAIL: with-pstl + // TODO: run clang-tidy with modules enabled once they are supported // RUN: clang-tidy %s --warnings-as-errors=* -header-filter=.* --checks='-*,libcpp-*' --load=%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin -- %{compile_flags} -fno-modules // RUN: clang-tidy %s --warnings-as-errors=* -header-filter=.* --config-file=%S/../../.clang-tidy -- -Wweak-vtables %{compile_flags} -fno-modules 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.sh.cpp b/libcxx/test/libcxx/transitive_includes.sh.cpp --- a/libcxx/test/libcxx/transitive_includes.sh.cpp +++ b/libcxx/test/libcxx/transitive_includes.sh.cpp @@ -35,6 +35,8 @@ // this test instead. // UNSUPPORTED: transitive-includes-disabled +// XFAIL: with-pstl + // Prevent from generating deprecated warnings for this test. #if defined(__DEPRECATED) # undef __DEPRECATED 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 @@ -436,6 +436,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 @@ -107,7 +107,7 @@ function generate-cmake() { generate-cmake-base \ - -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \ + -DLLVM_ENABLE_RUNTIMES="pstl;libcxx;libcxxabi;libunwind" \ -DLIBCXX_CXX_ABI=libcxxabi \ "${@}" } @@ -439,6 +439,11 @@ check-runtimes check-abi-list ;; +with-pstl) + clean + generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/With-pstl.cmake" + 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 @@ -211,6 +211,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 @@ -246,6 +249,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/CMakeLists.txt b/pstl/CMakeLists.txt --- a/pstl/CMakeLists.txt +++ b/pstl/CMakeLists.txt @@ -31,6 +31,8 @@ endif() endif() +option(PSTL_INSTALL_HEADERS "Install the pstl headers." ON) + ############################################################################### # Setup the ParallelSTL library target ############################################################################### @@ -56,15 +58,28 @@ set(PSTL_GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_headers") set(PSTL_CONFIG_SITE_PATH "${PSTL_GENERATED_HEADERS_DIR}/__pstl_config_site") -configure_file("include/__pstl_config_site.in" - "${PSTL_CONFIG_SITE_PATH}" - @ONLY) -target_include_directories(ParallelSTL - INTERFACE - $ - $ - $) +set(PSTL_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE PATH + "Path where target-agnostic pstl headers should be installed.") + +if (LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(PSTL_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(PSTL_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") + set(PSTL_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific pstl headers should be installed.") +else() + if(LLVM_LIBRARY_OUTPUT_INTDIR) + set(PSTL_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + else() + set(PSTL_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(PSTL_GENERATED_INCLUDE_TARGET_DIR "${PSTL_GENERATED_INCLUDE_DIR}") + set(PSTL_INSTALL_INCLUDE_TARGET_DIR "${PSTL_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific pstl headers should be installed.") +endif() + +add_subdirectory(include) +target_link_libraries(pstl-headers) ############################################################################### # Setup tests @@ -92,11 +107,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake" DESTINATION lib/cmake/ParallelSTL) -install(DIRECTORY include/ - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - PATTERN "*.in" EXCLUDE) -install(FILES "${PSTL_CONFIG_SITE_PATH}" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") add_custom_target(install-pstl + DEPENDS install-pstl-headers COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL) diff --git a/pstl/include/CMakeLists.txt b/pstl/include/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/pstl/include/CMakeLists.txt @@ -0,0 +1,85 @@ +set(files + __pstl_algorithm + __pstl_execution + __pstl_memory + __pstl_numeric + 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/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/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/unseq_backend_simd.h + pstl/internal/utils.h + ) + +configure_file("__pstl_config_site.in" "${PSTL_GENERATED_INCLUDE_TARGET_DIR}/__pstl_config_site" @ONLY) + +set(_all_includes "${PSTL_GENERATED_INCLUDE_TARGET_DIR}/__pstl_config_site") + +foreach(file ${files}) + set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}") + set(dst "${PSTL_GENERATED_INCLUDE_DIR}/${file}") + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying PSTL header ${file}") + list(APPEND _all_includes "${dst}") +endforeach() + +add_custom_target(generate-pstl-headers ALL DEPENDS ${_all_includes}) + +add_library(pstl-headers INTERFACE) +target_compile_features(pstl-headers INTERFACE cxx_std_17) + +add_dependencies(pstl-headers generate-pstl-headers) +target_include_directories(pstl-headers INTERFACE ${PSTL_GENERATED_INCLUDE_DIR} + ${PSTL_GENERATED_INCLUDE_TARGET_DIR}) + +if (PSTL_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} + DESTINATION "${PSTL_INSTALL_INCLUDE_DIR}/${dir}" + COMPONENT pstl-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) + endforeach() + + install(FILES "${PSTL_GENERATED_INCLUDE_TARGET_DIR}/__pstl_config_site" + DESTINATION "${PSTL_INSTALL_INCLUDE_TARGET_DIR}" + COMPONENT pstl-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) + + add_custom_target(install-pstl-headers + DEPENDS pstl-headers + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=pstl-headers + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + add_custom_target(install-pstl-headers-stripped DEPENDS install-pstl-headers) +endif() 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/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 @@ -22,7 +22,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_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc") set(LLVM_ENABLE_RUNTIMES "" CACHE STRING "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")