OpenCLBuiltins.td 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. //==--- OpenCLBuiltins.td - OpenCL builtin declarations -------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  6. // See https://llvm.org/LICENSE.txt for license information.
  7. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  8. //
  9. //===----------------------------------------------------------------------===//
  10. //
  11. // This file contains TableGen definitions for OpenCL builtin function
  12. // declarations. In case of an unresolved function name in OpenCL, Clang will
  13. // check for a function described in this file when -fdeclare-opencl-builtins
  14. // is specified.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. //===----------------------------------------------------------------------===//
  18. // Definitions of miscellaneous basic entities.
  19. //===----------------------------------------------------------------------===//
  20. // Versions of OpenCL
  21. class Version<int _Version> {
  22. int ID = _Version;
  23. }
  24. def CLAll : Version< 0>;
  25. def CL10 : Version<100>;
  26. def CL11 : Version<110>;
  27. def CL12 : Version<120>;
  28. def CL20 : Version<200>;
  29. // Address spaces
  30. // Pointer types need to be assigned an address space.
  31. class AddressSpace<string _AS> {
  32. string Name = _AS;
  33. }
  34. def DefaultAS : AddressSpace<"clang::LangAS::Default">;
  35. def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">;
  36. def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">;
  37. def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">;
  38. def LocalAS : AddressSpace<"clang::LangAS::opencl_local">;
  39. def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">;
  40. // Qualified Type. These map to ASTContext::QualType.
  41. class QualType<string _Name, bit _IsAbstract=0> {
  42. // Name of the field or function in a clang::ASTContext
  43. // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
  44. string Name = _Name;
  45. // Some QualTypes in this file represent an abstract type for which there is
  46. // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
  47. // without access qualifiers.
  48. bit IsAbstract = _IsAbstract;
  49. }
  50. // List of integers.
  51. class IntList<string _Name, list<int> _List> {
  52. string Name = _Name;
  53. list<int> List = _List;
  54. }
  55. //===----------------------------------------------------------------------===//
  56. // OpenCL C classes for types
  57. //===----------------------------------------------------------------------===//
  58. // OpenCL C basic data types (int, float, image2d_t, ...).
  59. // Its child classes can represent concrete types (e.g. VectorType) or
  60. // abstract types (e.g. GenType).
  61. class Type<string _Name, QualType _QTName> {
  62. // Name of the Type.
  63. string Name = _Name;
  64. // QualType associated with this type.
  65. QualType QTName = _QTName;
  66. // Size of the vector (if applicable).
  67. int VecWidth = 1;
  68. // Is a pointer.
  69. bit IsPointer = 0;
  70. // "const" qualifier.
  71. bit IsConst = 0;
  72. // "volatile" qualifier.
  73. bit IsVolatile = 0;
  74. // Access qualifier. Must be one of ("RO", "WO", "RW").
  75. string AccessQualifier = "";
  76. // Address space.
  77. string AddrSpace = DefaultAS.Name;
  78. }
  79. // OpenCL vector types (e.g. int2, int3, int16, float8, ...).
  80. class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
  81. let VecWidth = _VecWidth;
  82. let AccessQualifier = "";
  83. // Inherited fields
  84. let IsPointer = _Ty.IsPointer;
  85. let IsConst = _Ty.IsConst;
  86. let IsVolatile = _Ty.IsVolatile;
  87. let AddrSpace = _Ty.AddrSpace;
  88. }
  89. // OpenCL pointer types (e.g. int*, float*, ...).
  90. class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
  91. Type<_Ty.Name, _Ty.QTName> {
  92. let AddrSpace = _AS.Name;
  93. // Inherited fields
  94. let VecWidth = _Ty.VecWidth;
  95. let IsPointer = 1;
  96. let IsConst = _Ty.IsConst;
  97. let IsVolatile = _Ty.IsVolatile;
  98. let AccessQualifier = _Ty.AccessQualifier;
  99. }
  100. // OpenCL const types (e.g. const int).
  101. class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
  102. let IsConst = 1;
  103. // Inherited fields
  104. let VecWidth = _Ty.VecWidth;
  105. let IsPointer = _Ty.IsPointer;
  106. let IsVolatile = _Ty.IsVolatile;
  107. let AccessQualifier = _Ty.AccessQualifier;
  108. let AddrSpace = _Ty.AddrSpace;
  109. }
  110. // OpenCL volatile types (e.g. volatile int).
  111. class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
  112. let IsVolatile = 1;
  113. // Inherited fields
  114. let VecWidth = _Ty.VecWidth;
  115. let IsPointer = _Ty.IsPointer;
  116. let IsConst = _Ty.IsConst;
  117. let AccessQualifier = _Ty.AccessQualifier;
  118. let AddrSpace = _Ty.AddrSpace;
  119. }
  120. // OpenCL image types (e.g. image2d).
  121. class ImageType<Type _Ty, string _AccessQualifier> :
  122. Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
  123. let VecWidth = 0;
  124. let AccessQualifier = _AccessQualifier;
  125. // Inherited fields
  126. let IsPointer = _Ty.IsPointer;
  127. let IsConst = _Ty.IsConst;
  128. let IsVolatile = _Ty.IsVolatile;
  129. let AddrSpace = _Ty.AddrSpace;
  130. }
  131. // List of Types.
  132. class TypeList<string _Name, list<Type> _Type> {
  133. string Name = _Name;
  134. list<Type> List = _Type;
  135. }
  136. // A GenericType is an abstract type that defines a set of types as a
  137. // combination of Types and vector sizes.
  138. //
  139. // For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
  140. // represents <int, int2, int4, float, float2, float4>.
  141. //
  142. // Some rules apply when using multiple GenericType arguments in a declaration:
  143. // 1. The number of vector sizes must be equal or 1 for all gentypes in a
  144. // declaration.
  145. // 2. The number of Types must be equal or 1 for all gentypes in a
  146. // declaration.
  147. // 3. Generic types are combined by iterating over all generic types at once.
  148. // For example, for the following GenericTypes
  149. // GenT1 = GenericType<half, [1, 2]> and
  150. // GenT2 = GenericType<float, int, [1, 2]>
  151. // A declaration f(GenT1, GenT2) results in the combinations
  152. // f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
  153. // 4. "sgentype" from the OpenCL specification is supported by specifying
  154. // a single vector size.
  155. // For example, for the following GenericTypes
  156. // GenT = GenericType<half, int, [1, 2]> and
  157. // SGenT = GenericType<half, int, [1]>
  158. // A declaration f(GenT, SGenT) results in the combinations
  159. // f(half, half), f(half2, half), f(int, int), f(int2, int) .
  160. class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
  161. Type<_Ty, QualType<"null", 1>> {
  162. // Possible element types of the generic type.
  163. TypeList TypeList = _TypeList;
  164. // Possible vector sizes of the types in the TypeList.
  165. IntList VectorList = _VectorList;
  166. // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
  167. let VecWidth = 0;
  168. }
  169. //===----------------------------------------------------------------------===//
  170. // OpenCL C class for builtin functions
  171. //===----------------------------------------------------------------------===//
  172. class Builtin<string _Name, list<Type> _Signature> {
  173. // Name of the builtin function
  174. string Name = _Name;
  175. // List of types used by the function. The first one is the return type and
  176. // the following are the arguments. The list must have at least one element
  177. // (the return type).
  178. list<Type> Signature = _Signature;
  179. // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
  180. string Extension = "";
  181. // Version of OpenCL from which the function is available (e.g.: CL10).
  182. // MinVersion is inclusive.
  183. Version MinVersion = CL10;
  184. // Version of OpenCL from which the function is not supported anymore.
  185. // MaxVersion is exclusive.
  186. // CLAll makes the function available for all versions.
  187. Version MaxVersion = CLAll;
  188. }
  189. //===----------------------------------------------------------------------===//
  190. // Definitions of OpenCL C types
  191. //===----------------------------------------------------------------------===//
  192. // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
  193. def Bool : Type<"bool", QualType<"BoolTy">>;
  194. def Char : Type<"char", QualType<"CharTy">>;
  195. def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
  196. def Short : Type<"short", QualType<"ShortTy">>;
  197. def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
  198. def Int : Type<"int", QualType<"IntTy">>;
  199. def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
  200. def Long : Type<"long", QualType<"LongTy">>;
  201. def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
  202. def Float : Type<"float", QualType<"FloatTy">>;
  203. def Double : Type<"double", QualType<"DoubleTy">>;
  204. def Half : Type<"half", QualType<"HalfTy">>;
  205. def Size : Type<"size_t", QualType<"getSizeType()">>;
  206. def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
  207. def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
  208. def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
  209. def Void : Type<"void_t", QualType<"VoidTy">>;
  210. // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
  211. // Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
  212. // OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
  213. // The image definitions are "abstract". They should not be used without
  214. // specifying an access qualifier (RO/WO/RW).
  215. def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
  216. def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
  217. def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
  218. def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
  219. def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
  220. def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
  221. def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
  222. def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
  223. def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
  224. def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
  225. def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
  226. def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
  227. def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
  228. def Event : Type<"Event", QualType<"OCLEventTy">>;
  229. //===----------------------------------------------------------------------===//
  230. // Definitions of OpenCL gentype variants
  231. //===----------------------------------------------------------------------===//
  232. // The OpenCL specification often uses "gentype" in builtin function
  233. // declarations to indicate that a builtin function is available with various
  234. // argument and return types. The types represented by "gentype" vary between
  235. // different parts of the specification. The following definitions capture
  236. // the different type lists for gentypes in different parts of the
  237. // specification.
  238. // Vector width lists.
  239. def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
  240. def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
  241. def Vec1 : IntList<"Vec1", [1]>;
  242. // Type lists.
  243. def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
  244. def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
  245. def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
  246. // GenType definitions for multiple base types (e.g. all floating point types,
  247. // or all integer types).
  248. // All types
  249. def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
  250. def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
  251. // All integer
  252. def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
  253. def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
  254. def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
  255. // Float
  256. def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
  257. // GenType definitions for every single base type (e.g. fp32 only).
  258. // Names are like: GenTypeFloatVecAndScalar.
  259. foreach Type = [Char, UChar, Short, UShort,
  260. Int, UInt, Long, ULong,
  261. Float, Double, Half] in {
  262. foreach VecSizes = [VecAndScalar, VecNoScalar] in {
  263. def "GenType" # Type # VecSizes :
  264. GenericType<"GenType" # Type # VecSizes,
  265. TypeList<"GL" # Type.Name, [Type]>,
  266. VecSizes>;
  267. }
  268. }
  269. //===----------------------------------------------------------------------===//
  270. // Definitions of OpenCL builtin functions
  271. //===----------------------------------------------------------------------===//
  272. //--------------------------------------------------------------------
  273. // OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
  274. // OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
  275. // Generate the convert_* builtins functions.
  276. foreach RType = [Float, Double, Half, Char, UChar, Short,
  277. UShort, Int, UInt, Long, ULong] in {
  278. foreach IType = [Float, Double, Half, Char, UChar, Short,
  279. UShort, Int, UInt, Long, ULong] in {
  280. foreach sat = ["", "_sat"] in {
  281. foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
  282. def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType]>;
  283. foreach v = [2, 3, 4, 8, 16] in {
  284. def : Builtin<"convert_" # RType.Name # v # sat # rnd,
  285. [VectorType<RType, v>,
  286. VectorType<IType, v>]>;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. //--------------------------------------------------------------------
  293. // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
  294. // --- Table 7 ---
  295. def : Builtin<"get_work_dim", [UInt]>;
  296. foreach name = ["get_global_size", "get_global_id", "get_local_size",
  297. "get_local_id", "get_num_groups", "get_group_id",
  298. "get_global_offset"] in {
  299. def : Builtin<name, [Size, UInt]>;
  300. }
  301. let MinVersion = CL20 in {
  302. def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
  303. foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
  304. def : Builtin<name, [Size]>;
  305. }
  306. }
  307. //--------------------------------------------------------------------
  308. // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
  309. // 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
  310. // --- Table 15 ---
  311. // Variants for OpenCL versions below 2.0, using pointers to the global, local
  312. // and private address spaces.
  313. let MaxVersion = CL20 in {
  314. foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
  315. foreach VSize = [2, 3, 4, 8, 16] in {
  316. foreach name = ["vload" # VSize] in {
  317. def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
  318. def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
  319. def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
  320. def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
  321. def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
  322. def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
  323. def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
  324. def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
  325. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
  326. def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
  327. def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
  328. }
  329. foreach name = ["vstore" # VSize] in {
  330. def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
  331. def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
  332. def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
  333. def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
  334. def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
  335. def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
  336. def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
  337. def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
  338. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
  339. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
  340. def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
  341. }
  342. foreach name = ["vloada_half" # VSize] in {
  343. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
  344. }
  345. foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
  346. foreach name = ["vstorea_half" # VSize # rnd] in {
  347. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
  348. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. // Variants for OpenCL versions above 2.0, using pointers to the generic
  355. // address space.
  356. let MinVersion = CL20 in {
  357. foreach VSize = [2, 3, 4, 8, 16] in {
  358. foreach name = ["vload" # VSize] in {
  359. def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
  360. def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
  361. def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
  362. def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
  363. def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
  364. def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
  365. def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
  366. def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
  367. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
  368. def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
  369. def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
  370. }
  371. foreach name = ["vstore" # VSize] in {
  372. def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
  373. def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
  374. def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
  375. def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
  376. def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
  377. def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
  378. def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
  379. def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
  380. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
  381. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
  382. def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
  383. }
  384. foreach name = ["vloada_half" # VSize] in {
  385. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
  386. }
  387. foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
  388. foreach name = ["vstorea_half" # VSize # rnd] in {
  389. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
  390. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
  391. }
  392. }
  393. }
  394. }
  395. // Variants using pointers to the constant address space.
  396. foreach VSize = [2, 3, 4, 8, 16] in {
  397. foreach name = ["vload" # VSize] in {
  398. def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
  399. def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
  400. def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
  401. def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
  402. def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
  403. def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
  404. def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
  405. def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
  406. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
  407. def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
  408. def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
  409. }
  410. foreach name = ["vloada_half" # VSize] in {
  411. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
  412. }
  413. foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
  414. foreach name = ["vstorea_half" # VSize # rnd] in {
  415. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
  416. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
  417. }
  418. }
  419. }
  420. //--------------------------------------------------------------------
  421. // OpenCL v1.1 s6.11.10, v1.2 s6.12.10, v2.0 s6.13.10: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
  422. // OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
  423. // --- Table 18 ---
  424. foreach name = ["async_work_group_copy"] in {
  425. def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
  426. def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
  427. }
  428. foreach name = ["async_work_group_strided_copy"] in {
  429. def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
  430. def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
  431. }
  432. foreach name = ["wait_group_events"] in {
  433. def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
  434. }
  435. foreach name = ["prefetch"] in {
  436. def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
  437. }
  438. //--------------------------------------------------------------------
  439. // OpenCL v2.0 s6.13.11 - Atomics Functions.
  440. // Functions that use memory_order and cl_mem_fence_flags enums are not
  441. // declared here as the TableGen backend does not handle enums.
  442. // OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
  443. // --- Table 9.1 ---
  444. foreach Type = [Int, UInt] in {
  445. foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
  446. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
  447. }
  448. foreach name = ["atom_inc", "atom_dec"] in {
  449. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
  450. }
  451. foreach name = ["atom_cmpxchg"] in {
  452. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
  453. }
  454. }
  455. // OpenCL v1.2 s6.12.2: Math Functions
  456. foreach name = ["acos", "acosh", "acospi",
  457. "asin", "asinh", "asinpi",
  458. "atan", "atanh", "atanpi"] in {
  459. def : Builtin<name, [FGenTypeN, FGenTypeN]>;
  460. }
  461. foreach name = ["atan2", "atan2pi"] in {
  462. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
  463. }
  464. foreach name = ["fmax", "fmin"] in {
  465. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
  466. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float]>;
  467. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double]>;
  468. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half]>;
  469. }
  470. // OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
  471. foreach name = ["max", "min"] in {
  472. def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
  473. def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1]>;
  474. }
  475. //--------------------------------------------------------------------
  476. // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
  477. // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
  478. // --- Table 22: Image Read Functions with Samplers ---
  479. foreach imgTy = [Image1d] in {
  480. foreach coordTy = [Int, Float] in {
  481. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
  482. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
  483. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
  484. }
  485. }
  486. foreach imgTy = [Image2d, Image1dArray] in {
  487. foreach coordTy = [Int, Float] in {
  488. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
  489. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
  490. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
  491. }
  492. }
  493. foreach imgTy = [Image3d, Image2dArray] in {
  494. foreach coordTy = [Int, Float] in {
  495. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
  496. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
  497. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
  498. }
  499. }
  500. foreach coordTy = [Int, Float] in {
  501. def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>]>;
  502. def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>]>;
  503. }
  504. // --- Table 23: Sampler-less Read Functions ---
  505. foreach aQual = ["RO", "RW"] in {
  506. foreach imgTy = [Image2d, Image1dArray] in {
  507. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
  508. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
  509. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
  510. }
  511. foreach imgTy = [Image3d, Image2dArray] in {
  512. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
  513. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
  514. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
  515. }
  516. foreach imgTy = [Image1d, Image1dBuffer] in {
  517. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int]>;
  518. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int]>;
  519. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int]>;
  520. }
  521. def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>]>;
  522. def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>]>;
  523. }
  524. // --- Table 24: Image Write Functions ---
  525. foreach aQual = ["WO", "RW"] in {
  526. foreach imgTy = [Image2d] in {
  527. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
  528. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
  529. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
  530. }
  531. foreach imgTy = [Image2dArray] in {
  532. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
  533. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
  534. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
  535. }
  536. foreach imgTy = [Image1d, Image1dBuffer] in {
  537. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
  538. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
  539. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
  540. }
  541. foreach imgTy = [Image1dArray] in {
  542. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
  543. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
  544. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
  545. }
  546. foreach imgTy = [Image3d] in {
  547. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
  548. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
  549. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
  550. }
  551. def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
  552. def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
  553. }
  554. // --- Table 25: Image Query Functions ---
  555. foreach aQual = ["RO", "WO", "RW"] in {
  556. foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
  557. Image1dArray, Image2dArray, Image2dDepth,
  558. Image2dArrayDepth] in {
  559. foreach name = ["get_image_width", "get_image_channel_data_type",
  560. "get_image_channel_order"] in {
  561. def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
  562. }
  563. }
  564. foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
  565. Image2dArrayDepth] in {
  566. def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
  567. }
  568. def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
  569. foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
  570. Image2dArrayDepth] in {
  571. def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
  572. }
  573. def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
  574. foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
  575. def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
  576. }
  577. }
  578. // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
  579. // --- Table 8 ---
  580. foreach aQual = ["RO"] in {
  581. foreach name = ["read_imageh"] in {
  582. foreach coordTy = [Int, Float] in {
  583. foreach imgTy = [Image2d, Image1dArray] in {
  584. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>]>;
  585. }
  586. foreach imgTy = [Image3d, Image2dArray] in {
  587. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>]>;
  588. }
  589. foreach imgTy = [Image1d] in {
  590. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy]>;
  591. }
  592. }
  593. }
  594. }
  595. // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
  596. // --- Table 9 ---
  597. foreach aQual = ["RO", "RW"] in {
  598. foreach name = ["read_imageh"] in {
  599. foreach imgTy = [Image2d, Image1dArray] in {
  600. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
  601. }
  602. foreach imgTy = [Image3d, Image2dArray] in {
  603. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
  604. }
  605. foreach imgTy = [Image1d, Image1dBuffer] in {
  606. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int]>;
  607. }
  608. }
  609. }
  610. // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
  611. // --- Table 10 ---
  612. foreach aQual = ["WO", "RW"] in {
  613. foreach name = ["write_imageh"] in {
  614. def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
  615. def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
  616. def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
  617. def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
  618. def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
  619. def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
  620. }
  621. }
  622. // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
  623. let MinVersion = CL20 in {
  624. let Extension = "cl_khr_subgroups" in {
  625. def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
  626. def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
  627. def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
  628. }
  629. }