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 @@ -279,6 +279,11 @@ def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>; +// All unsigned integer types twice, to facilitate unsigned return types for e.g. +// uchar abs(char) and +// uchar abs(uchar). +def TLAllUIntsTwice : TypeList<"TLAllUIntsTwice", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>; + def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>; // GenType definitions for multiple base types (e.g. all floating point types, @@ -290,6 +295,8 @@ def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>; def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>; def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>; +// All integer to unsigned +def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>; // Float def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>; @@ -467,6 +474,61 @@ } //-------------------------------------------------------------------- +// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions +// --- Table 10 --- +// --- 1 argument --- +foreach name = ["abs"] in { + def : Builtin; +} +foreach name = ["clz", "popcount"] in { + def : Builtin; +} +let MinVersion = CL20 in { + foreach name = ["ctz"] in { + def : Builtin; + } +} + +// --- 2 arguments --- +foreach name = ["abs_diff"] in { + def : Builtin; +} +foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in { + def : Builtin; +} +foreach name = ["max", "min"] in { + def : Builtin; + def : Builtin; +} +foreach name = ["upsample"] in { + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; +} + +// --- 3 arguments --- +foreach name = ["clamp"] in { + def : Builtin; + def : Builtin; +} +foreach name = ["mad_hi", "mad_sat"] in { + def : Builtin; +} + +// --- Table 11 --- +foreach name = ["mad24"] in { + def : Builtin; + def : Builtin; +} +foreach name = ["mul24"] in { + def : Builtin; + def : Builtin; +} + +//-------------------------------------------------------------------- // OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions // OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions // --- Table 12 --- @@ -655,12 +717,6 @@ } } -// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions -foreach name = ["max", "min"] in { - def : Builtin; - def : Builtin; -} - //-------------------------------------------------------------------- // 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 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 @@ -20,18 +20,19 @@ // Provide typedefs when invoking clang without -finclude-default-header. #ifdef NO_HEADER +typedef unsigned char uchar; +typedef unsigned int uint; +typedef unsigned long ulong; +typedef unsigned short ushort; +typedef __SIZE_TYPE__ size_t; typedef char char2 __attribute__((ext_vector_type(2))); typedef char char4 __attribute__((ext_vector_type(4))); +typedef uchar uchar4 __attribute__((ext_vector_type(4))); 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 long long2 __attribute__((ext_vector_type(2))); -typedef unsigned char uchar; -typedef unsigned int uint; -typedef unsigned long ulong; -typedef unsigned short ushort; -typedef __SIZE_TYPE__ size_t; #endif kernel void test_pointers(volatile global void *global_p, global const int4 *a) { @@ -61,6 +62,8 @@ char4 test_int(char c, char4 c4) { char m = max(c, c); char4 m4 = max(c4, c4); + uchar4 abs1 = abs(c4); + uchar4 abs2 = abs(abs1); return max(c4, c); }