IntrinsicsWebAssembly.td 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. // Type definition for a table in an intrinsic
  14. def llvm_table_ty : LLVMQualPointerType<llvm_i8_ty, 1>;
  15. let TargetPrefix = "wasm" in { // All intrinsics start with "llvm.wasm.".
  16. // Query the current memory size, and increase the current memory size.
  17. // Note that memory.size is not IntrNoMem because it must be sequenced with
  18. // respect to memory.grow calls.
  19. def int_wasm_memory_size : Intrinsic<[llvm_anyint_ty],
  20. [llvm_i32_ty],
  21. [IntrReadMem]>;
  22. def int_wasm_memory_grow : Intrinsic<[llvm_anyint_ty],
  23. [llvm_i32_ty, LLVMMatchType<0>],
  24. []>;
  25. //===----------------------------------------------------------------------===//
  26. // ref.null intrinsics
  27. //===----------------------------------------------------------------------===//
  28. def int_wasm_ref_null_extern : Intrinsic<[llvm_externref_ty], [], [IntrNoMem]>;
  29. def int_wasm_ref_null_func : Intrinsic<[llvm_funcref_ty], [], [IntrNoMem]>;
  30. //===----------------------------------------------------------------------===//
  31. // Table intrinsics
  32. //===----------------------------------------------------------------------===//
  33. // Query the current table size, and increase the current table size.
  34. def int_wasm_table_size : Intrinsic<[llvm_i32_ty],
  35. [llvm_table_ty],
  36. [IntrReadMem]>;
  37. def int_wasm_table_copy : Intrinsic<[],
  38. [llvm_table_ty, llvm_table_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  39. []>;
  40. def int_wasm_table_grow_externref : Intrinsic<[llvm_i32_ty],
  41. [llvm_table_ty, llvm_externref_ty, llvm_i32_ty],
  42. []>;
  43. def int_wasm_table_grow_funcref : Intrinsic<[llvm_i32_ty],
  44. [llvm_table_ty, llvm_funcref_ty, llvm_i32_ty],
  45. []>;
  46. def int_wasm_table_fill_externref : Intrinsic<[],
  47. [llvm_table_ty, llvm_i32_ty, llvm_externref_ty, llvm_i32_ty],
  48. []>;
  49. def int_wasm_table_fill_funcref : Intrinsic<[],
  50. [llvm_table_ty, llvm_i32_ty, llvm_funcref_ty, llvm_i32_ty],
  51. []>;
  52. //===----------------------------------------------------------------------===//
  53. // Trapping float-to-int conversions
  54. //===----------------------------------------------------------------------===//
  55. def int_wasm_trunc_signed : Intrinsic<[llvm_anyint_ty],
  56. [llvm_anyfloat_ty],
  57. [IntrNoMem]>;
  58. def int_wasm_trunc_unsigned : Intrinsic<[llvm_anyint_ty],
  59. [llvm_anyfloat_ty],
  60. [IntrNoMem]>;
  61. //===----------------------------------------------------------------------===//
  62. // Saturating float-to-int conversions
  63. //===----------------------------------------------------------------------===//
  64. def int_wasm_trunc_saturate_signed : Intrinsic<[llvm_anyint_ty],
  65. [llvm_anyfloat_ty],
  66. [IntrNoMem, IntrSpeculatable]>;
  67. def int_wasm_trunc_saturate_unsigned : Intrinsic<[llvm_anyint_ty],
  68. [llvm_anyfloat_ty],
  69. [IntrNoMem, IntrSpeculatable]>;
  70. //===----------------------------------------------------------------------===//
  71. // Exception handling intrinsics
  72. //===----------------------------------------------------------------------===//
  73. // throw / rethrow
  74. // The first immediate argument is an index to a tag, which is 0 for C++
  75. // exception. The second argument is the thrown exception pointer.
  76. def int_wasm_throw : Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty],
  77. [Throws, IntrNoReturn, ImmArg<ArgIndex<0>>]>;
  78. def int_wasm_rethrow : Intrinsic<[], [], [Throws, IntrNoReturn]>;
  79. // Since wasm does not use landingpad instructions, these instructions return
  80. // exception pointer and selector values until we lower them in WasmEHPrepare.
  81. def int_wasm_get_exception : Intrinsic<[llvm_ptr_ty], [llvm_token_ty],
  82. [IntrHasSideEffects]>;
  83. def int_wasm_get_ehselector : Intrinsic<[llvm_i32_ty], [llvm_token_ty],
  84. [IntrHasSideEffects]>;
  85. // wasm.catch returns the pointer to the exception object caught by wasm 'catch'
  86. // instruction. This returns a single pointer, which is the case for C++
  87. // exceptions. The immediate argument is an index to for a tag, which is 0 for
  88. // C++ exceptions.
  89. def int_wasm_catch : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty],
  90. [IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
  91. // WebAssembly EH must maintain the landingpads in the order assigned to them
  92. // by WasmEHPrepare pass to generate landingpad table in EHStreamer. This is
  93. // used in order to give them the indices in WasmEHPrepare.
  94. def int_wasm_landingpad_index: Intrinsic<[], [llvm_token_ty, llvm_i32_ty],
  95. [IntrNoMem, ImmArg<ArgIndex<1>>]>;
  96. // Returns LSDA address of the current function.
  97. def int_wasm_lsda : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
  98. //===----------------------------------------------------------------------===//
  99. // Atomic intrinsics
  100. //===----------------------------------------------------------------------===//
  101. // wait / notify
  102. def int_wasm_memory_atomic_wait32 :
  103. Intrinsic<[llvm_i32_ty],
  104. [LLVMPointerType<llvm_i32_ty>, llvm_i32_ty, llvm_i64_ty],
  105. [IntrInaccessibleMemOrArgMemOnly, ReadOnly<ArgIndex<0>>,
  106. NoCapture<ArgIndex<0>>, IntrHasSideEffects],
  107. "", [SDNPMemOperand]>;
  108. def int_wasm_memory_atomic_wait64 :
  109. Intrinsic<[llvm_i32_ty],
  110. [LLVMPointerType<llvm_i64_ty>, llvm_i64_ty, llvm_i64_ty],
  111. [IntrInaccessibleMemOrArgMemOnly, ReadOnly<ArgIndex<0>>,
  112. NoCapture<ArgIndex<0>>, IntrHasSideEffects],
  113. "", [SDNPMemOperand]>;
  114. def int_wasm_memory_atomic_notify:
  115. Intrinsic<[llvm_i32_ty], [LLVMPointerType<llvm_i32_ty>, llvm_i32_ty],
  116. [IntrInaccessibleMemOnly, NoCapture<ArgIndex<0>>,
  117. IntrHasSideEffects],
  118. "", [SDNPMemOperand]>;
  119. //===----------------------------------------------------------------------===//
  120. // SIMD intrinsics
  121. //===----------------------------------------------------------------------===//
  122. def int_wasm_swizzle :
  123. Intrinsic<[llvm_v16i8_ty],
  124. [llvm_v16i8_ty, llvm_v16i8_ty],
  125. [IntrNoMem, IntrSpeculatable]>;
  126. def int_wasm_shuffle :
  127. Intrinsic<[llvm_v16i8_ty],
  128. [llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty, llvm_i32_ty,
  129. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
  130. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
  131. llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
  132. [IntrNoMem, IntrSpeculatable]>;
  133. def int_wasm_sub_sat_signed :
  134. Intrinsic<[llvm_anyvector_ty],
  135. [LLVMMatchType<0>, LLVMMatchType<0>],
  136. [IntrNoMem, IntrSpeculatable]>;
  137. def int_wasm_sub_sat_unsigned :
  138. Intrinsic<[llvm_anyvector_ty],
  139. [LLVMMatchType<0>, LLVMMatchType<0>],
  140. [IntrNoMem, IntrSpeculatable]>;
  141. def int_wasm_avgr_unsigned :
  142. Intrinsic<[llvm_anyvector_ty],
  143. [LLVMMatchType<0>, LLVMMatchType<0>],
  144. [IntrNoMem, IntrSpeculatable]>;
  145. def int_wasm_bitselect :
  146. Intrinsic<[llvm_anyvector_ty],
  147. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  148. [IntrNoMem, IntrSpeculatable]>;
  149. def int_wasm_anytrue :
  150. Intrinsic<[llvm_i32_ty],
  151. [llvm_anyvector_ty],
  152. [IntrNoMem, IntrSpeculatable]>;
  153. def int_wasm_alltrue :
  154. Intrinsic<[llvm_i32_ty],
  155. [llvm_anyvector_ty],
  156. [IntrNoMem, IntrSpeculatable]>;
  157. def int_wasm_bitmask :
  158. Intrinsic<[llvm_i32_ty],
  159. [llvm_anyvector_ty],
  160. [IntrNoMem, IntrSpeculatable]>;
  161. def int_wasm_dot :
  162. Intrinsic<[llvm_v4i32_ty],
  163. [llvm_v8i16_ty, llvm_v8i16_ty],
  164. [IntrNoMem, IntrSpeculatable]>;
  165. def int_wasm_narrow_signed :
  166. Intrinsic<[llvm_anyvector_ty],
  167. [llvm_anyvector_ty, LLVMMatchType<1>],
  168. [IntrNoMem, IntrSpeculatable]>;
  169. def int_wasm_narrow_unsigned :
  170. Intrinsic<[llvm_anyvector_ty],
  171. [llvm_anyvector_ty, LLVMMatchType<1>],
  172. [IntrNoMem, IntrSpeculatable]>;
  173. def int_wasm_q15mulr_sat_signed :
  174. Intrinsic<[llvm_v8i16_ty],
  175. [llvm_v8i16_ty, llvm_v8i16_ty],
  176. [IntrNoMem, IntrSpeculatable]>;
  177. def int_wasm_pmin :
  178. Intrinsic<[llvm_anyvector_ty],
  179. [LLVMMatchType<0>, LLVMMatchType<0>],
  180. [IntrNoMem, IntrSpeculatable]>;
  181. def int_wasm_pmax :
  182. Intrinsic<[llvm_anyvector_ty],
  183. [LLVMMatchType<0>, LLVMMatchType<0>],
  184. [IntrNoMem, IntrSpeculatable]>;
  185. def int_wasm_extadd_pairwise_signed :
  186. Intrinsic<[llvm_anyvector_ty],
  187. [LLVMSubdivide2VectorType<0>],
  188. [IntrNoMem, IntrSpeculatable]>;
  189. def int_wasm_extadd_pairwise_unsigned :
  190. Intrinsic<[llvm_anyvector_ty],
  191. [LLVMSubdivide2VectorType<0>],
  192. [IntrNoMem, IntrSpeculatable]>;
  193. //===----------------------------------------------------------------------===//
  194. // Relaxed SIMD intrinsics (experimental)
  195. //===----------------------------------------------------------------------===//
  196. def int_wasm_fma :
  197. Intrinsic<[llvm_anyvector_ty],
  198. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  199. [IntrNoMem, IntrSpeculatable]>;
  200. def int_wasm_fms :
  201. Intrinsic<[llvm_anyvector_ty],
  202. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  203. [IntrNoMem, IntrSpeculatable]>;
  204. def int_wasm_laneselect :
  205. Intrinsic<[llvm_anyvector_ty],
  206. [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
  207. [IntrNoMem, IntrSpeculatable]>;
  208. def int_wasm_relaxed_swizzle :
  209. Intrinsic<[llvm_v16i8_ty],
  210. [llvm_v16i8_ty, llvm_v16i8_ty],
  211. [IntrNoMem, IntrSpeculatable]>;
  212. def int_wasm_relaxed_min :
  213. Intrinsic<[llvm_anyvector_ty],
  214. [LLVMMatchType<0>, LLVMMatchType<0>],
  215. [IntrNoMem, IntrSpeculatable]>;
  216. def int_wasm_relaxed_max :
  217. Intrinsic<[llvm_anyvector_ty],
  218. [LLVMMatchType<0>, LLVMMatchType<0>],
  219. [IntrNoMem, IntrSpeculatable]>;
  220. def int_wasm_relaxed_trunc_signed:
  221. Intrinsic<[llvm_v4i32_ty],
  222. [llvm_v4f32_ty],
  223. [IntrNoMem, IntrSpeculatable]>;
  224. def int_wasm_relaxed_trunc_unsigned:
  225. Intrinsic<[llvm_v4i32_ty],
  226. [llvm_v4f32_ty],
  227. [IntrNoMem, IntrSpeculatable]>;
  228. def int_wasm_relaxed_trunc_zero_signed:
  229. Intrinsic<[llvm_v4i32_ty],
  230. [llvm_v2f64_ty],
  231. [IntrNoMem, IntrSpeculatable]>;
  232. def int_wasm_relaxed_trunc_zero_unsigned:
  233. Intrinsic<[llvm_v4i32_ty],
  234. [llvm_v2f64_ty],
  235. [IntrNoMem, IntrSpeculatable]>;
  236. //===----------------------------------------------------------------------===//
  237. // Thread-local storage intrinsics
  238. //===----------------------------------------------------------------------===//
  239. def int_wasm_tls_size :
  240. Intrinsic<[llvm_anyint_ty],
  241. [],
  242. [IntrNoMem, IntrSpeculatable]>;
  243. def int_wasm_tls_align :
  244. Intrinsic<[llvm_anyint_ty],
  245. [],
  246. [IntrNoMem, IntrSpeculatable]>;
  247. def int_wasm_tls_base :
  248. Intrinsic<[llvm_ptr_ty],
  249. [],
  250. [IntrReadMem]>;
  251. } // TargetPrefix = "wasm"