Skip to content

Commit 6336913

Browse files
authored
[SYCL] Avoid including std C++ headers into integration header file (#2662)
This is done to avoid compilation errors caused by usage TBB AND libstdc++ 10.X libstdc++10 conditionally defines (i.e. if is not defined already) the macro _GLIBCXX_USE_TBB_PAR_BACKEND. If the integration header file has includes of C++ headers, then that macro gets defined always. This does not let to define it properly in user's app (even if define is on the 1st line), which also causes different behavior for some C++ std files and compile error later. Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent 7561bc1 commit 6336913

File tree

5 files changed

+63
-55
lines changed

5 files changed

+63
-55
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3657,7 +3657,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
36573657
O << "// This is auto-generated SYCL integration header.\n";
36583658
O << "\n";
36593659

3660-
O << "#include <CL/sycl/detail/defines.hpp>\n";
3660+
O << "#include <CL/sycl/detail/defines_elementary.hpp>\n";
36613661
O << "#include <CL/sycl/detail/kernel_desc.hpp>\n";
36623662

36633663
O << "\n";

clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -fsycl-int-header=%t.h %s
33
// RUN: FileCheck -input-file=%t.h %s
44
//
5-
// CHECK: #include <CL/sycl/detail/defines.hpp>
5+
// CHECK: #include <CL/sycl/detail/defines_elementary.hpp>
66
// CHECK-NEXT: #include <CL/sycl/detail/kernel_desc.hpp>
77
//
88
// CHECK: static constexpr

sycl/include/CL/sycl/detail/defines.hpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,9 @@
88

99
#pragma once
1010

11-
#include <climits>
12-
13-
#ifndef __SYCL_DISABLE_NAMESPACE_INLINE__
14-
#define __SYCL_INLINE_NAMESPACE(X) inline namespace X
15-
#else
16-
#define __SYCL_INLINE_NAMESPACE(X) namespace X
17-
#endif // __SYCL_DISABLE_NAMESPACE_INLINE__
18-
19-
#ifndef __has_attribute
20-
#define __has_attribute(x) 0
21-
#endif
22-
23-
#ifndef __has_builtin
24-
#define __has_builtin(x) 0
25-
#endif
26-
27-
#if __has_attribute(always_inline)
28-
#define ALWAYS_INLINE __attribute__((always_inline))
29-
#else
30-
#define ALWAYS_INLINE
31-
#endif
32-
33-
#ifndef __has_builtin
34-
#define __has_builtin(x) 0
35-
#endif // __has_builtin
11+
#include <CL/sycl/detail/defines_elementary.hpp>
3612

37-
#ifndef SYCL_EXTERNAL
38-
#define SYCL_EXTERNAL
39-
#endif
40-
41-
#ifndef __SYCL_ID_QUERIES_FIT_IN_INT__
42-
#define __SYCL_ID_QUERIES_FIT_IN_INT__ 0
43-
#endif
13+
#include <climits>
4414

4515
#if __SYCL_ID_QUERIES_FIT_IN_INT__ && __has_builtin(__builtin_assume)
4616
#define __SYCL_ASSUME_INT(x) __builtin_assume((x) <= INT_MAX)
@@ -50,16 +20,3 @@
5020
#warning "No assumptions will be emitted due to no __builtin_assume available"
5121
#endif
5222
#endif
53-
54-
#ifdef _WIN32
55-
#define __SYCL_DEPRECATED(message) __declspec(deprecated(message))
56-
#else
57-
#define __SYCL_DEPRECATED(message) __attribute__((deprecated(message)))
58-
#endif
59-
60-
// inline constexpr is a C++17 feature
61-
#if __cplusplus >= 201703L
62-
#define __SYCL_INLINE_CONSTEXPR inline constexpr
63-
#else
64-
#define __SYCL_INLINE_CONSTEXPR static constexpr
65-
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//==--- defines_elementary.hpp ---- Preprocessor directives (simplified) ---==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#ifndef __SYCL_DISABLE_NAMESPACE_INLINE__
12+
#define __SYCL_INLINE_NAMESPACE(X) inline namespace X
13+
#else
14+
#define __SYCL_INLINE_NAMESPACE(X) namespace X
15+
#endif // __SYCL_DISABLE_NAMESPACE_INLINE__
16+
17+
#ifndef __has_attribute
18+
#define __has_attribute(x) 0
19+
#endif
20+
21+
#ifndef __has_builtin
22+
#define __has_builtin(x) 0
23+
#endif // __has_builtin
24+
25+
#if __has_attribute(always_inline)
26+
#define ALWAYS_INLINE __attribute__((always_inline))
27+
#else
28+
#define ALWAYS_INLINE
29+
#endif
30+
31+
#ifndef SYCL_EXTERNAL
32+
#define SYCL_EXTERNAL
33+
#endif
34+
35+
#ifndef __SYCL_ID_QUERIES_FIT_IN_INT__
36+
#define __SYCL_ID_QUERIES_FIT_IN_INT__ 0
37+
#endif
38+
39+
#ifdef _WIN32
40+
#define __SYCL_DEPRECATED(message) __declspec(deprecated(message))
41+
#else
42+
#define __SYCL_DEPRECATED(message) __attribute__((deprecated(message)))
43+
#endif
44+
45+
// inline constexpr is a C++17 feature
46+
#if __cplusplus >= 201703L
47+
#define __SYCL_INLINE_CONSTEXPR inline constexpr
48+
#else
49+
#define __SYCL_INLINE_CONSTEXPR static constexpr
50+
#endif

sycl/include/CL/sycl/detail/kernel_desc.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
#pragma once
1010

11-
#include <CL/sycl/access/access.hpp>
12-
#include <CL/sycl/detail/defines.hpp>
13-
#include <CL/sycl/detail/export.hpp> // for DLL_LOCAL used in int. header
11+
// This header file must not include any standard C++ header files.
1412

15-
#include <cstddef>
13+
#include <CL/sycl/detail/defines_elementary.hpp>
14+
#include <CL/sycl/detail/export.hpp>
1615

1716
__SYCL_INLINE_NAMESPACE(cl) {
1817
namespace sycl {
@@ -71,14 +70,16 @@ template <char...> struct KernelInfoData {
7170
// C++14 like index_sequence and make_index_sequence
7271
// not needed C++14 members (value_type, size) not implemented
7372
template <class T, T...> struct integer_sequence {};
74-
template <size_t... I> using index_sequence = integer_sequence<size_t, I...>;
75-
template <size_t N>
76-
using make_index_sequence = __make_integer_seq<integer_sequence, size_t, N>;
73+
template <unsigned long long... I>
74+
using index_sequence = integer_sequence<unsigned long long, I...>;
75+
template <unsigned long long N>
76+
using make_index_sequence =
77+
__make_integer_seq<integer_sequence, unsigned long long, N>;
7778

7879
template <typename T> struct KernelInfoImpl {
7980
private:
8081
static constexpr auto n = __builtin_unique_stable_name(T);
81-
template <size_t... I>
82+
template <unsigned long long... I>
8283
static KernelInfoData<n[I]...> impl(index_sequence<I...>) {
8384
return {};
8485
}

0 commit comments

Comments
 (0)