From: Sven van Haastregt Date: Tue, 26 Nov 2019 10:44:49 +0000 (+0000) Subject: [OpenCL] Add work-group and miscellaneous vector builtin functions X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e54c83ec4dd493f2c6a483be2f6f3fc93624d10a;p=platform%2Fupstream%2Fllvm.git [OpenCL] Add work-group and miscellaneous vector builtin functions Add the work-group and miscellaneous vector builtin functions from the OpenCL C specification. Patch by Pierre Gondois and Sven van Haastregt. --- diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index 0bd4c51..353e0c1 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -274,14 +274,21 @@ def Event : Type<"Event", QualType<"OCLEventTy">>; def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>; def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>; def Vec1 : IntList<"Vec1", [1]>; +def Vec2 : IntList<"Vec2", [2]>; +def Vec4 : IntList<"Vec4", [4]>; +def Vec8 : IntList<"Vec8", [8]>; +def Vec16 : IntList<"Vec16", [16]>; def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>; // Type lists. -def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; +def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; +def TLAllUnsigned : TypeList<"TLAllUnsigned", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>; def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>; def TLSignedInts : TypeList<"TLSignedInts", [Char, Short, Int, Long]>; def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>; +def TLIntLongFloats : TypeList<"TLIntLongFloats", [Int, UInt, Long, ULong, Float, Double, Half]>; + // All unsigned integer types twice, to facilitate unsigned return types for e.g. // uchar abs(char) and // uchar abs(uchar). @@ -306,6 +313,8 @@ def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>; // Float def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>; +// (u)int, (u)long, and all floats +def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>; // GenType definitions for every single base type (e.g. fp32 only). // Names are like: GenTypeFloatVecAndScalar. @@ -868,6 +877,31 @@ foreach Type = [Int, UInt] in { } //-------------------------------------------------------------------- +// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions +// --- Table 19 --- +foreach name = ["shuffle"] in { + foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in { + foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in { + def : Builtin, + GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>, + GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>], + Attr.Const>; + } + } +} +foreach name = ["shuffle2"] in { + foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in { + foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in { + def : Builtin, + GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>, + GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>, + GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>], + Attr.Const>; + } + } +} + +//-------------------------------------------------------------------- // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions // --- Table 22: Image Read Functions with Samplers --- @@ -1020,6 +1054,27 @@ foreach aQual = ["WO", "RW"] in { } +//-------------------------------------------------------------------- +// OpenCL v2.0 s6.13.15 - Work-group Functions +// --- Table 26 --- +let MinVersion = CL20 in { + foreach name = ["work_group_all", "work_group_any"] in { + def : Builtin; + } + foreach name = ["work_group_broadcast"] in { + def : Builtin; + def : Builtin; + def : Builtin; + } + foreach op = ["add", "min", "max"] in { + foreach name = ["work_group_reduce_", "work_group_scan_exclusive_", + "work_group_scan_inclusive_"] in { + def : Builtin; + } + } +} + + // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions let MinVersion = CL20 in { let Extension = "cl_khr_subgroups" in { diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl index 97a01a1..589d04c 100644 --- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -32,6 +32,7 @@ typedef float float4 __attribute__((ext_vector_type(4))); typedef half half4 __attribute__((ext_vector_type(4))); 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))); #endif @@ -67,6 +68,13 @@ char4 test_int(char c, char4 c4) { return max(c4, c); } +kernel void basic_vector_misc(float4 a) { + float4 res; + uint4 mask = (uint4)(1, 2, 3, 4); + + res = shuffle(a, mask); +} + kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) { int2 i2; sampler_t sampler;