diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -114,7 +114,11 @@ endif() else() if (LIBCXX_ENABLE_SHARED) - set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in") + if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-with-pstl.cfg.in") + else() + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in") + endif() else() set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in") endif() @@ -490,6 +494,12 @@ set(LIBCXX_DEBUG_BUILD OFF) endif() +# PSTL Configuration =========================================================== +if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + get_target_property(LIBCXX_PSTL_SOURCE_DIR pstl::ParallelSTL SOURCE_DIRECTORY) + get_target_property(LIBCXX_PSTL_GENERATED_SOURCE_DIR pstl::ParallelSTL GENERATED_DIRECTORY) +endif() + #=============================================================================== # Setup Compiler Flags #=============================================================================== diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -774,7 +774,7 @@ set_symmetric_difference(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // since C++20 - + template requires mergeable, iterator_t, O, Comp, Proj1, Proj2> @@ -787,13 +787,13 @@ indirect_strict_weak_order> Comp = ranges::less> constexpr subrange equal_range(I first, S last, const T& value, Comp comp = {}, Proj proj = {}); // since C++20 - + template, Proj>> Comp = ranges::less> constexpr borrowed_subrange_t equal_range(R&& r, const T& value, Comp comp = {}, Proj proj = {}); // since C++20 - + template using set_union_result = in_in_out_result; // since C++20 @@ -818,7 +818,7 @@ ranges::less> constexpr bool includes(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); // Since C++20 - + template, Proj1>, @@ -1669,7 +1669,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/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -186,6 +186,7 @@ endif() function(cxx_set_common_defines name) +# PSTL configuration =========================================================== if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) target_link_libraries(${name} PUBLIC pstl::ParallelSTL) endif() diff --git a/libcxx/test/configs/cmake-bridge.cfg.in b/libcxx/test/configs/cmake-bridge.cfg.in --- a/libcxx/test/configs/cmake-bridge.cfg.in +++ b/libcxx/test/configs/cmake-bridge.cfg.in @@ -27,6 +27,8 @@ config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@'))) config.substitutions.append(('%{libcxx}', '@LIBCXX_SOURCE_DIR@')) config.substitutions.append(('%{include}', '@LIBCXX_GENERATED_INCLUDE_DIR@')) +config.substitutions.append(('%{pstl-include}', '@LIBCXX_PSTL_SOURCE_DIR@')) +config.substitutions.append(('%{pstl-generated-include}', '@LIBCXX_PSTL_GENERATED_SOURCE_DIR@')) config.substitutions.append(('%{target-include}', '@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@')) config.substitutions.append(('%{lib}', '@LIBCXX_LIBRARY_DIR@')) config.substitutions.append(('%{executor}', '@LIBCXX_EXECUTOR@')) diff --git a/libcxx/test/configs/llvm-libc++-with-pstl.cfg.in b/libcxx/test/configs/llvm-libc++-with-pstl.cfg.in new file mode 100644 --- /dev/null +++ b/libcxx/test/configs/llvm-libc++-with-pstl.cfg.in @@ -0,0 +1,27 @@ +# This testing configuration handles running the test suite against LLVM's libc++ +# using a shared library. + +lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') + +config.substitutions.append(('%{flags}', + '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else '' +)) +config.substitutions.append(('%{compile_flags}', + '-nostdinc++ -I %{include} -I %{target-include} -I %{pstl-include} -I %{pstl-generated-include} -I %{libcxx}/test/support' +)) +config.substitutions.append(('%{link_flags}', + '-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread' +)) +config.substitutions.append(('%{exec}', + '%{executor} --execdir %T -- ' +)) + +import os, site +site.addsitedir(os.path.join('@LIBCXX_SOURCE_DIR@', 'utils')) +import libcxx.test.params, libcxx.test.newconfig +libcxx.test.newconfig.configure( + libcxx.test.params.DEFAULT_PARAMETERS, + libcxx.test.features.DEFAULT_FEATURES, + config, + lit_config +) 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 @@ -190,6 +190,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/CMakeLists.txt b/libcxxabi/CMakeLists.txt --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -155,7 +155,11 @@ endif() else() if (LIBCXXABI_ENABLE_SHARED) - set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared.cfg.in") + if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-with-pstl.cfg.in") + else() + set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-shared.cfg.in") + endif() else() set(LIBCXXABI_DEFAULT_TEST_CONFIG "llvm-libc++abi-static.cfg.in") endif() @@ -232,6 +236,12 @@ # Include macros for adding and removing libc++abi flags. include(HandleLibcxxabiFlags) +# PSTL Configuration =========================================================== +if (LIBCXX_ENABLE_PARALLEL_ALGORITHMS) + get_target_property(LIBCXXABI_PSTL_SOURCE_DIR pstl::ParallelSTL SOURCE_DIRECTORY) + get_target_property(LIBCXXABI_PSTL_GENERATED_SOURCE_DIR pstl::ParallelSTL GENERATED_DIRECTORY) +endif() + #=============================================================================== # Setup Compiler Flags #=============================================================================== 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/libcxxabi/test/configs/cmake-bridge.cfg.in b/libcxxabi/test/configs/cmake-bridge.cfg.in --- a/libcxxabi/test/configs/cmake-bridge.cfg.in +++ b/libcxxabi/test/configs/cmake-bridge.cfg.in @@ -31,6 +31,8 @@ config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include')) config.substitutions.append(('%{cxx-include}', '@LIBCXXABI_HEADER_DIR@/include/c++/v1')) config.substitutions.append(('%{cxx-target-include}', '@LIBCXXABI_HEADER_DIR@/include/%{triple}/c++/v1')) +config.substitutions.append(('%{pstl-include}', '@LIBCXXABI_PSTL_SOURCE_DIR@')) +config.substitutions.append(('%{pstl-generated-include}', '@LIBCXXABI_PSTL_GENERATED_SOURCE_DIR@')) config.substitutions.append(('%{lib}', '@LIBCXXABI_LIBRARY_DIR@')) config.substitutions.append(('%{executor}', '@LIBCXXABI_EXECUTOR@')) diff --git a/libcxxabi/test/configs/llvm-libc++abi-with-pstl.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-with-pstl.cfg.in new file mode 100644 --- /dev/null +++ b/libcxxabi/test/configs/llvm-libc++abi-with-pstl.cfg.in @@ -0,0 +1,27 @@ +# This testing configuration handles running the test suite against LLVM's libc++abi +# using a shared library. + +lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg') + +config.substitutions.append(('%{flags}', + '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else '' +)) +config.substitutions.append(('%{compile_flags}', + '-nostdinc++ -I %{include} -I %{pstl-include} -I %{pstl-generated-include} -I %{cxx-include} -I %{cxx-target-include} %{maybe-include-libunwind} -I %{libcxx}/test/support -I %{libcxx}/src -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS' +)) +config.substitutions.append(('%{link_flags}', + '-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -lc++abi -pthread' +)) +config.substitutions.append(('%{exec}', + '%{executor} --execdir %T -- ' +)) + +import os, site +site.addsitedir(os.path.join('@LIBCXXABI_LIBCXX_PATH@', 'utils')) +import libcxx.test.params, libcxx.test.newconfig +libcxx.test.newconfig.configure( + libcxx.test.params.DEFAULT_PARAMETERS, + libcxx.test.features.DEFAULT_FEATURES, + config, + lit_config +) diff --git a/pstl/CMakeLists.txt b/pstl/CMakeLists.txt --- a/pstl/CMakeLists.txt +++ b/pstl/CMakeLists.txt @@ -66,6 +66,11 @@ $ $) +set_target_properties(ParallelSTL PROPERTIES + SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include + GENERATED_DIRECTORY ${PSTL_GENERATED_HEADERS_DIR} + ) + ############################################################################### # Setup tests ############################################################################### 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\".")