diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -53,6 +53,7 @@ // FunctionExtension definitions. def FuncExtNone : FunctionExtension<"">; def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">; +def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">; def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">; def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">; def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">; @@ -344,6 +345,7 @@ // GenType definitions for multiple base types (e.g. all floating point types, // or all integer types). // All types +def AGenType1 : GenericType<"AGenType1", TLAll, Vec1>; def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>; def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>; // All integer @@ -1486,6 +1488,44 @@ } } +// OpenCL Extension v3.0 s38 - Extended Subgroup Functions + +// Section 38.4.1 - cl_khr_subgroup_extended_types +// TODO + +// Section 38.5.1 - cl_khr_subgroup_non_uniform_vote +// TODO + +// Section 38.6.1 - cl_khr_subgroup_ballot +let Extension = FuncExtKhrSubgroupBallot in { + def : Builtin<"sub_group_non_uniform_broadcast", [AGenTypeN, AGenTypeN, UInt]>; + def : Builtin<"sub_group_broadcast_first", [AGenType1, AGenType1]>; + def : Builtin<"sub_group_ballot", [VectorType, Int]>; + def : Builtin<"sub_group_inverse_ballot", [Int, VectorType], Attr.Const>; + def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType, UInt], Attr.Const>; + def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType], Attr.Const>; + def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType]>; + def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType]>; + def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType]>; + def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType]>; + + foreach op = ["eq", "ge", "gt", "le", "lt"] in { + def : Builtin<"get_sub_group_" # op # "_mask", [VectorType], Attr.Const>; + } +} + +// Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic +// TODO + +// Section 38.8.1 - cl_khr_subgroup_shuffle +// TODO + +// Section 38.9.1 - cl_khr_subgroup_shuffle_relative +// TODO + +// Section 38.10.1 - cl_khr_subgroup_clustered_reduce +// TODO + //-------------------------------------------------------------------- // Arm extensions. let Extension = ArmIntegerDotProductInt8 in { diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl --- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -7,7 +7,10 @@ // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header -// Test the -fdeclare-opencl-builtins option. +// Test the -fdeclare-opencl-builtins option. This is not a completeness +// test, so it should not test for all builtins defined by OpenCL. Instead +// this test should cover different functional aspects of the TableGen builtin +// function machinery. #pragma OPENCL EXTENSION cl_khr_fp16 : enable #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 @@ -30,6 +33,11 @@ typedef int int4 __attribute__((ext_vector_type(4))); typedef uint uint4 __attribute__((ext_vector_type(4))); typedef long long2 __attribute__((ext_vector_type(2))); + +// Enable extensions that are enabled in opencl-c-base.h. +#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) +#define cl_khr_subgroup_ballot 1 +#endif #endif kernel void test_pointers(volatile global void *global_p, global const int4 *a) { @@ -132,6 +140,14 @@ #endif } +kernel void extended_subgroup(global uint4 *out) { + out[0] = get_sub_group_eq_mask(); +#if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(__OPENCL_CPP_VERSION__) + // expected-error@-2{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}} + // expected-error@-3{{implicit conversion changes signedness}} +#endif +} + kernel void basic_vector_data() { #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 generic void *generic_p;