OpenCLBuiltins.td 92 KB

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