OpenCLBuiltins.td 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  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. // OpenCL language extension.
  41. class AbstractExtension<string _Ext> {
  42. // One or more OpenCL extensions, space separated. Each extension must be
  43. // a valid extension name for the opencl extension pragma.
  44. string ExtName = _Ext;
  45. }
  46. // Extension associated to a builtin function.
  47. class FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
  48. // Extension associated to a type. This enables implicit conditionalization of
  49. // builtin function overloads containing a type that depends on an extension.
  50. // During overload resolution, when a builtin function overload contains a type
  51. // with a TypeExtension, those overloads are skipped when the extension is
  52. // disabled.
  53. class TypeExtension<string _Ext> : AbstractExtension<_Ext>;
  54. // Concatenate zero or more space-separated extensions in NewExts to Base and
  55. // return the resulting FunctionExtension in ret.
  56. class concatExtension<FunctionExtension Base, string NewExts> {
  57. FunctionExtension ret = FunctionExtension<
  58. !cond(
  59. // Return Base extension if NewExts is empty,
  60. !empty(NewExts) : Base.ExtName,
  61. // otherwise, return NewExts if Base extension is empty,
  62. !empty(Base.ExtName) : NewExts,
  63. // otherwise, concatenate NewExts to Base.
  64. true : Base.ExtName # " " # NewExts
  65. )
  66. >;
  67. }
  68. // TypeExtension definitions.
  69. def NoTypeExt : TypeExtension<"">;
  70. def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
  71. def Fp64TypeExt : TypeExtension<"cl_khr_fp64">;
  72. def Atomic64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics">;
  73. def AtomicFp64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64">;
  74. // FunctionExtension definitions.
  75. def FuncExtNone : FunctionExtension<"">;
  76. def FuncExtKhrSubgroups : FunctionExtension<"__opencl_subgroup_builtins">;
  77. def FuncExtKhrSubgroupExtendedTypes : FunctionExtension<"cl_khr_subgroup_extended_types">;
  78. def FuncExtKhrSubgroupNonUniformVote : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
  79. def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">;
  80. def FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">;
  81. def FuncExtKhrSubgroupShuffle : FunctionExtension<"cl_khr_subgroup_shuffle">;
  82. def FuncExtKhrSubgroupShuffleRelative : FunctionExtension<"cl_khr_subgroup_shuffle_relative">;
  83. def FuncExtKhrSubgroupClusteredReduce : FunctionExtension<"cl_khr_subgroup_clustered_reduce">;
  84. def FuncExtKhrExtendedBitOps : FunctionExtension<"cl_khr_extended_bit_ops">;
  85. def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">;
  86. def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
  87. def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">;
  88. def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
  89. def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
  90. def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
  91. def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">;
  92. def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">;
  93. def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
  94. def FuncExtOpenCLCDeviceEnqueue : FunctionExtension<"__opencl_c_device_enqueue">;
  95. def FuncExtOpenCLCGenericAddressSpace : FunctionExtension<"__opencl_c_generic_address_space">;
  96. def FuncExtOpenCLCNamedAddressSpaceBuiltins : FunctionExtension<"__opencl_c_named_address_space_builtins">;
  97. def FuncExtOpenCLCPipes : FunctionExtension<"__opencl_c_pipes">;
  98. def FuncExtOpenCLCWGCollectiveFunctions : FunctionExtension<"__opencl_c_work_group_collective_functions">;
  99. def FuncExtOpenCLCReadWriteImages : FunctionExtension<"__opencl_c_read_write_images">;
  100. def FuncExtFloatAtomicsFp16GlobalASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store">;
  101. def FuncExtFloatAtomicsFp16LocalASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_load_store">;
  102. def FuncExtFloatAtomicsFp16GenericASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store __opencl_c_ext_fp16_local_atomic_load_store">;
  103. def FuncExtFloatAtomicsFp16GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_add">;
  104. def FuncExtFloatAtomicsFp32GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_add">;
  105. def FuncExtFloatAtomicsFp64GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_add">;
  106. def FuncExtFloatAtomicsFp16LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add">;
  107. def FuncExtFloatAtomicsFp32LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add">;
  108. def FuncExtFloatAtomicsFp64LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add">;
  109. def FuncExtFloatAtomicsFp16GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add __opencl_c_ext_fp16_global_atomic_add">;
  110. def FuncExtFloatAtomicsFp32GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add __opencl_c_ext_fp32_global_atomic_add">;
  111. def FuncExtFloatAtomicsFp64GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add __opencl_c_ext_fp64_global_atomic_add">;
  112. def FuncExtFloatAtomicsFp16GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_min_max">;
  113. def FuncExtFloatAtomicsFp32GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_min_max">;
  114. def FuncExtFloatAtomicsFp64GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_min_max">;
  115. def FuncExtFloatAtomicsFp16LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max">;
  116. def FuncExtFloatAtomicsFp32LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max">;
  117. def FuncExtFloatAtomicsFp64LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max">;
  118. def FuncExtFloatAtomicsFp16GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max __opencl_c_ext_fp16_global_atomic_min_max">;
  119. def FuncExtFloatAtomicsFp32GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max __opencl_c_ext_fp32_global_atomic_min_max">;
  120. def FuncExtFloatAtomicsFp64GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max __opencl_c_ext_fp64_global_atomic_min_max">;
  121. // Not a real extension, but a workaround to add C++ for OpenCL specific builtins.
  122. def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
  123. // Arm extensions.
  124. def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">;
  125. def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
  126. def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
  127. def ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">;
  128. // Qualified Type. These map to ASTContext::QualType.
  129. class QualType<string _TypeExpr, bit _IsAbstract=0> {
  130. // Expression to obtain the QualType inside OCL2Qual.
  131. // E.g. TypeExpr="Context.IntTy" for the int type.
  132. string TypeExpr = _TypeExpr;
  133. // Some QualTypes in this file represent an abstract type for which there is
  134. // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
  135. // without access qualifiers.
  136. bit IsAbstract = _IsAbstract;
  137. }
  138. // List of integers.
  139. class IntList<string _Name, list<int> _List> {
  140. string Name = _Name;
  141. list<int> List = _List;
  142. }
  143. //===----------------------------------------------------------------------===//
  144. // OpenCL C classes for types
  145. //===----------------------------------------------------------------------===//
  146. // OpenCL C basic data types (int, float, image2d_t, ...).
  147. // Its child classes can represent concrete types (e.g. VectorType) or
  148. // abstract types (e.g. GenType).
  149. class Type<string _Name, QualType _QTExpr> {
  150. // Name of the Type.
  151. string Name = _Name;
  152. // QualType associated with this type.
  153. QualType QTExpr = _QTExpr;
  154. // Size of the vector (if applicable).
  155. int VecWidth = 1;
  156. // Is a pointer.
  157. bit IsPointer = 0;
  158. // "const" qualifier.
  159. bit IsConst = 0;
  160. // "volatile" qualifier.
  161. bit IsVolatile = 0;
  162. // Access qualifier. Must be one of ("RO", "WO", "RW").
  163. string AccessQualifier = "";
  164. // Address space.
  165. string AddrSpace = DefaultAS.Name;
  166. // Extension that needs to be enabled to expose a builtin that uses this type.
  167. TypeExtension Extension = NoTypeExt;
  168. }
  169. // OpenCL vector types (e.g. int2, int3, int16, float8, ...).
  170. class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTExpr> {
  171. let VecWidth = _VecWidth;
  172. let AccessQualifier = "";
  173. // Inherited fields
  174. let IsPointer = _Ty.IsPointer;
  175. let IsConst = _Ty.IsConst;
  176. let IsVolatile = _Ty.IsVolatile;
  177. let AddrSpace = _Ty.AddrSpace;
  178. let Extension = _Ty.Extension;
  179. }
  180. // OpenCL pointer types (e.g. int*, float*, ...).
  181. class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
  182. Type<_Ty.Name, _Ty.QTExpr> {
  183. let AddrSpace = _AS.Name;
  184. // Inherited fields
  185. let VecWidth = _Ty.VecWidth;
  186. let IsPointer = 1;
  187. let IsConst = _Ty.IsConst;
  188. let IsVolatile = _Ty.IsVolatile;
  189. let AccessQualifier = _Ty.AccessQualifier;
  190. let Extension = _Ty.Extension;
  191. }
  192. // OpenCL const types (e.g. const int).
  193. class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> {
  194. let IsConst = 1;
  195. // Inherited fields
  196. let VecWidth = _Ty.VecWidth;
  197. let IsPointer = _Ty.IsPointer;
  198. let IsVolatile = _Ty.IsVolatile;
  199. let AccessQualifier = _Ty.AccessQualifier;
  200. let AddrSpace = _Ty.AddrSpace;
  201. let Extension = _Ty.Extension;
  202. }
  203. // OpenCL volatile types (e.g. volatile int).
  204. class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> {
  205. let IsVolatile = 1;
  206. // Inherited fields
  207. let VecWidth = _Ty.VecWidth;
  208. let IsPointer = _Ty.IsPointer;
  209. let IsConst = _Ty.IsConst;
  210. let AccessQualifier = _Ty.AccessQualifier;
  211. let AddrSpace = _Ty.AddrSpace;
  212. let Extension = _Ty.Extension;
  213. }
  214. // OpenCL image types (e.g. image2d).
  215. class ImageType<Type _Ty, string _AccessQualifier> :
  216. Type<_Ty.Name, QualType<_Ty.QTExpr.TypeExpr # _AccessQualifier # "Ty", 0>> {
  217. let VecWidth = 0;
  218. let AccessQualifier = _AccessQualifier;
  219. // Inherited fields
  220. let IsPointer = _Ty.IsPointer;
  221. let IsConst = _Ty.IsConst;
  222. let IsVolatile = _Ty.IsVolatile;
  223. let AddrSpace = _Ty.AddrSpace;
  224. // Add TypeExtensions for writable "image3d_t" and "read_write" image types.
  225. let Extension = !cond(
  226. !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : TypeExtension<"cl_khr_3d_image_writes">,
  227. !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">,
  228. !or(!eq(_Ty.Name, "image2d_depth_t"), !eq(_Ty.Name, "image2d_array_depth_t")) : TypeExtension<"cl_khr_depth_images">,
  229. !eq(_AccessQualifier, "RW") : TypeExtension<"__opencl_c_read_write_images">,
  230. true : _Ty.Extension);
  231. }
  232. // OpenCL enum type (e.g. memory_scope).
  233. class EnumType<string _Name> :
  234. Type<_Name, QualType<"getOpenCLEnumType(S, \"" # _Name # "\")", 0>> {
  235. }
  236. // OpenCL typedef type (e.g. cl_mem_fence_flags).
  237. class TypedefType<string _Name> :
  238. Type<_Name, QualType<"getOpenCLTypedefType(S, \"" # _Name # "\")", 0>> {
  239. }
  240. // List of Types.
  241. class TypeList<list<Type> _Type> {
  242. list<Type> List = _Type;
  243. }
  244. // A GenericType is an abstract type that defines a set of types as a
  245. // combination of Types and vector sizes.
  246. //
  247. // For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
  248. // represents <int, int2, int4, float, float2, float4>.
  249. //
  250. // Some rules apply when using multiple GenericType arguments in a declaration:
  251. // 1. The number of vector sizes must be equal or 1 for all gentypes in a
  252. // declaration.
  253. // 2. The number of Types must be equal or 1 for all gentypes in a
  254. // declaration.
  255. // 3. Generic types are combined by iterating over all generic types at once.
  256. // For example, for the following GenericTypes
  257. // GenT1 = GenericType<half, [1, 2]> and
  258. // GenT2 = GenericType<float, int, [1, 2]>
  259. // A declaration f(GenT1, GenT2) results in the combinations
  260. // f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
  261. // 4. "sgentype" from the OpenCL specification is supported by specifying
  262. // a single vector size.
  263. // For example, for the following GenericTypes
  264. // GenT = GenericType<half, int, [1, 2]> and
  265. // SGenT = GenericType<half, int, [1]>
  266. // A declaration f(GenT, SGenT) results in the combinations
  267. // f(half, half), f(half2, half), f(int, int), f(int2, int) .
  268. class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
  269. Type<_Ty, QualType<"null", 1>> {
  270. // Possible element types of the generic type.
  271. TypeList TypeList = _TypeList;
  272. // Possible vector sizes of the types in the TypeList.
  273. IntList VectorList = _VectorList;
  274. // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
  275. let VecWidth = 0;
  276. }
  277. // Builtin function attributes.
  278. def Attr {
  279. list<bit> None = [0, 0, 0];
  280. list<bit> Pure = [1, 0, 0];
  281. list<bit> Const = [0, 1, 0];
  282. list<bit> Convergent = [0, 0, 1];
  283. }
  284. //===----------------------------------------------------------------------===//
  285. // OpenCL C class for builtin functions
  286. //===----------------------------------------------------------------------===//
  287. class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
  288. // Name of the builtin function
  289. string Name = _Name;
  290. // List of types used by the function. The first one is the return type and
  291. // the following are the arguments. The list must have at least one element
  292. // (the return type).
  293. list<Type> Signature = _Signature;
  294. // Function attribute __attribute__((pure))
  295. bit IsPure = _Attributes[0];
  296. // Function attribute __attribute__((const))
  297. bit IsConst = _Attributes[1];
  298. // Function attribute __attribute__((convergent))
  299. bit IsConv = _Attributes[2];
  300. // OpenCL extensions to which the function belongs.
  301. FunctionExtension Extension = FuncExtNone;
  302. // Version of OpenCL from which the function is available (e.g.: CL10).
  303. // MinVersion is inclusive.
  304. Version MinVersion = CL10;
  305. // Version of OpenCL from which the function is not supported anymore.
  306. // MaxVersion is exclusive.
  307. // CLAll makes the function available for all versions.
  308. Version MaxVersion = CLAll;
  309. }
  310. //===----------------------------------------------------------------------===//
  311. // Definitions of OpenCL C types
  312. //===----------------------------------------------------------------------===//
  313. // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
  314. def Bool : Type<"bool", QualType<"Context.BoolTy">>;
  315. def Char : Type<"char", QualType<"Context.CharTy">>;
  316. def UChar : Type<"uchar", QualType<"Context.UnsignedCharTy">>;
  317. def Short : Type<"short", QualType<"Context.ShortTy">>;
  318. def UShort : Type<"ushort", QualType<"Context.UnsignedShortTy">>;
  319. def Int : Type<"int", QualType<"Context.IntTy">>;
  320. def UInt : Type<"uint", QualType<"Context.UnsignedIntTy">>;
  321. def Long : Type<"long", QualType<"Context.LongTy">>;
  322. def ULong : Type<"ulong", QualType<"Context.UnsignedLongTy">>;
  323. def Float : Type<"float", QualType<"Context.FloatTy">>;
  324. let Extension = Fp64TypeExt in {
  325. def Double : Type<"double", QualType<"Context.DoubleTy">>;
  326. }
  327. // The half type for builtins that require the cl_khr_fp16 extension.
  328. let Extension = Fp16TypeExt in {
  329. def Half : Type<"half", QualType<"Context.HalfTy">>;
  330. }
  331. // Without the cl_khr_fp16 extension, the half type can only be used to declare
  332. // a pointer. Define const and non-const pointer types in all address spaces.
  333. // Use the "__half" alias to allow the TableGen emitter to distinguish the
  334. // (extensionless) pointee type of these pointer-to-half types from the "half"
  335. // type defined above that already carries the cl_khr_fp16 extension.
  336. foreach AS = [PrivateAS, GlobalAS, ConstantAS, LocalAS, GenericAS] in {
  337. def "HalfPtr" # AS : PointerType<Type<"__half", QualType<"Context.HalfTy">>, AS>;
  338. def "HalfPtrConst" # AS : PointerType<ConstType<Type<"__half", QualType<"Context.HalfTy">>>, AS>;
  339. }
  340. def Size : Type<"size_t", QualType<"Context.getSizeType()">>;
  341. def PtrDiff : Type<"ptrdiff_t", QualType<"Context.getPointerDiffType()">>;
  342. def IntPtr : Type<"intptr_t", QualType<"Context.getIntPtrType()">>;
  343. def UIntPtr : Type<"uintptr_t", QualType<"Context.getUIntPtrType()">>;
  344. def Void : Type<"void", QualType<"Context.VoidTy">>;
  345. // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
  346. // Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
  347. // OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
  348. // The image definitions are "abstract". They should not be used without
  349. // specifying an access qualifier (RO/WO/RW).
  350. def Image1d : Type<"image1d_t", QualType<"Context.OCLImage1d", 1>>;
  351. def Image2d : Type<"image2d_t", QualType<"Context.OCLImage2d", 1>>;
  352. def Image3d : Type<"image3d_t", QualType<"Context.OCLImage3d", 1>>;
  353. def Image1dArray : Type<"image1d_array_t", QualType<"Context.OCLImage1dArray", 1>>;
  354. def Image1dBuffer : Type<"image1d_buffer_t", QualType<"Context.OCLImage1dBuffer", 1>>;
  355. def Image2dArray : Type<"image2d_array_t", QualType<"Context.OCLImage2dArray", 1>>;
  356. def Image2dDepth : Type<"image2d_depth_t", QualType<"Context.OCLImage2dDepth", 1>>;
  357. def Image2dArrayDepth : Type<"image2d_array_depth_t", QualType<"Context.OCLImage2dArrayDepth", 1>>;
  358. def Image2dMsaa : Type<"image2d_msaa_t", QualType<"Context.OCLImage2dMSAA", 1>>;
  359. def Image2dArrayMsaa : Type<"image2d_array_msaa_t", QualType<"Context.OCLImage2dArrayMSAA", 1>>;
  360. def Image2dMsaaDepth : Type<"image2d_msaa_depth_t", QualType<"Context.OCLImage2dMSAADepth", 1>>;
  361. def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"Context.OCLImage2dArrayMSAADepth", 1>>;
  362. def Sampler : Type<"sampler_t", QualType<"Context.OCLSamplerTy">>;
  363. def ClkEvent : Type<"clk_event_t", QualType<"Context.OCLClkEventTy">>;
  364. def Event : Type<"event_t", QualType<"Context.OCLEventTy">>;
  365. def Queue : Type<"queue_t", QualType<"Context.OCLQueueTy">>;
  366. def ReserveId : Type<"reserve_id_t", QualType<"Context.OCLReserveIDTy">>;
  367. def MemFenceFlags : TypedefType<"cl_mem_fence_flags">;
  368. def ClkProfilingInfo : TypedefType<"clk_profiling_info">;
  369. def NDRange : TypedefType<"ndrange_t">;
  370. // OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
  371. def AtomicInt : Type<"atomic_int", QualType<"Context.getAtomicType(Context.IntTy)">>;
  372. def AtomicUInt : Type<"atomic_uint", QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>;
  373. let Extension = Atomic64TypeExt in {
  374. def AtomicLong : Type<"atomic_long", QualType<"Context.getAtomicType(Context.LongTy)">>;
  375. def AtomicULong : Type<"atomic_ulong", QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>;
  376. }
  377. def AtomicFloat : Type<"atomic_float", QualType<"Context.getAtomicType(Context.FloatTy)">>;
  378. let Extension = AtomicFp64TypeExt in {
  379. def AtomicDouble : Type<"atomic_double", QualType<"Context.getAtomicType(Context.DoubleTy)">>;
  380. }
  381. def AtomicHalf : Type<"atomic_half", QualType<"Context.getAtomicType(Context.HalfTy)">>;
  382. def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"Context.getAtomicType(Context.getIntPtrType())">>;
  383. def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"Context.getAtomicType(Context.getUIntPtrType())">>;
  384. def AtomicSize : Type<"atomic_size_t", QualType<"Context.getAtomicType(Context.getSizeType())">>;
  385. def AtomicPtrDiff : Type<"atomic_ptrdiff_t", QualType<"Context.getAtomicType(Context.getPointerDiffType())">>;
  386. def AtomicFlag : TypedefType<"atomic_flag">;
  387. def MemoryOrder : EnumType<"memory_order">;
  388. def MemoryScope : EnumType<"memory_scope">;
  389. //===----------------------------------------------------------------------===//
  390. // Definitions of OpenCL gentype variants
  391. //===----------------------------------------------------------------------===//
  392. // The OpenCL specification often uses "gentype" in builtin function
  393. // declarations to indicate that a builtin function is available with various
  394. // argument and return types. The types represented by "gentype" vary between
  395. // different parts of the specification. The following definitions capture
  396. // the different type lists for gentypes in different parts of the
  397. // specification.
  398. // Vector width lists.
  399. def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
  400. def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
  401. def Vec1 : IntList<"Vec1", [1]>;
  402. def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
  403. // Type lists.
  404. def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
  405. def TLFloat : TypeList<[Float, Double, Half]>;
  406. def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
  407. def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
  408. def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
  409. // All unsigned integer types twice, to facilitate unsigned return types for e.g.
  410. // uchar abs(char) and
  411. // uchar abs(uchar).
  412. def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
  413. def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
  414. // GenType definitions for multiple base types (e.g. all floating point types,
  415. // or all integer types).
  416. // All types
  417. def AGenType1 : GenericType<"AGenType1", TLAll, Vec1>;
  418. def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
  419. def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
  420. // All integer
  421. def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
  422. def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
  423. def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
  424. // All integer to unsigned
  425. def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
  426. // Signed integer
  427. def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
  428. // Unsigned integer
  429. def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
  430. // Float
  431. def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
  432. // (u)int, (u)long, and all floats
  433. def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
  434. // (u)char and (u)short
  435. def CharShortGenType1 : GenericType<"CharShortGenType1",
  436. TypeList<[Char, UChar, Short, UShort]>, Vec1>;
  437. // GenType definitions for every single base type (e.g. fp32 only).
  438. // Names are like: GenTypeFloatVecAndScalar.
  439. foreach Type = [Char, UChar, Short, UShort,
  440. Int, UInt, Long, ULong,
  441. Float, Double, Half] in {
  442. foreach VecSizes = [VecAndScalar, VecNoScalar] in {
  443. def "GenType" # Type # VecSizes :
  444. GenericType<"GenType" # Type # VecSizes,
  445. TypeList<[Type]>, VecSizes>;
  446. }
  447. }
  448. // GenType definitions for vec1234.
  449. foreach Type = [Float, Double, Half] in {
  450. def "GenType" # Type # Vec1234 :
  451. GenericType<"GenType" # Type # Vec1234,
  452. TypeList<[Type]>, Vec1234>;
  453. }
  454. //===----------------------------------------------------------------------===//
  455. // Definitions of OpenCL builtin functions
  456. //===----------------------------------------------------------------------===//
  457. //--------------------------------------------------------------------
  458. // OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
  459. // OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
  460. // Generate the convert_* builtins functions.
  461. foreach RType = [Float, Double, Half, Char, UChar, Short,
  462. UShort, Int, UInt, Long, ULong] in {
  463. foreach IType = [Float, Double, Half, Char, UChar, Short,
  464. UShort, Int, UInt, Long, ULong] in {
  465. // Conversions to integer type have a sat and non-sat variant.
  466. foreach sat = !cond(!eq(RType.Name, "float") : [""],
  467. !eq(RType.Name, "double") : [""],
  468. !eq(RType.Name, "half") : [""],
  469. 1 : ["", "_sat"]) in {
  470. foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
  471. def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
  472. Attr.Const>;
  473. foreach v = [2, 3, 4, 8, 16] in {
  474. def : Builtin<"convert_" # RType.Name # v # sat # rnd,
  475. [VectorType<RType, v>, VectorType<IType, v>],
  476. Attr.Const>;
  477. }
  478. }
  479. }
  480. }
  481. }
  482. //--------------------------------------------------------------------
  483. // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
  484. // --- Table 7 ---
  485. def : Builtin<"get_work_dim", [UInt], Attr.Const>;
  486. foreach name = ["get_global_size", "get_global_id", "get_local_size",
  487. "get_local_id", "get_num_groups", "get_group_id",
  488. "get_global_offset"] in {
  489. def : Builtin<name, [Size, UInt], Attr.Const>;
  490. }
  491. let MinVersion = CL20 in {
  492. def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
  493. foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
  494. def : Builtin<name, [Size]>;
  495. }
  496. }
  497. //--------------------------------------------------------------------
  498. // OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
  499. // OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
  500. // --- Table 8 ---
  501. // --- 1 argument ---
  502. foreach name = ["acos", "acosh", "acospi",
  503. "asin", "asinh", "asinpi",
  504. "atan", "atanh", "atanpi",
  505. "cbrt", "ceil",
  506. "cos", "cosh", "cospi",
  507. "erfc", "erf",
  508. "exp", "exp2", "exp10", "expm1",
  509. "fabs", "floor",
  510. "log", "log2", "log10", "log1p", "logb",
  511. "rint", "round", "rsqrt",
  512. "sin", "sinh", "sinpi",
  513. "sqrt",
  514. "tan", "tanh", "tanpi",
  515. "tgamma", "trunc",
  516. "lgamma"] in {
  517. def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
  518. }
  519. foreach name = ["nan"] in {
  520. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  521. def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
  522. def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
  523. }
  524. // --- 2 arguments ---
  525. foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
  526. "maxmag", "minmag", "nextafter", "pow", "powr",
  527. "remainder"] in {
  528. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  529. }
  530. foreach name = ["fmax", "fmin"] in {
  531. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  532. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
  533. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
  534. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
  535. }
  536. foreach name = ["ilogb"] in {
  537. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
  538. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
  539. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
  540. }
  541. foreach name = ["ldexp"] in {
  542. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  543. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
  544. def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  545. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
  546. def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  547. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
  548. }
  549. foreach name = ["pown", "rootn"] in {
  550. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  551. def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  552. def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  553. }
  554. // --- 3 arguments ---
  555. foreach name = ["fma", "mad"] in {
  556. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  557. }
  558. // The following math builtins take pointer arguments. Which overloads are
  559. // available depends on whether the generic address space feature is enabled.
  560. multiclass MathWithPointer<list<AddressSpace> addrspaces> {
  561. foreach AS = addrspaces in {
  562. foreach name = ["fract", "modf", "sincos"] in {
  563. def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
  564. }
  565. foreach name = ["frexp", "lgamma_r"] in {
  566. foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
  567. def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
  568. }
  569. }
  570. foreach name = ["remquo"] in {
  571. foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
  572. def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
  573. }
  574. }
  575. }
  576. }
  577. let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
  578. defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>;
  579. }
  580. let Extension = FuncExtOpenCLCGenericAddressSpace in {
  581. defm : MathWithPointer<[GenericAS]>;
  582. }
  583. // --- Table 9 ---
  584. foreach name = ["half_cos",
  585. "half_exp", "half_exp2", "half_exp10",
  586. "half_log", "half_log2", "half_log10",
  587. "half_recip", "half_rsqrt",
  588. "half_sin", "half_sqrt", "half_tan",
  589. "native_cos",
  590. "native_exp", "native_exp2", "native_exp10",
  591. "native_log", "native_log2", "native_log10",
  592. "native_recip", "native_rsqrt",
  593. "native_sin", "native_sqrt", "native_tan"] in {
  594. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
  595. }
  596. foreach name = ["half_divide", "half_powr",
  597. "native_divide", "native_powr"] in {
  598. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
  599. }
  600. //--------------------------------------------------------------------
  601. // OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
  602. // --- Table 10 ---
  603. // --- 1 argument ---
  604. foreach name = ["abs"] in {
  605. def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
  606. }
  607. def : Builtin<"clz", [AIGenTypeN, AIGenTypeN], Attr.Const>;
  608. let MinVersion = CL12 in {
  609. def : Builtin<"popcount", [AIGenTypeN, AIGenTypeN], Attr.Const>;
  610. }
  611. let MinVersion = CL20 in {
  612. foreach name = ["ctz"] in {
  613. def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
  614. }
  615. }
  616. // --- 2 arguments ---
  617. foreach name = ["abs_diff"] in {
  618. def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
  619. }
  620. foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
  621. def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
  622. }
  623. foreach name = ["max", "min"] in {
  624. def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
  625. def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
  626. }
  627. foreach name = ["upsample"] in {
  628. def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
  629. def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
  630. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
  631. def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
  632. def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  633. def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  634. }
  635. // --- 3 arguments ---
  636. foreach name = ["clamp"] in {
  637. def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
  638. def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
  639. }
  640. foreach name = ["mad_hi", "mad_sat"] in {
  641. def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
  642. }
  643. // --- Table 11 ---
  644. foreach name = ["mad24"] in {
  645. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  646. def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  647. }
  648. foreach name = ["mul24"] in {
  649. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  650. def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  651. }
  652. //--------------------------------------------------------------------
  653. // OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
  654. // OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
  655. // --- Table 12 ---
  656. // --- 1 argument ---
  657. foreach name = ["degrees", "radians", "sign"] in {
  658. def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
  659. }
  660. // --- 2 arguments ---
  661. foreach name = ["max", "min"] in {
  662. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  663. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
  664. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
  665. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
  666. }
  667. foreach name = ["step"] in {
  668. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  669. def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
  670. def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
  671. def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
  672. }
  673. // --- 3 arguments ---
  674. foreach name = ["clamp"] in {
  675. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  676. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
  677. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
  678. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
  679. }
  680. foreach name = ["mix"] in {
  681. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  682. def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
  683. def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
  684. def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
  685. }
  686. foreach name = ["smoothstep"] in {
  687. def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
  688. def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
  689. def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
  690. def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
  691. }
  692. //--------------------------------------------------------------------
  693. // OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
  694. // OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
  695. // --- Table 13 ---
  696. // --- 1 argument ---
  697. foreach name = ["length"] in {
  698. def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
  699. def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
  700. def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
  701. }
  702. foreach name = ["normalize"] in {
  703. def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
  704. def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
  705. def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
  706. }
  707. foreach name = ["fast_length"] in {
  708. def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
  709. }
  710. foreach name = ["fast_normalize"] in {
  711. def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
  712. }
  713. // --- 2 arguments ---
  714. foreach name = ["cross"] in {
  715. foreach VSize = [3, 4] in {
  716. def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
  717. def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
  718. def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
  719. }
  720. }
  721. foreach name = ["dot", "distance"] in {
  722. def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
  723. def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
  724. def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
  725. }
  726. foreach name = ["fast_distance"] in {
  727. def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
  728. }
  729. //--------------------------------------------------------------------
  730. // OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
  731. // OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
  732. // --- Table 14 ---
  733. // --- 1 argument ---
  734. foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
  735. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
  736. def : Builtin<name, [Int, Double], Attr.Const>;
  737. def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
  738. def : Builtin<name, [Int, Half], Attr.Const>;
  739. def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
  740. }
  741. foreach name = ["any", "all"] in {
  742. def : Builtin<name, [Int, SGenTypeN], Attr.Const>;
  743. }
  744. // --- 2 arguments ---
  745. foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
  746. "isless", "islessequal", "islessgreater", "isordered",
  747. "isunordered"] in {
  748. def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
  749. def : Builtin<name, [Int, Double, Double], Attr.Const>;
  750. def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
  751. def : Builtin<name, [Int, Half, Half], Attr.Const>;
  752. def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
  753. }
  754. // --- 3 arguments ---
  755. foreach name = ["bitselect"] in {
  756. def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
  757. }
  758. foreach name = ["select"] in {
  759. def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
  760. def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
  761. def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
  762. def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
  763. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
  764. def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
  765. def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
  766. def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
  767. def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
  768. def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
  769. }
  770. //--------------------------------------------------------------------
  771. // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
  772. // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s5.1.6 and s6.1.6 - Vector Data Load and Store Functions
  773. // --- Table 15 ---
  774. multiclass VloadVstore<list<AddressSpace> addrspaces, bit defStores> {
  775. foreach AS = addrspaces in {
  776. foreach VSize = [2, 3, 4, 8, 16] in {
  777. foreach name = ["vload" # VSize] in {
  778. def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>], Attr.Pure>;
  779. def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>], Attr.Pure>;
  780. def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>], Attr.Pure>;
  781. def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>], Attr.Pure>;
  782. def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>], Attr.Pure>;
  783. def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>], Attr.Pure>;
  784. def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>], Attr.Pure>;
  785. def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>], Attr.Pure>;
  786. def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>], Attr.Pure>;
  787. def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>], Attr.Pure>;
  788. def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>], Attr.Pure>;
  789. }
  790. if defStores then {
  791. foreach name = ["vstore" # VSize] in {
  792. def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>;
  793. def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>;
  794. def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>;
  795. def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>;
  796. def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>;
  797. def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>;
  798. def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>;
  799. def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>;
  800. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>;
  801. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>;
  802. def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>;
  803. }
  804. }
  805. }
  806. }
  807. }
  808. let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
  809. defm : VloadVstore<[GlobalAS, LocalAS, PrivateAS], 1>;
  810. }
  811. let Extension = FuncExtOpenCLCGenericAddressSpace in {
  812. defm : VloadVstore<[GenericAS], 1>;
  813. }
  814. // vload with constant address space is available regardless of version.
  815. defm : VloadVstore<[ConstantAS], 0>;
  816. multiclass VloadVstoreHalf<list<AddressSpace> addrspaces, bit defStores> {
  817. foreach AS = addrspaces in {
  818. def : Builtin<"vload_half", [Float, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
  819. foreach VSize = [2, 3, 4, 8, 16] in {
  820. foreach name = ["vload_half" # VSize, "vloada_half" # VSize] in {
  821. def : Builtin<name, [VectorType<Float, VSize>, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
  822. }
  823. }
  824. if defStores then {
  825. foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
  826. foreach name = ["vstore_half" # rnd] in {
  827. def : Builtin<name, [Void, Float, Size, !cast<Type>("HalfPtr" # AS)]>;
  828. def : Builtin<name, [Void, Double, Size, !cast<Type>("HalfPtr" # AS)]>;
  829. }
  830. foreach VSize = [2, 3, 4, 8, 16] in {
  831. foreach name = ["vstore_half" # VSize # rnd, "vstorea_half" # VSize # rnd] in {
  832. def : Builtin<name, [Void, VectorType<Float, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
  833. def : Builtin<name, [Void, VectorType<Double, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
  841. defm : VloadVstoreHalf<[GlobalAS, LocalAS, PrivateAS], 1>;
  842. }
  843. let Extension = FuncExtOpenCLCGenericAddressSpace in {
  844. defm : VloadVstoreHalf<[GenericAS], 1>;
  845. }
  846. // vload_half and vloada_half with constant address space are available regardless of version.
  847. defm : VloadVstoreHalf<[ConstantAS], 0>;
  848. // OpenCL v3.0 s6.15.8 - Synchronization Functions.
  849. def : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>;
  850. let MinVersion = CL20 in {
  851. def : Builtin<"work_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
  852. def : Builtin<"work_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
  853. }
  854. // OpenCL v3.0 s6.15.9 - Legacy Explicit Memory Fence Functions.
  855. def : Builtin<"mem_fence", [Void, MemFenceFlags]>;
  856. def : Builtin<"read_mem_fence", [Void, MemFenceFlags]>;
  857. def : Builtin<"write_mem_fence", [Void, MemFenceFlags]>;
  858. // OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions.
  859. // to_global, to_local, to_private are declared in Builtins.def.
  860. let Extension = FuncExtOpenCLCGenericAddressSpace in {
  861. // The OpenCL 3.0 specification defines these with a "gentype" argument indicating any builtin
  862. // type or user-defined type, which cannot be represented currently. Hence we slightly diverge
  863. // by providing only the following overloads with a void pointer.
  864. def : Builtin<"get_fence", [MemFenceFlags, PointerType<Void, GenericAS>]>;
  865. def : Builtin<"get_fence", [MemFenceFlags, PointerType<ConstType<Void>, GenericAS>]>;
  866. }
  867. //--------------------------------------------------------------------
  868. // 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
  869. // OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
  870. // --- Table 18 ---
  871. foreach name = ["async_work_group_copy"] in {
  872. def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
  873. def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
  874. }
  875. foreach name = ["async_work_group_strided_copy"] in {
  876. def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
  877. def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
  878. }
  879. foreach name = ["wait_group_events"] in {
  880. def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
  881. }
  882. foreach name = ["prefetch"] in {
  883. def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
  884. }
  885. //--------------------------------------------------------------------
  886. // OpenCL v2.0 s6.13.11 - Atomics Functions.
  887. // Functions that use memory_order and cl_mem_fence_flags enums are not
  888. // declared here as the TableGen backend does not handle enums.
  889. // OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
  890. // --- Table 9.1 ---
  891. let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
  892. foreach Type = [Int, UInt] in {
  893. foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
  894. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
  895. }
  896. foreach name = ["atom_inc", "atom_dec"] in {
  897. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
  898. }
  899. foreach name = ["atom_cmpxchg"] in {
  900. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
  901. }
  902. }
  903. }
  904. // --- Table 9.3 ---
  905. let Extension = FuncExtKhrLocalInt32BaseAtomics in {
  906. foreach Type = [Int, UInt] in {
  907. foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
  908. def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
  909. }
  910. foreach name = ["atom_inc", "atom_dec"] in {
  911. def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
  912. }
  913. foreach name = ["atom_cmpxchg"] in {
  914. def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
  915. }
  916. }
  917. }
  918. // --- Table 9.5 ---
  919. let Extension = FuncExtKhrInt64BaseAtomics in {
  920. foreach AS = [GlobalAS, LocalAS] in {
  921. foreach Type = [Long, ULong] in {
  922. foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
  923. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
  924. }
  925. foreach name = ["atom_inc", "atom_dec"] in {
  926. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
  927. }
  928. foreach name = ["atom_cmpxchg"] in {
  929. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
  930. }
  931. }
  932. }
  933. }
  934. // --- Table 9.2 ---
  935. let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
  936. foreach Type = [Int, UInt] in {
  937. foreach name = ["atom_min", "atom_max", "atom_and",
  938. "atom_or", "atom_xor"] in {
  939. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
  940. }
  941. }
  942. }
  943. // --- Table 9.4 ---
  944. let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
  945. foreach Type = [Int, UInt] in {
  946. foreach name = ["atom_min", "atom_max", "atom_and",
  947. "atom_or", "atom_xor"] in {
  948. def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
  949. }
  950. }
  951. }
  952. // --- Table 9.6 ---
  953. let Extension = FuncExtKhrInt64ExtendedAtomics in {
  954. foreach AS = [GlobalAS, LocalAS] in {
  955. foreach Type = [Long, ULong] in {
  956. foreach name = ["atom_min", "atom_max", "atom_and",
  957. "atom_or", "atom_xor"] in {
  958. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
  959. }
  960. }
  961. }
  962. }
  963. // OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
  964. foreach AS = [GlobalAS, LocalAS] in {
  965. def : Builtin<"atomic_xchg", [Float, PointerType<VolatileType<Float>, AS>, Float]>;
  966. foreach Type = [Int, UInt] in {
  967. foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
  968. "atomic_min", "atomic_max", "atomic_and",
  969. "atomic_or", "atomic_xor"] in {
  970. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
  971. }
  972. foreach name = ["atomic_inc", "atomic_dec"] in {
  973. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
  974. }
  975. foreach name = ["atomic_cmpxchg"] in {
  976. def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
  977. }
  978. }
  979. }
  980. let Extension = FuncExtOpenCLCxx in {
  981. foreach Type = [Int, UInt] in {
  982. foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
  983. "atomic_min", "atomic_max", "atomic_and",
  984. "atomic_or", "atomic_xor"] in {
  985. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type]>;
  986. }
  987. foreach name = ["atomic_inc", "atomic_dec"] in {
  988. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>]>;
  989. }
  990. foreach name = ["atomic_cmpxchg"] in {
  991. def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type, Type]>;
  992. }
  993. }
  994. }
  995. // OpenCL v2.0 s6.13.11 - Atomic Functions.
  996. // An atomic builtin with 2 additional _explicit variants.
  997. multiclass BuiltinAtomicExplicit<string Name, list<Type> Types, FunctionExtension BaseExt> {
  998. // Without explicit MemoryOrder or MemoryScope.
  999. let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
  1000. def : Builtin<Name, Types>;
  1001. }
  1002. // With an explicit MemoryOrder argument.
  1003. let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
  1004. def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder])>;
  1005. }
  1006. // With explicit MemoryOrder and MemoryScope arguments.
  1007. let Extension = BaseExt in {
  1008. def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder, MemoryScope])>;
  1009. }
  1010. }
  1011. // OpenCL 2.0 atomic functions that have a pointer argument in a given address space.
  1012. multiclass OpenCL2Atomics<AddressSpace addrspace, FunctionExtension BaseExt> {
  1013. foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
  1014. [AtomicLong, Long], [AtomicULong, ULong],
  1015. [AtomicFloat, Float], [AtomicDouble, Double]] in {
  1016. let Extension = BaseExt in {
  1017. def : Builtin<"atomic_init",
  1018. [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]]>;
  1019. }
  1020. defm : BuiltinAtomicExplicit<"atomic_store",
  1021. [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
  1022. defm : BuiltinAtomicExplicit<"atomic_load",
  1023. [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>], BaseExt>;
  1024. defm : BuiltinAtomicExplicit<"atomic_exchange",
  1025. [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
  1026. foreach Variant = ["weak", "strong"] in {
  1027. foreach exp_ptr_addrspace = !cond(
  1028. !eq(BaseExt, FuncExtOpenCLCGenericAddressSpace): [GenericAS],
  1029. !eq(BaseExt, FuncExtOpenCLCNamedAddressSpaceBuiltins): [GlobalAS, LocalAS, PrivateAS])
  1030. in {
  1031. let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
  1032. def : Builtin<"atomic_compare_exchange_" # Variant,
  1033. [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
  1034. PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1]]>;
  1035. }
  1036. let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
  1037. def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
  1038. [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
  1039. PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder]>;
  1040. }
  1041. let Extension = BaseExt in {
  1042. def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
  1043. [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
  1044. PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
  1050. [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
  1051. [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
  1052. foreach ModOp = ["add", "sub"] in {
  1053. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1054. [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
  1055. }
  1056. }
  1057. foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
  1058. [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in {
  1059. foreach ModOp = ["or", "xor", "and", "min", "max"] in {
  1060. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1061. [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
  1062. }
  1063. }
  1064. defm : BuiltinAtomicExplicit<"atomic_flag_clear",
  1065. [Void, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
  1066. defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
  1067. [Bool, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
  1068. }
  1069. let MinVersion = CL20 in {
  1070. def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>;
  1071. defm : OpenCL2Atomics<GenericAS, FuncExtOpenCLCGenericAddressSpace>;
  1072. defm : OpenCL2Atomics<GlobalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
  1073. defm : OpenCL2Atomics<LocalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
  1074. }
  1075. // The functionality added by cl_ext_float_atomics extension
  1076. let MinVersion = CL20 in {
  1077. foreach addrspace = [GlobalAS, LocalAS, GenericAS] in {
  1078. defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "LoadStore");
  1079. defm : BuiltinAtomicExplicit<"atomic_store",
  1080. [Void, PointerType<VolatileType<AtomicHalf>, addrspace>, AtomicHalf], extension_fp16>;
  1081. defm : BuiltinAtomicExplicit<"atomic_load",
  1082. [Half, PointerType<VolatileType<AtomicHalf>, addrspace>], extension_fp16>;
  1083. defm : BuiltinAtomicExplicit<"atomic_exchange",
  1084. [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
  1085. foreach ModOp = ["add", "sub"] in {
  1086. defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "Add");
  1087. defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "Add");
  1088. defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "Add");
  1089. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1090. [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
  1091. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1092. [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
  1093. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1094. [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
  1095. }
  1096. foreach ModOp = ["min", "max"] in {
  1097. defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "MinMax");
  1098. defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "MinMax");
  1099. defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "MinMax");
  1100. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1101. [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
  1102. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1103. [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
  1104. defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
  1105. [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
  1106. }
  1107. }
  1108. }
  1109. //--------------------------------------------------------------------
  1110. // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
  1111. // --- Table 19 ---
  1112. foreach VSize1 = [2, 4, 8, 16] in {
  1113. foreach VSize2 = [2, 4, 8, 16] in {
  1114. foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
  1115. [Short, UShort], [UShort, UShort],
  1116. [Int, UInt], [UInt, UInt],
  1117. [Long, ULong], [ULong, ULong],
  1118. [Float, UInt], [Double, ULong], [Half, UShort]] in {
  1119. def : Builtin<"shuffle", [VectorType<VecAndMaskType[0], VSize1>,
  1120. VectorType<VecAndMaskType[0], VSize2>,
  1121. VectorType<VecAndMaskType[1], VSize1>],
  1122. Attr.Const>;
  1123. }
  1124. }
  1125. }
  1126. foreach VSize1 = [2, 4, 8, 16] in {
  1127. foreach VSize2 = [2, 4, 8, 16] in {
  1128. foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
  1129. [Short, UShort], [UShort, UShort],
  1130. [Int, UInt], [UInt, UInt],
  1131. [Long, ULong], [ULong, ULong],
  1132. [Float, UInt], [Double, ULong], [Half, UShort]] in {
  1133. def : Builtin<"shuffle2", [VectorType<VecAndMaskType[0], VSize1>,
  1134. VectorType<VecAndMaskType[0], VSize2>,
  1135. VectorType<VecAndMaskType[0], VSize2>,
  1136. VectorType<VecAndMaskType[1], VSize1>],
  1137. Attr.Const>;
  1138. }
  1139. }
  1140. }
  1141. //--------------------------------------------------------------------
  1142. // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
  1143. // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
  1144. // --- Table 22: Image Read Functions with Samplers ---
  1145. foreach imgTy = [Image1d] in {
  1146. foreach coordTy = [Int, Float] in {
  1147. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
  1148. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
  1149. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
  1150. }
  1151. }
  1152. foreach imgTy = [Image2d, Image1dArray] in {
  1153. foreach coordTy = [Int, Float] in {
  1154. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
  1155. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
  1156. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
  1157. }
  1158. }
  1159. foreach imgTy = [Image3d, Image2dArray] in {
  1160. foreach coordTy = [Int, Float] in {
  1161. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
  1162. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
  1163. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
  1164. }
  1165. }
  1166. foreach coordTy = [Int, Float] in {
  1167. def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
  1168. def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
  1169. }
  1170. // --- Table 23: Sampler-less Read Functions ---
  1171. multiclass ImageReadSamplerless<string aQual> {
  1172. foreach imgTy = [Image2d, Image1dArray] in {
  1173. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
  1174. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
  1175. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
  1176. }
  1177. foreach imgTy = [Image3d, Image2dArray] in {
  1178. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
  1179. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
  1180. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
  1181. }
  1182. foreach imgTy = [Image1d, Image1dBuffer] in {
  1183. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
  1184. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
  1185. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
  1186. }
  1187. def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
  1188. def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
  1189. }
  1190. let MinVersion = CL12 in {
  1191. defm : ImageReadSamplerless<"RO">;
  1192. let Extension = FuncExtOpenCLCReadWriteImages in {
  1193. defm : ImageReadSamplerless<"RW">;
  1194. }
  1195. }
  1196. // --- Table 24: Image Write Functions ---
  1197. multiclass ImageWrite<string aQual> {
  1198. foreach imgTy = [Image2d] in {
  1199. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
  1200. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
  1201. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
  1202. }
  1203. foreach imgTy = [Image2dArray] in {
  1204. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
  1205. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
  1206. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
  1207. }
  1208. foreach imgTy = [Image1d, Image1dBuffer] in {
  1209. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
  1210. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
  1211. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
  1212. }
  1213. foreach imgTy = [Image1dArray] in {
  1214. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
  1215. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
  1216. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
  1217. }
  1218. foreach imgTy = [Image3d] in {
  1219. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
  1220. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
  1221. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
  1222. }
  1223. def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
  1224. def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
  1225. }
  1226. defm : ImageWrite<"WO">;
  1227. let Extension = FuncExtOpenCLCReadWriteImages in {
  1228. defm : ImageWrite<"RW">;
  1229. }
  1230. // --- Table 25: Image Query Functions ---
  1231. multiclass ImageQuery<string aQual> {
  1232. foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
  1233. Image1dArray, Image2dArray, Image2dDepth,
  1234. Image2dArrayDepth] in {
  1235. foreach name = ["get_image_width", "get_image_channel_data_type",
  1236. "get_image_channel_order"] in {
  1237. def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
  1238. }
  1239. }
  1240. foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
  1241. Image2dArrayDepth] in {
  1242. def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>], Attr.Const>;
  1243. }
  1244. def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>], Attr.Const>;
  1245. foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
  1246. Image2dArrayDepth] in {
  1247. def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
  1248. }
  1249. def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>], Attr.Const>;
  1250. foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
  1251. def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
  1252. }
  1253. }
  1254. defm : ImageQuery<"RO">;
  1255. defm : ImageQuery<"WO">;
  1256. let Extension = FuncExtOpenCLCReadWriteImages in {
  1257. defm : ImageQuery<"RW">;
  1258. }
  1259. // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
  1260. // --- Table 8 ---
  1261. foreach aQual = ["RO"] in {
  1262. foreach name = ["read_imageh"] in {
  1263. foreach coordTy = [Int, Float] in {
  1264. foreach imgTy = [Image2d, Image1dArray] in {
  1265. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
  1266. }
  1267. foreach imgTy = [Image3d, Image2dArray] in {
  1268. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
  1269. }
  1270. foreach imgTy = [Image1d] in {
  1271. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
  1272. }
  1273. }
  1274. }
  1275. }
  1276. // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
  1277. // --- Table 9 ---
  1278. let MinVersion = CL12 in {
  1279. multiclass ImageReadHalf<string aQual> {
  1280. foreach name = ["read_imageh"] in {
  1281. foreach imgTy = [Image2d, Image1dArray] in {
  1282. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
  1283. }
  1284. foreach imgTy = [Image3d, Image2dArray] in {
  1285. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
  1286. }
  1287. foreach imgTy = [Image1d, Image1dBuffer] in {
  1288. def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
  1289. }
  1290. }
  1291. }
  1292. defm : ImageReadHalf<"RO">;
  1293. let Extension = FuncExtOpenCLCReadWriteImages in {
  1294. defm : ImageReadHalf<"RW">;
  1295. }
  1296. }
  1297. // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
  1298. // --- Table 10 ---
  1299. multiclass ImageWriteHalf<string aQual> {
  1300. foreach name = ["write_imageh"] in {
  1301. def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
  1302. def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
  1303. def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
  1304. def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
  1305. def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
  1306. def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
  1307. }
  1308. }
  1309. defm : ImageWriteHalf<"WO">;
  1310. let Extension = FuncExtOpenCLCReadWriteImages in {
  1311. defm : ImageWriteHalf<"RW">;
  1312. }
  1313. //--------------------------------------------------------------------
  1314. // OpenCL v2.0 s6.13.15 - Work-group Functions
  1315. // --- Table 26 ---
  1316. let Extension = FuncExtOpenCLCWGCollectiveFunctions in {
  1317. foreach name = ["work_group_all", "work_group_any"] in {
  1318. def : Builtin<name, [Int, Int], Attr.Convergent>;
  1319. }
  1320. foreach name = ["work_group_broadcast"] in {
  1321. def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
  1322. def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
  1323. def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
  1324. }
  1325. foreach op = ["add", "min", "max"] in {
  1326. foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
  1327. "work_group_scan_inclusive_"] in {
  1328. def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
  1329. }
  1330. }
  1331. }
  1332. //--------------------------------------------------------------------
  1333. // OpenCL2.0 : 6.13.16 : Pipe Functions
  1334. // --- Table 27 ---
  1335. // Defined in Builtins.def
  1336. // --- Table 28 ---
  1337. // Builtins taking pipe arguments are defined in Builtins.def
  1338. let Extension = FuncExtOpenCLCPipes in {
  1339. def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
  1340. }
  1341. // --- Table 29 ---
  1342. // Defined in Builtins.def
  1343. //--------------------------------------------------------------------
  1344. // OpenCL2.0 : 6.13.17 : Enqueuing Kernels
  1345. // --- Table 30 ---
  1346. // Defined in Builtins.def
  1347. // --- Table 32 ---
  1348. // Defined in Builtins.def
  1349. // --- Table 33 ---
  1350. let Extension = FuncExtOpenCLCDeviceEnqueue in {
  1351. def : Builtin<"enqueue_marker",
  1352. [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>;
  1353. // --- Table 34 ---
  1354. def : Builtin<"retain_event", [Void, ClkEvent]>;
  1355. def : Builtin<"release_event", [Void, ClkEvent]>;
  1356. def : Builtin<"create_user_event", [ClkEvent]>;
  1357. def : Builtin<"is_valid_event", [Bool, ClkEvent]>;
  1358. def : Builtin<"set_user_event_status", [Void, ClkEvent, Int]>;
  1359. def : Builtin<"capture_event_profiling_info",
  1360. [Void, ClkEvent, ClkProfilingInfo, PointerType<Void, GlobalAS>]>;
  1361. // --- Table 35 ---
  1362. def : Builtin<"get_default_queue", [Queue]>;
  1363. def : Builtin<"ndrange_1D", [NDRange, Size]>;
  1364. def : Builtin<"ndrange_1D", [NDRange, Size, Size]>;
  1365. def : Builtin<"ndrange_1D", [NDRange, Size, Size, Size]>;
  1366. def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>;
  1367. def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
  1368. PointerType<ConstType<Size>, PrivateAS>]>;
  1369. def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
  1370. PointerType<ConstType<Size>, PrivateAS>,
  1371. PointerType<ConstType<Size>, PrivateAS>]>;
  1372. def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>;
  1373. def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
  1374. PointerType<ConstType<Size>, PrivateAS>]>;
  1375. def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
  1376. PointerType<ConstType<Size>, PrivateAS>,
  1377. PointerType<ConstType<Size>, PrivateAS>]>;
  1378. }
  1379. //--------------------------------------------------------------------
  1380. // End of the builtin functions defined in the OpenCL C specification.
  1381. // Builtin functions defined in the OpenCL C Extension are below.
  1382. //--------------------------------------------------------------------
  1383. // OpenCL Extension v2.0 s9.18 - Mipmaps
  1384. let Extension = FuncExtKhrMipmapImage in {
  1385. // Added to section 6.13.14.2.
  1386. foreach aQual = ["RO"] in {
  1387. foreach imgTy = [Image2d] in {
  1388. foreach name = ["read_imagef"] in {
  1389. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1390. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1391. }
  1392. foreach name = ["read_imagei"] in {
  1393. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1394. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1395. }
  1396. foreach name = ["read_imageui"] in {
  1397. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1398. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1399. }
  1400. }
  1401. foreach imgTy = [Image2dDepth] in {
  1402. foreach name = ["read_imagef"] in {
  1403. def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1404. def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1405. }
  1406. }
  1407. foreach imgTy = [Image1d] in {
  1408. foreach name = ["read_imagef"] in {
  1409. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
  1410. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
  1411. }
  1412. foreach name = ["read_imagei"] in {
  1413. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
  1414. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
  1415. }
  1416. foreach name = ["read_imageui"] in {
  1417. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
  1418. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
  1419. }
  1420. }
  1421. foreach imgTy = [Image3d] in {
  1422. foreach name = ["read_imagef"] in {
  1423. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
  1424. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1425. }
  1426. foreach name = ["read_imagei"] in {
  1427. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
  1428. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1429. }
  1430. foreach name = ["read_imageui"] in {
  1431. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
  1432. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1433. }
  1434. }
  1435. foreach imgTy = [Image1dArray] in {
  1436. foreach name = ["read_imagef"] in {
  1437. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1438. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
  1439. }
  1440. foreach name = ["read_imagei"] in {
  1441. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1442. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
  1443. }
  1444. foreach name = ["read_imageui"] in {
  1445. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
  1446. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
  1447. }
  1448. }
  1449. foreach imgTy = [Image2dArray] in {
  1450. foreach name = ["read_imagef"] in {
  1451. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1452. def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1453. }
  1454. foreach name = ["read_imagei"] in {
  1455. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1456. def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1457. }
  1458. foreach name = ["read_imageui"] in {
  1459. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1460. def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1461. }
  1462. }
  1463. foreach imgTy = [Image2dArrayDepth] in {
  1464. foreach name = ["read_imagef"] in {
  1465. def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
  1466. def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
  1467. }
  1468. }
  1469. }
  1470. }
  1471. // Added to section 6.13.14.5
  1472. multiclass ImageQueryNumMipLevels<string aQual> {
  1473. foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
  1474. def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
  1475. }
  1476. }
  1477. let Extension = FuncExtKhrMipmapImage in {
  1478. defm : ImageQueryNumMipLevels<"RO">;
  1479. defm : ImageQueryNumMipLevels<"WO">;
  1480. defm : ImageQueryNumMipLevels<"RW">;
  1481. }
  1482. // Write functions are enabled using a separate extension.
  1483. let Extension = FuncExtKhrMipmapImageWrites in {
  1484. // Added to section 6.13.14.4.
  1485. foreach aQual = ["WO"] in {
  1486. foreach imgTy = [Image2d] in {
  1487. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
  1488. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
  1489. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
  1490. }
  1491. def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
  1492. foreach imgTy = [Image1d] in {
  1493. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
  1494. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
  1495. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
  1496. }
  1497. foreach imgTy = [Image1dArray] in {
  1498. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
  1499. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
  1500. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
  1501. }
  1502. foreach imgTy = [Image2dArray] in {
  1503. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
  1504. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
  1505. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
  1506. }
  1507. def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
  1508. foreach imgTy = [Image3d] in {
  1509. def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
  1510. def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
  1511. def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
  1512. }
  1513. }
  1514. }
  1515. //--------------------------------------------------------------------
  1516. // OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
  1517. // --- Table 6.13.14.3 ---
  1518. multiclass ImageReadMsaa<string aQual> {
  1519. foreach imgTy = [Image2dMsaa] in {
  1520. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
  1521. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
  1522. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
  1523. }
  1524. foreach imgTy = [Image2dArrayMsaa] in {
  1525. def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
  1526. def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
  1527. def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
  1528. }
  1529. foreach name = ["read_imagef"] in {
  1530. def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
  1531. def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
  1532. }
  1533. }
  1534. // --- Table 6.13.14.5 ---
  1535. multiclass ImageQueryMsaa<string aQual> {
  1536. foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
  1537. foreach name = ["get_image_width", "get_image_height",
  1538. "get_image_channel_data_type", "get_image_channel_order",
  1539. "get_image_num_samples"] in {
  1540. def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
  1541. }
  1542. def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
  1543. }
  1544. foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in {
  1545. def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
  1546. }
  1547. }
  1548. let Extension = FuncExtKhrGlMsaaSharing in {
  1549. defm : ImageReadMsaa<"RO">;
  1550. defm : ImageQueryMsaa<"RO">;
  1551. defm : ImageQueryMsaa<"WO">;
  1552. defm : ImageReadMsaa<"RW">;
  1553. defm : ImageQueryMsaa<"RW">;
  1554. }
  1555. //--------------------------------------------------------------------
  1556. // OpenCL Extension v2.0 s28 - Subgroups
  1557. // --- Table 28.2.1 ---
  1558. let Extension = FuncExtKhrSubgroups in {
  1559. foreach name = ["get_sub_group_size", "get_max_sub_group_size",
  1560. "get_num_sub_groups", "get_sub_group_id",
  1561. "get_sub_group_local_id"] in {
  1562. def : Builtin<name, [UInt]>;
  1563. }
  1564. let MinVersion = CL20 in {
  1565. foreach name = ["get_enqueued_num_sub_groups"] in {
  1566. def : Builtin<name, [UInt]>;
  1567. }
  1568. }
  1569. }
  1570. // --- Table 28.2.2 ---
  1571. let Extension = FuncExtKhrSubgroups in {
  1572. def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
  1573. let MinVersion = CL20 in {
  1574. def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
  1575. }
  1576. }
  1577. // --- Table 28.2.4 ---
  1578. let Extension = FuncExtKhrSubgroups in {
  1579. foreach name = ["sub_group_all", "sub_group_any"] in {
  1580. def : Builtin<name, [Int, Int], Attr.Convergent>;
  1581. }
  1582. foreach name = ["sub_group_broadcast"] in {
  1583. def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, UInt], Attr.Convergent>;
  1584. }
  1585. foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
  1586. "sub_group_scan_inclusive_"] in {
  1587. foreach op = ["add", "min", "max"] in {
  1588. def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
  1589. }
  1590. }
  1591. }
  1592. // OpenCL Extension v3.0 s38 - Extended Subgroup Functions
  1593. // Section 38.4.1 - cl_khr_subgroup_extended_types
  1594. let Extension = FuncExtKhrSubgroupExtendedTypes in {
  1595. // For sub_group_broadcast, add scalar char, uchar, short, and ushort support,
  1596. def : Builtin<"sub_group_broadcast", [CharShortGenType1, CharShortGenType1, UInt], Attr.Convergent>;
  1597. // gentype may additionally be one of the supported built-in vector data types.
  1598. def : Builtin<"sub_group_broadcast", [AGenTypeNNoScalar, AGenTypeNNoScalar, UInt], Attr.Convergent>;
  1599. foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
  1600. "sub_group_scan_inclusive_"] in {
  1601. foreach op = ["add", "min", "max"] in {
  1602. def : Builtin<name # op, [CharShortGenType1, CharShortGenType1], Attr.Convergent>;
  1603. }
  1604. }
  1605. }
  1606. // Section 38.5.1 - cl_khr_subgroup_non_uniform_vote
  1607. let Extension = FuncExtKhrSubgroupNonUniformVote in {
  1608. def : Builtin<"sub_group_elect", [Int]>;
  1609. def : Builtin<"sub_group_non_uniform_all", [Int, Int]>;
  1610. def : Builtin<"sub_group_non_uniform_any", [Int, Int]>;
  1611. def : Builtin<"sub_group_non_uniform_all_equal", [Int, AGenType1]>;
  1612. }
  1613. // Section 38.6.1 - cl_khr_subgroup_ballot
  1614. let Extension = FuncExtKhrSubgroupBallot in {
  1615. def : Builtin<"sub_group_non_uniform_broadcast", [AGenTypeN, AGenTypeN, UInt]>;
  1616. def : Builtin<"sub_group_broadcast_first", [AGenType1, AGenType1]>;
  1617. def : Builtin<"sub_group_ballot", [VectorType<UInt, 4>, Int]>;
  1618. def : Builtin<"sub_group_inverse_ballot", [Int, VectorType<UInt, 4>], Attr.Const>;
  1619. def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType<UInt, 4>, UInt], Attr.Const>;
  1620. def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType<UInt, 4>], Attr.Const>;
  1621. def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType<UInt, 4>]>;
  1622. def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType<UInt, 4>]>;
  1623. def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType<UInt, 4>]>;
  1624. def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType<UInt, 4>]>;
  1625. foreach op = ["eq", "ge", "gt", "le", "lt"] in {
  1626. def : Builtin<"get_sub_group_" # op # "_mask", [VectorType<UInt, 4>], Attr.Const>;
  1627. }
  1628. }
  1629. // Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic
  1630. let Extension = FuncExtKhrSubgroupNonUniformArithmetic in {
  1631. foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in {
  1632. foreach op = ["add", "min", "max", "mul"] in {
  1633. def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, AGenType1]>;
  1634. }
  1635. foreach op = ["and", "or", "xor"] in {
  1636. def : Builtin<"sub_group_non_uniform_" # name # op, [AIGenType1, AIGenType1]>;
  1637. }
  1638. foreach op = ["and", "or", "xor"] in {
  1639. def : Builtin<"sub_group_non_uniform_" # name # "logical_" # op, [Int, Int]>;
  1640. }
  1641. }
  1642. }
  1643. // Section 38.8.1 - cl_khr_subgroup_shuffle
  1644. let Extension = FuncExtKhrSubgroupShuffle in {
  1645. def : Builtin<"sub_group_shuffle", [AGenType1, AGenType1, UInt]>;
  1646. def : Builtin<"sub_group_shuffle_xor", [AGenType1, AGenType1, UInt]>;
  1647. }
  1648. // Section 38.9.1 - cl_khr_subgroup_shuffle_relative
  1649. let Extension = FuncExtKhrSubgroupShuffleRelative in {
  1650. def : Builtin<"sub_group_shuffle_up", [AGenType1, AGenType1, UInt]>;
  1651. def : Builtin<"sub_group_shuffle_down", [AGenType1, AGenType1, UInt]>;
  1652. }
  1653. // Section 38.10.1 - cl_khr_subgroup_clustered_reduce
  1654. let Extension = FuncExtKhrSubgroupClusteredReduce in {
  1655. foreach op = ["add", "min", "max", "mul"] in {
  1656. def : Builtin<"sub_group_clustered_reduce_" # op, [AGenType1, AGenType1, UInt]>;
  1657. }
  1658. foreach op = ["and", "or", "xor"] in {
  1659. def : Builtin<"sub_group_clustered_reduce_" # op, [AIGenType1, AIGenType1, UInt]>;
  1660. }
  1661. foreach op = ["and", "or", "xor"] in {
  1662. def : Builtin<"sub_group_clustered_reduce_logical_" # op, [Int, Int, UInt]>;
  1663. }
  1664. }
  1665. // Section 40.3.1 - cl_khr_extended_bit_ops
  1666. let Extension = FuncExtKhrExtendedBitOps in {
  1667. def : Builtin<"bitfield_insert", [AIGenTypeN, AIGenTypeN, AIGenTypeN, UInt, UInt], Attr.Const>;
  1668. def : Builtin<"bitfield_extract_signed", [SGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
  1669. def : Builtin<"bitfield_extract_signed", [SGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
  1670. def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
  1671. def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
  1672. def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
  1673. }
  1674. // Section 42.3 - cl_khr_integer_dot_product
  1675. let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
  1676. def : Builtin<"dot", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>], Attr.Const>;
  1677. def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<Char, 4>], Attr.Const>;
  1678. def : Builtin<"dot", [Int, VectorType<UChar, 4>, VectorType<Char, 4>], Attr.Const>;
  1679. def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<UChar, 4>], Attr.Const>;
  1680. def : Builtin<"dot_acc_sat", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt], Attr.Const>;
  1681. def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int], Attr.Const>;
  1682. def : Builtin<"dot_acc_sat", [Int, VectorType<UChar, 4>, VectorType<Char, 4>, Int], Attr.Const>;
  1683. def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<UChar, 4>, Int], Attr.Const>;
  1684. }
  1685. let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
  1686. def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
  1687. def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
  1688. def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
  1689. def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
  1690. def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>;
  1691. def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>;
  1692. def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>;
  1693. def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>;
  1694. }
  1695. // Section 48.3 - cl_khr_subgroup_rotate
  1696. let Extension = FunctionExtension<"cl_khr_subgroup_rotate"> in {
  1697. def : Builtin<"sub_group_rotate", [AGenType1, AGenType1, Int], Attr.Convergent>;
  1698. def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, UInt], Attr.Convergent>;
  1699. }
  1700. //--------------------------------------------------------------------
  1701. // Arm extensions.
  1702. let Extension = ArmIntegerDotProductInt8 in {
  1703. foreach name = ["arm_dot"] in {
  1704. def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;
  1705. def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>;
  1706. }
  1707. }
  1708. let Extension = ArmIntegerDotProductAccumulateInt8 in {
  1709. foreach name = ["arm_dot_acc"] in {
  1710. def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
  1711. def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
  1712. }
  1713. }
  1714. let Extension = ArmIntegerDotProductAccumulateInt16 in {
  1715. foreach name = ["arm_dot_acc"] in {
  1716. def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>;
  1717. def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>;
  1718. }
  1719. }
  1720. let Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
  1721. foreach name = ["arm_dot_acc_sat"] in {
  1722. def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
  1723. def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
  1724. }
  1725. }