Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit d0cac52

Browse files
author
Anastasia Stulova
committed
[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
1 parent 4fa1f77 commit d0cac52

File tree

8 files changed

+77
-39
lines changed

8 files changed

+77
-39
lines changed

Diff for: include/clang/Basic/Builtins.def

+19-19
Original file line numberDiff line numberDiff line change
@@ -1282,34 +1282,34 @@ BUILTIN(__builtin_nontemporal_load, "v.", "t")
12821282

12831283
// OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
12841284
// We need the generic prototype, since the packet type could be anything.
1285-
LANGBUILTIN(read_pipe, "i.", "tn", OCLC_LANG)
1286-
LANGBUILTIN(write_pipe, "i.", "tn", OCLC_LANG)
1285+
LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
1286+
LANGBUILTIN(write_pipe, "i.", "tn", OCLC20_LANG)
12871287

1288-
LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG)
1289-
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG)
1288+
LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC20_LANG)
1289+
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC20_LANG)
12901290

1291-
LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC_LANG)
1292-
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC_LANG)
1291+
LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC20_LANG)
1292+
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC20_LANG)
12931293

1294-
LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC_LANG)
1295-
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
1294+
LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
1295+
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
12961296

1297-
LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC_LANG)
1298-
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
1297+
LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
1298+
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
12991299

1300-
LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC_LANG)
1301-
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC_LANG)
1300+
LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
1301+
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
13021302

1303-
LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC_LANG)
1304-
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC_LANG)
1303+
LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
1304+
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
13051305

1306-
LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC_LANG)
1307-
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC_LANG)
1306+
LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC20_LANG)
1307+
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC20_LANG)
13081308

13091309
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
1310-
LANGBUILTIN(to_global, "v*v*", "tn", OCLC_LANG)
1311-
LANGBUILTIN(to_local, "v*v*", "tn", OCLC_LANG)
1312-
LANGBUILTIN(to_private, "v*v*", "tn", OCLC_LANG)
1310+
LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
1311+
LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
1312+
LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
13131313

13141314
#undef BUILTIN
13151315
#undef LIBBUILTIN

Diff for: include/clang/Basic/Builtins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum LanguageID {
3636
CXX_LANG = 0x4, // builtin for cplusplus only.
3737
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
3838
MS_LANG = 0x10, // builtin requires MS mode.
39-
OCLC_LANG = 0x20, // builtin for OpenCL C only.
39+
OCLC20_LANG = 0x20, // builtin for OpenCL C only.
4040
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
4141
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
4242
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.

Diff for: include/clang/Basic/DiagnosticSemaKinds.td

-2
Original file line numberDiff line numberDiff line change
@@ -7908,8 +7908,6 @@ def err_opencl_type_can_only_be_used_as_function_parameter : Error <
79087908
def warn_opencl_attr_deprecated_ignored : Warning <
79097909
"%0 attribute is deprecated and ignored in OpenCL version %1">,
79107910
InGroup<IgnoredAttributes>;
7911-
def err_opencl_builtin_requires_version : Error<
7912-
"%0 requires OpenCL version %1%select{| or above}2">;
79137911

79147912
// OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
79157913
def err_opencl_builtin_pipe_first_arg : Error<

Diff for: lib/Basic/Builtins.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo,
6969
bool MSModeUnsupported =
7070
!LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG);
7171
bool ObjCUnsupported = !LangOpts.ObjC1 && BuiltinInfo.Langs == OBJC_LANG;
72-
bool OclCUnsupported = !LangOpts.OpenCL && BuiltinInfo.Langs == OCLC_LANG;
72+
bool OclCUnsupported = LangOpts.OpenCLVersion != 200 &&
73+
BuiltinInfo.Langs == OCLC20_LANG;
7374
return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported &&
7475
!GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
7576
}

Diff for: lib/CodeGen/CGBuiltin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
21272127
return RValue::get(
21282128
Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1}));
21292129
}
2130-
// OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe commit read and write
2130+
// OpenCL v2.0 s6.13.16, s9.17.3.5 - Built-in pipe commit read and write
21312131
// functions
21322132
case Builtin::BIcommit_read_pipe:
21332133
case Builtin::BIcommit_write_pipe:

Diff for: lib/Sema/SemaChecking.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,14 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
454454

455455
return false;
456456
}
457-
457+
// \brief OpenCL v2.0 s6.13.9 - Address space qualifier functions.
458458
// \brief Performs semantic analysis for the to_global/local/private call.
459459
// \param S Reference to the semantic analyzer.
460460
// \param BuiltinID ID of the builtin function.
461461
// \param Call A pointer to the builtin call.
462462
// \return True if a semantic error has been found, false otherwise.
463463
static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
464464
CallExpr *Call) {
465-
// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
466-
if (S.getLangOpts().OpenCLVersion < 200) {
467-
S.Diag(Call->getLocStart(), diag::err_opencl_builtin_requires_version)
468-
<< Call->getDirectCallee() << "2.0" << 1 << Call->getSourceRange();
469-
return true;
470-
}
471-
472465
if (Call->getNumArgs() != 1) {
473466
S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_arg_num)
474467
<< Call->getDirectCallee() << Call->getSourceRange();
@@ -801,6 +794,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
801794

802795
TheCall->setType(Context.VoidPtrTy);
803796
break;
797+
// OpenCL v2.0, s6.13.16 - Pipe functions
804798
case Builtin::BIread_pipe:
805799
case Builtin::BIwrite_pipe:
806800
// Since those two functions are declared with var args, we need a semantic

Diff for: test/SemaOpenCL/clang-builtin-version.cl

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100
2+
3+
// Confirm CL2.0 Clang builtins are not available in earlier versions
4+
5+
kernel void dse_builtins() {
6+
int tmp;
7+
enqueue_kernel(tmp, tmp, tmp, ^(void) { // expected-warning{{implicit declaration of function 'enqueue_kernel' is invalid in C99}}
8+
return;
9+
});
10+
unsigned size = get_kernel_work_group_size(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_work_group_size' is invalid in C99}}
11+
return;
12+
});
13+
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}}
14+
return;
15+
});
16+
}
17+
18+
void pipe_builtins() {
19+
int tmp;
20+
21+
read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'read_pipe' is invalid in C99}}
22+
write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'write_pipe' is invalid in C99}}
23+
24+
reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_read_pipe' is invalid in C99}}
25+
reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_write_pipe' is invalid in C99}}
26+
27+
work_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_read_pipe' is invalid in C99}}
28+
work_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_write_pipe' is invalid in C99}}
29+
30+
sub_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_write_pipe' is invalid in C99}}
31+
sub_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_read_pipe' is invalid in C99}}
32+
33+
commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_read_pipe' is invalid in C99}}
34+
commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_write_pipe' is invalid in C99}}
35+
36+
work_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_read_pipe' is invalid in C99}}
37+
work_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_write_pipe' is invalid in C99}}
38+
39+
sub_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_write_pipe' is invalid in C99}}
40+
sub_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_read_pipe' is invalid in C99}}
41+
42+
get_pipe_num_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_num_packets' is invalid in C99}}
43+
get_pipe_max_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_max_packets' is invalid in C99}}
44+
}

Diff for: test/SemaOpenCL/to_addr_builtin.cl

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,44 @@ void test(void) {
1010

1111
glob = to_global(glob, loc);
1212
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
13-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
13+
// expected-warning@-2{{implicit declaration of function 'to_global' is invalid in C99}}
14+
// expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
1415
#else
15-
// expected-error@-4{{invalid number of arguments to function: 'to_global'}}
16+
// expected-error@-5{{invalid number of arguments to function: 'to_global'}}
1617
#endif
1718

1819
int x;
1920
glob = to_global(x);
2021
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
21-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
22+
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
2223
#else
2324
// expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
2425
#endif
2526

2627
glob = to_global(con);
2728
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
28-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
29+
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
2930
#else
3031
// expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
3132
#endif
3233

3334
glob = to_global(con_typedef);
3435
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
35-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
36+
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
3637
#else
3738
// expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}}
3839
#endif
3940

4041
loc = to_global(glob);
4142
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
42-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
43+
// expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}}
4344
#else
4445
// expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}}
4546
#endif
4647

4748
global char *glob_c = to_global(loc);
4849
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
49-
// expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}}
50+
// expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}}
5051
#else
5152
// expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}}
5253
#endif

0 commit comments

Comments
 (0)