[PATCH 2/5] libstdc++: Hardcode _ONEDPL macros from internal oneDPL headers

Jonathan Wakely jwakely@redhat.com
Sat Nov 14 01:57:04 GMT 2026


Define some internal macros based on whether known properties of
libstdc++, instead of via internal oneDPL headers that are not present
in libstdc++.

Rename the user-facing macros ONEDPL_USE_TBB_BACKEND and
ONEDPL_USE_OPENMP_BACKEND to be in the _GLIBCXX namespace. The
non-user-facing macros such as _ONEDPL_TBB_AVAILABLE are not changed,
which mean they would conflict with the macros in the oneDPL project if
a program included both sets of headers. The include guards on the
headers already have that problem. Maybe we should rename all of those
macros to be in our own namespace.

Disable the config for the SYCL backend which has not been tested at
all.

Currently this is consistent with the upstream oneDPL code which prefers
to use the TBB backend if the OpenMP one is not explicitly selected.
That is consistent with past GCC releases, which only supported the TBB
backend. We should consider making OpenMP the default, so that it works
out of the box with libgomp and doesn't require the third-party TBB
library. Programs which use the TBB backend today would need to define
the _GLIBCXX_USE_TBB_PAR_BACKEND macro to continue using that backend.

This change is an ABI break for the std::execution::xxx_policy tag
types, which were previously defined in ::__pstl::execution::v1 and are
now defined in std::__onedpl::_V1. The types are still just empty tag
types, so don't change size or layout, but it's technically a breaking
change if code depends on the mangled names of those types. But the old
names used the non-reserved name "v1" so we need to change that
anyway. We considered the previous pstl implementation to be
experimental, which would allow us to change these types, but I'm not
sure how well we communicated that to users.

With the way that a backend is selected in <pstl/onedpl_config.h> (based
on the availability of TBB and OpenMP and which user-facing macros are
defined) we no longer need the PSTL configuration section in
<bits/c++config.h> which set _GLIBCXX_USE_TBB_PAR_BACKEND automatically.
The <pstl/pstl_config.h> header is no longer used anywhere, but is left
in the tree because it's present in the upstream oneDPL release too.

libstdc++-v3/ChangeLog:

	* include/bits/c++config: Remove PSTL configuration.
	* include/pstl/onedpl_config.h (_ONEDPL_CPP20_CONCEPTS_PRESENT)
	(_ONEDPL_CPP20_RANGES_PRESENT): Define in terms of
	__cpp_concepts.
	(_ONEDPL_STD_FEATURE_MACROS_PRESENT): Define to 1.
	(_ONEDPL___cplusplus): Define to __cplusplus.
	(ONEDPL_USE_TBB_BACKEND): Rename to _GLIBCXX_USE_TBB_PAR_BACKEND.
	(ONEDPL_USE_OPENMP_BACKEND): Rename to
	_GLIBCXX_USE_OPENMP_PAR_BACKEND.
	* include/pstl/parallel_backend.h: Adjust for new macro names.
	* src/c++23/std.cc.in: Adjust TBB suppression.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Use
	new macro.
---
 libstdc++-v3/include/bits/c++config           | 26 -------------------
 libstdc++-v3/include/pstl/onedpl_config.h     | 19 +++++++++++---
 libstdc++-v3/include/pstl/parallel_backend.h  |  4 +--
 libstdc++-v3/src/c++23/std.cc.in              |  6 ++---
 .../pstl/alg_sorting/partial_sort.cc          |  2 +-
 5 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 0c2407ccd07c..00b103d06efc 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -943,32 +943,6 @@ namespace __gnu_cxx
 // Mark code that should be ignored by the compiler, but seen by Doxygen.
 #define _GLIBCXX_DOXYGEN_ONLY(X)
 
-// PSTL configuration
-
-#if __cplusplus >= 201703L
-// This header is not installed for freestanding:
-#if __has_include(<pstl/pstl_config.h>)
-// Preserved here so we have some idea which version of upstream we've pulled in
-// #define PSTL_VERSION 9000
-
-// For now this defaults to being based on the presence of Thread Building Blocks
-# ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
-#  define _GLIBCXX_USE_TBB_PAR_BACKEND __has_include(<tbb/tbb.h>)
-# endif
-// This section will need some rework when a new (default) backend type is added
-# if _GLIBCXX_USE_TBB_PAR_BACKEND
-#  define _PSTL_PAR_BACKEND_TBB
-# else
-#  define _PSTL_PAR_BACKEND_SERIAL
-# endif
-
-# define _PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
-# define _PSTL_ASSERT_MSG(_Condition, _Message) __glibcxx_assert(_Condition)
-
-#include <pstl/pstl_config.h>
-#endif // __has_include
-#endif // C++17
-
 #if __cplusplus >= 201103L && !defined(_GLIBCXX_USE_NEW_PIECEWISE_DISTRIBUTIONS)
 # define _GLIBCXX_USE_NEW_PIECEWISE_DISTRIBUTIONS 1
 #endif
diff --git a/libstdc++-v3/include/pstl/onedpl_config.h b/libstdc++-v3/include/pstl/onedpl_config.h
index 411d30eee9c8..7c1581a3d826 100644
--- a/libstdc++-v3/include/pstl/onedpl_config.h
+++ b/libstdc++-v3/include/pstl/onedpl_config.h
@@ -16,15 +16,22 @@
 #ifndef _ONEDPL_CONFIG_H
 #define _ONEDPL_CONFIG_H
 
-// The version header also defines a few configuration macros used in this file
-#include "../internal/version_impl.h"
+// In oneDPL these are defined by ../internal/version_impl.h but we can
+// hardcode the values based on properties we know to be true.
+#define _ONEDPL_CPP20_CONCEPTS_PRESENT (__cpp_concepts >= 201907L)
+#define _ONEDPL_CPP20_RANGES_PRESENT _ONEDPL_CPP20_CONCEPTS_PRESENT
+#define _ONEDPL_STD_FEATURE_MACROS_PRESENT 1
+// Similarly for this one from ../internal/common_config.h
+#define _ONEDPL___cplusplus __cplusplus
 
 // -- Check availability of parallel backends --
 
+// TODO rename all _ONEDPL_xxx macros to be in our own namespace?
+
 #if __has_include(<tbb/tbb.h>)
 #    define _ONEDPL_TBB_AVAILABLE 1
 #endif
-#if ONEDPL_USE_TBB_BACKEND && !_ONEDPL_TBB_AVAILABLE
+#if _GLIBCXX_USE_TBB_PAR_BACKEND && !_ONEDPL_TBB_AVAILABLE
 #    error "Parallel execution policies with oneTBB or Intel(R) TBB support are enabled, but the library is not found"
 #endif
 
@@ -33,11 +40,13 @@
 #endif
 // During compilation for a device _OPENMP may not be set, so avoid throwing an error if
 // __SYCL_DEVICE_ONLY__ found
-#if ONEDPL_USE_OPENMP_BACKEND && !_ONEDPL_OPENMP_AVAILABLE && !defined(__SYCL_DEVICE_ONLY__)
+#if _GLIBCXX_USE_OPENMP_PAR_BACKEND && !_ONEDPL_OPENMP_AVAILABLE && !defined(__SYCL_DEVICE_ONLY__)
 #    error "Parallel execution policies with OpenMP* support are enabled, \
         but OpenMP headers are not found or the compiler does not support OpenMP"
 #endif
 
+#if 0 // disabled for libstdc++
+
 // -- Check availability of heterogeneous backends --
 
 // If DPCPP backend is explicitly requested, optimistically assume SYCL availability;
@@ -65,6 +74,8 @@
 #    define _ONEDPL_HETERO_BACKEND 1
 #endif
 
+#endif
+
 // -- Configure host backends and common parts --
 
 // Check the user-defined macro for warnings
diff --git a/libstdc++-v3/include/pstl/parallel_backend.h b/libstdc++-v3/include/pstl/parallel_backend.h
index 13433f23fb86..ddf4a6ef7585 100644
--- a/libstdc++-v3/include/pstl/parallel_backend.h
+++ b/libstdc++-v3/include/pstl/parallel_backend.h
@@ -17,10 +17,10 @@
 #include "onedpl_config.h"
 
 // Select a parallel backend
-#if ONEDPL_USE_TBB_BACKEND || (!defined(ONEDPL_USE_TBB_BACKEND) && !ONEDPL_USE_OPENMP_BACKEND && _ONEDPL_TBB_AVAILABLE)
+#if _GLIBCXX_USE_TBB_PAR_BACKEND || (!defined(_GLIBCXX_USE_TBB_PAR_BACKEND) && !_GLIBCXX_USE_OPENMP_PAR_BACKEND && _ONEDPL_TBB_AVAILABLE)
 #    define _ONEDPL_PAR_BACKEND_TBB 1
 #    include "parallel_backend_tbb.h"
-#elif ONEDPL_USE_OPENMP_BACKEND || (!defined(ONEDPL_USE_OPENMP_BACKEND) && _ONEDPL_OPENMP_AVAILABLE)
+#elif _GLIBCXX_USE_OPENMP_PAR_BACKEND || (!defined(_GLIBCXX_USE_OPENMP_PAR_BACKEND) && _ONEDPL_OPENMP_AVAILABLE)
 #    define _ONEDPL_PAR_BACKEND_OPENMP 1
 #    include "parallel_backend_omp.h"
 #else
diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in
index 15349adf1be0..cf99c7665939 100644
--- a/libstdc++-v3/src/c++23/std.cc.in
+++ b/libstdc++-v3/src/c++23/std.cc.in
@@ -27,10 +27,8 @@ module;
 
 // stdc++.h doesn't include <execution> because of TBB issues;
 // FIXME for now let's avoid the problem by suppressing TBB.
-#ifdef _PSTL_PAR_BACKEND_TBB
-#undef _PSTL_PAR_BACKEND_TBB
-#define _PSTL_PAR_BACKEND_SERIAL
-#endif
+#undef _GLIBCXX_USE_TBB_PAR_BACKEND
+#define _GLIBCXX_USE_TBB_PAR_BACKEND 0
 #include <execution>
 
 // Module std does include deprecated library interfaces.
diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
index 797d0ee9340c..53f8a861c47a 100644
--- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc
@@ -92,7 +92,7 @@ struct test_brick_partial_sort
             if (m1 - first > 1)
             {
 #ifdef _DEBUG
-#    if defined(_PSTL_PAR_BACKEND_TBB)
+#    if defined(_ONEDPL_PAR_BACKEND_TBB)
                 auto p = tbb::this_task_arena::max_concurrency();
 #    else
                 auto p = 1;
-- 
2.56.0



More information about the Libstdc++ mailing list