[OpenCL] Make OpenCL Builtins added according to the right version.

Currently we only have OpenCL 2.0 Builtins i.e. pipes or address space conversions.

They have to be added only in the version 2.0 compilation mode to make the identifiers
available for use in the other versions.

Review: http://reviews.llvm.org/D20249
llvm-svn: 274509
This commit is contained in:
Anastasia Stulova 2016-07-04 16:07:18 +00:00
parent 5e37aeaf6a
commit 7f8d6dc0ef
8 changed files with 77 additions and 39 deletions

View File

@ -1282,34 +1282,34 @@ BUILTIN(__builtin_nontemporal_load, "v.", "t")
// OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
// We need the generic prototype, since the packet type could be anything.
LANGBUILTIN(read_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(write_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC_LANG)
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC_LANG)
LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC20_LANG)
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
LANGBUILTIN(to_global, "v*v*", "tn", OCLC_LANG)
LANGBUILTIN(to_local, "v*v*", "tn", OCLC_LANG)
LANGBUILTIN(to_private, "v*v*", "tn", OCLC_LANG)
LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
#undef BUILTIN
#undef LIBBUILTIN

View File

@ -36,7 +36,7 @@ enum LanguageID {
CXX_LANG = 0x4, // builtin for cplusplus only.
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
MS_LANG = 0x10, // builtin requires MS mode.
OCLC_LANG = 0x20, // builtin for OpenCL C only.
OCLC20_LANG = 0x20, // builtin for OpenCL C only.
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.

View File

@ -7908,8 +7908,6 @@ def err_opencl_type_can_only_be_used_as_function_parameter : Error <
def warn_opencl_attr_deprecated_ignored : Warning <
"%0 attribute is deprecated and ignored in OpenCL version %1">,
InGroup<IgnoredAttributes>;
def err_opencl_builtin_requires_version : Error<
"%0 requires OpenCL version %1%select{| or above}2">;
// OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
def err_opencl_builtin_pipe_first_arg : Error<

View File

@ -69,7 +69,8 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo,
bool MSModeUnsupported =
!LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG);
bool ObjCUnsupported = !LangOpts.ObjC1 && BuiltinInfo.Langs == OBJC_LANG;
bool OclCUnsupported = !LangOpts.OpenCL && BuiltinInfo.Langs == OCLC_LANG;
bool OclCUnsupported = LangOpts.OpenCLVersion != 200 &&
BuiltinInfo.Langs == OCLC20_LANG;
return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
!GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
}

View File

@ -2127,7 +2127,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
return RValue::get(
Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1}));
}
// OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe commit read and write
// OpenCL v2.0 s6.13.16, s9.17.3.5 - Built-in pipe commit read and write
// functions
case Builtin::BIcommit_read_pipe:
case Builtin::BIcommit_write_pipe:

View File

@ -454,7 +454,7 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
return false;
}
// \brief OpenCL v2.0 s6.13.9 - Address space qualifier functions.
// \brief Performs semantic analysis for the to_global/local/private call.
// \param S Reference to the semantic analyzer.
// \param BuiltinID ID of the builtin function.
@ -462,13 +462,6 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
// \return True if a semantic error has been found, false otherwise.
static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
CallExpr *Call) {
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
if (S.getLangOpts().OpenCLVersion < 200) {
S.Diag(Call->getLocStart(), diag::err_opencl_builtin_requires_version)
<< Call->getDirectCallee() << "2.0" << 1 << Call->getSourceRange();
return true;
}
if (Call->getNumArgs() != 1) {
S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_arg_num)
<< Call->getDirectCallee() << Call->getSourceRange();
@ -801,6 +794,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
TheCall->setType(Context.VoidPtrTy);
break;
// OpenCL v2.0, s6.13.16 - Pipe functions
case Builtin::BIread_pipe:
case Builtin::BIwrite_pipe:
// Since those two functions are declared with var args, we need a semantic

View File

@ -0,0 +1,44 @@
// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100
// Confirm CL2.0 Clang builtins are not available in earlier versions
kernel void dse_builtins() {
int tmp;
enqueue_kernel(tmp, tmp, tmp, ^(void) { // expected-warning{{implicit declaration of function 'enqueue_kernel' is invalid in C99}}
return;
});
unsigned size = get_kernel_work_group_size(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_work_group_size' is invalid in C99}}
return;
});
size = get_kernel_preferred_work_group_size_multiple(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_preferred_work_group_size_multiple' is invalid in C99}}
return;
});
}
void pipe_builtins() {
int tmp;
read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'read_pipe' is invalid in C99}}
write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'write_pipe' is invalid in C99}}
reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_read_pipe' is invalid in C99}}
reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_write_pipe' is invalid in C99}}
work_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_read_pipe' is invalid in C99}}
work_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_write_pipe' is invalid in C99}}
sub_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_write_pipe' is invalid in C99}}
sub_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_read_pipe' is invalid in C99}}
commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_read_pipe' is invalid in C99}}
commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_write_pipe' is invalid in C99}}
work_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_read_pipe' is invalid in C99}}
work_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_write_pipe' is invalid in C99}}
sub_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_write_pipe' is invalid in C99}}
sub_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_read_pipe' is invalid in C99}}
get_pipe_num_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_num_packets' is invalid in C99}}
get_pipe_max_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_max_packets' is invalid in C99}}
}

View File

@ -10,43 +10,44 @@ void test(void) {
glob = to_global(glob, loc);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{implicit declaration of function 'to_global' is invalid in C99}}
// expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
#else
// expected-error@-4{{invalid number of arguments to function: 'to_global'}}
// expected-error@-5{{invalid number of arguments to function: 'to_global'}}
#endif
int x;
glob = to_global(x);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
#else
// expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
#endif
glob = to_global(con);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
#else
// expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
#endif
glob = to_global(con_typedef);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
#else
// expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
#endif
loc = to_global(glob);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
#else
// expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}}
#endif
global char *glob_c = to_global(loc);
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
// expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}}
#else
// expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}}
#endif