jit_ir.def 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (C) 2021 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. /**
  6. * @file jit-ir.def
  7. *
  8. * @brief Definition of JIT IR instructions and annotations.
  9. */
  10. /**
  11. * @def INSN (NAME, OPND_KIND, OPND_NUM, FIRST_USE)
  12. *
  13. * Definition of IR instructions
  14. *
  15. * @param NAME name of the opcode
  16. * @param OPND_KIND kind of the operand(s)
  17. * @param OPND_NUM number of the operand(s)
  18. * @param FIRST_USE index of the first use register
  19. *
  20. * @p OPND_KIND and @p OPND_NUM together determine the format of an
  21. * instruction. There are four kinds of formats:
  22. *
  23. * 1) Reg: fixed-number register operands, @p OPND_NUM specifies the
  24. * number of operands;
  25. *
  26. * 2) VReg: variable-number register operands, @p OPND_NUM specifies
  27. * the number of fixed register operands;
  28. *
  29. * 3) TableSwitch: tableswitch instruction's format, @p OPND_NUM must
  30. * be 1;
  31. *
  32. * 4) LookupSwitch: lookupswitch instruction's format, @p OPND_NUM
  33. * must be 1.
  34. *
  35. * Instruction operands are all registers and they are organized in an
  36. * order that all registers defined by the instruction, if any, appear
  37. * before the registers used by the instruction. The @p FIRST_USE is
  38. * the index of the first use register in the register vector sorted
  39. * in this order. Use @c jit_insn_opnd_regs to get the register
  40. * vector in this order and use @c jit_insn_opnd_first_use to get the
  41. * index of the first use register.
  42. *
  43. * Every instruction with name @p NAME has the following definitions:
  44. *
  45. * @c JEFF_OP_NAME: the enum opcode of insn NAME
  46. * @c jit_insn_new_NAME (...): creates a new instance of insn NAME
  47. *
  48. * An instruction is deleted by function:
  49. *
  50. * @c jit_insn_delete (@p insn)
  51. *
  52. * In the scope of this IR's terminology, operand and argument have
  53. * different meanings. The operand is a general notation, which
  54. * denotes every raw operand of an instruction, while the argument
  55. * only denotes the variable part of operands of instructions of VReg
  56. * kind. For example, a VReg instruction phi node "r0 = phi(r1, r2)"
  57. * has three operands opnd[0]: r0, opnd[1]: r1 and opnd[2]: r2, but
  58. * only two arguments arg[0]: r1 and arg[1]: r2. Operands or
  59. * arguments of instructions with various formats can be access
  60. * through the following APIs:
  61. *
  62. * @c jit_insn_opnd (@p insn, @p n): for Reg_N formats
  63. * @c jit_insn_opndv (@p insn, @p n): for VReg_N formats
  64. * @c jit_insn_opndv_num (@p insn): for VReg_N formats
  65. * @c jit_insn_opndts (@p insn): for TableSwitch_1 format
  66. * @c jit_insn_opndls (@p insn): for LookupSwitch_1 format
  67. */
  68. #ifndef INSN
  69. #define INSN(NAME, OPND_KIND, OPND_NUM, FIRST_USE)
  70. #endif
  71. /* Move and conversion instructions that transfer values among
  72. registers of the same kind (move) or different kinds (convert) */
  73. INSN(MOV, Reg, 2, 1)
  74. INSN(PHI, VReg, 1, 1)
  75. /* conversion. will extend or truncate */
  76. INSN(I8TOI32, Reg, 2, 1)
  77. INSN(I8TOI64, Reg, 2, 1)
  78. INSN(I16TOI32, Reg, 2, 1)
  79. INSN(I16TOI64, Reg, 2, 1)
  80. INSN(I32TOI8, Reg, 2, 1)
  81. INSN(I32TOU8, Reg, 2, 1)
  82. INSN(I32TOI16, Reg, 2, 1)
  83. INSN(I32TOU16, Reg, 2, 1)
  84. INSN(I32TOI64, Reg, 2, 1)
  85. INSN(I32TOF32, Reg, 2, 1)
  86. INSN(I32TOF64, Reg, 2, 1)
  87. INSN(U32TOI64, Reg, 2, 1)
  88. INSN(U32TOF32, Reg, 2, 1)
  89. INSN(U32TOF64, Reg, 2, 1)
  90. INSN(I64TOI8, Reg, 2, 1)
  91. INSN(I64TOI16, Reg, 2, 1)
  92. INSN(I64TOI32, Reg, 2, 1)
  93. INSN(I64TOF32, Reg, 2, 1)
  94. INSN(I64TOF64, Reg, 2, 1)
  95. INSN(F32TOI32, Reg, 2, 1)
  96. INSN(F32TOI64, Reg, 2, 1)
  97. INSN(F32TOF64, Reg, 2, 1)
  98. INSN(F32TOU32, Reg, 2, 1)
  99. INSN(F64TOI32, Reg, 2, 1)
  100. INSN(F64TOI64, Reg, 2, 1)
  101. INSN(F64TOF32, Reg, 2, 1)
  102. INSN(F64TOU32, Reg, 2, 1)
  103. /**
  104. * Re-interpret binary presentations:
  105. * *(i32 *)&f32, *(i64 *)&f64, *(f32 *)&i32, *(f64 *)&i64
  106. */
  107. INSN(I32CASTF32, Reg, 2, 1)
  108. INSN(I64CASTF64, Reg, 2, 1)
  109. INSN(F32CASTI32, Reg, 2, 1)
  110. INSN(F64CASTI64, Reg, 2, 1)
  111. /* Arithmetic and bitwise instructions: */
  112. INSN(NEG, Reg, 2, 1)
  113. INSN(NOT, Reg, 2, 1)
  114. INSN(ADD, Reg, 3, 1)
  115. INSN(SUB, Reg, 3, 1)
  116. INSN(MUL, Reg, 3, 1)
  117. INSN(DIV_S, Reg, 3, 1)
  118. INSN(REM_S, Reg, 3, 1)
  119. INSN(DIV_U, Reg, 3, 1)
  120. INSN(REM_U, Reg, 3, 1)
  121. INSN(SHL, Reg, 3, 1)
  122. INSN(SHRS, Reg, 3, 1)
  123. INSN(SHRU, Reg, 3, 1)
  124. INSN(ROTL, Reg, 3, 1)
  125. INSN(ROTR, Reg, 3, 1)
  126. INSN(OR, Reg, 3, 1)
  127. INSN(XOR, Reg, 3, 1)
  128. INSN(AND, Reg, 3, 1)
  129. INSN(CMP, Reg, 3, 1)
  130. INSN(MAX, Reg, 3, 1)
  131. INSN(MIN, Reg, 3, 1)
  132. INSN(CLZ, Reg, 2, 1)
  133. INSN(CTZ, Reg, 2, 1)
  134. INSN(POPCNT, Reg, 2, 1)
  135. /* Select instruction: */
  136. INSN(SELECTEQ, Reg, 4, 1)
  137. INSN(SELECTNE, Reg, 4, 1)
  138. INSN(SELECTGTS, Reg, 4, 1)
  139. INSN(SELECTGES, Reg, 4, 1)
  140. INSN(SELECTLTS, Reg, 4, 1)
  141. INSN(SELECTLES, Reg, 4, 1)
  142. INSN(SELECTGTU, Reg, 4, 1)
  143. INSN(SELECTGEU, Reg, 4, 1)
  144. INSN(SELECTLTU, Reg, 4, 1)
  145. INSN(SELECTLEU, Reg, 4, 1)
  146. /* Memory access instructions: */
  147. INSN(LDEXECENV, Reg, 1, 1)
  148. INSN(LDJITINFO, Reg, 1, 1)
  149. INSN(LDI8, Reg, 3, 1)
  150. INSN(LDU8, Reg, 3, 1)
  151. INSN(LDI16, Reg, 3, 1)
  152. INSN(LDU16, Reg, 3, 1)
  153. INSN(LDI32, Reg, 3, 1)
  154. INSN(LDU32, Reg, 3, 1)
  155. INSN(LDI64, Reg, 3, 1)
  156. INSN(LDU64, Reg, 3, 1)
  157. INSN(LDF32, Reg, 3, 1)
  158. INSN(LDF64, Reg, 3, 1)
  159. INSN(LDPTR, Reg, 3, 1)
  160. INSN(LDV64, Reg, 3, 1)
  161. INSN(LDV128, Reg, 3, 1)
  162. INSN(LDV256, Reg, 3, 1)
  163. INSN(STI8, Reg, 3, 0)
  164. INSN(STI16, Reg, 3, 0)
  165. INSN(STI32, Reg, 3, 0)
  166. INSN(STI64, Reg, 3, 0)
  167. INSN(STF32, Reg, 3, 0)
  168. INSN(STF64, Reg, 3, 0)
  169. INSN(STPTR, Reg, 3, 0)
  170. INSN(STV64, Reg, 3, 1)
  171. INSN(STV128, Reg, 3, 1)
  172. INSN(STV256, Reg, 3, 1)
  173. /* Control instructions */
  174. INSN(JMP, Reg, 1, 0)
  175. INSN(BEQ, Reg, 3, 0)
  176. INSN(BNE, Reg, 3, 0)
  177. INSN(BGTS, Reg, 3, 0)
  178. INSN(BGES, Reg, 3, 0)
  179. INSN(BLTS, Reg, 3, 0)
  180. INSN(BLES, Reg, 3, 0)
  181. INSN(BGTU, Reg, 3, 0)
  182. INSN(BGEU, Reg, 3, 0)
  183. INSN(BLTU, Reg, 3, 0)
  184. INSN(BLEU, Reg, 3, 0)
  185. INSN(LOOKUPSWITCH, LookupSwitch, 1, 0)
  186. /* Call and return instructions */
  187. INSN(CALLNATIVE, VReg, 2, 1)
  188. INSN(CALLBC, Reg, 3, 2)
  189. INSN(RETURNBC, Reg, 3, 0)
  190. INSN(RETURN, Reg, 1, 0)
  191. #undef INSN
  192. /**
  193. * @def ANN_LABEL (TYPE, NAME)
  194. *
  195. * Definition of label annotations.
  196. *
  197. * @param TYPE type of the annotation
  198. * @param NAME name of the annotation
  199. *
  200. * Each defined annotation with name NAME has the following APIs:
  201. *
  202. * @c jit_annl_NAME (cc, label): accesses the annotation NAME of
  203. * label @p label
  204. * @c jit_annl_enable_NAME (cc): enables the annotation NAME
  205. * @c jit_annl_disable_NAME (cc): disables the annotation NAME
  206. * @c jit_annl_is_enabled_NAME (cc): check whether the annotation NAME
  207. * is enabled
  208. */
  209. #ifndef ANN_LABEL
  210. #define ANN_LABEL(TYPE, NAME)
  211. #endif
  212. /* Basic Block of a label. */
  213. ANN_LABEL(JitBasicBlock *, basic_block)
  214. /* Predecessor number of the block that is only used in
  215. jit_cc_update_cfg for updating the CFG. */
  216. ANN_LABEL(uint16, pred_num)
  217. /* Execution frequency of a block. We can split critical edges with
  218. empty blocks so we don't need to store frequencies of edges. */
  219. ANN_LABEL(uint16, freq)
  220. /* Begin bytecode instruction pointer of the block. */
  221. ANN_LABEL(uint8 *, begin_bcip)
  222. /* End bytecode instruction pointer of the block. */
  223. ANN_LABEL(uint8 *, end_bcip)
  224. /* Stack pointer offset at the end of the block. */
  225. ANN_LABEL(uint16, end_sp)
  226. /* The label of the next physically adjacent block. */
  227. ANN_LABEL(JitReg, next_label)
  228. /* Compiled code address of the block. */
  229. ANN_LABEL(void *, jitted_addr)
  230. #undef ANN_LABEL
  231. /**
  232. * @def ANN_INSN (TYPE, NAME)
  233. *
  234. * Definition of instruction annotations.
  235. *
  236. * @param TYPE type of the annotation
  237. * @param NAME name of the annotation
  238. *
  239. * Each defined annotation with name NAME has the following APIs:
  240. *
  241. * @c jit_anni_NAME (cc, insn): accesses the annotation NAME of
  242. * instruction @p insn
  243. * @c jit_anni_enable_NAME (cc): enables the annotation NAME
  244. * @c jit_anni_disable_NAME (cc): disables the annotation NAME
  245. * @c jit_anni_is_enabled_NAME (cc): check whether the annotation NAME
  246. * is enabled
  247. */
  248. #ifndef ANN_INSN
  249. #define ANN_INSN(TYPE, NAME)
  250. #endif
  251. /* A private annotation for linking instructions with the same hash
  252. value, which is only used by the compilation context's hash table
  253. of instructions. */
  254. ANN_INSN(JitInsn *, _hash_link)
  255. #undef ANN_INSN
  256. /**
  257. * @def ANN_REG (TYPE, NAME)
  258. *
  259. * Definition of register annotations.
  260. *
  261. * @param TYPE type of the annotation
  262. * @param NAME name of the annotation
  263. *
  264. * Each defined annotation with name NAME has the following APIs:
  265. *
  266. * @c jit_annr_NAME (cc, reg): accesses the annotation NAME of
  267. * register @p reg
  268. * @c jit_annr_enable_NAME (cc): enables the annotation NAME
  269. * @c jit_annr_disable_NAME (cc): disables the annotation NAME
  270. * @c jit_annr_is_enabled_NAME (cc): check whether the annotation NAME
  271. * is enabled
  272. */
  273. #ifndef ANN_REG
  274. #define ANN_REG(TYPE, NAME)
  275. #endif
  276. /* Defining instruction of registers satisfying SSA property. */
  277. ANN_REG(JitInsn *, def_insn)
  278. #undef ANN_REG