[OpenCL] Add cl_khr_subgroup_ballot to TableGen BIFs

Add the builtin functions brought by the cl_khr_subgroup_ballot
extension to `-fdeclare-opencl-builtins`.

Also add placeholder comments for the other Extended Subgroup
Functions from the OpenCL Extension Specification.

Add a comment clarifying the scope of the test.

Differential Revision: https://reviews.llvm.org/D95523
This commit is contained in:
Sven van Haastregt 2021-02-02 17:20:38 +00:00
parent d38973aa4d
commit 9caf364d69
2 changed files with 57 additions and 1 deletions

View File

@ -53,6 +53,7 @@ class FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
// 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 @@ def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULo
// 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 @@ let Extension = FuncExtKhrSubgroups in {
}
}
// 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<UInt, 4>, Int]>;
def : Builtin<"sub_group_inverse_ballot", [Int, VectorType<UInt, 4>], Attr.Const>;
def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType<UInt, 4>, UInt], Attr.Const>;
def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType<UInt, 4>], Attr.Const>;
def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType<UInt, 4>]>;
def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType<UInt, 4>]>;
def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType<UInt, 4>]>;
def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType<UInt, 4>]>;
foreach op = ["eq", "ge", "gt", "le", "lt"] in {
def : Builtin<"get_sub_group_" # op # "_mask", [VectorType<UInt, 4>], 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 {

View File

@ -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 int2 __attribute__((ext_vector_type(2)));
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 @@ kernel void basic_subgroup(global uint *out) {
#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;