VPIntrinsics.def 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //===-- IR/VPIntrinsics.def - Describes llvm.vp.* Intrinsics -*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains descriptions of the various Vector Predication intrinsics.
  10. // This is used as a central place for enumerating the different instructions
  11. // and should eventually be the place to put comments about the instructions.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. // NOTE: NO INCLUDE GUARD DESIRED!
  15. // Provide definitions of macros so that users of this file do not have to
  16. // define everything to use it...
  17. //
  18. // Register a VP intrinsic and begin its property scope.
  19. // All VP intrinsic scopes are top level, ie it is illegal to place a
  20. // BEGIN_REGISTER_VP_INTRINSIC within a VP intrinsic scope.
  21. // \p VPID The VP intrinsic id.
  22. // \p MASKPOS The mask operand position.
  23. // \p EVLPOS The explicit vector length operand position.
  24. #ifndef BEGIN_REGISTER_VP_INTRINSIC
  25. #define BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, EVLPOS)
  26. #endif
  27. // End the property scope of a VP intrinsic.
  28. #ifndef END_REGISTER_VP_INTRINSIC
  29. #define END_REGISTER_VP_INTRINSIC(VPID)
  30. #endif
  31. // Register a new VP SDNode and begin its property scope.
  32. // When the SDNode scope is nested within a VP intrinsic scope, it is
  33. // implicitly registered as the canonical SDNode for this VP intrinsic. There
  34. // is one VP intrinsic that maps directly to one SDNode that goes by the
  35. // same name. Since the operands are also the same, we open the property
  36. // scopes for both the VPIntrinsic and the SDNode at once.
  37. // \p VPSD The SelectionDAG Node id (eg VP_ADD).
  38. // \p LEGALPOS The operand position of the SDNode that is used for legalizing.
  39. // If LEGALPOS < 0, then the return type given by
  40. // TheNode->getValueType(-1-LEGALPOS) is used.
  41. // \p TDNAME The name of the TableGen definition of this SDNode.
  42. // \p MASKPOS The mask operand position.
  43. // \p EVLPOS The explicit vector length operand position.
  44. #ifndef BEGIN_REGISTER_VP_SDNODE
  45. #define BEGIN_REGISTER_VP_SDNODE(VPSD, LEGALPOS, TDNAME, MASKPOS, EVLPOS)
  46. #endif
  47. // End the property scope of a new VP SDNode.
  48. #ifndef END_REGISTER_VP_SDNODE
  49. #define END_REGISTER_VP_SDNODE(VPSD)
  50. #endif
  51. // Helper macros for the common "1:1 - Intrinsic : SDNode" case.
  52. //
  53. // There is one VP intrinsic that maps directly to one SDNode that goes by the
  54. // same name. Since the operands are also the same, we open the property
  55. // scopes for both the VPIntrinsic and the SDNode at once.
  56. //
  57. // \p VPID The canonical name (eg `vp_add`, which at the same time is the
  58. // name of the intrinsic and the TableGen def of the SDNode).
  59. // \p MASKPOS The mask operand position.
  60. // \p EVLPOS The explicit vector length operand position.
  61. // \p VPSD The SelectionDAG Node id (eg VP_ADD).
  62. // \p LEGALPOS The operand position of the SDNode that is used for legalizing
  63. // this SDNode. This can be `-1`, in which case the return type of
  64. // the SDNode is used.
  65. #define BEGIN_REGISTER_VP(VPID, MASKPOS, EVLPOS, VPSD, LEGALPOS) \
  66. BEGIN_REGISTER_VP_INTRINSIC(VPID, MASKPOS, EVLPOS) \
  67. BEGIN_REGISTER_VP_SDNODE(VPSD, LEGALPOS, VPID, MASKPOS, EVLPOS)
  68. #define END_REGISTER_VP(VPID, VPSD) \
  69. END_REGISTER_VP_INTRINSIC(VPID) \
  70. END_REGISTER_VP_SDNODE(VPSD)
  71. // The following macros attach properties to the scope they are placed in. This
  72. // assigns the property to the VP Intrinsic and/or SDNode that belongs to the
  73. // scope.
  74. //
  75. // Property Macros {
  76. // The intrinsic and/or SDNode has the same function as this LLVM IR Opcode.
  77. // \p OPC The opcode of the instruction with the same function.
  78. #ifndef VP_PROPERTY_FUNCTIONAL_OPC
  79. #define VP_PROPERTY_FUNCTIONAL_OPC(OPC)
  80. #endif
  81. // Whether the intrinsic may have a rounding mode or exception behavior operand
  82. // bundle.
  83. // \p HASROUND '1' if the intrinsic can have a rounding mode operand bundle,
  84. // '0' otherwise.
  85. // \p HASEXCEPT '1' if the intrinsic can have an exception behavior operand
  86. // bundle, '0' otherwise.
  87. // \p INTRINID The constrained fp intrinsic this VP intrinsic corresponds to.
  88. #ifndef VP_PROPERTY_CONSTRAINEDFP
  89. #define VP_PROPERTY_CONSTRAINEDFP(HASROUND, HASEXCEPT, INTRINID)
  90. #endif
  91. // Map this VP intrinsic to its canonical functional intrinsic.
  92. // \p INTRIN The non-VP intrinsics with the same function.
  93. #ifndef VP_PROPERTY_FUNCTIONAL_INTRINSIC
  94. #define VP_PROPERTY_FUNCTIONAL_INTRINSIC(INTRIN)
  95. #endif
  96. // This VP Intrinsic is a memory operation
  97. // The pointer arg is at POINTERPOS and the data arg is at DATAPOS.
  98. #ifndef VP_PROPERTY_MEMOP
  99. #define VP_PROPERTY_MEMOP(POINTERPOS, DATAPOS)
  100. #endif
  101. // Map this VP reduction intrinsic to its reduction operand positions.
  102. #ifndef VP_PROPERTY_REDUCTION
  103. #define VP_PROPERTY_REDUCTION(STARTPOS, VECTORPOS)
  104. #endif
  105. // A property to infer VP binary-op SDNode opcodes automatically.
  106. #ifndef VP_PROPERTY_BINARYOP
  107. #define VP_PROPERTY_BINARYOP
  108. #endif
  109. /// } Property Macros
  110. ///// Integer Arithmetic {
  111. // Specialized helper macro for integer binary operators (%x, %y, %mask, %evl).
  112. #ifdef HELPER_REGISTER_BINARY_INT_VP
  113. #error \
  114. "The internal helper macro HELPER_REGISTER_BINARY_INT_VP is already defined!"
  115. #endif
  116. #define HELPER_REGISTER_BINARY_INT_VP(VPID, VPSD, IROPC) \
  117. BEGIN_REGISTER_VP(VPID, 2, 3, VPSD, -1) \
  118. VP_PROPERTY_FUNCTIONAL_OPC(IROPC) \
  119. VP_PROPERTY_BINARYOP \
  120. END_REGISTER_VP(VPID, VPSD)
  121. // llvm.vp.add(x,y,mask,vlen)
  122. HELPER_REGISTER_BINARY_INT_VP(vp_add, VP_ADD, Add)
  123. // llvm.vp.and(x,y,mask,vlen)
  124. HELPER_REGISTER_BINARY_INT_VP(vp_and, VP_AND, And)
  125. // llvm.vp.ashr(x,y,mask,vlen)
  126. HELPER_REGISTER_BINARY_INT_VP(vp_ashr, VP_ASHR, AShr)
  127. // llvm.vp.lshr(x,y,mask,vlen)
  128. HELPER_REGISTER_BINARY_INT_VP(vp_lshr, VP_LSHR, LShr)
  129. // llvm.vp.mul(x,y,mask,vlen)
  130. HELPER_REGISTER_BINARY_INT_VP(vp_mul, VP_MUL, Mul)
  131. // llvm.vp.or(x,y,mask,vlen)
  132. HELPER_REGISTER_BINARY_INT_VP(vp_or, VP_OR, Or)
  133. // llvm.vp.sdiv(x,y,mask,vlen)
  134. HELPER_REGISTER_BINARY_INT_VP(vp_sdiv, VP_SDIV, SDiv)
  135. // llvm.vp.shl(x,y,mask,vlen)
  136. HELPER_REGISTER_BINARY_INT_VP(vp_shl, VP_SHL, Shl)
  137. // llvm.vp.srem(x,y,mask,vlen)
  138. HELPER_REGISTER_BINARY_INT_VP(vp_srem, VP_SREM, SRem)
  139. // llvm.vp.sub(x,y,mask,vlen)
  140. HELPER_REGISTER_BINARY_INT_VP(vp_sub, VP_SUB, Sub)
  141. // llvm.vp.udiv(x,y,mask,vlen)
  142. HELPER_REGISTER_BINARY_INT_VP(vp_udiv, VP_UDIV, UDiv)
  143. // llvm.vp.urem(x,y,mask,vlen)
  144. HELPER_REGISTER_BINARY_INT_VP(vp_urem, VP_UREM, URem)
  145. // llvm.vp.xor(x,y,mask,vlen)
  146. HELPER_REGISTER_BINARY_INT_VP(vp_xor, VP_XOR, Xor)
  147. #undef HELPER_REGISTER_BINARY_INT_VP
  148. ///// } Integer Arithmetic
  149. ///// Floating-Point Arithmetic {
  150. // Specialized helper macro for floating-point binary operators
  151. // <operation>(%x, %y, %mask, %evl).
  152. #ifdef HELPER_REGISTER_BINARY_FP_VP
  153. #error \
  154. "The internal helper macro HELPER_REGISTER_BINARY_FP_VP is already defined!"
  155. #endif
  156. #define HELPER_REGISTER_BINARY_FP_VP(OPSUFFIX, VPSD, IROPC) \
  157. BEGIN_REGISTER_VP(vp_##OPSUFFIX, 2, 3, VPSD, -1) \
  158. VP_PROPERTY_FUNCTIONAL_OPC(IROPC) \
  159. VP_PROPERTY_CONSTRAINEDFP(1, 1, experimental_constrained_##OPSUFFIX) \
  160. VP_PROPERTY_BINARYOP \
  161. END_REGISTER_VP(vp_##OPSUFFIX, VPSD)
  162. // llvm.vp.fadd(x,y,mask,vlen)
  163. HELPER_REGISTER_BINARY_FP_VP(fadd, VP_FADD, FAdd)
  164. // llvm.vp.fsub(x,y,mask,vlen)
  165. HELPER_REGISTER_BINARY_FP_VP(fsub, VP_FSUB, FSub)
  166. // llvm.vp.fmul(x,y,mask,vlen)
  167. HELPER_REGISTER_BINARY_FP_VP(fmul, VP_FMUL, FMul)
  168. // llvm.vp.fdiv(x,y,mask,vlen)
  169. HELPER_REGISTER_BINARY_FP_VP(fdiv, VP_FDIV, FDiv)
  170. // llvm.vp.frem(x,y,mask,vlen)
  171. HELPER_REGISTER_BINARY_FP_VP(frem, VP_FREM, FRem)
  172. #undef HELPER_REGISTER_BINARY_FP_VP
  173. ///// } Floating-Point Arithmetic
  174. ///// Memory Operations {
  175. // llvm.vp.store(val,ptr,mask,vlen)
  176. BEGIN_REGISTER_VP_INTRINSIC(vp_store, 2, 3)
  177. // chain = VP_STORE chain,val,base,offset,mask,evl
  178. BEGIN_REGISTER_VP_SDNODE(VP_STORE, 0, vp_store, 4, 5)
  179. VP_PROPERTY_FUNCTIONAL_OPC(Store)
  180. VP_PROPERTY_FUNCTIONAL_INTRINSIC(masked_store)
  181. VP_PROPERTY_MEMOP(1, 0)
  182. END_REGISTER_VP(vp_store, VP_STORE)
  183. // llvm.vp.scatter(ptr,val,mask,vlen)
  184. BEGIN_REGISTER_VP_INTRINSIC(vp_scatter, 2, 3)
  185. // chain = VP_SCATTER chain,val,base,indices,scale,mask,evl
  186. BEGIN_REGISTER_VP_SDNODE(VP_SCATTER, -1, vp_scatter, 5, 6)
  187. VP_PROPERTY_FUNCTIONAL_INTRINSIC(masked_scatter)
  188. VP_PROPERTY_MEMOP(1, 0)
  189. END_REGISTER_VP(vp_scatter, VP_SCATTER)
  190. // llvm.vp.load(ptr,mask,vlen)
  191. BEGIN_REGISTER_VP_INTRINSIC(vp_load, 1, 2)
  192. // val,chain = VP_LOAD chain,base,offset,mask,evl
  193. BEGIN_REGISTER_VP_SDNODE(VP_LOAD, -1, vp_load, 3, 4)
  194. VP_PROPERTY_FUNCTIONAL_OPC(Load)
  195. VP_PROPERTY_FUNCTIONAL_INTRINSIC(masked_load)
  196. VP_PROPERTY_MEMOP(0, None)
  197. END_REGISTER_VP(vp_load, VP_LOAD)
  198. // llvm.vp.gather(ptr,mask,vlen)
  199. BEGIN_REGISTER_VP_INTRINSIC(vp_gather, 1, 2)
  200. // val,chain = VP_GATHER chain,base,indices,scale,mask,evl
  201. BEGIN_REGISTER_VP_SDNODE(VP_GATHER, -1, vp_gather, 4, 5)
  202. VP_PROPERTY_FUNCTIONAL_INTRINSIC(masked_gather)
  203. VP_PROPERTY_MEMOP(0, None)
  204. END_REGISTER_VP(vp_gather, VP_GATHER)
  205. ///// } Memory Operations
  206. ///// Reductions {
  207. // Specialized helper macro for VP reductions (%start, %x, %mask, %evl).
  208. #ifdef HELPER_REGISTER_REDUCTION_VP
  209. #error \
  210. "The internal helper macro HELPER_REGISTER_REDUCTION_VP is already defined!"
  211. #endif
  212. #define HELPER_REGISTER_REDUCTION_VP(VPID, VPSD, INTRIN) \
  213. BEGIN_REGISTER_VP(VPID, 2, 3, VPSD, -1) \
  214. VP_PROPERTY_FUNCTIONAL_INTRINSIC(INTRIN) \
  215. VP_PROPERTY_REDUCTION(0, 1) \
  216. END_REGISTER_VP(VPID, VPSD)
  217. // llvm.vp.reduce.add(start,x,mask,vlen)
  218. HELPER_REGISTER_REDUCTION_VP(vp_reduce_add, VP_REDUCE_ADD,
  219. experimental_vector_reduce_add)
  220. // llvm.vp.reduce.mul(start,x,mask,vlen)
  221. HELPER_REGISTER_REDUCTION_VP(vp_reduce_mul, VP_REDUCE_MUL,
  222. experimental_vector_reduce_mul)
  223. // llvm.vp.reduce.and(start,x,mask,vlen)
  224. HELPER_REGISTER_REDUCTION_VP(vp_reduce_and, VP_REDUCE_AND,
  225. experimental_vector_reduce_and)
  226. // llvm.vp.reduce.or(start,x,mask,vlen)
  227. HELPER_REGISTER_REDUCTION_VP(vp_reduce_or, VP_REDUCE_OR,
  228. experimental_vector_reduce_or)
  229. // llvm.vp.reduce.xor(start,x,mask,vlen)
  230. HELPER_REGISTER_REDUCTION_VP(vp_reduce_xor, VP_REDUCE_XOR,
  231. experimental_vector_reduce_xor)
  232. // llvm.vp.reduce.smax(start,x,mask,vlen)
  233. HELPER_REGISTER_REDUCTION_VP(vp_reduce_smax, VP_REDUCE_SMAX,
  234. experimental_vector_reduce_smax)
  235. // llvm.vp.reduce.smin(start,x,mask,vlen)
  236. HELPER_REGISTER_REDUCTION_VP(vp_reduce_smin, VP_REDUCE_SMIN,
  237. experimental_vector_reduce_smin)
  238. // llvm.vp.reduce.umax(start,x,mask,vlen)
  239. HELPER_REGISTER_REDUCTION_VP(vp_reduce_umax, VP_REDUCE_UMAX,
  240. experimental_vector_reduce_umax)
  241. // llvm.vp.reduce.umin(start,x,mask,vlen)
  242. HELPER_REGISTER_REDUCTION_VP(vp_reduce_umin, VP_REDUCE_UMIN,
  243. experimental_vector_reduce_umin)
  244. // llvm.vp.reduce.fmax(start,x,mask,vlen)
  245. HELPER_REGISTER_REDUCTION_VP(vp_reduce_fmax, VP_REDUCE_FMAX,
  246. experimental_vector_reduce_fmax)
  247. // llvm.vp.reduce.fmin(start,x,mask,vlen)
  248. HELPER_REGISTER_REDUCTION_VP(vp_reduce_fmin, VP_REDUCE_FMIN,
  249. experimental_vector_reduce_fmin)
  250. #undef HELPER_REGISTER_REDUCTION_VP
  251. // Specialized helper macro for VP reductions as above but with two forms:
  252. // sequential and reassociative. These manifest as the presence of 'reassoc'
  253. // fast-math flags in the IR and as two distinct ISD opcodes in the
  254. // SelectionDAG.
  255. #ifdef HELPER_REGISTER_REDUCTION_SEQ_VP
  256. #error \
  257. "The internal helper macro HELPER_REGISTER_REDUCTION_SEQ_VP is already defined!"
  258. #endif
  259. #define HELPER_REGISTER_REDUCTION_SEQ_VP(VPID, VPSD, SEQ_VPSD, INTRIN) \
  260. BEGIN_REGISTER_VP_INTRINSIC(VPID, 2, 3) \
  261. BEGIN_REGISTER_VP_SDNODE(VPSD, -1, VPID, 2, 3) \
  262. VP_PROPERTY_REDUCTION(0, 1) \
  263. END_REGISTER_VP_SDNODE(VPSD) \
  264. BEGIN_REGISTER_VP_SDNODE(SEQ_VPSD, -1, VPID, 2, 3) \
  265. VP_PROPERTY_REDUCTION(0, 1) \
  266. END_REGISTER_VP_SDNODE(SEQ_VPSD) \
  267. VP_PROPERTY_FUNCTIONAL_INTRINSIC(INTRIN) \
  268. END_REGISTER_VP_INTRINSIC(VPID)
  269. // llvm.vp.reduce.fadd(start,x,mask,vlen)
  270. HELPER_REGISTER_REDUCTION_SEQ_VP(vp_reduce_fadd, VP_REDUCE_FADD,
  271. VP_REDUCE_SEQ_FADD,
  272. experimental_vector_reduce_fadd)
  273. // llvm.vp.reduce.fmul(start,x,mask,vlen)
  274. HELPER_REGISTER_REDUCTION_SEQ_VP(vp_reduce_fmul, VP_REDUCE_FMUL,
  275. VP_REDUCE_SEQ_FMUL,
  276. experimental_vector_reduce_fmul)
  277. #undef HELPER_REGISTER_REDUCTION_SEQ_VP
  278. ///// } Reduction
  279. ///// Shuffles {
  280. // llvm.vp.select(mask,on_true,on_false,vlen)
  281. BEGIN_REGISTER_VP(vp_select, 0, 3, VP_SELECT, -1)
  282. VP_PROPERTY_FUNCTIONAL_OPC(Select)
  283. END_REGISTER_VP(vp_select, VP_SELECT)
  284. // llvm.vp.merge(mask,on_true,on_false,pivot)
  285. BEGIN_REGISTER_VP(vp_merge, 0, 3, VP_MERGE, -1)
  286. END_REGISTER_VP(vp_merge, VP_MERGE)
  287. BEGIN_REGISTER_VP(experimental_vp_splice, 3, 5, EXPERIMENTAL_VP_SPLICE, -1)
  288. END_REGISTER_VP(experimental_vp_splice, EXPERIMENTAL_VP_SPLICE)
  289. ///// } Shuffles
  290. #undef BEGIN_REGISTER_VP
  291. #undef BEGIN_REGISTER_VP_INTRINSIC
  292. #undef BEGIN_REGISTER_VP_SDNODE
  293. #undef END_REGISTER_VP
  294. #undef END_REGISTER_VP_INTRINSIC
  295. #undef END_REGISTER_VP_SDNODE
  296. #undef VP_PROPERTY_BINARYOP
  297. #undef VP_PROPERTY_CONSTRAINEDFP
  298. #undef VP_PROPERTY_FUNCTIONAL_INTRINSIC
  299. #undef VP_PROPERTY_FUNCTIONAL_OPC
  300. #undef VP_PROPERTY_MEMOP
  301. #undef VP_PROPERTY_REDUCTION