Skip to content

Commit e341679

Browse files
committed
[LLVM 16] Bring missing LLVM 15 patches to LLVM 16
We've found that there are missing patches affecting OpenCL / Images feature. This PR tries to resolve that problem by adding missing patches from https://github.com/intel/opencl-clang/tree/ocl-open-150/patches/clang to the ocl-open-160 branch
1 parent c0f0801 commit e341679

4 files changed

+236
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From 1ca45b5f5725a447ded14c0096df39f2751c4e9a Mon Sep 17 00:00:00 2001
2+
From: Haonan Yang <[email protected]>
3+
Date: Fri, 25 Feb 2022 10:36:57 +0800
4+
Subject: [PATCH] Remove __IMAGE_SUPPORT__ macro for SPIR
5+
6+
Signed-off-by: Haonan Yang <[email protected]>
7+
---
8+
clang/lib/Frontend/InitPreprocessor.cpp | 3 ---
9+
clang/test/Preprocessor/predefined-macros.c | 4 ----
10+
2 files changed, 7 deletions(-)
11+
12+
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
13+
index e259ab47c558..0bfdd62f17a2 100644
14+
--- a/clang/lib/Frontend/InitPreprocessor.cpp
15+
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
16+
@@ -1234,9 +1234,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
17+
// OpenCL definitions.
18+
if (LangOpts.OpenCL) {
19+
InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
20+
-
21+
- if (TI.getTriple().isSPIR() || TI.getTriple().isSPIRV())
22+
- Builder.defineMacro("__IMAGE_SUPPORT__");
23+
}
24+
25+
if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
26+
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
27+
index 0b67cbe233ca..aad4a6f05563 100644
28+
--- a/clang/test/Preprocessor/predefined-macros.c
29+
+++ b/clang/test/Preprocessor/predefined-macros.c
30+
@@ -207,28 +207,24 @@
31+
32+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
33+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
34+
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
35+
// CHECK-SPIR-DAG: #define __SPIR__ 1
36+
// CHECK-SPIR-DAG: #define __SPIR32__ 1
37+
// CHECK-SPIR-NOT: #define __SPIR64__ 1
38+
39+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
40+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
41+
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
42+
// CHECK-SPIR64-DAG: #define __SPIR__ 1
43+
// CHECK-SPIR64-DAG: #define __SPIR64__ 1
44+
// CHECK-SPIR64-NOT: #define __SPIR32__ 1
45+
46+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv32-unknown-unknown \
47+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV32
48+
-// CHECK-SPIRV32-DAG: #define __IMAGE_SUPPORT__ 1
49+
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
50+
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
51+
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
52+
53+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
54+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
55+
-// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
56+
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
57+
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
58+
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
59+
--
60+
2.29.2
61+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 9780cc0e044c73dcd549c67a1278a4ff7daf3b01 Mon Sep 17 00:00:00 2001
2+
From: Marcin Naczk <[email protected]>
3+
Date: Fri, 4 Nov 2022 15:41:16 +0100
4+
Subject: [PATCH] Remove wrong check of __opencl_c_images feature macro
5+
6+
Deleted mechanism that wrongly assumes that
7+
all functions that use image types must be under
8+
__opencl_c_images feature macro
9+
Mechanism added by https://reviews.llvm.org/D103911
10+
More info on github issue:
11+
https://github.com/llvm/llvm-project/issues/58017
12+
---
13+
clang/lib/Sema/SemaType.cpp | 8 +-------
14+
1 file changed, 1 insertion(+), 7 deletions(-)
15+
16+
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
17+
index ab47e9f03eaf..f72c2fb57ddd 100644
18+
--- a/clang/lib/Sema/SemaType.cpp
19+
+++ b/clang/lib/Sema/SemaType.cpp
20+
@@ -1741,13 +1741,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
21+
// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
22+
// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when and
23+
// only when the optional feature is supported
24+
- if ((Result->isImageType() || Result->isSamplerT()) &&
25+
- (IsOpenCLC30Compatible &&
26+
- !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts()))) {
27+
- S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
28+
- << 0 << Result << "__opencl_c_images";
29+
- declarator.setInvalidType();
30+
- } else if (Result->isOCLImage3dWOType() &&
31+
+ if (Result->isOCLImage3dWOType() &&
32+
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
33+
S.getLangOpts())) {
34+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
35+
--
36+
2.33.0.windows.1
37+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From bb5e22800857f7dda9a2491a4f2fc7387d4205b0 Mon Sep 17 00:00:00 2001
2+
From: Marcin Naczk <[email protected]>
3+
Date: Fri, 4 Nov 2022 15:45:17 +0100
4+
Subject: [PATCH] Fix checking mechanism for read_write Image type
5+
6+
The commit
7+
https://github.com/llvm/llvm-project/commit/91a0b464a853821734db8b1c521df03f8e2e56e7
8+
Enabled opencl feature macro __opencl_c_read_write_images
9+
by default for the SPIR and SPIR-V targets
10+
therefore the mechanism of checking read_write image type
11+
should take into account if the target is SPIR or SPIR-V
12+
---
13+
clang/lib/Sema/SemaDeclAttr.cpp | 5 +++--
14+
1 file changed, 3 insertions(+), 2 deletions(-)
15+
16+
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
17+
index e76e7c608e0c..2d60d2b03169 100644
18+
--- a/clang/lib/Sema/SemaDeclAttr.cpp
19+
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
20+
@@ -7823,8 +7823,9 @@ static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
21+
bool ReadWriteImagesUnsupported =
22+
(S.getLangOpts().getOpenCLCompatibleVersion() < 200) ||
23+
(S.getLangOpts().getOpenCLCompatibleVersion() == 300 &&
24+
- !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images",
25+
- S.getLangOpts()));
26+
+ !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images", S.getLangOpts()) &&
27+
+ !S.getASTContext().getTargetInfo().getTriple().isSPIR() &&
28+
+ !S.getASTContext().getTargetInfo().getTriple().isSPIRV());
29+
if (ReadWriteImagesUnsupported || DeclTy->isPipeType()) {
30+
S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write)
31+
<< AL << PDecl->getType() << DeclTy->isImageType();
32+
--
33+
2.33.0.windows.1
34+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
From a60b8f468119065f8a6cb4a16598263cb00de0b5 Mon Sep 17 00:00:00 2001
2+
From: Sven van Haastregt <[email protected]>
3+
Date: Mon, 16 Jan 2023 11:32:12 +0000
4+
Subject: [PATCH] [OpenCL] Allow undefining header-only features
5+
6+
`opencl-c-base.h` always defines 5 particular feature macros for
7+
SPIR-V, making it impossible to disable those features.
8+
9+
To allow disabling any of those features, let the header recognize
10+
`__undef_<feature>` macros. The user can then pass the
11+
`-D__undef_<feature>` flag on the command line to disable a specific
12+
feature. The __undef macro could potentially also be set from
13+
`-cl-ext=-feature`, but for now only change the header and only
14+
provide __undef macros for the 5 features that are always enabled in
15+
`opencl-c-base.h`.
16+
17+
Differential Revision: https://reviews.llvm.org/D141297
18+
---
19+
clang/lib/Headers/opencl-c-base.h | 19 ++++++++++++++++
20+
clang/test/SemaOpenCL/features.cl | 37 ++++++++++++++++++++++---------
21+
2 files changed, 45 insertions(+), 11 deletions(-)
22+
23+
diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
24+
index c433b4f7eb1af..fad2f9c0272bf 100644
25+
--- a/clang/lib/Headers/opencl-c-base.h
26+
+++ b/clang/lib/Headers/opencl-c-base.h
27+
@@ -74,6 +74,25 @@
28+
#define __opencl_c_atomic_scope_all_devices 1
29+
#define __opencl_c_read_write_images 1
30+
#endif // defined(__SPIR__)
31+
+
32+
+// Undefine any feature macros that have been explicitly disabled using
33+
+// an __undef_<feature> macro.
34+
+#ifdef __undef___opencl_c_work_group_collective_functions
35+
+#undef __opencl_c_work_group_collective_functions
36+
+#endif
37+
+#ifdef __undef___opencl_c_atomic_order_seq_cst
38+
+#undef __opencl_c_atomic_order_seq_cst
39+
+#endif
40+
+#ifdef __undef___opencl_c_atomic_scope_device
41+
+#undef __opencl_c_atomic_scope_device
42+
+#endif
43+
+#ifdef __undef___opencl_c_atomic_scope_all_devices
44+
+#undef __opencl_c_atomic_scope_all_devices
45+
+#endif
46+
+#ifdef __undef___opencl_c_read_write_images
47+
+#undef __opencl_c_read_write_images
48+
+#endif
49+
+
50+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
51+
52+
#if !defined(__opencl_c_generic_address_space)
53+
diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl
54+
index af058b5e69828..3f59b4ea3b5ae 100644
55+
--- a/clang/test/SemaOpenCL/features.cl
56+
+++ b/clang/test/SemaOpenCL/features.cl
57+
@@ -26,6 +26,15 @@
58+
// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=clc++1.0 \
59+
// RUN: | FileCheck -match-full-lines %s --check-prefix=NO-FEATURES
60+
61+
+// For OpenCL C 3.0, header-only features can be disabled using macros.
62+
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
63+
+// RUN: -D__undef___opencl_c_work_group_collective_functions=1 \
64+
+// RUN: -D__undef___opencl_c_atomic_order_seq_cst=1 \
65+
+// RUN: -D__undef___opencl_c_atomic_scope_device=1 \
66+
+// RUN: -D__undef___opencl_c_atomic_scope_all_devices=1 \
67+
+// RUN: -D__undef___opencl_c_read_write_images=1 \
68+
+// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
69+
+
70+
// Note that __opencl_c_int64 is always defined assuming
71+
// always compiling for FULL OpenCL profile
72+
73+
@@ -43,14 +52,20 @@
74+
// FEATURES: #define __opencl_c_subgroups 1
75+
76+
// NO-FEATURES: #define __opencl_c_int64 1
77+
-// NO-FEATURES-NOT: __opencl_c_3d_image_writes
78+
-// NO-FEATURES-NOT: __opencl_c_atomic_order_acq_rel
79+
-// NO-FEATURES-NOT: __opencl_c_atomic_order_seq_cst
80+
-// NO-FEATURES-NOT: __opencl_c_device_enqueue
81+
-// NO-FEATURES-NOT: __opencl_c_fp64
82+
-// NO-FEATURES-NOT: __opencl_c_generic_address_space
83+
-// NO-FEATURES-NOT: __opencl_c_images
84+
-// NO-FEATURES-NOT: __opencl_c_pipes
85+
-// NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
86+
-// NO-FEATURES-NOT: __opencl_c_read_write_images
87+
-// NO-FEATURES-NOT: __opencl_c_subgroups
88+
+// NO-FEATURES-NOT: #define __opencl_c_3d_image_writes
89+
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_acq_rel
90+
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
91+
+// NO-FEATURES-NOT: #define __opencl_c_device_enqueue
92+
+// NO-FEATURES-NOT: #define __opencl_c_fp64
93+
+// NO-FEATURES-NOT: #define __opencl_c_generic_address_space
94+
+// NO-FEATURES-NOT: #define __opencl_c_images
95+
+// NO-FEATURES-NOT: #define __opencl_c_pipes
96+
+// NO-FEATURES-NOT: #define __opencl_c_program_scope_global_variables
97+
+// NO-FEATURES-NOT: #define __opencl_c_read_write_images
98+
+// NO-FEATURES-NOT: #define __opencl_c_subgroups
99+
+
100+
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_work_group_collective_functions
101+
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
102+
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_device
103+
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_all_devices
104+
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_read_write_images

0 commit comments

Comments
 (0)