Skip to content

Commit 97b4f77

Browse files
authored
[LLVM 16] Bring missing LLVM 15 patches to LLVM 16 (#562)
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 97b4f77

4 files changed

+180
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
9+
index 208c6a8db159..33c8409eaf12 100644
10+
--- a/clang/lib/Frontend/InitPreprocessor.cpp
11+
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
12+
@@ -1288,9 +1288,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
13+
// OpenCL definitions.
14+
if (LangOpts.OpenCL) {
15+
InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
16+
-
17+
- if (TI.getTriple().isSPIR() || TI.getTriple().isSPIRV())
18+
- Builder.defineMacro("__IMAGE_SUPPORT__");
19+
}
20+
21+
if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
22+
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
23+
index d77b699674af..4dd02c3cfde4 100644
24+
--- a/clang/test/Preprocessor/predefined-macros.c
25+
+++ b/clang/test/Preprocessor/predefined-macros.c
26+
@@ -210,28 +210,24 @@
27+
28+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
29+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
30+
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
31+
// CHECK-SPIR-DAG: #define __SPIR__ 1
32+
// CHECK-SPIR-DAG: #define __SPIR32__ 1
33+
// CHECK-SPIR-NOT: #define __SPIR64__ 1
34+
35+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
36+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
37+
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
38+
// CHECK-SPIR64-DAG: #define __SPIR__ 1
39+
// CHECK-SPIR64-DAG: #define __SPIR64__ 1
40+
// CHECK-SPIR64-NOT: #define __SPIR32__ 1
41+
42+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv32-unknown-unknown \
43+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV32
44+
-// CHECK-SPIRV32-DAG: #define __IMAGE_SUPPORT__ 1
45+
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
46+
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
47+
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
48+
49+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
50+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
51+
-// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
52+
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
53+
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
54+
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
14+
index 8cb1ed28fe3e..a3d3f16fd8a4 100644
15+
--- a/clang/lib/Sema/SemaType.cpp
16+
+++ b/clang/lib/Sema/SemaType.cpp
17+
@@ -1751,13 +1751,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
18+
// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
19+
// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when and
20+
// only when the optional feature is supported
21+
- if ((Result->isImageType() || Result->isSamplerT()) &&
22+
- (IsOpenCLC30Compatible &&
23+
- !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts()))) {
24+
- S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
25+
- << 0 << Result << "__opencl_c_images";
26+
- declarator.setInvalidType();
27+
- } else if (Result->isOCLImage3dWOType() &&
28+
+ if (Result->isOCLImage3dWOType() &&
29+
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
30+
S.getLangOpts())) {
31+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
14+
index a303c7f57280..61242e69a33e 100644
15+
--- a/clang/lib/Sema/SemaDeclAttr.cpp
16+
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
17+
@@ -8200,8 +8200,9 @@ static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
18+
bool ReadWriteImagesUnsupported =
19+
(S.getLangOpts().getOpenCLCompatibleVersion() < 200) ||
20+
(S.getLangOpts().getOpenCLCompatibleVersion() == 300 &&
21+
- !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images",
22+
- S.getLangOpts()));
23+
+ !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images", S.getLangOpts()) &&
24+
+ !S.getASTContext().getTargetInfo().getTriple().isSPIR() &&
25+
+ !S.getASTContext().getTargetInfo().getTriple().isSPIRV());
26+
if (ReadWriteImagesUnsupported || DeclTy->isPipeType()) {
27+
S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write)
28+
<< AL << PDecl->getType() << DeclTy->isImageType();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
20+
index fad2f9c0272b..84a2d834aa3c 100644
21+
--- a/clang/lib/Headers/opencl-c-base.h
22+
+++ b/clang/lib/Headers/opencl-c-base.h
23+
@@ -93,6 +93,24 @@
24+
#undef __opencl_c_read_write_images
25+
#endif
26+
27+
+// Undefine any feature macros that have been explicitly disabled using
28+
+// an __undef_<feature> macro.
29+
+#ifdef __undef___opencl_c_work_group_collective_functions
30+
+#undef __opencl_c_work_group_collective_functions
31+
+#endif
32+
+#ifdef __undef___opencl_c_atomic_order_seq_cst
33+
+#undef __opencl_c_atomic_order_seq_cst
34+
+#endif
35+
+#ifdef __undef___opencl_c_atomic_scope_device
36+
+#undef __opencl_c_atomic_scope_device
37+
+#endif
38+
+#ifdef __undef___opencl_c_atomic_scope_all_devices
39+
+#undef __opencl_c_atomic_scope_all_devices
40+
+#endif
41+
+#ifdef __undef___opencl_c_read_write_images
42+
+#undef __opencl_c_read_write_images
43+
+#endif
44+
+
45+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
46+
47+
#if !defined(__opencl_c_generic_address_space)
48+
diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl
49+
index 3f59b4ea3b5a..7006fb5d181a 100644
50+
--- a/clang/test/SemaOpenCL/features.cl
51+
+++ b/clang/test/SemaOpenCL/features.cl
52+
@@ -35,6 +35,15 @@
53+
// RUN: -D__undef___opencl_c_read_write_images=1 \
54+
// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
55+
56+
+// For OpenCL C 3.0, header-only features can be disabled using macros.
57+
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
58+
+// RUN: -D__undef___opencl_c_work_group_collective_functions=1 \
59+
+// RUN: -D__undef___opencl_c_atomic_order_seq_cst=1 \
60+
+// RUN: -D__undef___opencl_c_atomic_scope_device=1 \
61+
+// RUN: -D__undef___opencl_c_atomic_scope_all_devices=1 \
62+
+// RUN: -D__undef___opencl_c_read_write_images=1 \
63+
+// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
64+
+
65+
// Note that __opencl_c_int64 is always defined assuming
66+
// always compiling for FULL OpenCL profile
67+

0 commit comments

Comments
 (0)