From: Anastasia Stulova Date: Mon, 4 Jul 2016 16:07:18 +0000 (+0000) Subject: [OpenCL] Make OpenCL Builtins added according to the right version. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0cac52466b00f3a94a0df1e53f3df4f422e03e6;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index bbefc38529..0f88211ffa 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -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 diff --git a/include/clang/Basic/Builtins.h b/include/clang/Basic/Builtins.h index 0ef35b6fba..15e9a413fb 100644 --- a/include/clang/Basic/Builtins.h +++ b/include/clang/Basic/Builtins.h @@ -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. diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 25165bae48..762c7c4db1 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; -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< diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp index e3d31a11d9..28695d649a 100644 --- a/lib/Basic/Builtins.cpp +++ b/lib/Basic/Builtins.cpp @@ -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; } diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 57628f0f44..c86c420c94 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -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: diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 89e5e3e5af..0dbc8da9cc 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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 diff --git a/test/SemaOpenCL/clang-builtin-version.cl b/test/SemaOpenCL/clang-builtin-version.cl new file mode 100644 index 0000000000..8574682ab9 --- /dev/null +++ b/test/SemaOpenCL/clang-builtin-version.cl @@ -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}} +} diff --git a/test/SemaOpenCL/to_addr_builtin.cl b/test/SemaOpenCL/to_addr_builtin.cl index 5fefaa5adc..a145626cfc 100644 --- a/test/SemaOpenCL/to_addr_builtin.cl +++ b/test/SemaOpenCL/to_addr_builtin.cl @@ -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