WebAssemblyRuntimeLibcallSignatures.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. // CodeGen/RuntimeLibcallSignatures.cpp - R.T. Lib. Call Signatures -*- 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. /// \file
  10. /// This file contains signature information for runtime libcalls.
  11. ///
  12. /// CodeGen uses external symbols, which it refers to by name. The WebAssembly
  13. /// target needs type information for all functions. This file contains a big
  14. /// table providing type signatures for all runtime library functions that LLVM
  15. /// uses.
  16. ///
  17. /// This is currently a fairly heavy-handed solution.
  18. ///
  19. //===----------------------------------------------------------------------===//
  20. #include "WebAssemblyRuntimeLibcallSignatures.h"
  21. #include "WebAssemblySubtarget.h"
  22. #include "llvm/CodeGen/RuntimeLibcalls.h"
  23. using namespace llvm;
  24. namespace {
  25. enum RuntimeLibcallSignature {
  26. func,
  27. f32_func_f32,
  28. f32_func_f64,
  29. f32_func_i32,
  30. f32_func_i64,
  31. f32_func_i16,
  32. f64_func_f32,
  33. f64_func_f64,
  34. f64_func_i32,
  35. f64_func_i64,
  36. i32_func_f32,
  37. i32_func_f64,
  38. i32_func_i32,
  39. i64_func_f32,
  40. i64_func_f64,
  41. i64_func_i64,
  42. f32_func_f32_f32,
  43. f32_func_f32_i32,
  44. f32_func_i64_i64,
  45. f64_func_f64_f64,
  46. f64_func_f64_i32,
  47. f64_func_i64_i64,
  48. i16_func_f32,
  49. i16_func_f64,
  50. i16_func_i64_i64,
  51. i8_func_i8_i8,
  52. func_f32_iPTR_iPTR,
  53. func_f64_iPTR_iPTR,
  54. i16_func_i16_i16,
  55. i32_func_f32_f32,
  56. i32_func_f64_f64,
  57. i32_func_i32_i32,
  58. i32_func_i32_i32_iPTR,
  59. i64_func_i64_i64,
  60. i64_func_i64_i64_iPTR,
  61. i64_i64_func_f32,
  62. i64_i64_func_f64,
  63. i16_i16_func_i16_i16,
  64. i32_i32_func_i32_i32,
  65. i64_i64_func_i64_i64,
  66. i64_i64_func_i64_i64_i64_i64,
  67. i64_i64_func_i64_i64_i64_i64_iPTR,
  68. i64_i64_i64_i64_func_i64_i64_i64_i64,
  69. i64_i64_func_i64_i64_i32,
  70. iPTR_func_i32,
  71. iPTR_func_iPTR_i32_iPTR,
  72. iPTR_func_iPTR_iPTR_iPTR,
  73. f32_func_f32_f32_f32,
  74. f64_func_f64_f64_f64,
  75. func_i64_i64_iPTR_iPTR,
  76. func_iPTR_f32,
  77. func_iPTR_f64,
  78. func_iPTR_i32,
  79. func_iPTR_i64,
  80. func_iPTR_i64_i64,
  81. func_iPTR_i64_i64_i32,
  82. func_iPTR_i64_i64_i64_i64,
  83. func_iPTR_i64_i64_i64_i64_i64_i64,
  84. i32_func_i64_i64,
  85. i32_func_i64_i64_i64_i64,
  86. iPTR_func_f32,
  87. iPTR_func_f64,
  88. iPTR_func_i64_i64,
  89. unsupported
  90. };
  91. struct RuntimeLibcallSignatureTable {
  92. std::vector<RuntimeLibcallSignature> Table;
  93. // Any newly-added libcalls will be unsupported by default.
  94. RuntimeLibcallSignatureTable() : Table(RTLIB::UNKNOWN_LIBCALL, unsupported) {
  95. // Integer
  96. Table[RTLIB::SHL_I16] = i16_func_i16_i16;
  97. Table[RTLIB::SHL_I32] = i32_func_i32_i32;
  98. Table[RTLIB::SHL_I64] = i64_func_i64_i64;
  99. Table[RTLIB::SHL_I128] = i64_i64_func_i64_i64_i32;
  100. Table[RTLIB::SRL_I16] = i16_func_i16_i16;
  101. Table[RTLIB::SRL_I32] = i32_func_i32_i32;
  102. Table[RTLIB::SRL_I64] = i64_func_i64_i64;
  103. Table[RTLIB::SRL_I128] = i64_i64_func_i64_i64_i32;
  104. Table[RTLIB::SRA_I16] = i16_func_i16_i16;
  105. Table[RTLIB::SRA_I32] = i32_func_i32_i32;
  106. Table[RTLIB::SRA_I64] = i64_func_i64_i64;
  107. Table[RTLIB::SRA_I128] = i64_i64_func_i64_i64_i32;
  108. Table[RTLIB::MUL_I8] = i8_func_i8_i8;
  109. Table[RTLIB::MUL_I16] = i16_func_i16_i16;
  110. Table[RTLIB::MUL_I32] = i32_func_i32_i32;
  111. Table[RTLIB::MUL_I64] = i64_func_i64_i64;
  112. Table[RTLIB::MUL_I128] = i64_i64_func_i64_i64_i64_i64;
  113. Table[RTLIB::MULO_I32] = i32_func_i32_i32_iPTR;
  114. Table[RTLIB::MULO_I64] = i64_func_i64_i64_iPTR;
  115. Table[RTLIB::MULO_I128] = i64_i64_func_i64_i64_i64_i64_iPTR;
  116. Table[RTLIB::SDIV_I8] = i8_func_i8_i8;
  117. Table[RTLIB::SDIV_I16] = i16_func_i16_i16;
  118. Table[RTLIB::SDIV_I32] = i32_func_i32_i32;
  119. Table[RTLIB::SDIV_I64] = i64_func_i64_i64;
  120. Table[RTLIB::SDIV_I128] = i64_i64_func_i64_i64_i64_i64;
  121. Table[RTLIB::UDIV_I8] = i8_func_i8_i8;
  122. Table[RTLIB::UDIV_I16] = i16_func_i16_i16;
  123. Table[RTLIB::UDIV_I32] = i32_func_i32_i32;
  124. Table[RTLIB::UDIV_I64] = i64_func_i64_i64;
  125. Table[RTLIB::UDIV_I128] = i64_i64_func_i64_i64_i64_i64;
  126. Table[RTLIB::SREM_I8] = i8_func_i8_i8;
  127. Table[RTLIB::SREM_I16] = i16_func_i16_i16;
  128. Table[RTLIB::SREM_I32] = i32_func_i32_i32;
  129. Table[RTLIB::SREM_I64] = i64_func_i64_i64;
  130. Table[RTLIB::SREM_I128] = i64_i64_func_i64_i64_i64_i64;
  131. Table[RTLIB::UREM_I8] = i8_func_i8_i8;
  132. Table[RTLIB::UREM_I16] = i16_func_i16_i16;
  133. Table[RTLIB::UREM_I32] = i32_func_i32_i32;
  134. Table[RTLIB::UREM_I64] = i64_func_i64_i64;
  135. Table[RTLIB::UREM_I128] = i64_i64_func_i64_i64_i64_i64;
  136. Table[RTLIB::SDIVREM_I8] = i8_func_i8_i8;
  137. Table[RTLIB::SDIVREM_I16] = i16_i16_func_i16_i16;
  138. Table[RTLIB::SDIVREM_I32] = i32_i32_func_i32_i32;
  139. Table[RTLIB::SDIVREM_I64] = i64_func_i64_i64;
  140. Table[RTLIB::SDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
  141. Table[RTLIB::UDIVREM_I8] = i8_func_i8_i8;
  142. Table[RTLIB::UDIVREM_I16] = i16_i16_func_i16_i16;
  143. Table[RTLIB::UDIVREM_I32] = i32_i32_func_i32_i32;
  144. Table[RTLIB::UDIVREM_I64] = i64_i64_func_i64_i64;
  145. Table[RTLIB::UDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
  146. Table[RTLIB::NEG_I32] = i32_func_i32;
  147. Table[RTLIB::NEG_I64] = i64_func_i64;
  148. // Floating-point.
  149. // All F80 and PPCF128 routines are unsupported.
  150. Table[RTLIB::ADD_F32] = f32_func_f32_f32;
  151. Table[RTLIB::ADD_F64] = f64_func_f64_f64;
  152. Table[RTLIB::ADD_F128] = func_iPTR_i64_i64_i64_i64;
  153. Table[RTLIB::SUB_F32] = f32_func_f32_f32;
  154. Table[RTLIB::SUB_F64] = f64_func_f64_f64;
  155. Table[RTLIB::SUB_F128] = func_iPTR_i64_i64_i64_i64;
  156. Table[RTLIB::MUL_F32] = f32_func_f32_f32;
  157. Table[RTLIB::MUL_F64] = f64_func_f64_f64;
  158. Table[RTLIB::MUL_F128] = func_iPTR_i64_i64_i64_i64;
  159. Table[RTLIB::DIV_F32] = f32_func_f32_f32;
  160. Table[RTLIB::DIV_F64] = f64_func_f64_f64;
  161. Table[RTLIB::DIV_F128] = func_iPTR_i64_i64_i64_i64;
  162. Table[RTLIB::REM_F32] = f32_func_f32_f32;
  163. Table[RTLIB::REM_F64] = f64_func_f64_f64;
  164. Table[RTLIB::REM_F128] = func_iPTR_i64_i64_i64_i64;
  165. Table[RTLIB::FMA_F32] = f32_func_f32_f32_f32;
  166. Table[RTLIB::FMA_F64] = f64_func_f64_f64_f64;
  167. Table[RTLIB::FMA_F128] = func_iPTR_i64_i64_i64_i64_i64_i64;
  168. Table[RTLIB::POWI_F32] = f32_func_f32_i32;
  169. Table[RTLIB::POWI_F64] = f64_func_f64_i32;
  170. Table[RTLIB::POWI_F128] = func_iPTR_i64_i64_i32;
  171. Table[RTLIB::SQRT_F32] = f32_func_f32;
  172. Table[RTLIB::SQRT_F64] = f64_func_f64;
  173. Table[RTLIB::SQRT_F128] = func_iPTR_i64_i64;
  174. Table[RTLIB::CBRT_F32] = f32_func_f32;
  175. Table[RTLIB::CBRT_F64] = f64_func_f64;
  176. Table[RTLIB::CBRT_F128] = func_iPTR_i64_i64;
  177. Table[RTLIB::LOG_F32] = f32_func_f32;
  178. Table[RTLIB::LOG_F64] = f64_func_f64;
  179. Table[RTLIB::LOG_F128] = func_iPTR_i64_i64;
  180. Table[RTLIB::LOG2_F32] = f32_func_f32;
  181. Table[RTLIB::LOG2_F64] = f64_func_f64;
  182. Table[RTLIB::LOG2_F128] = func_iPTR_i64_i64;
  183. Table[RTLIB::LOG10_F32] = f32_func_f32;
  184. Table[RTLIB::LOG10_F64] = f64_func_f64;
  185. Table[RTLIB::LOG10_F128] = func_iPTR_i64_i64;
  186. Table[RTLIB::EXP_F32] = f32_func_f32;
  187. Table[RTLIB::EXP_F64] = f64_func_f64;
  188. Table[RTLIB::EXP_F128] = func_iPTR_i64_i64;
  189. Table[RTLIB::EXP2_F32] = f32_func_f32;
  190. Table[RTLIB::EXP2_F64] = f64_func_f64;
  191. Table[RTLIB::EXP2_F128] = func_iPTR_i64_i64;
  192. Table[RTLIB::SIN_F32] = f32_func_f32;
  193. Table[RTLIB::SIN_F64] = f64_func_f64;
  194. Table[RTLIB::SIN_F128] = func_iPTR_i64_i64;
  195. Table[RTLIB::COS_F32] = f32_func_f32;
  196. Table[RTLIB::COS_F64] = f64_func_f64;
  197. Table[RTLIB::COS_F128] = func_iPTR_i64_i64;
  198. Table[RTLIB::SINCOS_F32] = func_f32_iPTR_iPTR;
  199. Table[RTLIB::SINCOS_F64] = func_f64_iPTR_iPTR;
  200. Table[RTLIB::SINCOS_F128] = func_i64_i64_iPTR_iPTR;
  201. Table[RTLIB::POW_F32] = f32_func_f32_f32;
  202. Table[RTLIB::POW_F64] = f64_func_f64_f64;
  203. Table[RTLIB::POW_F128] = func_iPTR_i64_i64_i64_i64;
  204. Table[RTLIB::CEIL_F32] = f32_func_f32;
  205. Table[RTLIB::CEIL_F64] = f64_func_f64;
  206. Table[RTLIB::CEIL_F128] = func_iPTR_i64_i64;
  207. Table[RTLIB::TRUNC_F32] = f32_func_f32;
  208. Table[RTLIB::TRUNC_F64] = f64_func_f64;
  209. Table[RTLIB::TRUNC_F128] = func_iPTR_i64_i64;
  210. Table[RTLIB::RINT_F32] = f32_func_f32;
  211. Table[RTLIB::RINT_F64] = f64_func_f64;
  212. Table[RTLIB::RINT_F128] = func_iPTR_i64_i64;
  213. Table[RTLIB::NEARBYINT_F32] = f32_func_f32;
  214. Table[RTLIB::NEARBYINT_F64] = f64_func_f64;
  215. Table[RTLIB::NEARBYINT_F128] = func_iPTR_i64_i64;
  216. Table[RTLIB::ROUND_F32] = f32_func_f32;
  217. Table[RTLIB::ROUND_F64] = f64_func_f64;
  218. Table[RTLIB::ROUND_F128] = func_iPTR_i64_i64;
  219. Table[RTLIB::LROUND_F32] = iPTR_func_f32;
  220. Table[RTLIB::LROUND_F64] = iPTR_func_f64;
  221. Table[RTLIB::LROUND_F128] = iPTR_func_i64_i64;
  222. Table[RTLIB::LLROUND_F32] = i64_func_f32;
  223. Table[RTLIB::LLROUND_F64] = i64_func_f64;
  224. Table[RTLIB::LLROUND_F128] = i64_func_i64_i64;
  225. Table[RTLIB::LRINT_F32] = iPTR_func_f32;
  226. Table[RTLIB::LRINT_F64] = iPTR_func_f64;
  227. Table[RTLIB::LRINT_F128] = iPTR_func_i64_i64;
  228. Table[RTLIB::LLRINT_F32] = i64_func_f32;
  229. Table[RTLIB::LLRINT_F64] = i64_func_f64;
  230. Table[RTLIB::LLRINT_F128] = i64_func_i64_i64;
  231. Table[RTLIB::FLOOR_F32] = f32_func_f32;
  232. Table[RTLIB::FLOOR_F64] = f64_func_f64;
  233. Table[RTLIB::FLOOR_F128] = func_iPTR_i64_i64;
  234. Table[RTLIB::COPYSIGN_F32] = f32_func_f32_f32;
  235. Table[RTLIB::COPYSIGN_F64] = f64_func_f64_f64;
  236. Table[RTLIB::COPYSIGN_F128] = func_iPTR_i64_i64_i64_i64;
  237. Table[RTLIB::FMIN_F32] = f32_func_f32_f32;
  238. Table[RTLIB::FMIN_F64] = f64_func_f64_f64;
  239. Table[RTLIB::FMIN_F128] = func_iPTR_i64_i64_i64_i64;
  240. Table[RTLIB::FMAX_F32] = f32_func_f32_f32;
  241. Table[RTLIB::FMAX_F64] = f64_func_f64_f64;
  242. Table[RTLIB::FMAX_F128] = func_iPTR_i64_i64_i64_i64;
  243. // Conversion
  244. // All F80 and PPCF128 routines are unsupported.
  245. Table[RTLIB::FPEXT_F64_F128] = func_iPTR_f64;
  246. Table[RTLIB::FPEXT_F32_F128] = func_iPTR_f32;
  247. Table[RTLIB::FPEXT_F32_F64] = f64_func_f32;
  248. Table[RTLIB::FPEXT_F16_F32] = f32_func_i16;
  249. Table[RTLIB::FPROUND_F32_F16] = i16_func_f32;
  250. Table[RTLIB::FPROUND_F64_F16] = i16_func_f64;
  251. Table[RTLIB::FPROUND_F64_F32] = f32_func_f64;
  252. Table[RTLIB::FPROUND_F128_F16] = i16_func_i64_i64;
  253. Table[RTLIB::FPROUND_F128_F32] = f32_func_i64_i64;
  254. Table[RTLIB::FPROUND_F128_F64] = f64_func_i64_i64;
  255. Table[RTLIB::FPTOSINT_F32_I32] = i32_func_f32;
  256. Table[RTLIB::FPTOSINT_F32_I64] = i64_func_f32;
  257. Table[RTLIB::FPTOSINT_F32_I128] = i64_i64_func_f32;
  258. Table[RTLIB::FPTOSINT_F64_I32] = i32_func_f64;
  259. Table[RTLIB::FPTOSINT_F64_I64] = i64_func_f64;
  260. Table[RTLIB::FPTOSINT_F64_I128] = i64_i64_func_f64;
  261. Table[RTLIB::FPTOSINT_F128_I32] = i32_func_i64_i64;
  262. Table[RTLIB::FPTOSINT_F128_I64] = i64_func_i64_i64;
  263. Table[RTLIB::FPTOSINT_F128_I128] = i64_i64_func_i64_i64;
  264. Table[RTLIB::FPTOUINT_F32_I32] = i32_func_f32;
  265. Table[RTLIB::FPTOUINT_F32_I64] = i64_func_f32;
  266. Table[RTLIB::FPTOUINT_F32_I128] = i64_i64_func_f32;
  267. Table[RTLIB::FPTOUINT_F64_I32] = i32_func_f64;
  268. Table[RTLIB::FPTOUINT_F64_I64] = i64_func_f64;
  269. Table[RTLIB::FPTOUINT_F64_I128] = i64_i64_func_f64;
  270. Table[RTLIB::FPTOUINT_F128_I32] = i32_func_i64_i64;
  271. Table[RTLIB::FPTOUINT_F128_I64] = i64_func_i64_i64;
  272. Table[RTLIB::FPTOUINT_F128_I128] = i64_i64_func_i64_i64;
  273. Table[RTLIB::SINTTOFP_I32_F32] = f32_func_i32;
  274. Table[RTLIB::SINTTOFP_I32_F64] = f64_func_i32;
  275. Table[RTLIB::SINTTOFP_I32_F128] = func_iPTR_i32;
  276. Table[RTLIB::SINTTOFP_I64_F32] = f32_func_i64;
  277. Table[RTLIB::SINTTOFP_I64_F64] = f64_func_i64;
  278. Table[RTLIB::SINTTOFP_I64_F128] = func_iPTR_i64;
  279. Table[RTLIB::SINTTOFP_I128_F32] = f32_func_i64_i64;
  280. Table[RTLIB::SINTTOFP_I128_F64] = f64_func_i64_i64;
  281. Table[RTLIB::SINTTOFP_I128_F128] = func_iPTR_i64_i64;
  282. Table[RTLIB::UINTTOFP_I32_F32] = f32_func_i32;
  283. Table[RTLIB::UINTTOFP_I32_F64] = f64_func_i64;
  284. Table[RTLIB::UINTTOFP_I32_F128] = func_iPTR_i32;
  285. Table[RTLIB::UINTTOFP_I64_F32] = f32_func_i64;
  286. Table[RTLIB::UINTTOFP_I64_F64] = f64_func_i64;
  287. Table[RTLIB::UINTTOFP_I64_F128] = func_iPTR_i64;
  288. Table[RTLIB::UINTTOFP_I128_F32] = f32_func_i64_i64;
  289. Table[RTLIB::UINTTOFP_I128_F64] = f64_func_i64_i64;
  290. Table[RTLIB::UINTTOFP_I128_F128] = func_iPTR_i64_i64;
  291. // Comparison
  292. // ALl F80 and PPCF128 routines are unsupported.
  293. Table[RTLIB::OEQ_F32] = i32_func_f32_f32;
  294. Table[RTLIB::OEQ_F64] = i32_func_f64_f64;
  295. Table[RTLIB::OEQ_F128] = i32_func_i64_i64_i64_i64;
  296. Table[RTLIB::UNE_F32] = i32_func_f32_f32;
  297. Table[RTLIB::UNE_F64] = i32_func_f64_f64;
  298. Table[RTLIB::UNE_F128] = i32_func_i64_i64_i64_i64;
  299. Table[RTLIB::OGE_F32] = i32_func_f32_f32;
  300. Table[RTLIB::OGE_F64] = i32_func_f64_f64;
  301. Table[RTLIB::OGE_F128] = i32_func_i64_i64_i64_i64;
  302. Table[RTLIB::OLT_F32] = i32_func_f32_f32;
  303. Table[RTLIB::OLT_F64] = i32_func_f64_f64;
  304. Table[RTLIB::OLT_F128] = i32_func_i64_i64_i64_i64;
  305. Table[RTLIB::OLE_F32] = i32_func_f32_f32;
  306. Table[RTLIB::OLE_F64] = i32_func_f64_f64;
  307. Table[RTLIB::OLE_F128] = i32_func_i64_i64_i64_i64;
  308. Table[RTLIB::OGT_F32] = i32_func_f32_f32;
  309. Table[RTLIB::OGT_F64] = i32_func_f64_f64;
  310. Table[RTLIB::OGT_F128] = i32_func_i64_i64_i64_i64;
  311. Table[RTLIB::UO_F32] = i32_func_f32_f32;
  312. Table[RTLIB::UO_F64] = i32_func_f64_f64;
  313. Table[RTLIB::UO_F128] = i32_func_i64_i64_i64_i64;
  314. // Memory
  315. Table[RTLIB::MEMCPY] = iPTR_func_iPTR_iPTR_iPTR;
  316. Table[RTLIB::MEMSET] = iPTR_func_iPTR_i32_iPTR;
  317. Table[RTLIB::MEMMOVE] = iPTR_func_iPTR_iPTR_iPTR;
  318. // __stack_chk_fail
  319. Table[RTLIB::STACKPROTECTOR_CHECK_FAIL] = func;
  320. // Return address handling
  321. Table[RTLIB::RETURN_ADDRESS] = iPTR_func_i32;
  322. // Element-wise Atomic memory
  323. // TODO: Fix these when we implement atomic support
  324. Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
  325. Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
  326. Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
  327. Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
  328. Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
  329. Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
  330. Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
  331. Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
  332. Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
  333. Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
  334. Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
  335. Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
  336. Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
  337. Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
  338. Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
  339. // Atomic '__sync_*' libcalls.
  340. // TODO: Fix these when we implement atomic support
  341. Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = unsupported;
  342. Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = unsupported;
  343. Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = unsupported;
  344. Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = unsupported;
  345. Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = unsupported;
  346. Table[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = unsupported;
  347. Table[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = unsupported;
  348. Table[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = unsupported;
  349. Table[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = unsupported;
  350. Table[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = unsupported;
  351. Table[RTLIB::SYNC_FETCH_AND_ADD_1] = unsupported;
  352. Table[RTLIB::SYNC_FETCH_AND_ADD_2] = unsupported;
  353. Table[RTLIB::SYNC_FETCH_AND_ADD_4] = unsupported;
  354. Table[RTLIB::SYNC_FETCH_AND_ADD_8] = unsupported;
  355. Table[RTLIB::SYNC_FETCH_AND_ADD_16] = unsupported;
  356. Table[RTLIB::SYNC_FETCH_AND_SUB_1] = unsupported;
  357. Table[RTLIB::SYNC_FETCH_AND_SUB_2] = unsupported;
  358. Table[RTLIB::SYNC_FETCH_AND_SUB_4] = unsupported;
  359. Table[RTLIB::SYNC_FETCH_AND_SUB_8] = unsupported;
  360. Table[RTLIB::SYNC_FETCH_AND_SUB_16] = unsupported;
  361. Table[RTLIB::SYNC_FETCH_AND_AND_1] = unsupported;
  362. Table[RTLIB::SYNC_FETCH_AND_AND_2] = unsupported;
  363. Table[RTLIB::SYNC_FETCH_AND_AND_4] = unsupported;
  364. Table[RTLIB::SYNC_FETCH_AND_AND_8] = unsupported;
  365. Table[RTLIB::SYNC_FETCH_AND_AND_16] = unsupported;
  366. Table[RTLIB::SYNC_FETCH_AND_OR_1] = unsupported;
  367. Table[RTLIB::SYNC_FETCH_AND_OR_2] = unsupported;
  368. Table[RTLIB::SYNC_FETCH_AND_OR_4] = unsupported;
  369. Table[RTLIB::SYNC_FETCH_AND_OR_8] = unsupported;
  370. Table[RTLIB::SYNC_FETCH_AND_OR_16] = unsupported;
  371. Table[RTLIB::SYNC_FETCH_AND_XOR_1] = unsupported;
  372. Table[RTLIB::SYNC_FETCH_AND_XOR_2] = unsupported;
  373. Table[RTLIB::SYNC_FETCH_AND_XOR_4] = unsupported;
  374. Table[RTLIB::SYNC_FETCH_AND_XOR_8] = unsupported;
  375. Table[RTLIB::SYNC_FETCH_AND_XOR_16] = unsupported;
  376. Table[RTLIB::SYNC_FETCH_AND_NAND_1] = unsupported;
  377. Table[RTLIB::SYNC_FETCH_AND_NAND_2] = unsupported;
  378. Table[RTLIB::SYNC_FETCH_AND_NAND_4] = unsupported;
  379. Table[RTLIB::SYNC_FETCH_AND_NAND_8] = unsupported;
  380. Table[RTLIB::SYNC_FETCH_AND_NAND_16] = unsupported;
  381. Table[RTLIB::SYNC_FETCH_AND_MAX_1] = unsupported;
  382. Table[RTLIB::SYNC_FETCH_AND_MAX_2] = unsupported;
  383. Table[RTLIB::SYNC_FETCH_AND_MAX_4] = unsupported;
  384. Table[RTLIB::SYNC_FETCH_AND_MAX_8] = unsupported;
  385. Table[RTLIB::SYNC_FETCH_AND_MAX_16] = unsupported;
  386. Table[RTLIB::SYNC_FETCH_AND_UMAX_1] = unsupported;
  387. Table[RTLIB::SYNC_FETCH_AND_UMAX_2] = unsupported;
  388. Table[RTLIB::SYNC_FETCH_AND_UMAX_4] = unsupported;
  389. Table[RTLIB::SYNC_FETCH_AND_UMAX_8] = unsupported;
  390. Table[RTLIB::SYNC_FETCH_AND_UMAX_16] = unsupported;
  391. Table[RTLIB::SYNC_FETCH_AND_MIN_1] = unsupported;
  392. Table[RTLIB::SYNC_FETCH_AND_MIN_2] = unsupported;
  393. Table[RTLIB::SYNC_FETCH_AND_MIN_4] = unsupported;
  394. Table[RTLIB::SYNC_FETCH_AND_MIN_8] = unsupported;
  395. Table[RTLIB::SYNC_FETCH_AND_MIN_16] = unsupported;
  396. Table[RTLIB::SYNC_FETCH_AND_UMIN_1] = unsupported;
  397. Table[RTLIB::SYNC_FETCH_AND_UMIN_2] = unsupported;
  398. Table[RTLIB::SYNC_FETCH_AND_UMIN_4] = unsupported;
  399. Table[RTLIB::SYNC_FETCH_AND_UMIN_8] = unsupported;
  400. Table[RTLIB::SYNC_FETCH_AND_UMIN_16] = unsupported;
  401. // Atomic '__atomic_*' libcalls.
  402. // TODO: Fix these when we implement atomic support
  403. Table[RTLIB::ATOMIC_LOAD] = unsupported;
  404. Table[RTLIB::ATOMIC_LOAD_1] = unsupported;
  405. Table[RTLIB::ATOMIC_LOAD_2] = unsupported;
  406. Table[RTLIB::ATOMIC_LOAD_4] = unsupported;
  407. Table[RTLIB::ATOMIC_LOAD_8] = unsupported;
  408. Table[RTLIB::ATOMIC_LOAD_16] = unsupported;
  409. Table[RTLIB::ATOMIC_STORE] = unsupported;
  410. Table[RTLIB::ATOMIC_STORE_1] = unsupported;
  411. Table[RTLIB::ATOMIC_STORE_2] = unsupported;
  412. Table[RTLIB::ATOMIC_STORE_4] = unsupported;
  413. Table[RTLIB::ATOMIC_STORE_8] = unsupported;
  414. Table[RTLIB::ATOMIC_STORE_16] = unsupported;
  415. Table[RTLIB::ATOMIC_EXCHANGE] = unsupported;
  416. Table[RTLIB::ATOMIC_EXCHANGE_1] = unsupported;
  417. Table[RTLIB::ATOMIC_EXCHANGE_2] = unsupported;
  418. Table[RTLIB::ATOMIC_EXCHANGE_4] = unsupported;
  419. Table[RTLIB::ATOMIC_EXCHANGE_8] = unsupported;
  420. Table[RTLIB::ATOMIC_EXCHANGE_16] = unsupported;
  421. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE] = unsupported;
  422. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_1] = unsupported;
  423. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_2] = unsupported;
  424. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_4] = unsupported;
  425. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_8] = unsupported;
  426. Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_16] = unsupported;
  427. Table[RTLIB::ATOMIC_FETCH_ADD_1] = unsupported;
  428. Table[RTLIB::ATOMIC_FETCH_ADD_2] = unsupported;
  429. Table[RTLIB::ATOMIC_FETCH_ADD_4] = unsupported;
  430. Table[RTLIB::ATOMIC_FETCH_ADD_8] = unsupported;
  431. Table[RTLIB::ATOMIC_FETCH_ADD_16] = unsupported;
  432. Table[RTLIB::ATOMIC_FETCH_SUB_1] = unsupported;
  433. Table[RTLIB::ATOMIC_FETCH_SUB_2] = unsupported;
  434. Table[RTLIB::ATOMIC_FETCH_SUB_4] = unsupported;
  435. Table[RTLIB::ATOMIC_FETCH_SUB_8] = unsupported;
  436. Table[RTLIB::ATOMIC_FETCH_SUB_16] = unsupported;
  437. Table[RTLIB::ATOMIC_FETCH_AND_1] = unsupported;
  438. Table[RTLIB::ATOMIC_FETCH_AND_2] = unsupported;
  439. Table[RTLIB::ATOMIC_FETCH_AND_4] = unsupported;
  440. Table[RTLIB::ATOMIC_FETCH_AND_8] = unsupported;
  441. Table[RTLIB::ATOMIC_FETCH_AND_16] = unsupported;
  442. Table[RTLIB::ATOMIC_FETCH_OR_1] = unsupported;
  443. Table[RTLIB::ATOMIC_FETCH_OR_2] = unsupported;
  444. Table[RTLIB::ATOMIC_FETCH_OR_4] = unsupported;
  445. Table[RTLIB::ATOMIC_FETCH_OR_8] = unsupported;
  446. Table[RTLIB::ATOMIC_FETCH_OR_16] = unsupported;
  447. Table[RTLIB::ATOMIC_FETCH_XOR_1] = unsupported;
  448. Table[RTLIB::ATOMIC_FETCH_XOR_2] = unsupported;
  449. Table[RTLIB::ATOMIC_FETCH_XOR_4] = unsupported;
  450. Table[RTLIB::ATOMIC_FETCH_XOR_8] = unsupported;
  451. Table[RTLIB::ATOMIC_FETCH_XOR_16] = unsupported;
  452. Table[RTLIB::ATOMIC_FETCH_NAND_1] = unsupported;
  453. Table[RTLIB::ATOMIC_FETCH_NAND_2] = unsupported;
  454. Table[RTLIB::ATOMIC_FETCH_NAND_4] = unsupported;
  455. Table[RTLIB::ATOMIC_FETCH_NAND_8] = unsupported;
  456. Table[RTLIB::ATOMIC_FETCH_NAND_16] = unsupported;
  457. }
  458. };
  459. RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() {
  460. static RuntimeLibcallSignatureTable RuntimeLibcallSignatures;
  461. return RuntimeLibcallSignatures;
  462. }
  463. // Maps libcall names to their RTLIB::Libcall number. Builds the map in a
  464. // constructor for use with a static variable
  465. struct StaticLibcallNameMap {
  466. StringMap<RTLIB::Libcall> Map;
  467. StaticLibcallNameMap() {
  468. static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
  469. #define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
  470. #include "llvm/IR/RuntimeLibcalls.def"
  471. #undef HANDLE_LIBCALL
  472. };
  473. for (const auto &NameLibcall : NameLibcalls) {
  474. if (NameLibcall.first != nullptr &&
  475. getRuntimeLibcallSignatures().Table[NameLibcall.second] !=
  476. unsupported) {
  477. assert(Map.find(NameLibcall.first) == Map.end() &&
  478. "duplicate libcall names in name map");
  479. Map[NameLibcall.first] = NameLibcall.second;
  480. }
  481. }
  482. // Override the __gnu_f2h_ieee/__gnu_h2f_ieee names so that the f32 name is
  483. // consistent with the f64 and f128 names.
  484. Map["__extendhfsf2"] = RTLIB::FPEXT_F16_F32;
  485. Map["__truncsfhf2"] = RTLIB::FPROUND_F32_F16;
  486. Map["emscripten_return_address"] = RTLIB::RETURN_ADDRESS;
  487. }
  488. };
  489. } // end anonymous namespace
  490. void llvm::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
  491. RTLIB::Libcall LC,
  492. SmallVectorImpl<wasm::ValType> &Rets,
  493. SmallVectorImpl<wasm::ValType> &Params) {
  494. assert(Rets.empty());
  495. assert(Params.empty());
  496. wasm::ValType PtrTy =
  497. Subtarget.hasAddr64() ? wasm::ValType::I64 : wasm::ValType::I32;
  498. auto &Table = getRuntimeLibcallSignatures().Table;
  499. switch (Table[LC]) {
  500. case func:
  501. break;
  502. case f32_func_f32:
  503. Rets.push_back(wasm::ValType::F32);
  504. Params.push_back(wasm::ValType::F32);
  505. break;
  506. case f32_func_f64:
  507. Rets.push_back(wasm::ValType::F32);
  508. Params.push_back(wasm::ValType::F64);
  509. break;
  510. case f32_func_i32:
  511. Rets.push_back(wasm::ValType::F32);
  512. Params.push_back(wasm::ValType::I32);
  513. break;
  514. case f32_func_i64:
  515. Rets.push_back(wasm::ValType::F32);
  516. Params.push_back(wasm::ValType::I64);
  517. break;
  518. case f32_func_i16:
  519. Rets.push_back(wasm::ValType::F32);
  520. Params.push_back(wasm::ValType::I32);
  521. break;
  522. case f64_func_f32:
  523. Rets.push_back(wasm::ValType::F64);
  524. Params.push_back(wasm::ValType::F32);
  525. break;
  526. case f64_func_f64:
  527. Rets.push_back(wasm::ValType::F64);
  528. Params.push_back(wasm::ValType::F64);
  529. break;
  530. case f64_func_i32:
  531. Rets.push_back(wasm::ValType::F64);
  532. Params.push_back(wasm::ValType::I32);
  533. break;
  534. case f64_func_i64:
  535. Rets.push_back(wasm::ValType::F64);
  536. Params.push_back(wasm::ValType::I64);
  537. break;
  538. case i32_func_f32:
  539. Rets.push_back(wasm::ValType::I32);
  540. Params.push_back(wasm::ValType::F32);
  541. break;
  542. case i32_func_f64:
  543. Rets.push_back(wasm::ValType::I32);
  544. Params.push_back(wasm::ValType::F64);
  545. break;
  546. case i32_func_i32:
  547. Rets.push_back(wasm::ValType::I32);
  548. Params.push_back(wasm::ValType::I32);
  549. break;
  550. case i64_func_f32:
  551. Rets.push_back(wasm::ValType::I64);
  552. Params.push_back(wasm::ValType::F32);
  553. break;
  554. case i64_func_f64:
  555. Rets.push_back(wasm::ValType::I64);
  556. Params.push_back(wasm::ValType::F64);
  557. break;
  558. case i64_func_i64:
  559. Rets.push_back(wasm::ValType::I64);
  560. Params.push_back(wasm::ValType::I64);
  561. break;
  562. case f32_func_f32_f32:
  563. Rets.push_back(wasm::ValType::F32);
  564. Params.push_back(wasm::ValType::F32);
  565. Params.push_back(wasm::ValType::F32);
  566. break;
  567. case f32_func_f32_i32:
  568. Rets.push_back(wasm::ValType::F32);
  569. Params.push_back(wasm::ValType::F32);
  570. Params.push_back(wasm::ValType::I32);
  571. break;
  572. case f32_func_i64_i64:
  573. Rets.push_back(wasm::ValType::F32);
  574. Params.push_back(wasm::ValType::I64);
  575. Params.push_back(wasm::ValType::I64);
  576. break;
  577. case f64_func_f64_f64:
  578. Rets.push_back(wasm::ValType::F64);
  579. Params.push_back(wasm::ValType::F64);
  580. Params.push_back(wasm::ValType::F64);
  581. break;
  582. case f64_func_f64_i32:
  583. Rets.push_back(wasm::ValType::F64);
  584. Params.push_back(wasm::ValType::F64);
  585. Params.push_back(wasm::ValType::I32);
  586. break;
  587. case f64_func_i64_i64:
  588. Rets.push_back(wasm::ValType::F64);
  589. Params.push_back(wasm::ValType::I64);
  590. Params.push_back(wasm::ValType::I64);
  591. break;
  592. case i16_func_f32:
  593. Rets.push_back(wasm::ValType::I32);
  594. Params.push_back(wasm::ValType::F32);
  595. break;
  596. case i16_func_f64:
  597. Rets.push_back(wasm::ValType::I32);
  598. Params.push_back(wasm::ValType::F64);
  599. break;
  600. case i16_func_i64_i64:
  601. Rets.push_back(wasm::ValType::I32);
  602. Params.push_back(wasm::ValType::I64);
  603. Params.push_back(wasm::ValType::I64);
  604. break;
  605. case i8_func_i8_i8:
  606. Rets.push_back(wasm::ValType::I32);
  607. Params.push_back(wasm::ValType::I32);
  608. Params.push_back(wasm::ValType::I32);
  609. break;
  610. case func_f32_iPTR_iPTR:
  611. Params.push_back(wasm::ValType::F32);
  612. Params.push_back(PtrTy);
  613. Params.push_back(PtrTy);
  614. break;
  615. case func_f64_iPTR_iPTR:
  616. Params.push_back(wasm::ValType::F64);
  617. Params.push_back(PtrTy);
  618. Params.push_back(PtrTy);
  619. break;
  620. case i16_func_i16_i16:
  621. Rets.push_back(wasm::ValType::I32);
  622. Params.push_back(wasm::ValType::I32);
  623. Params.push_back(wasm::ValType::I32);
  624. break;
  625. case i32_func_f32_f32:
  626. Rets.push_back(wasm::ValType::I32);
  627. Params.push_back(wasm::ValType::F32);
  628. Params.push_back(wasm::ValType::F32);
  629. break;
  630. case i32_func_f64_f64:
  631. Rets.push_back(wasm::ValType::I32);
  632. Params.push_back(wasm::ValType::F64);
  633. Params.push_back(wasm::ValType::F64);
  634. break;
  635. case i32_func_i32_i32:
  636. Rets.push_back(wasm::ValType::I32);
  637. Params.push_back(wasm::ValType::I32);
  638. Params.push_back(wasm::ValType::I32);
  639. break;
  640. case i32_func_i32_i32_iPTR:
  641. Rets.push_back(wasm::ValType::I32);
  642. Params.push_back(wasm::ValType::I32);
  643. Params.push_back(wasm::ValType::I32);
  644. Params.push_back(PtrTy);
  645. break;
  646. case i64_func_i64_i64:
  647. Rets.push_back(wasm::ValType::I64);
  648. Params.push_back(wasm::ValType::I64);
  649. Params.push_back(wasm::ValType::I64);
  650. break;
  651. case i64_func_i64_i64_iPTR:
  652. Rets.push_back(wasm::ValType::I64);
  653. Params.push_back(wasm::ValType::I64);
  654. Params.push_back(wasm::ValType::I64);
  655. Params.push_back(PtrTy);
  656. break;
  657. case i64_i64_func_f32:
  658. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  659. Rets.push_back(wasm::ValType::I64);
  660. Rets.push_back(wasm::ValType::I64);
  661. #else
  662. Params.push_back(PtrTy);
  663. #endif
  664. Params.push_back(wasm::ValType::F32);
  665. break;
  666. case i64_i64_func_f64:
  667. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  668. Rets.push_back(wasm::ValType::I64);
  669. Rets.push_back(wasm::ValType::I64);
  670. #else
  671. Params.push_back(PtrTy);
  672. #endif
  673. Params.push_back(wasm::ValType::F64);
  674. break;
  675. case i16_i16_func_i16_i16:
  676. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  677. Rets.push_back(wasm::ValType::I32);
  678. Rets.push_back(wasm::ValType::I32);
  679. #else
  680. Params.push_back(PtrTy);
  681. #endif
  682. Params.push_back(wasm::ValType::I32);
  683. Params.push_back(wasm::ValType::I32);
  684. break;
  685. case i32_i32_func_i32_i32:
  686. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  687. Rets.push_back(wasm::ValType::I32);
  688. Rets.push_back(wasm::ValType::I32);
  689. #else
  690. Params.push_back(PtrTy);
  691. #endif
  692. Params.push_back(wasm::ValType::I32);
  693. Params.push_back(wasm::ValType::I32);
  694. break;
  695. case i64_i64_func_i64_i64:
  696. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  697. Rets.push_back(wasm::ValType::I64);
  698. Rets.push_back(wasm::ValType::I64);
  699. #else
  700. Params.push_back(PtrTy);
  701. #endif
  702. Params.push_back(wasm::ValType::I64);
  703. Params.push_back(wasm::ValType::I64);
  704. break;
  705. case i64_i64_func_i64_i64_i64_i64:
  706. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  707. Rets.push_back(wasm::ValType::I64);
  708. Rets.push_back(wasm::ValType::I64);
  709. #else
  710. Params.push_back(PtrTy);
  711. #endif
  712. Params.push_back(wasm::ValType::I64);
  713. Params.push_back(wasm::ValType::I64);
  714. Params.push_back(wasm::ValType::I64);
  715. Params.push_back(wasm::ValType::I64);
  716. break;
  717. case i64_i64_func_i64_i64_i64_i64_iPTR:
  718. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  719. Rets.push_back(wasm::ValType::I64);
  720. Rets.push_back(wasm::ValType::I64);
  721. #else
  722. Params.push_back(PtrTy);
  723. #endif
  724. Params.push_back(wasm::ValType::I64);
  725. Params.push_back(wasm::ValType::I64);
  726. Params.push_back(wasm::ValType::I64);
  727. Params.push_back(wasm::ValType::I64);
  728. Params.push_back(PtrTy);
  729. break;
  730. case i64_i64_i64_i64_func_i64_i64_i64_i64:
  731. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  732. Rets.push_back(wasm::ValType::I64);
  733. Rets.push_back(wasm::ValType::I64);
  734. Rets.push_back(wasm::ValType::I64);
  735. Rets.push_back(wasm::ValType::I64);
  736. #else
  737. Params.push_back(PtrTy);
  738. #endif
  739. Params.push_back(wasm::ValType::I64);
  740. Params.push_back(wasm::ValType::I64);
  741. Params.push_back(wasm::ValType::I64);
  742. Params.push_back(wasm::ValType::I64);
  743. break;
  744. case i64_i64_func_i64_i64_i32:
  745. #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
  746. Rets.push_back(wasm::ValType::I64);
  747. Rets.push_back(wasm::ValType::I64);
  748. Rets.push_back(wasm::ValType::I64);
  749. Rets.push_back(wasm::ValType::I64);
  750. #else
  751. Params.push_back(PtrTy);
  752. #endif
  753. Params.push_back(wasm::ValType::I64);
  754. Params.push_back(wasm::ValType::I64);
  755. Params.push_back(wasm::ValType::I32);
  756. break;
  757. case iPTR_func_i32:
  758. Rets.push_back(PtrTy);
  759. Params.push_back(wasm::ValType::I32);
  760. break;
  761. case iPTR_func_iPTR_i32_iPTR:
  762. Rets.push_back(PtrTy);
  763. Params.push_back(PtrTy);
  764. Params.push_back(wasm::ValType::I32);
  765. Params.push_back(PtrTy);
  766. break;
  767. case iPTR_func_iPTR_iPTR_iPTR:
  768. Rets.push_back(PtrTy);
  769. Params.push_back(PtrTy);
  770. Params.push_back(PtrTy);
  771. Params.push_back(PtrTy);
  772. break;
  773. case f32_func_f32_f32_f32:
  774. Rets.push_back(wasm::ValType::F32);
  775. Params.push_back(wasm::ValType::F32);
  776. Params.push_back(wasm::ValType::F32);
  777. Params.push_back(wasm::ValType::F32);
  778. break;
  779. case f64_func_f64_f64_f64:
  780. Rets.push_back(wasm::ValType::F64);
  781. Params.push_back(wasm::ValType::F64);
  782. Params.push_back(wasm::ValType::F64);
  783. Params.push_back(wasm::ValType::F64);
  784. break;
  785. case func_i64_i64_iPTR_iPTR:
  786. Params.push_back(wasm::ValType::I64);
  787. Params.push_back(wasm::ValType::I64);
  788. Params.push_back(PtrTy);
  789. Params.push_back(PtrTy);
  790. break;
  791. case func_iPTR_f32:
  792. Params.push_back(PtrTy);
  793. Params.push_back(wasm::ValType::F32);
  794. break;
  795. case func_iPTR_f64:
  796. Params.push_back(PtrTy);
  797. Params.push_back(wasm::ValType::F64);
  798. break;
  799. case func_iPTR_i32:
  800. Params.push_back(PtrTy);
  801. Params.push_back(wasm::ValType::I32);
  802. break;
  803. case func_iPTR_i64:
  804. Params.push_back(PtrTy);
  805. Params.push_back(wasm::ValType::I64);
  806. break;
  807. case func_iPTR_i64_i64:
  808. Params.push_back(PtrTy);
  809. Params.push_back(wasm::ValType::I64);
  810. Params.push_back(wasm::ValType::I64);
  811. break;
  812. case func_iPTR_i64_i64_i32:
  813. Params.push_back(PtrTy);
  814. Params.push_back(wasm::ValType::I64);
  815. Params.push_back(wasm::ValType::I64);
  816. Params.push_back(wasm::ValType::I32);
  817. break;
  818. case func_iPTR_i64_i64_i64_i64:
  819. Params.push_back(PtrTy);
  820. Params.push_back(wasm::ValType::I64);
  821. Params.push_back(wasm::ValType::I64);
  822. Params.push_back(wasm::ValType::I64);
  823. Params.push_back(wasm::ValType::I64);
  824. break;
  825. case func_iPTR_i64_i64_i64_i64_i64_i64:
  826. Params.push_back(PtrTy);
  827. Params.push_back(wasm::ValType::I64);
  828. Params.push_back(wasm::ValType::I64);
  829. Params.push_back(wasm::ValType::I64);
  830. Params.push_back(wasm::ValType::I64);
  831. Params.push_back(wasm::ValType::I64);
  832. Params.push_back(wasm::ValType::I64);
  833. break;
  834. case i32_func_i64_i64:
  835. Rets.push_back(wasm::ValType::I32);
  836. Params.push_back(wasm::ValType::I64);
  837. Params.push_back(wasm::ValType::I64);
  838. break;
  839. case i32_func_i64_i64_i64_i64:
  840. Rets.push_back(wasm::ValType::I32);
  841. Params.push_back(wasm::ValType::I64);
  842. Params.push_back(wasm::ValType::I64);
  843. Params.push_back(wasm::ValType::I64);
  844. Params.push_back(wasm::ValType::I64);
  845. break;
  846. case iPTR_func_f32:
  847. Rets.push_back(PtrTy);
  848. Params.push_back(wasm::ValType::F32);
  849. break;
  850. case iPTR_func_f64:
  851. Rets.push_back(PtrTy);
  852. Params.push_back(wasm::ValType::F64);
  853. break;
  854. case iPTR_func_i64_i64:
  855. Rets.push_back(PtrTy);
  856. Params.push_back(wasm::ValType::I64);
  857. Params.push_back(wasm::ValType::I64);
  858. break;
  859. case unsupported:
  860. llvm_unreachable("unsupported runtime library signature");
  861. }
  862. }
  863. // TODO: If the RTLIB::Libcall-taking flavor of GetSignature remains unsed
  864. // other than here, just roll its logic into this version.
  865. void llvm::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
  866. StringRef Name,
  867. SmallVectorImpl<wasm::ValType> &Rets,
  868. SmallVectorImpl<wasm::ValType> &Params) {
  869. static StaticLibcallNameMap LibcallNameMap;
  870. auto &Map = LibcallNameMap.Map;
  871. auto Val = Map.find(Name);
  872. #ifndef NDEBUG
  873. if (Val == Map.end()) {
  874. auto message = std::string("unexpected runtime library name: ") +
  875. std::string(Name);
  876. llvm_unreachable(message.c_str());
  877. }
  878. #endif
  879. return getLibcallSignature(Subtarget, Val->second, Rets, Params);
  880. }