Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions patches/clang/0001-Remove-__IMAGE_SUPPORT__-macro-for-SPIR.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 1ca45b5f5725a447ded14c0096df39f2751c4e9a Mon Sep 17 00:00:00 2001
From: Haonan Yang <haonan.yang@intel.com>
Date: Fri, 25 Feb 2022 10:36:57 +0800
Subject: [PATCH] Remove __IMAGE_SUPPORT__ macro for SPIR

Signed-off-by: Haonan Yang <haonan.yang@intel.com>

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 208c6a8db159..33c8409eaf12 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1288,9 +1288,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
// OpenCL definitions.
if (LangOpts.OpenCL) {
InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
-
- if (TI.getTriple().isSPIR() || TI.getTriple().isSPIRV())
- Builder.defineMacro("__IMAGE_SUPPORT__");
}

if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
index d77b699674af..4dd02c3cfde4 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/clang/test/Preprocessor/predefined-macros.c
@@ -210,28 +210,24 @@

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIR-DAG: #define __SPIR__ 1
// CHECK-SPIR-DAG: #define __SPIR32__ 1
// CHECK-SPIR-NOT: #define __SPIR64__ 1

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIR64-DAG: #define __SPIR__ 1
// CHECK-SPIR64-DAG: #define __SPIR64__ 1
// CHECK-SPIR64-NOT: #define __SPIR32__ 1

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv32-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV32
-// CHECK-SPIRV32-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
-// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 9780cc0e044c73dcd549c67a1278a4ff7daf3b01 Mon Sep 17 00:00:00 2001
From: Marcin Naczk <marcin.naczk@intel.com>
Date: Fri, 4 Nov 2022 15:41:16 +0100
Subject: [PATCH] Remove wrong check of __opencl_c_images feature macro

Deleted mechanism that wrongly assumes that
all functions that use image types must be under
__opencl_c_images feature macro
Mechanism added by https://reviews.llvm.org/D103911
More info on github issue:
https://github.com/llvm/llvm-project/issues/58017

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 8cb1ed28fe3e..a3d3f16fd8a4 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1751,13 +1751,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when and
// only when the optional feature is supported
- if ((Result->isImageType() || Result->isSamplerT()) &&
- (IsOpenCLC30Compatible &&
- !OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts()))) {
- S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
- << 0 << Result << "__opencl_c_images";
- declarator.setInvalidType();
- } else if (Result->isOCLImage3dWOType() &&
+ if (Result->isOCLImage3dWOType() &&
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
S.getLangOpts())) {
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From bb5e22800857f7dda9a2491a4f2fc7387d4205b0 Mon Sep 17 00:00:00 2001
From: Marcin Naczk <marcin.naczk@intel.com>
Date: Fri, 4 Nov 2022 15:45:17 +0100
Subject: [PATCH] Fix checking mechanism for read_write Image type

The commit
https://github.com/llvm/llvm-project/commit/91a0b464a853821734db8b1c521df03f8e2e56e7
Enabled opencl feature macro __opencl_c_read_write_images
by default for the SPIR and SPIR-V targets
therefore the mechanism of checking read_write image type
should take into account if the target is SPIR or SPIR-V

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index a303c7f57280..61242e69a33e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -8200,8 +8200,9 @@ static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
bool ReadWriteImagesUnsupported =
(S.getLangOpts().getOpenCLCompatibleVersion() < 200) ||
(S.getLangOpts().getOpenCLCompatibleVersion() == 300 &&
- !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images",
- S.getLangOpts()));
+ !S.getOpenCLOptions().isSupported("__opencl_c_read_write_images", S.getLangOpts()) &&
+ !S.getASTContext().getTargetInfo().getTriple().isSPIR() &&
+ !S.getASTContext().getTargetInfo().getTriple().isSPIRV());
if (ReadWriteImagesUnsupported || DeclTy->isPipeType()) {
S.Diag(AL.getLoc(), diag::err_opencl_invalid_read_write)
<< AL << PDecl->getType() << DeclTy->isImageType();
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From a60b8f468119065f8a6cb4a16598263cb00de0b5 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt <sven.vanhaastregt@arm.com>
Date: Mon, 16 Jan 2023 11:32:12 +0000
Subject: [PATCH] [OpenCL] Allow undefining header-only features

`opencl-c-base.h` always defines 5 particular feature macros for
SPIR-V, making it impossible to disable those features.

To allow disabling any of those features, let the header recognize
`__undef_<feature>` macros. The user can then pass the
`-D__undef_<feature>` flag on the command line to disable a specific
feature. The __undef macro could potentially also be set from
`-cl-ext=-feature`, but for now only change the header and only
provide __undef macros for the 5 features that are always enabled in
`opencl-c-base.h`.

Differential Revision: https://reviews.llvm.org/D141297

diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
index fad2f9c0272b..84a2d834aa3c 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -93,6 +93,24 @@
#undef __opencl_c_read_write_images
#endif

+// Undefine any feature macros that have been explicitly disabled using
+// an __undef_<feature> macro.
+#ifdef __undef___opencl_c_work_group_collective_functions
+#undef __opencl_c_work_group_collective_functions
+#endif
+#ifdef __undef___opencl_c_atomic_order_seq_cst
+#undef __opencl_c_atomic_order_seq_cst
+#endif
+#ifdef __undef___opencl_c_atomic_scope_device
+#undef __opencl_c_atomic_scope_device
+#endif
+#ifdef __undef___opencl_c_atomic_scope_all_devices
+#undef __opencl_c_atomic_scope_all_devices
+#endif
+#ifdef __undef___opencl_c_read_write_images
+#undef __opencl_c_read_write_images
+#endif
+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)

#if !defined(__opencl_c_generic_address_space)
diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl
index 3f59b4ea3b5a..7006fb5d181a 100644
--- a/clang/test/SemaOpenCL/features.cl
+++ b/clang/test/SemaOpenCL/features.cl
@@ -35,6 +35,15 @@
// RUN: -D__undef___opencl_c_read_write_images=1 \
// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES

+// For OpenCL C 3.0, header-only features can be disabled using macros.
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
+// RUN: -D__undef___opencl_c_work_group_collective_functions=1 \
+// RUN: -D__undef___opencl_c_atomic_order_seq_cst=1 \
+// RUN: -D__undef___opencl_c_atomic_scope_device=1 \
+// RUN: -D__undef___opencl_c_atomic_scope_all_devices=1 \
+// RUN: -D__undef___opencl_c_read_write_images=1 \
+// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
+
// Note that __opencl_c_int64 is always defined assuming
// always compiling for FULL OpenCL profile