Skip to content

Commit f16a4fc

Browse files
committed
[OpenCL] Add support of __opencl_c_3d_image_writes feature macro
This feature requires support of __opencl_c_images, so diagnostics for that is provided as well. Also, ensure that cl_khr_3d_image_writes feature macro is set to the same value. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D106260
1 parent ac2ffde commit f16a4fc

File tree

6 files changed

+55
-27
lines changed

6 files changed

+55
-27
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10106,8 +10106,6 @@ def err_opencl_requires_extension : Error<
1010610106
def ext_opencl_double_without_pragma : Extension<
1010710107
"Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is"
1010810108
" supported">;
10109-
def err_opencl_double_requires_extension : Error<
10110-
"use of type 'double' requires %select{cl_khr_fp64|cl_khr_fp64 and __opencl_c_fp64}0 support">;
1011110109
def warn_opencl_generic_address_space_arg : Warning<
1011210110
"passing non-generic address space pointer to %0"
1011310111
" may cause dynamic conversion affecting performance">,

clang/lib/Basic/OpenCLOptions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ bool OpenCLOptions::diagnoseUnsupportedFeatureDependencies(
111111
// Feature pairs. First feature in a pair requires the second one to be
112112
// supported.
113113
static const llvm::StringMap<llvm::StringRef> DependentFeaturesMap = {
114-
{"__opencl_c_read_write_images", "__opencl_c_images"}};
114+
{"__opencl_c_read_write_images", "__opencl_c_images"},
115+
{"__opencl_c_3d_image_writes", "__opencl_c_images"}};
115116

116117
auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
117118

@@ -130,7 +131,8 @@ bool OpenCLOptions::diagnoseFeatureExtensionDifferences(
130131
const TargetInfo &TI, DiagnosticsEngine &Diags) {
131132
// Extensions and equivalent feature pairs.
132133
static const llvm::StringMap<llvm::StringRef> FeatureExtensionMap = {
133-
{"cl_khr_fp64", "__opencl_c_fp64"}};
134+
{"cl_khr_fp64", "__opencl_c_fp64"},
135+
{"cl_khr_3d_image_writes", "__opencl_c_3d_image_writes"}};
134136

135137
auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
136138

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
310310
Opts["cl_khr_mipmap_image"] = true;
311311
Opts["cl_khr_mipmap_image_writes"] = true;
312312
Opts["cl_khr_subgroups"] = true;
313-
Opts["cl_khr_3d_image_writes"] = true;
314313
Opts["cl_amd_media_ops"] = true;
315314
Opts["cl_amd_media_ops2"] = true;
315+
316+
Opts["__opencl_c_images"] = true;
317+
Opts["__opencl_c_3d_image_writes"] = true;
318+
Opts["cl_khr_3d_image_writes"] = true;
316319
}
317320
}
318321

clang/lib/Sema/SemaType.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,18 +1525,20 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15251525
break;
15261526
case DeclSpec::TST_float: Result = Context.FloatTy; break;
15271527
case DeclSpec::TST_double:
1528+
if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
1529+
Result = Context.LongDoubleTy;
1530+
else
1531+
Result = Context.DoubleTy;
15281532
if (S.getLangOpts().OpenCL) {
15291533
if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
1530-
S.Diag(DS.getTypeSpecTypeLoc(),
1531-
diag::err_opencl_double_requires_extension)
1532-
<< (S.getLangOpts().OpenCLVersion >= 300);
1534+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
1535+
<< 0 << Result
1536+
<< (S.getLangOpts().OpenCLVersion == 300
1537+
? "cl_khr_fp64 and __opencl_c_fp64"
1538+
: "cl_khr_fp64");
15331539
else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts()))
15341540
S.Diag(DS.getTypeSpecTypeLoc(), diag::ext_opencl_double_without_pragma);
15351541
}
1536-
if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
1537-
Result = Context.LongDoubleTy;
1538-
else
1539-
Result = Context.DoubleTy;
15401542
break;
15411543
case DeclSpec::TST_float128:
15421544
if (!S.Context.getTargetInfo().hasFloat128Type() &&
@@ -1724,21 +1726,28 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
17241726

17251727
if (S.getLangOpts().OpenCL) {
17261728
const auto &OpenCLOptions = S.getOpenCLOptions();
1727-
StringRef OptName;
1729+
bool IsOpenCLC30 = (S.getLangOpts().OpenCLVersion == 300);
17281730
// OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images
1729-
// support
1731+
// support.
1732+
// OpenCL C v3.0 s6.2.1 - OpenCL 3d image write types requires support
1733+
// for OpenCL C 2.0, or OpenCL C 3.0 or newer and the
1734+
// __opencl_c_3d_image_writes feature. OpenCL C v3.0 API s4.2 - For devices
1735+
// that support OpenCL 3.0, cl_khr_3d_image_writes must be returned when and
1736+
// only when the optional feature is supported
17301737
if ((Result->isImageType() || Result->isSamplerT()) &&
1731-
(S.getLangOpts().OpenCLVersion >= 300 &&
1732-
!OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts())))
1733-
OptName = "__opencl_c_images";
1734-
else if (Result->isOCLImage3dWOType() &&
1735-
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
1736-
S.getLangOpts()))
1737-
OptName = "cl_khr_3d_image_writes";
1738-
1739-
if (!OptName.empty()) {
1738+
(IsOpenCLC30 &&
1739+
!OpenCLOptions.isSupported("__opencl_c_images", S.getLangOpts()))) {
1740+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
1741+
<< 0 << Result << "__opencl_c_images";
1742+
declarator.setInvalidType();
1743+
} else if (Result->isOCLImage3dWOType() &&
1744+
!OpenCLOptions.isSupported("cl_khr_3d_image_writes",
1745+
S.getLangOpts())) {
17401746
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
1741-
<< 0 << Result << OptName;
1747+
<< 0 << Result
1748+
<< (IsOpenCLC30
1749+
? "cl_khr_3d_image_writes and __opencl_c_3d_image_writes"
1750+
: "cl_khr_3d_image_writes");
17421751
declarator.setInvalidType();
17431752
}
17441753
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
22
// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
3+
34
// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
45

6+
// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
7+
// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
8+
59
// CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
10+
611
// CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
12+
13+
// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
14+
// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature

clang/test/SemaOpenCL/unsupported-image.cl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
2-
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
1+
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
2+
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
3+
// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
34

4-
#ifdef __opencl_c_images
5+
#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
56
//expected-no-diagnostics
67
#endif
78

@@ -59,3 +60,10 @@ void test11(sampler_t s) {}
5960
#if !defined(__opencl_c_images)
6061
// expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
6162
#endif
63+
64+
void test12(write_only image3d_t i) {}
65+
#if !defined(__opencl_c_images)
66+
// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
67+
#elif !defined(__opencl_c_3d_image_writes)
68+
// expected-error@-4{{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
69+
#endif

0 commit comments

Comments
 (0)