From 3d30f2cff7a4976a84911748c61de05a43d244e4 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 7 Nov 2019 15:00:19 +0000 Subject: [PATCH] [OpenCL] Add geometric and relational builtin functions Add the geometric and relational builtin functions from the OpenCL C specification. Patch by Pierre Gondois and Sven van Haastregt. Differential Revision: https://reviews.llvm.org/D69908 --- clang/lib/Sema/OpenCLBuiltins.td | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index 40070cc..080963a 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -274,10 +274,13 @@ 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 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 TLFloat : TypeList<"TLFloat", [Float, Double, Half]>; +def TLSignedInts : TypeList<"TLSignedInts", [Char, Short, Int, Long]>; +def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>; // All unsigned integer types twice, to facilitate unsigned return types for e.g. // uchar abs(char) and @@ -297,6 +300,10 @@ def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>; def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>; // All integer to unsigned def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>; +// Signed integer +def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>; +// Unsigned integer +def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>; // Float def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>; @@ -313,6 +320,14 @@ foreach Type = [Char, UChar, Short, UShort, } } +// GenType definitions for vec1234. +foreach Type = [Float, Double, Half] in { + def "GenType" # Type # Vec1234 : + GenericType<"GenType" # Type # Vec1234, + TypeList<"GL" # Type.Name, [Type]>, + Vec1234>; +} + //===----------------------------------------------------------------------===// // Definitions of OpenCL builtin functions @@ -566,6 +581,91 @@ foreach name = ["smoothstep"] in { } +//-------------------------------------------------------------------- +// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions +// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions +// --- Table 13 --- +// --- 1 argument --- +foreach name = ["length"] in { + def : Builtin; + def : Builtin; + def : Builtin; +} +foreach name = ["normalize"] in { + def : Builtin; + def : Builtin; + def : Builtin; +} +foreach name = ["fast_length"] in { + def : Builtin; +} +foreach name = ["fast_normalize"] in { + def : Builtin; +} + +// --- 2 arguments --- +foreach name = ["cross"] in { + foreach VSize = [3, 4] in { + def : Builtin, VectorType, VectorType], Attr.Const>; + def : Builtin, VectorType, VectorType], Attr.Const>; + def : Builtin, VectorType, VectorType], Attr.Const>; + } +} +foreach name = ["dot", "distance"] in { + def : Builtin; + def : Builtin; + def : Builtin; +} +foreach name = ["fast_distance"] in { + def : Builtin; +} + + +//-------------------------------------------------------------------- +// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions +// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions +// --- Table 14 --- +// --- 1 argument --- +foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in { + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; +} +foreach name = ["any", "all"] in { + def : Builtin; +} + +// --- 2 arguments --- +foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal", + "isless", "islessequal", "islessgreater", "isordered", + "isunordered"] in { + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; +} + +// --- 3 arguments --- +foreach name = ["bitselect"] in { + def : Builtin; +} +foreach name = ["select"] in { + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; +} + + // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s9.4.6, v2.0 s5.1.6 and 6.1.6 - Vector Data Load and Store Functions // --- Table 15 --- -- 2.7.4