Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for llvm/llvm-project#53763 #46

Open
wants to merge 1 commit into
base: release/14.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1625,50 +1625,50 @@ LANGBUILTIN(__builtin_coro_suspend, "cIb", "n", COR_LANG)

// 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", OCLC20_LANG)
LANGBUILTIN(write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(read_pipe, "i.", "tn", OCL_PIPE)
LANGBUILTIN(write_pipe, "i.", "tn", OCL_PIPE)

LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCL_PIPE)
LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCL_PIPE)

LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(commit_write_pipe, "v.", "tn", OCL_PIPE)
LANGBUILTIN(commit_read_pipe, "v.", "tn", OCL_PIPE)

LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCL_PIPE)
LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCL_PIPE)

LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCL_PIPE)
LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCL_PIPE)

LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCL_PIPE)
LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCL_PIPE)

LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC20_LANG)
LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCL_PIPE)
LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCL_PIPE)

LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCL_PIPE)
LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCL_PIPE)

// OpenCL v2.0 s6.13.17 - Enqueue kernel functions.
// Custom builtin check allows to perform special check of passed block arguments.
LANGBUILTIN(enqueue_kernel, "i.", "tn", OCLC20_LANG)
LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
LANGBUILTIN(enqueue_kernel, "i.", "tn", OCL_DSE)
LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCL_DSE)
LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", OCL_DSE)
LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", OCL_DSE)
LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCL_DSE)

// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
// FIXME: Pointer parameters of OpenCL builtins should have their address space
// requirement defined.
LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)
LANGBUILTIN(to_global, "v*v*", "tn", OCL_GAS)
LANGBUILTIN(to_local, "v*v*", "tn", OCL_GAS)
LANGBUILTIN(to_private, "v*v*", "tn", OCL_GAS)

// OpenCL half load/store builtin
LANGBUILTIN(__builtin_store_half, "vdh*", "n", ALL_OCLC_LANGUAGES)
LANGBUILTIN(__builtin_store_halff, "vfh*", "n", ALL_OCLC_LANGUAGES)
LANGBUILTIN(__builtin_load_half, "dhC*", "nc", ALL_OCLC_LANGUAGES)
LANGBUILTIN(__builtin_load_halff, "fhC*", "nc", ALL_OCLC_LANGUAGES)
LANGBUILTIN(__builtin_store_half, "vdh*", "n", ALL_OCL_LANGUAGES)
LANGBUILTIN(__builtin_store_halff, "vfh*", "n", ALL_OCL_LANGUAGES)
LANGBUILTIN(__builtin_load_half, "dhC*", "nc", ALL_OCL_LANGUAGES)
LANGBUILTIN(__builtin_load_halff, "fhC*", "nc", ALL_OCL_LANGUAGES)

// Builtins for os_log/os_trace
BUILTIN(__builtin_os_log_format_buffer_size, "zcC*.", "p:0:nut")
Expand Down
25 changes: 13 additions & 12 deletions clang/include/clang/Basic/Builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ class IdentifierTable;
class LangOptions;

enum LanguageID {
GNU_LANG = 0x1, // builtin requires GNU mode.
C_LANG = 0x2, // builtin for c only.
CXX_LANG = 0x4, // builtin for cplusplus only.
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
MS_LANG = 0x10, // builtin requires MS mode.
OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
OMP_LANG = 0x80, // builtin requires OpenMP.
CUDA_LANG = 0x100, // builtin requires CUDA.
COR_LANG = 0x200, // builtin requires use of 'fcoroutine-ts' option.
GNU_LANG = 0x1, // builtin requires GNU mode.
C_LANG = 0x2, // builtin for c only.
CXX_LANG = 0x4, // builtin for cplusplus only.
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
MS_LANG = 0x10, // builtin requires MS mode.
OMP_LANG = 0x20, // builtin requires OpenMP.
CUDA_LANG = 0x40, // builtin requires CUDA.
COR_LANG = 0x80, // builtin requires use of 'fcoroutine-ts' option.
OCL_GAS = 0x100, // builtin requires OpenCL generic address space.
OCL_PIPE = 0x200, // builtin requires OpenCL pipe.
OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue.
ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
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.
ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC20_LANG // builtin for OCLC languages.
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
};

namespace Builtin {
Expand Down
26 changes: 15 additions & 11 deletions clang/lib/Basic/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,26 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo,
bool MSModeUnsupported =
!LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG);
bool ObjCUnsupported = !LangOpts.ObjC && BuiltinInfo.Langs == OBJC_LANG;
bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) == OCLC1X_LANG;
bool OclC2Unsupported =
(LangOpts.getOpenCLCompatibleVersion() != 200) &&
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
bool OclCUnsupported = !LangOpts.OpenCL &&
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
bool OclCUnsupported =
!LangOpts.OpenCL && (BuiltinInfo.Langs & ALL_OCL_LANGUAGES);
bool OclGASUnsupported =
!LangOpts.OpenCLGenericAddressSpace && (BuiltinInfo.Langs & OCL_GAS);
bool OclPipeUnsupported =
!LangOpts.OpenCLPipes && (BuiltinInfo.Langs & OCL_PIPE);
// Device side enqueue is not supported until OpenCL 2.0. In 2.0 and higher
// support is indicated with language option for blocks.
bool OclDSEUnsupported =
(LangOpts.getOpenCLCompatibleVersion() < 200 || !LangOpts.Blocks) &&
(BuiltinInfo.Langs & OCL_DSE);
bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
bool CUDAUnsupported = !LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG;
bool CPlusPlusUnsupported =
!LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG;
return !BuiltinsUnsupported && !CorBuiltinsUnsupported &&
!MathBuiltinsUnsupported && !OclCUnsupported && !OclC1Unsupported &&
!OclC2Unsupported && !OpenMPUnsupported && !GnuModeUnsupported &&
!MSModeUnsupported && !ObjCUnsupported && !CPlusPlusUnsupported &&
!CUDAUnsupported;
!MathBuiltinsUnsupported && !OclCUnsupported && !OclGASUnsupported &&
!OclPipeUnsupported && !OclDSEUnsupported && !OpenMPUnsupported &&
!GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported &&
!CPlusPlusUnsupported && !CUDAUnsupported;
}

/// initializeBuiltins - Mark the identifiers for all the builtins with their
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL2.0 -ffake-address-space-map -O1 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=CHECK-LIFETIMES
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL3.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL3.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64
// RUN: %clang_cc1 -disable-noundef-analysis %s -cl-std=CL3.0 -ffake-address-space-map -O1 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=CHECK-LIFETIMES

#pragma OPENCL EXTENSION cl_khr_subgroups : enable

Expand Down
5 changes: 1 addition & 4 deletions clang/test/CodeGenOpenCL/pipe_types.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -DTEST_STRUCT -o - %s | FileCheck --check-prefixes=CHECK,CHECK-STRUCT %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck --check-prefixes=CHECK,CHECK-STRUCT %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_pipes,+__opencl_c_generic_address_space,+__opencl_c_program_scope_global_variables -o - %s | FileCheck --check-prefixes=CHECK %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_pipes,+__opencl_c_generic_address_space -o - %s | FileCheck --check-prefixes=CHECK %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_pipes,+__opencl_c_generic_address_space,+__opencl_c_program_scope_global_variables -o - %s | FileCheck --check-prefixes=CHECK %s
Expand Down Expand Up @@ -36,8 +36,6 @@ kernel void test6(MyPipe p) {
// CHECK: define{{.*}} spir_kernel void @test6(%opencl.pipe_ro_t* %p)
}

#ifdef TEST_STRUCT
// FIXME: not supported for OpenCL C 3.0 as language built-ins not supported yet
struct Person {
const char *Name;
bool isFemale;
Expand All @@ -52,4 +50,3 @@ void test_reserved_read_pipe(global struct Person *SDst,
read_pipe (SPipe, SDst);
// CHECK-STRUCT: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
}
#endif // TEST_STRUCT
2 changes: 2 additions & 0 deletions clang/test/CodeGenOpenCL/to_addr_builtin.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=clc++ -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=cl2.0 -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -O0 -cl-std=cl3.0 -o - %s | FileCheck %s

// CHECK: %[[A:.*]] = type { float, float, float }
typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
// RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
// RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
// RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"

typedef struct {int a;} ndrange_t;
// Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec.
Expand Down
9 changes: 8 additions & 1 deletion clang/test/SemaOpenCL/clang-builtin-version.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100
// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100 -cl-std=CL1.2
// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100 -cl-std=CL3.0 -cl-ext=-__opencl_c_device_enqueue,-__opencl_c_generic_address_space,-__opencl_c_pipes

// Confirm CL2.0 Clang builtins are not available in earlier versions
// Confirm CL2.0 Clang builtins are not available in earlier versions and in OpenCL C 3.0 without required features.

kernel void dse_builtins() {
int tmp;
Expand All @@ -13,6 +15,11 @@ kernel void dse_builtins() {
size = get_kernel_preferred_work_group_size_multiple(^(void) { // expected-error{{implicit declaration of function 'get_kernel_preferred_work_group_size_multiple' is invalid in OpenCL}}
return;
});
#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0) && !defined(__opencl_c_device_enqueue)
// expected-error@-10{{support disabled - compile with -fblocks or for OpenCL C 2.0 or OpenCL C 3.0 with __opencl_c_device_enqueue feature}}
// expected-error@-8{{support disabled - compile with -fblocks or for OpenCL C 2.0 or OpenCL C 3.0 with __opencl_c_device_enqueue feature}}
// expected-error@-6{{support disabled - compile with -fblocks or for OpenCL C 2.0 or OpenCL C 3.0 with __opencl_c_device_enqueue feature}}
#endif
}

void pipe_builtins() {
Expand Down
Loading