[libcxx-commits] [libcxx] [libc++][pstl] Statpart backend is unconditionally used when threading is enabled (PR #237177)
Michael G. Kazakov via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 30 05:00:50 PDT 2026
https://github.com/mikekazakov updated https://github.com/llvm/llvm-project/pull/237177
>From e480cb6f5e9fe669b750ec75e8cc6f32e2557ef4 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Fri, 30 Oct 2026 11:24:35 +0000
Subject: [PATCH 1/2] Removed PSTL knobs from CMake, statpart is
unconditionally used when threading is enabled
---
libcxx/CMakeLists.txt | 23 -------------------
libcxx/include/__config_site.in | 6 -----
libcxx/include/__pstl/backend.h | 14 +++--------
libcxx/include/__pstl/backend_fwd.h | 17 +++-----------
libcxx/src/CMakeLists.txt | 7 +-----
.../apple/system-install-properties.sh.cpp | 4 ----
.../pstl.statpart.partition.pass.cpp | 1 -
.../apple/system-install-properties.sh.cpp | 4 ----
.../libcxx/test/features/libcxx_macros.py | 2 --
9 files changed, 7 insertions(+), 71 deletions(-)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index ff6f8d1593fe2c..befd8dad924da6 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -321,16 +321,6 @@ option(LIBCXX_HAS_EXTERNAL_THREAD_API
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
option(LIBCXX_HAS_C11_THREAD_API "Ignore auto-detection and force use of C11 thread API" OFF)
-if (APPLE)
- set(LIBCXX_PSTL_BACKEND_DEFAULT_VALUE "libdispatch")
-elseif(LIBCXX_ENABLE_THREADS)
- set(LIBCXX_PSTL_BACKEND_DEFAULT_VALUE "std_thread")
-else()
- set(LIBCXX_PSTL_BACKEND_DEFAULT_VALUE "serial")
-endif()
-
-set(LIBCXX_PSTL_BACKEND "${LIBCXX_PSTL_BACKEND_DEFAULT_VALUE}" CACHE STRING "Which PSTL backend to use")
-
# Misc options ----------------------------------------------------------------
# FIXME: Turn -pedantic back ON. It is currently off because it warns
# about #include_next which is used everywhere.
@@ -799,19 +789,6 @@ elseif (LIBCXX_ASSERTION_SEMANTIC STREQUAL "enforce")
config_define(32 _LIBCPP_ASSERTION_SEMANTIC_DEFAULT)
endif()
-if (LIBCXX_PSTL_BACKEND STREQUAL "serial")
- config_define(1 _LIBCPP_PSTL_BACKEND_SERIAL)
-elseif(LIBCXX_PSTL_BACKEND STREQUAL "std_thread")
- config_define(1 _LIBCPP_PSTL_BACKEND_STD_THREAD)
-elseif(LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
- config_define(1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH)
-elseif(LIBCXX_PSTL_BACKEND STREQUAL "statpart")
- config_define(1 _LIBCPP_PSTL_BACKEND_STATPART)
-else()
- message(FATAL_ERROR "LIBCXX_PSTL_BACKEND is set to ${LIBCXX_PSTL_BACKEND}, which is not a valid backend.
- Valid backends are: serial, std_thread, libdispatch and statpart")
-endif()
-
if (LIBCXX_ABI_DEFINES)
set(abi_defines)
foreach (abi_define ${LIBCXX_ABI_DEFINES})
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index b003f1c2ddc49a..693a4b089a360e 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -33,12 +33,6 @@
#cmakedefine01 _LIBCPP_HAS_TIME_ZONE_DATABASE
#cmakedefine01 _LIBCPP_INSTRUMENTED_WITH_ASAN
-// PSTL backends
-#cmakedefine _LIBCPP_PSTL_BACKEND_SERIAL
-#cmakedefine _LIBCPP_PSTL_BACKEND_STD_THREAD
-#cmakedefine _LIBCPP_PSTL_BACKEND_LIBDISPATCH
-#cmakedefine _LIBCPP_PSTL_BACKEND_STATPART
-
// Hardening.
#cmakedefine _LIBCPP_HARDENING_MODE_DEFAULT @_LIBCPP_HARDENING_MODE_DEFAULT@
#cmakedefine _LIBCPP_ASSERTION_SEMANTIC_DEFAULT @_LIBCPP_ASSERTION_SEMANTIC_DEFAULT@
diff --git a/libcxx/include/__pstl/backend.h b/libcxx/include/__pstl/backend.h
index aa01dcb5cf19a0..33081bdf3a6dad 100644
--- a/libcxx/include/__pstl/backend.h
+++ b/libcxx/include/__pstl/backend.h
@@ -21,21 +21,13 @@ _LIBCPP_PUSH_MACROS
#if _LIBCPP_STD_VER >= 17
-# if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
+# if _LIBCPP_HAS_THREADS
# include <__pstl/backends/default.h>
# include <__pstl/backends/serial.h>
-# elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
-# include <__pstl/backends/default.h>
-# include <__pstl/backends/serial.h>
-# include <__pstl/backends/std_thread.h>
-# elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
-# include <__pstl/backends/default.h>
-# include <__pstl/backends/libdispatch.h>
-# include <__pstl/backends/serial.h>
-# elif defined(_LIBCPP_PSTL_BACKEND_STATPART)
+# include <__pstl/backends/statpart.h>
+# else // ...New vendors can add parallel backends here...
# include <__pstl/backends/default.h>
# include <__pstl/backends/serial.h>
-# include <__pstl/backends/statpart.h>
# endif
#endif // _LIBCPP_STD_VER >= 17
diff --git a/libcxx/include/__pstl/backend_fwd.h b/libcxx/include/__pstl/backend_fwd.h
index 184d2b6df1dd1d..4f2823a2340d01 100644
--- a/libcxx/include/__pstl/backend_fwd.h
+++ b/libcxx/include/__pstl/backend_fwd.h
@@ -53,22 +53,11 @@ struct __serial_backend_tag;
struct __std_thread_backend_tag;
struct __statpart_backend_tag;
-# if defined(_LIBCPP_PSTL_BACKEND_SERIAL)
-using __current_configuration _LIBCPP_NODEBUG = __backend_configuration<__serial_backend_tag, __default_backend_tag>;
-# elif defined(_LIBCPP_PSTL_BACKEND_STD_THREAD)
-using __current_configuration _LIBCPP_NODEBUG =
- __backend_configuration<__std_thread_backend_tag, __default_backend_tag, __serial_backend_tag>;
-# elif defined(_LIBCPP_PSTL_BACKEND_LIBDISPATCH)
-using __current_configuration _LIBCPP_NODEBUG =
- __backend_configuration<__libdispatch_backend_tag, __default_backend_tag, __serial_backend_tag>;
-# elif defined(_LIBCPP_PSTL_BACKEND_STATPART)
+# if _LIBCPP_HAS_THREADS
using __current_configuration _LIBCPP_NODEBUG =
__backend_configuration<__statpart_backend_tag, __default_backend_tag, __serial_backend_tag>;
-# else
-
-// ...New vendors can add parallel backends here...
-
-# error "Invalid PSTL backend configuration"
+# else // ...New vendors can add parallel backends here...
+using __current_configuration _LIBCPP_NODEBUG = __backend_configuration<__serial_backend_tag, __default_backend_tag>;
# endif
template <class _Backend, class _ExecutionPolicy>
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 770b9ffa21d8b2..8960e052435718 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -308,6 +308,7 @@ endif()
set(LIBCXX_EXPERIMENTAL_SOURCES
experimental/keep.cpp
experimental/log_hardening_failure.cpp
+ pstl/statpart.cpp
)
if (LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
@@ -316,12 +317,6 @@ if (LIBCXX_PSTL_BACKEND STREQUAL "libdispatch")
)
endif()
-if (LIBCXX_PSTL_BACKEND STREQUAL "statpart")
- list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
- pstl/statpart.cpp
- )
-endif()
-
if (LIBCXX_ENABLE_LOCALIZATION AND LIBCXX_ENABLE_FILESYSTEM AND LIBCXX_ENABLE_TIME_ZONE_DATABASE)
list(APPEND LIBCXX_EXPERIMENTAL_SOURCES
experimental/include/tzdb/time_zone_private.h
diff --git a/libcxx/test/libcxx-03/vendor/apple/system-install-properties.sh.cpp b/libcxx/test/libcxx-03/vendor/apple/system-install-properties.sh.cpp
index eeae4fc0a3c003..abe311396bbbb4 100644
--- a/libcxx/test/libcxx-03/vendor/apple/system-install-properties.sh.cpp
+++ b/libcxx/test/libcxx-03/vendor/apple/system-install-properties.sh.cpp
@@ -40,7 +40,3 @@
// when they are loaded by dyld, if the compatibility version was bumped.
//
// RUN: otool -L "%{lib-dir}/libc++.1.dylib" | grep "libc++.1.dylib" | grep "compatibility version 1.0.0"
-
-// Make sure we use the libdispatch backend for the PSTL.
-//
-// RUN: grep "%{include-dir}/__config_site" -e '#define _LIBCPP_PSTL_BACKEND_LIBDISPATCH'
diff --git a/libcxx/test/libcxx/algorithms/pstl.statpart.partition.pass.cpp b/libcxx/test/libcxx/algorithms/pstl.statpart.partition.pass.cpp
index 457d97a39831de..f487b742ed71e1 100644
--- a/libcxx/test/libcxx/algorithms/pstl.statpart.partition.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/pstl.statpart.partition.pass.cpp
@@ -9,7 +9,6 @@
// <algorithm>
// REQUIRES: std-at-least-c++17
-// REQUIRES: libcpp-pstl-backend-statpart
// UNSUPPORTED: libcpp-has-no-incomplete-pstl
// template <class Iterator>
diff --git a/libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp b/libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp
index eeae4fc0a3c003..abe311396bbbb4 100644
--- a/libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp
+++ b/libcxx/test/libcxx/vendor/apple/system-install-properties.sh.cpp
@@ -40,7 +40,3 @@
// when they are loaded by dyld, if the compatibility version was bumped.
//
// RUN: otool -L "%{lib-dir}/libc++.1.dylib" | grep "libc++.1.dylib" | grep "compatibility version 1.0.0"
-
-// Make sure we use the libdispatch backend for the PSTL.
-//
-// RUN: grep "%{include-dir}/__config_site" -e '#define _LIBCPP_PSTL_BACKEND_LIBDISPATCH'
diff --git a/libcxx/utils/libcxx/test/features/libcxx_macros.py b/libcxx/utils/libcxx/test/features/libcxx_macros.py
index 67531098972746..cf1549fd0e5580 100644
--- a/libcxx/utils/libcxx/test/features/libcxx_macros.py
+++ b/libcxx/utils/libcxx/test/features/libcxx_macros.py
@@ -33,8 +33,6 @@
"_LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE": "libcpp-has-abi-fix-unordered-container-size-type",
"_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR": "libcpp-deprecated-abi-disable-pair-trivial-copy-ctor",
"_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING": "libcpp-abi-no-compressed-pair-padding",
- "_LIBCPP_PSTL_BACKEND_LIBDISPATCH": "libcpp-pstl-backend-libdispatch",
- "_LIBCPP_PSTL_BACKEND_STATPART": "libcpp-pstl-backend-statpart",
"_LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE": "libcpp-abi-use-small-deque-block-size",
"_LIBCPP_ABI_COMPACT_LOCALE_ID": "libcpp-abi-compact-locale-id",
}
>From 57c8a41eecad74978eba203a03385789926bcd95 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Fri, 30 Oct 2026 12:00:33 +0000
Subject: [PATCH 2/2] Fixed a variable shadowing, added a missing include
---
libcxx/include/__pstl/backends/statpart/basis.h | 4 ++--
libcxx/include/__pstl/backends/statpart/for_each.h | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__pstl/backends/statpart/basis.h b/libcxx/include/__pstl/backends/statpart/basis.h
index a678d5c3e5a181..9c65b81129b309 100644
--- a/libcxx/include/__pstl/backends/statpart/basis.h
+++ b/libcxx/include/__pstl/backends/statpart/basis.h
@@ -188,8 +188,8 @@ _LIBCPP_HIDE_FROM_ABI void __for_each_partition(const __iterator_partitions<_Ite
struct __ctx_t {
const __iterator_partitions<_Iterator>& __partitions_;
_Functor& __func_;
- } __ctx{__partitions, __func};
- __statpart::__apply(__partitions.__partitions_count(), &__ctx, [](void* __context, size_t __partition) {
+ } __apply_ctx{__partitions, __func};
+ __statpart::__apply(__partitions.__partitions_count(), &__apply_ctx, [](void* __context, size_t __partition) {
__ctx_t& __ctx = *static_cast<__ctx_t*>(__context);
auto __range = __ctx.__partitions_.__partition(__partition);
__ctx.__func_(__range.__first, __range.__last);
diff --git a/libcxx/include/__pstl/backends/statpart/for_each.h b/libcxx/include/__pstl/backends/statpart/for_each.h
index b1004231c0f7dc..5f1245003afc04 100644
--- a/libcxx/include/__pstl/backends/statpart/for_each.h
+++ b/libcxx/include/__pstl/backends/statpart/for_each.h
@@ -10,6 +10,7 @@
#define _LIBCPP___PSTL_BACKENDS_STATPART_FOR_EACH_H
#include <__algorithm/for_each.h>
+#include <__assert>
#include <__config>
#include <__execution/is_execution_policy.h>
#include <__iterator/concepts.h>
More information about the libcxx-commits
mailing list