IntrinsicsWebAssembly.td 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //===- IntrinsicsWebAssembly.td - Defines wasm intrinsics --*- tablegen -*-===//
  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. /// \file
  10. /// This file defines all of the WebAssembly-specific intrinsics.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. let TargetPrefix = "wasm" in { // All intrinsics start with "llvm.wasm.".
  14. // Query the current memory size, and increase the current memory size.
  15. // Note that memory.size is not IntrNoMem because it must be sequenced with
  16. // respect to memory.grow calls.
  17. def int_wasm_memory_size : Intrinsic<[llvm_anyint_ty],
  18. [llvm_i32_ty],
  19. [IntrReadMem]>;
  20. def int_wasm_memory_grow : Intrinsic<[llvm_anyint_ty],
  21. [llvm_i32_ty, LLVMMatchType<0>],
  22. []>;
  23. //===----------------------------------------------------------------------===//
  24. // Trapping float-to-int conversions
  25. //===----------------------------------------------------------------------===//
  26. def int_wasm_trunc_signed : Intrinsic<[llvm_anyint_ty],
  27. [llvm_anyfloat_ty],
  28. [IntrNoMem]>;
  29. def int_wasm_trunc_unsigned : Intrinsic<[llvm_anyint_ty],
  30. [llvm_anyfloat_ty],
  31. [IntrNoMem]>;
  32. //===----------------------------------------------------------------------===//
  33. // Saturating float-to-int conversions
  34. //===----------------------------------------------------------------------===//
  35. def int_wasm_trunc_saturate_signed : Intrinsic<[llvm_anyint_ty],
  36. [llvm_anyfloat_ty],
  37. [IntrNoMem, IntrSpeculatable]>;
  38. def int_wasm_trunc_saturate_unsigned : Intrinsic<[llvm_anyint_ty],
  39. [llvm_anyfloat_ty],
  40. [IntrNoMem, IntrSpeculatable]>;
  41. //===----------------------------------------------------------------------===//
  42. // Exception handling intrinsics
  43. //===----------------------------------------------------------------------===//
  44. // throw / rethrow
  45. // The immediate argument is an index to a tag, which is 0 for C++.
  46. def int_wasm_throw : Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty],
  47. [Throws, IntrNoReturn, ImmArg<ArgIndex<0>>]>;
  48. def int_wasm_rethrow : Intrinsic<[], [], [Throws, IntrNoReturn]>;
  49. // Since wasm does not use landingpad instructions, these instructions return
  50. // exception pointer and selector values until we lower them in WasmEHPrepare.
  51. def int_wasm_get_exception : Intrinsic<[llvm_ptr_ty], [llvm_token_ty],
  52. [IntrHasSideEffects]>;
  53. def int_wasm_get_ehselector : Intrinsic<[llvm_i32_ty], [llvm_token_ty],
  54. [IntrHasSideEffects]>;
  55. // wasm.catch returns the pointer to the exception object caught by wasm 'catch'
  56. // instruction. This returns a single pointer, which is sufficient for C++
  57. // support. The immediate argument is an index to for a tag, which is 0 for C++.
  58. def int_wasm_catch : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty],
  59. [IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
  60. // WebAssembly EH must maintain the landingpads in the order assigned to them
  61. // by WasmEHPrepare pass to generate landingpad table in EHStreamer. This is
  62. // used in order to give them the indices in WasmEHPrepare.
  63. def int_wasm_landingpad_index: Intrinsic<[], [llvm_token_ty, llvm_i32_ty],
  64. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  65. // Returns LSDA address of the current function.
  66. def int_wasm_lsda : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
  67. //===----------------------------------------------------------------------===//
  68. // Atomic intrinsics
  69. //===----------------------------------------------------------------------===//
  70. // wait / notify
  71. def int_wasm_memory_atomic_wait32 :
  72. Intrinsic<[llvm_i32_ty],
  73. [LLVMPointerType<llvm_i32_ty>, llvm_i32_ty, llvm_i64_ty],
  74. [IntrInaccessibleMemOrArgMemOnly, ReadOnly<ArgIndex<0>>,
  75. NoCapture<ArgIndex<0>>, IntrHasSideEffects],
  76. "", [SDNPMemOperand]>;
  77. def int_wasm_memory_atomic_wait64 :
  78. Intrinsic<[llvm_i32_ty],
  79. [LLVMPointerType<llvm_i64_ty>, llvm_i64_ty, llvm_i64_ty],
  80. [IntrInaccessibleMemOrArgMemOnly, ReadOnly<ArgIndex<0>>,
  81. NoCapture<ArgIndex<0>>, IntrHasSideEffects],
  82. "", [SDNPMemOperand]>;
  83. def int_wasm_memory_atomic_notify:
  84. Intrinsic<[llvm_i32_ty], [LLVMPointerType<llvm_i32_ty>, llvm_i32_ty],
  85. [IntrInaccessibleMemOnly, NoCapture<ArgIndex<0>>,
  86. IntrHasSideEffects],
  87. "", [SDNPMemOperand]>;
  88. //===----------------------------------------------------------------------===//
  89. // SIMD intrinsics
  90. //===----------------------------------------------------------------------===//
  91. def int_wasm_swizzle :
  92. Intrinsic<[llvm_v16i8_ty],
  93. [llvm_v16i8_ty, llvm_v16i8_ty],
  94. [IntrNoMem, IntrSpeculatable]>;
  95. def int_wasm_shuffle :
  96. Intrinsic<[llvm_v16i8_ty],
  97. [llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty, llvm_i32_ty,
  98. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
  99. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
  100. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  101. [IntrNoMem, IntrSpeculatable]>;
  102. def int_wasm_sub_sat_signed :
  103. Intrinsic<[llvm_anyvector_ty],
  104. [LLVMMatchType<0>, LLVMMatchType<0>],
  105. [IntrNoMem, IntrSpeculatable]>;
  106. def int_wasm_sub_sat_unsigned :
  107. Intrinsic<[llvm_anyvector_ty],
  108. [LLVMMatchType<0>, LLVMMatchType<0>],
  109. [IntrNoMem, IntrSpeculatable]>;
  110. def int_wasm_avgr_unsigned :
  111. Intrinsic<[llvm_anyvector_ty],
  112. [LLVMMatchType<0>, LLVMMatchType<0>],
  113. [IntrNoMem, IntrSpeculatable]>;
  114. def int_wasm_bitselect :
  115. Intrinsic<[llvm_anyvector_ty],
  116. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  117. [IntrNoMem, IntrSpeculatable]>;
  118. def int_wasm_anytrue :
  119. Intrinsic<[llvm_i32_ty],
  120. [llvm_anyvector_ty],
  121. [IntrNoMem, IntrSpeculatable]>;
  122. def int_wasm_alltrue :
  123. Intrinsic<[llvm_i32_ty],
  124. [llvm_anyvector_ty],
  125. [IntrNoMem, IntrSpeculatable]>;
  126. def int_wasm_bitmask :
  127. Intrinsic<[llvm_i32_ty],
  128. [llvm_anyvector_ty],
  129. [IntrNoMem, IntrSpeculatable]>;
  130. def int_wasm_dot :
  131. Intrinsic<[llvm_v4i32_ty],
  132. [llvm_v8i16_ty, llvm_v8i16_ty],
  133. [IntrNoMem, IntrSpeculatable]>;
  134. def int_wasm_narrow_signed :
  135. Intrinsic<[llvm_anyvector_ty],
  136. [llvm_anyvector_ty, LLVMMatchType<1>],
  137. [IntrNoMem, IntrSpeculatable]>;
  138. def int_wasm_narrow_unsigned :
  139. Intrinsic<[llvm_anyvector_ty],
  140. [llvm_anyvector_ty, LLVMMatchType<1>],
  141. [IntrNoMem, IntrSpeculatable]>;
  142. def int_wasm_q15mulr_sat_signed :
  143. Intrinsic<[llvm_v8i16_ty],
  144. [llvm_v8i16_ty, llvm_v8i16_ty],
  145. [IntrNoMem, IntrSpeculatable]>;
  146. // TODO: Replace these intrinsics with normal ISel patterns
  147. def int_wasm_pmin :
  148. Intrinsic<[llvm_anyvector_ty],
  149. [LLVMMatchType<0>, LLVMMatchType<0>],
  150. [IntrNoMem, IntrSpeculatable]>;
  151. def int_wasm_pmax :
  152. Intrinsic<[llvm_anyvector_ty],
  153. [LLVMMatchType<0>, LLVMMatchType<0>],
  154. [IntrNoMem, IntrSpeculatable]>;
  155. // TODO: Replace these intrinsic with normal ISel patterns once the
  156. // load_zero instructions are merged to the proposal.
  157. def int_wasm_load32_zero :
  158. Intrinsic<[llvm_v4i32_ty],
  159. [LLVMPointerType<llvm_i32_ty>],
  160. [IntrReadMem, IntrArgMemOnly],
  161. "", [SDNPMemOperand]>;
  162. def int_wasm_load64_zero :
  163. Intrinsic<[llvm_v2i64_ty],
  164. [LLVMPointerType<llvm_i64_ty>],
  165. [IntrReadMem, IntrArgMemOnly],
  166. "", [SDNPMemOperand]>;
  167. // These intrinsics do not mark their lane index arguments as immediate because
  168. // that changes the corresponding SDNode from ISD::Constant to
  169. // ISD::TargetConstant, which would require extra complications in the ISel
  170. // tablegen patterns. TODO: Replace these intrinsic with normal ISel patterns
  171. // once the load_lane instructions are merged to the proposal.
  172. def int_wasm_load8_lane :
  173. Intrinsic<[llvm_v16i8_ty],
  174. [LLVMPointerType<llvm_i8_ty>, llvm_v16i8_ty, llvm_i32_ty],
  175. [IntrReadMem, IntrArgMemOnly],
  176. "", [SDNPMemOperand]>;
  177. def int_wasm_load16_lane :
  178. Intrinsic<[llvm_v8i16_ty],
  179. [LLVMPointerType<llvm_i16_ty>, llvm_v8i16_ty, llvm_i32_ty],
  180. [IntrReadMem, IntrArgMemOnly],
  181. "", [SDNPMemOperand]>;
  182. def int_wasm_load32_lane :
  183. Intrinsic<[llvm_v4i32_ty],
  184. [LLVMPointerType<llvm_i32_ty>, llvm_v4i32_ty, llvm_i32_ty],
  185. [IntrReadMem, IntrArgMemOnly],
  186. "", [SDNPMemOperand]>;
  187. def int_wasm_load64_lane :
  188. Intrinsic<[llvm_v2i64_ty],
  189. [LLVMPointerType<llvm_i64_ty>, llvm_v2i64_ty, llvm_i32_ty],
  190. [IntrReadMem, IntrArgMemOnly],
  191. "", [SDNPMemOperand]>;
  192. def int_wasm_store8_lane :
  193. Intrinsic<[],
  194. [LLVMPointerType<llvm_i8_ty>, llvm_v16i8_ty, llvm_i32_ty],
  195. [IntrWriteMem, IntrArgMemOnly],
  196. "", [SDNPMemOperand]>;
  197. def int_wasm_store16_lane :
  198. Intrinsic<[],
  199. [LLVMPointerType<llvm_i16_ty>, llvm_v8i16_ty, llvm_i32_ty],
  200. [IntrWriteMem, IntrArgMemOnly],
  201. "", [SDNPMemOperand]>;
  202. def int_wasm_store32_lane :
  203. Intrinsic<[],
  204. [LLVMPointerType<llvm_i32_ty>, llvm_v4i32_ty, llvm_i32_ty],
  205. [IntrWriteMem, IntrArgMemOnly],
  206. "", [SDNPMemOperand]>;
  207. def int_wasm_store64_lane :
  208. Intrinsic<[],
  209. [LLVMPointerType<llvm_i64_ty>, llvm_v2i64_ty, llvm_i32_ty],
  210. [IntrWriteMem, IntrArgMemOnly],
  211. "", [SDNPMemOperand]>;
  212. // TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged
  213. // to the proposal.
  214. def int_wasm_popcnt :
  215. Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>;
  216. def int_wasm_extmul_low_signed :
  217. Intrinsic<[llvm_anyvector_ty],
  218. [LLVMSubdivide2VectorType<0>, LLVMSubdivide2VectorType<0>],
  219. [IntrNoMem, IntrSpeculatable]>;
  220. def int_wasm_extmul_high_signed :
  221. Intrinsic<[llvm_anyvector_ty],
  222. [LLVMSubdivide2VectorType<0>, LLVMSubdivide2VectorType<0>],
  223. [IntrNoMem, IntrSpeculatable]>;
  224. def int_wasm_extmul_low_unsigned :
  225. Intrinsic<[llvm_anyvector_ty],
  226. [LLVMSubdivide2VectorType<0>, LLVMSubdivide2VectorType<0>],
  227. [IntrNoMem, IntrSpeculatable]>;
  228. def int_wasm_extmul_high_unsigned :
  229. Intrinsic<[llvm_anyvector_ty],
  230. [LLVMSubdivide2VectorType<0>, LLVMSubdivide2VectorType<0>],
  231. [IntrNoMem, IntrSpeculatable]>;
  232. def int_wasm_extadd_pairwise_signed :
  233. Intrinsic<[llvm_anyvector_ty],
  234. [LLVMSubdivide2VectorType<0>],
  235. [IntrNoMem, IntrSpeculatable]>;
  236. def int_wasm_extadd_pairwise_unsigned :
  237. Intrinsic<[llvm_anyvector_ty],
  238. [LLVMSubdivide2VectorType<0>],
  239. [IntrNoMem, IntrSpeculatable]>;
  240. // TODO: Remove these if possible if they are merged to the spec.
  241. def int_wasm_demote_zero :
  242. Intrinsic<[llvm_v4f32_ty], [llvm_v2f64_ty],
  243. [IntrNoMem, IntrSpeculatable]>;
  244. def int_wasm_promote_low :
  245. Intrinsic<[llvm_v2f64_ty], [llvm_v4f32_ty],
  246. [IntrNoMem, IntrSpeculatable]>;
  247. //===----------------------------------------------------------------------===//
  248. // Thread-local storage intrinsics
  249. //===----------------------------------------------------------------------===//
  250. def int_wasm_tls_size :
  251. Intrinsic<[llvm_anyint_ty],
  252. [],
  253. [IntrNoMem, IntrSpeculatable]>;
  254. def int_wasm_tls_align :
  255. Intrinsic<[llvm_anyint_ty],
  256. [],
  257. [IntrNoMem, IntrSpeculatable]>;
  258. def int_wasm_tls_base :
  259. Intrinsic<[llvm_ptr_ty],
  260. [],
  261. [IntrReadMem]>;
  262. } // TargetPrefix = "wasm"