r281915 - [OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 19 10:11:22 PDT 2016
Author: yaxunl
Date: Mon Sep 19 12:11:22 2016
New Revision: 281915
URL: http://llvm.org/viewvc/llvm-project?rev=281915&view=rev
Log:
[OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/half.cl
cfe/trunk/test/SemaOpenCL/invalid-kernel-parameters.cl
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=281915&r1=281914&r2=281915&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Sep 19 12:11:22 2016
@@ -7526,7 +7526,7 @@ enum OpenCLParamType {
RecordKernelParam
};
-static OpenCLParamType getOpenCLKernelParameterType(QualType PT) {
+static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT) {
if (PT->isPointerType()) {
QualType PointeeType = PT->getPointeeType();
if (PointeeType->isPointerType())
@@ -7547,7 +7547,10 @@ static OpenCLParamType getOpenCLKernelPa
if (PT->isEventT())
return InvalidKernelParam;
- if (PT->isHalfType())
+ // OpenCL extension spec v1.2 s9.5:
+ // This extension adds support for half scalar and vector types as built-in
+ // types that can be used for arithmetic operations, conversions etc.
+ if (!S.getOpenCLOptions().cl_khr_fp16 && PT->isHalfType())
return InvalidKernelParam;
if (PT->isRecordType())
@@ -7568,7 +7571,7 @@ static void checkIsValidOpenCLKernelPara
if (ValidTypes.count(PT.getTypePtr()))
return;
- switch (getOpenCLKernelParameterType(PT)) {
+ switch (getOpenCLKernelParameterType(S, PT)) {
case PtrPtrKernelParam:
// OpenCL v1.2 s6.9.a:
// A kernel function argument cannot be declared as a
@@ -7595,7 +7598,10 @@ static void checkIsValidOpenCLKernelPara
// OpenCL v1.2 s6.8 n:
// A kernel function argument cannot be declared
// of event_t type.
- S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
+ // Do not diagnose half type since it is diagnosed as invalid argument
+ // type for any function elsewhere.
+ if (!PT->isHalfType())
+ S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
D.setInvalidType();
return;
@@ -7651,7 +7657,7 @@ static void checkIsValidOpenCLKernelPara
if (ValidTypes.count(QT.getTypePtr()))
continue;
- OpenCLParamType ParamType = getOpenCLKernelParameterType(QT);
+ OpenCLParamType ParamType = getOpenCLKernelParameterType(S, QT);
if (ParamType == ValidKernelParam)
continue;
Modified: cfe/trunk/test/SemaOpenCL/half.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/half.cl?rev=281915&r1=281914&r2=281915&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/half.cl (original)
+++ cfe/trunk/test/SemaOpenCL/half.cl Mon Sep 19 12:11:22 2016
@@ -25,6 +25,9 @@ half half_disabled(half *p, // expected-
return h;
}
+kernel void half_disabled_kernel(global half *p,
+ half h); // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
+
// Exactly the same as above but with the cl_khr_fp16 extension enabled.
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
constant half a = 1.0h;
@@ -48,3 +51,7 @@ half half_enabled(half *p, half h)
return h;
}
+
+kernel void half_enabled_kernel(global half *p,
+ half h);
+
Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-parameters.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-parameters.cl?rev=281915&r1=281914&r2=281915&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel-parameters.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel-parameters.cl Mon Sep 19 12:11:22 2016
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown
+kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
@@ -11,7 +13,8 @@
kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}}
-kernel void half_arg(half x) { } // expected-error{{'half' cannot be used as the type of a kernel parameter}}
+// half kernel argument is allowed when cl_khr_fp16 is enabled.
+kernel void half_arg(half x) { }
typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}}
{
More information about the cfe-commits
mailing list