immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,935 @@
1
+ /*
2
+ ** Memory access optimizations.
3
+ ** AA: Alias Analysis using high-level semantic disambiguation.
4
+ ** FWD: Load Forwarding (L2L) + Store Forwarding (S2L).
5
+ ** DSE: Dead-Store Elimination.
6
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
7
+ */
8
+
9
+ #define lj_opt_mem_c
10
+ #define LUA_CORE
11
+
12
+ #include "lj_obj.h"
13
+
14
+ #if LJ_HASJIT
15
+
16
+ #include "lj_tab.h"
17
+ #include "lj_ir.h"
18
+ #include "lj_jit.h"
19
+ #include "lj_iropt.h"
20
+ #include "lj_ircall.h"
21
+
22
+ /* Some local macros to save typing. Undef'd at the end. */
23
+ #define IR(ref) (&J->cur.ir[(ref)])
24
+ #define fins (&J->fold.ins)
25
+ #define fleft (&J->fold.left)
26
+ #define fright (&J->fold.right)
27
+
28
+ /*
29
+ ** Caveat #1: return value is not always a TRef -- only use with tref_ref().
30
+ ** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold().
31
+ */
32
+
33
+ /* Return values from alias analysis. */
34
+ typedef enum {
35
+ ALIAS_NO, /* The two refs CANNOT alias (exact). */
36
+ ALIAS_MAY, /* The two refs MAY alias (inexact). */
37
+ ALIAS_MUST /* The two refs MUST alias (exact). */
38
+ } AliasRet;
39
+
40
+ /* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */
41
+
42
+ /* Simplified escape analysis: check for intervening stores. */
43
+ static AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop)
44
+ {
45
+ IRRef ref = (IRRef)(ir - J->cur.ir); /* The ref that might be stored. */
46
+ for (ir++; ir < stop; ir++)
47
+ if (ir->op2 == ref &&
48
+ (ir->o == IR_ASTORE || ir->o == IR_HSTORE ||
49
+ ir->o == IR_USTORE || ir->o == IR_FSTORE))
50
+ return ALIAS_MAY; /* Reference was stored and might alias. */
51
+ return ALIAS_NO; /* Reference was not stored. */
52
+ }
53
+
54
+ /* Alias analysis for two different table references. */
55
+ static AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb)
56
+ {
57
+ IRIns *taba = IR(ta), *tabb = IR(tb);
58
+ int newa, newb;
59
+ lua_assert(ta != tb);
60
+ lua_assert(irt_istab(taba->t) && irt_istab(tabb->t));
61
+ /* Disambiguate new allocations. */
62
+ newa = (taba->o == IR_TNEW || taba->o == IR_TDUP);
63
+ newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP);
64
+ if (newa && newb)
65
+ return ALIAS_NO; /* Two different allocations never alias. */
66
+ if (newb) { /* At least one allocation? */
67
+ IRIns *tmp = taba; taba = tabb; tabb = tmp;
68
+ } else if (!newa) {
69
+ return ALIAS_MAY; /* Anything else: we just don't know. */
70
+ }
71
+ return aa_escape(J, taba, tabb);
72
+ }
73
+
74
+ /* Alias analysis for array and hash access using key-based disambiguation. */
75
+ static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)
76
+ {
77
+ IRRef ka = refa->op2;
78
+ IRRef kb = refb->op2;
79
+ IRIns *keya, *keyb;
80
+ IRRef ta, tb;
81
+ if (refa == refb)
82
+ return ALIAS_MUST; /* Shortcut for same refs. */
83
+ keya = IR(ka);
84
+ if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); }
85
+ keyb = IR(kb);
86
+ if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); }
87
+ ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1;
88
+ tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1;
89
+ if (ka == kb) {
90
+ /* Same key. Check for same table with different ref (NEWREF vs. HREF). */
91
+ if (ta == tb)
92
+ return ALIAS_MUST; /* Same key, same table. */
93
+ else
94
+ return aa_table(J, ta, tb); /* Same key, possibly different table. */
95
+ }
96
+ if (irref_isk(ka) && irref_isk(kb))
97
+ return ALIAS_NO; /* Different constant keys. */
98
+ if (refa->o == IR_AREF) {
99
+ /* Disambiguate array references based on index arithmetic. */
100
+ int32_t ofsa = 0, ofsb = 0;
101
+ IRRef basea = ka, baseb = kb;
102
+ lua_assert(refb->o == IR_AREF);
103
+ /* Gather base and offset from t[base] or t[base+-ofs]. */
104
+ if (keya->o == IR_ADD && irref_isk(keya->op2)) {
105
+ basea = keya->op1;
106
+ ofsa = IR(keya->op2)->i;
107
+ if (basea == kb && ofsa != 0)
108
+ return ALIAS_NO; /* t[base+-ofs] vs. t[base]. */
109
+ }
110
+ if (keyb->o == IR_ADD && irref_isk(keyb->op2)) {
111
+ baseb = keyb->op1;
112
+ ofsb = IR(keyb->op2)->i;
113
+ if (ka == baseb && ofsb != 0)
114
+ return ALIAS_NO; /* t[base] vs. t[base+-ofs]. */
115
+ }
116
+ if (basea == baseb && ofsa != ofsb)
117
+ return ALIAS_NO; /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */
118
+ } else {
119
+ /* Disambiguate hash references based on the type of their keys. */
120
+ lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&
121
+ (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF));
122
+ if (!irt_sametype(keya->t, keyb->t))
123
+ return ALIAS_NO; /* Different key types. */
124
+ }
125
+ if (ta == tb)
126
+ return ALIAS_MAY; /* Same table, cannot disambiguate keys. */
127
+ else
128
+ return aa_table(J, ta, tb); /* Try to disambiguate tables. */
129
+ }
130
+
131
+ /* Array and hash load forwarding. */
132
+ static TRef fwd_ahload(jit_State *J, IRRef xref)
133
+ {
134
+ IRIns *xr = IR(xref);
135
+ IRRef lim = xref; /* Search limit. */
136
+ IRRef ref;
137
+
138
+ /* Search for conflicting stores. */
139
+ ref = J->chain[fins->o+IRDELTA_L2S];
140
+ while (ref > xref) {
141
+ IRIns *store = IR(ref);
142
+ switch (aa_ahref(J, xr, IR(store->op1))) {
143
+ case ALIAS_NO: break; /* Continue searching. */
144
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
145
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
146
+ }
147
+ ref = store->prev;
148
+ }
149
+
150
+ /* No conflicting store (yet): const-fold loads from allocations. */
151
+ {
152
+ IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr;
153
+ IRRef tab = ir->op1;
154
+ ir = IR(tab);
155
+ if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) {
156
+ /* A NEWREF with a number key may end up pointing to the array part.
157
+ ** But it's referenced from HSTORE and not found in the ASTORE chain.
158
+ ** For now simply consider this a conflict without forwarding anything.
159
+ */
160
+ if (xr->o == IR_AREF) {
161
+ IRRef ref2 = J->chain[IR_NEWREF];
162
+ while (ref2 > tab) {
163
+ IRIns *newref = IR(ref2);
164
+ if (irt_isnum(IR(newref->op2)->t))
165
+ goto cselim;
166
+ ref2 = newref->prev;
167
+ }
168
+ }
169
+ /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF.
170
+ ** But the above search for conflicting stores was limited by xref.
171
+ ** So continue searching, limited by the TNEW/TDUP. Store forwarding
172
+ ** is ok, too. A conflict does NOT limit the search for a matching load.
173
+ */
174
+ while (ref > tab) {
175
+ IRIns *store = IR(ref);
176
+ switch (aa_ahref(J, xr, IR(store->op1))) {
177
+ case ALIAS_NO: break; /* Continue searching. */
178
+ case ALIAS_MAY: goto cselim; /* Conflicting store. */
179
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
180
+ }
181
+ ref = store->prev;
182
+ }
183
+ lua_assert(ir->o != IR_TNEW || irt_isnil(fins->t));
184
+ if (irt_ispri(fins->t)) {
185
+ return TREF_PRI(irt_type(fins->t));
186
+ } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) ||
187
+ irt_isstr(fins->t)) {
188
+ TValue keyv;
189
+ cTValue *tv;
190
+ IRIns *key = IR(xr->op2);
191
+ if (key->o == IR_KSLOT) key = IR(key->op1);
192
+ lj_ir_kvalue(J->L, &keyv, key);
193
+ tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv);
194
+ lua_assert(itype2irt(tv) == irt_type(fins->t));
195
+ if (irt_isnum(fins->t))
196
+ return lj_ir_knum_u64(J, tv->u64);
197
+ else if (LJ_DUALNUM && irt_isint(fins->t))
198
+ return lj_ir_kint(J, intV(tv));
199
+ else
200
+ return lj_ir_kstr(J, strV(tv));
201
+ }
202
+ /* Othwerwise: don't intern as a constant. */
203
+ }
204
+ }
205
+
206
+ cselim:
207
+ /* Try to find a matching load. Below the conflicting store, if any. */
208
+ ref = J->chain[fins->o];
209
+ while (ref > lim) {
210
+ IRIns *load = IR(ref);
211
+ if (load->op1 == xref)
212
+ return ref; /* Load forwarding. */
213
+ ref = load->prev;
214
+ }
215
+ return 0; /* Conflict or no match. */
216
+ }
217
+
218
+ /* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */
219
+ static TRef fwd_aload_reassoc(jit_State *J)
220
+ {
221
+ IRIns *irx = IR(fins->op1);
222
+ IRIns *key = IR(irx->op2);
223
+ if (key->o == IR_ADD && irref_isk(key->op2)) {
224
+ IRIns *add2 = IR(key->op1);
225
+ if (add2->o == IR_ADD && irref_isk(add2->op2) &&
226
+ IR(key->op2)->i == -IR(add2->op2)->i) {
227
+ IRRef ref = J->chain[IR_AREF];
228
+ IRRef lim = add2->op1;
229
+ if (irx->op1 > lim) lim = irx->op1;
230
+ while (ref > lim) {
231
+ IRIns *ir = IR(ref);
232
+ if (ir->op1 == irx->op1 && ir->op2 == add2->op1)
233
+ return fwd_ahload(J, ref);
234
+ ref = ir->prev;
235
+ }
236
+ }
237
+ }
238
+ return 0;
239
+ }
240
+
241
+ /* ALOAD forwarding. */
242
+ TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J)
243
+ {
244
+ IRRef ref;
245
+ if ((ref = fwd_ahload(J, fins->op1)) ||
246
+ (ref = fwd_aload_reassoc(J)))
247
+ return ref;
248
+ return EMITFOLD;
249
+ }
250
+
251
+ /* HLOAD forwarding. */
252
+ TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J)
253
+ {
254
+ IRRef ref = fwd_ahload(J, fins->op1);
255
+ if (ref)
256
+ return ref;
257
+ return EMITFOLD;
258
+ }
259
+
260
+ /* HREFK forwarding. */
261
+ TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J)
262
+ {
263
+ IRRef tab = fleft->op1;
264
+ IRRef ref = J->chain[IR_NEWREF];
265
+ while (ref > tab) {
266
+ IRIns *newref = IR(ref);
267
+ if (tab == newref->op1) {
268
+ if (fright->op1 == newref->op2)
269
+ return ref; /* Forward from NEWREF. */
270
+ else
271
+ goto docse;
272
+ } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) {
273
+ goto docse;
274
+ }
275
+ ref = newref->prev;
276
+ }
277
+ /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */
278
+ if (IR(tab)->o == IR_TDUP)
279
+ fins->t.irt &= ~IRT_GUARD; /* Drop HREFK guard. */
280
+ docse:
281
+ return CSEFOLD;
282
+ }
283
+
284
+ /* Check whether HREF of TNEW/TDUP can be folded to niltv. */
285
+ int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J)
286
+ {
287
+ IRRef lim = fins->op1; /* Search limit. */
288
+ IRRef ref;
289
+
290
+ /* The key for an ASTORE may end up in the hash part after a NEWREF. */
291
+ if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) {
292
+ ref = J->chain[IR_ASTORE];
293
+ while (ref > lim) {
294
+ if (ref < J->chain[IR_NEWREF])
295
+ return 0; /* Conflict. */
296
+ ref = IR(ref)->prev;
297
+ }
298
+ }
299
+
300
+ /* Search for conflicting stores. */
301
+ ref = J->chain[IR_HSTORE];
302
+ while (ref > lim) {
303
+ IRIns *store = IR(ref);
304
+ if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO)
305
+ return 0; /* Conflict. */
306
+ ref = store->prev;
307
+ }
308
+
309
+ return 1; /* No conflict. Can fold to niltv. */
310
+ }
311
+
312
+ /* Check whether there's no aliasing table.clear. */
313
+ static int fwd_aa_tab_clear(jit_State *J, IRRef lim, IRRef ta)
314
+ {
315
+ IRRef ref = J->chain[IR_CALLS];
316
+ while (ref > lim) {
317
+ IRIns *calls = IR(ref);
318
+ if (calls->op2 == IRCALL_lj_tab_clear &&
319
+ (ta == calls->op1 || aa_table(J, ta, calls->op1) != ALIAS_NO))
320
+ return 0; /* Conflict. */
321
+ ref = calls->prev;
322
+ }
323
+ return 1; /* No conflict. Can safely FOLD/CSE. */
324
+ }
325
+
326
+ /* Check whether there's no aliasing NEWREF/table.clear for the left operand. */
327
+ int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim)
328
+ {
329
+ IRRef ta = fins->op1;
330
+ IRRef ref = J->chain[IR_NEWREF];
331
+ while (ref > lim) {
332
+ IRIns *newref = IR(ref);
333
+ if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO)
334
+ return 0; /* Conflict. */
335
+ ref = newref->prev;
336
+ }
337
+ return fwd_aa_tab_clear(J, lim, ta);
338
+ }
339
+
340
+ /* ASTORE/HSTORE elimination. */
341
+ TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
342
+ {
343
+ IRRef xref = fins->op1; /* xREF reference. */
344
+ IRRef val = fins->op2; /* Stored value reference. */
345
+ IRIns *xr = IR(xref);
346
+ IRRef1 *refp = &J->chain[fins->o];
347
+ IRRef ref = *refp;
348
+ while (ref > xref) { /* Search for redundant or conflicting stores. */
349
+ IRIns *store = IR(ref);
350
+ switch (aa_ahref(J, xr, IR(store->op1))) {
351
+ case ALIAS_NO:
352
+ break; /* Continue searching. */
353
+ case ALIAS_MAY: /* Store to MAYBE the same location. */
354
+ if (store->op2 != val) /* Conflict if the value is different. */
355
+ goto doemit;
356
+ break; /* Otherwise continue searching. */
357
+ case ALIAS_MUST: /* Store to the same location. */
358
+ if (store->op2 == val) /* Same value: drop the new store. */
359
+ return DROPFOLD;
360
+ /* Different value: try to eliminate the redundant store. */
361
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
362
+ IRIns *ir;
363
+ /* Check for any intervening guards (includes conflicting loads). */
364
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
365
+ if (irt_isguard(ir->t) || ir->o == IR_CALLL)
366
+ goto doemit; /* No elimination possible. */
367
+ /* Remove redundant store from chain and replace with NOP. */
368
+ *refp = store->prev;
369
+ store->o = IR_NOP;
370
+ store->t.irt = IRT_NIL;
371
+ store->op1 = store->op2 = 0;
372
+ store->prev = 0;
373
+ /* Now emit the new store instead. */
374
+ }
375
+ goto doemit;
376
+ }
377
+ ref = *(refp = &store->prev);
378
+ }
379
+ doemit:
380
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
381
+ }
382
+
383
+ /* -- ULOAD forwarding ---------------------------------------------------- */
384
+
385
+ /* The current alias analysis for upvalues is very simplistic. It only
386
+ ** disambiguates between the unique upvalues of the same function.
387
+ ** This is good enough for now, since most upvalues are read-only.
388
+ **
389
+ ** A more precise analysis would be feasible with the help of the parser:
390
+ ** generate a unique key for every upvalue, even across all prototypes.
391
+ ** Lacking a realistic use-case, it's unclear whether this is beneficial.
392
+ */
393
+ static AliasRet aa_uref(IRIns *refa, IRIns *refb)
394
+ {
395
+ if (refa->o != refb->o)
396
+ return ALIAS_NO; /* Different UREFx type. */
397
+ if (refa->op1 == refb->op1) { /* Same function. */
398
+ if (refa->op2 == refb->op2)
399
+ return ALIAS_MUST; /* Same function, same upvalue idx. */
400
+ else
401
+ return ALIAS_NO; /* Same function, different upvalue idx. */
402
+ } else { /* Different functions, check disambiguation hash values. */
403
+ if (((refa->op2 ^ refb->op2) & 0xff))
404
+ return ALIAS_NO; /* Upvalues with different hash values cannot alias. */
405
+ else
406
+ return ALIAS_MAY; /* No conclusion can be drawn for same hash value. */
407
+ }
408
+ }
409
+
410
+ /* ULOAD forwarding. */
411
+ TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J)
412
+ {
413
+ IRRef uref = fins->op1;
414
+ IRRef lim = REF_BASE; /* Search limit. */
415
+ IRIns *xr = IR(uref);
416
+ IRRef ref;
417
+
418
+ /* Search for conflicting stores. */
419
+ ref = J->chain[IR_USTORE];
420
+ while (ref > lim) {
421
+ IRIns *store = IR(ref);
422
+ switch (aa_uref(xr, IR(store->op1))) {
423
+ case ALIAS_NO: break; /* Continue searching. */
424
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
425
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
426
+ }
427
+ ref = store->prev;
428
+ }
429
+
430
+ cselim:
431
+ /* Try to find a matching load. Below the conflicting store, if any. */
432
+
433
+ ref = J->chain[IR_ULOAD];
434
+ while (ref > lim) {
435
+ IRIns *ir = IR(ref);
436
+ if (ir->op1 == uref ||
437
+ (IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o))
438
+ return ref; /* Match for identical or equal UREFx (non-CSEable UREFO). */
439
+ ref = ir->prev;
440
+ }
441
+ return lj_ir_emit(J);
442
+ }
443
+
444
+ /* USTORE elimination. */
445
+ TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)
446
+ {
447
+ IRRef xref = fins->op1; /* xREF reference. */
448
+ IRRef val = fins->op2; /* Stored value reference. */
449
+ IRIns *xr = IR(xref);
450
+ IRRef1 *refp = &J->chain[IR_USTORE];
451
+ IRRef ref = *refp;
452
+ while (ref > xref) { /* Search for redundant or conflicting stores. */
453
+ IRIns *store = IR(ref);
454
+ switch (aa_uref(xr, IR(store->op1))) {
455
+ case ALIAS_NO:
456
+ break; /* Continue searching. */
457
+ case ALIAS_MAY: /* Store to MAYBE the same location. */
458
+ if (store->op2 != val) /* Conflict if the value is different. */
459
+ goto doemit;
460
+ break; /* Otherwise continue searching. */
461
+ case ALIAS_MUST: /* Store to the same location. */
462
+ if (store->op2 == val) /* Same value: drop the new store. */
463
+ return DROPFOLD;
464
+ /* Different value: try to eliminate the redundant store. */
465
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
466
+ IRIns *ir;
467
+ /* Check for any intervening guards (includes conflicting loads). */
468
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
469
+ if (irt_isguard(ir->t))
470
+ goto doemit; /* No elimination possible. */
471
+ /* Remove redundant store from chain and replace with NOP. */
472
+ *refp = store->prev;
473
+ store->o = IR_NOP;
474
+ store->t.irt = IRT_NIL;
475
+ store->op1 = store->op2 = 0;
476
+ store->prev = 0;
477
+ if (ref+1 < J->cur.nins &&
478
+ store[1].o == IR_OBAR && store[1].op1 == xref) {
479
+ IRRef1 *bp = &J->chain[IR_OBAR];
480
+ IRIns *obar;
481
+ for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp))
482
+ bp = &obar->prev;
483
+ /* Remove OBAR, too. */
484
+ *bp = obar->prev;
485
+ obar->o = IR_NOP;
486
+ obar->t.irt = IRT_NIL;
487
+ obar->op1 = obar->op2 = 0;
488
+ obar->prev = 0;
489
+ }
490
+ /* Now emit the new store instead. */
491
+ }
492
+ goto doemit;
493
+ }
494
+ ref = *(refp = &store->prev);
495
+ }
496
+ doemit:
497
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
498
+ }
499
+
500
+ /* -- FLOAD forwarding and FSTORE elimination ----------------------------- */
501
+
502
+ /* Alias analysis for field access.
503
+ ** Field loads are cheap and field stores are rare.
504
+ ** Simple disambiguation based on field types is good enough.
505
+ */
506
+ static AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb)
507
+ {
508
+ if (refa->op2 != refb->op2)
509
+ return ALIAS_NO; /* Different fields. */
510
+ if (refa->op1 == refb->op1)
511
+ return ALIAS_MUST; /* Same field, same object. */
512
+ else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM)
513
+ return aa_table(J, refa->op1, refb->op1); /* Disambiguate tables. */
514
+ else
515
+ return ALIAS_MAY; /* Same field, possibly different object. */
516
+ }
517
+
518
+ /* Only the loads for mutable fields end up here (see FOLD). */
519
+ TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J)
520
+ {
521
+ IRRef oref = fins->op1; /* Object reference. */
522
+ IRRef fid = fins->op2; /* Field ID. */
523
+ IRRef lim = oref; /* Search limit. */
524
+ IRRef ref;
525
+
526
+ /* Search for conflicting stores. */
527
+ ref = J->chain[IR_FSTORE];
528
+ while (ref > oref) {
529
+ IRIns *store = IR(ref);
530
+ switch (aa_fref(J, fins, IR(store->op1))) {
531
+ case ALIAS_NO: break; /* Continue searching. */
532
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
533
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
534
+ }
535
+ ref = store->prev;
536
+ }
537
+
538
+ /* No conflicting store: const-fold field loads from allocations. */
539
+ if (fid == IRFL_TAB_META) {
540
+ IRIns *ir = IR(oref);
541
+ if (ir->o == IR_TNEW || ir->o == IR_TDUP)
542
+ return lj_ir_knull(J, IRT_TAB);
543
+ }
544
+
545
+ cselim:
546
+ /* Try to find a matching load. Below the conflicting store, if any. */
547
+ return lj_opt_cselim(J, lim);
548
+ }
549
+
550
+ /* FSTORE elimination. */
551
+ TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J)
552
+ {
553
+ IRRef fref = fins->op1; /* FREF reference. */
554
+ IRRef val = fins->op2; /* Stored value reference. */
555
+ IRIns *xr = IR(fref);
556
+ IRRef1 *refp = &J->chain[IR_FSTORE];
557
+ IRRef ref = *refp;
558
+ while (ref > fref) { /* Search for redundant or conflicting stores. */
559
+ IRIns *store = IR(ref);
560
+ switch (aa_fref(J, xr, IR(store->op1))) {
561
+ case ALIAS_NO:
562
+ break; /* Continue searching. */
563
+ case ALIAS_MAY:
564
+ if (store->op2 != val) /* Conflict if the value is different. */
565
+ goto doemit;
566
+ break; /* Otherwise continue searching. */
567
+ case ALIAS_MUST:
568
+ if (store->op2 == val) /* Same value: drop the new store. */
569
+ return DROPFOLD;
570
+ /* Different value: try to eliminate the redundant store. */
571
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
572
+ IRIns *ir;
573
+ /* Check for any intervening guards or conflicting loads. */
574
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
575
+ if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2))
576
+ goto doemit; /* No elimination possible. */
577
+ /* Remove redundant store from chain and replace with NOP. */
578
+ *refp = store->prev;
579
+ store->o = IR_NOP;
580
+ store->t.irt = IRT_NIL;
581
+ store->op1 = store->op2 = 0;
582
+ store->prev = 0;
583
+ /* Now emit the new store instead. */
584
+ }
585
+ goto doemit;
586
+ }
587
+ ref = *(refp = &store->prev);
588
+ }
589
+ doemit:
590
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
591
+ }
592
+
593
+ /* -- XLOAD forwarding and XSTORE elimination ----------------------------- */
594
+
595
+ /* Find cdata allocation for a reference (if any). */
596
+ static IRIns *aa_findcnew(jit_State *J, IRIns *ir)
597
+ {
598
+ while (ir->o == IR_ADD) {
599
+ if (!irref_isk(ir->op1)) {
600
+ IRIns *ir1 = aa_findcnew(J, IR(ir->op1)); /* Left-recursion. */
601
+ if (ir1) return ir1;
602
+ }
603
+ if (irref_isk(ir->op2)) return NULL;
604
+ ir = IR(ir->op2); /* Flatten right-recursion. */
605
+ }
606
+ return ir->o == IR_CNEW ? ir : NULL;
607
+ }
608
+
609
+ /* Alias analysis for two cdata allocations. */
610
+ static AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb)
611
+ {
612
+ IRIns *cnewa = aa_findcnew(J, refa);
613
+ IRIns *cnewb = aa_findcnew(J, refb);
614
+ if (cnewa == cnewb)
615
+ return ALIAS_MAY; /* Same allocation or neither is an allocation. */
616
+ if (cnewa && cnewb)
617
+ return ALIAS_NO; /* Two different allocations never alias. */
618
+ if (cnewb) { cnewa = cnewb; refb = refa; }
619
+ return aa_escape(J, cnewa, refb);
620
+ }
621
+
622
+ /* Alias analysis for XLOAD/XSTORE. */
623
+ static AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb)
624
+ {
625
+ ptrdiff_t ofsa = 0, ofsb = 0;
626
+ IRIns *refb = IR(xb->op1);
627
+ IRIns *basea = refa, *baseb = refb;
628
+ if (refa == refb && irt_sametype(xa->t, xb->t))
629
+ return ALIAS_MUST; /* Shortcut for same refs with identical type. */
630
+ /* Offset-based disambiguation. */
631
+ if (refa->o == IR_ADD && irref_isk(refa->op2)) {
632
+ IRIns *irk = IR(refa->op2);
633
+ basea = IR(refa->op1);
634
+ ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
635
+ (ptrdiff_t)irk->i;
636
+ }
637
+ if (refb->o == IR_ADD && irref_isk(refb->op2)) {
638
+ IRIns *irk = IR(refb->op2);
639
+ baseb = IR(refb->op1);
640
+ ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
641
+ (ptrdiff_t)irk->i;
642
+ }
643
+ /* Treat constified pointers like base vs. base+offset. */
644
+ if (basea->o == IR_KPTR && baseb->o == IR_KPTR) {
645
+ ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea);
646
+ baseb = basea;
647
+ }
648
+ /* This implements (very) strict aliasing rules.
649
+ ** Different types do NOT alias, except for differences in signedness.
650
+ ** Type punning through unions is allowed (but forces a reload).
651
+ */
652
+ if (basea == baseb) {
653
+ ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t);
654
+ if (ofsa == ofsb) {
655
+ if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t))
656
+ return ALIAS_MUST; /* Same-sized, same-kind. May need to convert. */
657
+ } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) {
658
+ return ALIAS_NO; /* Non-overlapping base+-o1 vs. base+-o2. */
659
+ }
660
+ /* NYI: extract, extend or reinterpret bits (int <-> fp). */
661
+ return ALIAS_MAY; /* Overlapping or type punning: force reload. */
662
+ }
663
+ if (!irt_sametype(xa->t, xb->t) &&
664
+ !(irt_typerange(xa->t, IRT_I8, IRT_U64) &&
665
+ ((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1))
666
+ return ALIAS_NO;
667
+ /* NYI: structural disambiguation. */
668
+ return aa_cnew(J, basea, baseb); /* Try to disambiguate allocations. */
669
+ }
670
+
671
+ /* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */
672
+ static IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2)
673
+ {
674
+ IRRef ref = J->chain[op];
675
+ IRRef lim = op1;
676
+ if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; }
677
+ while (ref > lim) {
678
+ IRIns *ir = IR(ref);
679
+ if (ir->op1 == op1 && ir->op2 == op2)
680
+ return ref;
681
+ ref = ir->prev;
682
+ }
683
+ return 0;
684
+ }
685
+
686
+ /* Reassociate index references. */
687
+ static IRRef reassoc_xref(jit_State *J, IRIns *ir)
688
+ {
689
+ ptrdiff_t ofs = 0;
690
+ if (ir->o == IR_ADD && irref_isk(ir->op2)) { /* Get constant offset. */
691
+ IRIns *irk = IR(ir->op2);
692
+ ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
693
+ (ptrdiff_t)irk->i;
694
+ ir = IR(ir->op1);
695
+ }
696
+ if (ir->o == IR_ADD) { /* Add of base + index. */
697
+ /* Index ref > base ref for loop-carried dependences. Only check op1. */
698
+ IRIns *ir2, *ir1 = IR(ir->op1);
699
+ int32_t shift = 0;
700
+ IRRef idxref;
701
+ /* Determine index shifts. Don't bother with IR_MUL here. */
702
+ if (ir1->o == IR_BSHL && irref_isk(ir1->op2))
703
+ shift = IR(ir1->op2)->i;
704
+ else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2)
705
+ shift = 1;
706
+ else
707
+ ir1 = ir;
708
+ ir2 = IR(ir1->op1);
709
+ /* A non-reassociated add. Must be a loop-carried dependence. */
710
+ if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2))
711
+ ofs += (ptrdiff_t)IR(ir2->op2)->i << shift;
712
+ else
713
+ return 0;
714
+ idxref = ir2->op1;
715
+ /* Try to CSE the reassociated chain. Give up if not found. */
716
+ if (ir1 != ir &&
717
+ !(idxref = reassoc_trycse(J, ir1->o, idxref,
718
+ ir1->o == IR_BSHL ? ir1->op2 : idxref)))
719
+ return 0;
720
+ if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2)))
721
+ return 0;
722
+ if (ofs != 0) {
723
+ IRRef refk = tref_ref(lj_ir_kintp(J, ofs));
724
+ if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk)))
725
+ return 0;
726
+ }
727
+ return idxref; /* Success, found a reassociated index reference. Phew. */
728
+ }
729
+ return 0; /* Failure. */
730
+ }
731
+
732
+ /* XLOAD forwarding. */
733
+ TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J)
734
+ {
735
+ IRRef xref = fins->op1;
736
+ IRIns *xr = IR(xref);
737
+ IRRef lim = xref; /* Search limit. */
738
+ IRRef ref;
739
+
740
+ if ((fins->op2 & IRXLOAD_READONLY))
741
+ goto cselim;
742
+ if ((fins->op2 & IRXLOAD_VOLATILE))
743
+ goto doemit;
744
+
745
+ /* Search for conflicting stores. */
746
+ ref = J->chain[IR_XSTORE];
747
+ retry:
748
+ if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];
749
+ if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];
750
+ while (ref > lim) {
751
+ IRIns *store = IR(ref);
752
+ switch (aa_xref(J, xr, fins, store)) {
753
+ case ALIAS_NO: break; /* Continue searching. */
754
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
755
+ case ALIAS_MUST:
756
+ /* Emit conversion if the loaded type doesn't match the forwarded type. */
757
+ if (!irt_sametype(fins->t, IR(store->op2)->t)) {
758
+ IRType dt = irt_type(fins->t), st = irt_type(IR(store->op2)->t);
759
+ if (dt == IRT_I8 || dt == IRT_I16) { /* Trunc + sign-extend. */
760
+ st = dt | IRCONV_SEXT;
761
+ dt = IRT_INT;
762
+ } else if (dt == IRT_U8 || dt == IRT_U16) { /* Trunc + zero-extend. */
763
+ st = dt;
764
+ dt = IRT_INT;
765
+ }
766
+ fins->ot = IRT(IR_CONV, dt);
767
+ fins->op1 = store->op2;
768
+ fins->op2 = (dt<<5)|st;
769
+ return RETRYFOLD;
770
+ }
771
+ return store->op2; /* Store forwarding. */
772
+ }
773
+ ref = store->prev;
774
+ }
775
+
776
+ cselim:
777
+ /* Try to find a matching load. Below the conflicting store, if any. */
778
+ ref = J->chain[IR_XLOAD];
779
+ while (ref > lim) {
780
+ /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */
781
+ if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t))
782
+ return ref;
783
+ ref = IR(ref)->prev;
784
+ }
785
+
786
+ /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */
787
+ if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] &&
788
+ xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) {
789
+ ref = J->chain[IR_XSTORE];
790
+ while (ref > lim) /* Skip stores that have already been checked. */
791
+ ref = IR(ref)->prev;
792
+ lim = xref;
793
+ xr = IR(xref);
794
+ goto retry; /* Retry with the reassociated reference. */
795
+ }
796
+ doemit:
797
+ return EMITFOLD;
798
+ }
799
+
800
+ /* XSTORE elimination. */
801
+ TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J)
802
+ {
803
+ IRRef xref = fins->op1;
804
+ IRIns *xr = IR(xref);
805
+ IRRef lim = xref; /* Search limit. */
806
+ IRRef val = fins->op2; /* Stored value reference. */
807
+ IRRef1 *refp = &J->chain[IR_XSTORE];
808
+ IRRef ref = *refp;
809
+ if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];
810
+ if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];
811
+ if (J->chain[IR_XSNEW] > lim) lim = J->chain[IR_XSNEW];
812
+ while (ref > lim) { /* Search for redundant or conflicting stores. */
813
+ IRIns *store = IR(ref);
814
+ switch (aa_xref(J, xr, fins, store)) {
815
+ case ALIAS_NO:
816
+ break; /* Continue searching. */
817
+ case ALIAS_MAY:
818
+ if (store->op2 != val) /* Conflict if the value is different. */
819
+ goto doemit;
820
+ break; /* Otherwise continue searching. */
821
+ case ALIAS_MUST:
822
+ if (store->op2 == val) /* Same value: drop the new store. */
823
+ return DROPFOLD;
824
+ /* Different value: try to eliminate the redundant store. */
825
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
826
+ IRIns *ir;
827
+ /* Check for any intervening guards or any XLOADs (no AA performed). */
828
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
829
+ if (irt_isguard(ir->t) || ir->o == IR_XLOAD)
830
+ goto doemit; /* No elimination possible. */
831
+ /* Remove redundant store from chain and replace with NOP. */
832
+ *refp = store->prev;
833
+ store->o = IR_NOP;
834
+ store->t.irt = IRT_NIL;
835
+ store->op1 = store->op2 = 0;
836
+ store->prev = 0;
837
+ /* Now emit the new store instead. */
838
+ }
839
+ goto doemit;
840
+ }
841
+ ref = *(refp = &store->prev);
842
+ }
843
+ doemit:
844
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
845
+ }
846
+
847
+ /* -- Forwarding of lj_tab_len -------------------------------------------- */
848
+
849
+ /* This is rather simplistic right now, but better than nothing. */
850
+ TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J)
851
+ {
852
+ IRRef tab = fins->op1; /* Table reference. */
853
+ IRRef lim = tab; /* Search limit. */
854
+ IRRef ref;
855
+
856
+ /* Any ASTORE is a conflict and limits the search. */
857
+ if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE];
858
+
859
+ /* Search for conflicting HSTORE with numeric key. */
860
+ ref = J->chain[IR_HSTORE];
861
+ while (ref > lim) {
862
+ IRIns *store = IR(ref);
863
+ IRIns *href = IR(store->op1);
864
+ IRIns *key = IR(href->op2);
865
+ if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {
866
+ lim = ref; /* Conflicting store found, limits search for TLEN. */
867
+ break;
868
+ }
869
+ ref = store->prev;
870
+ }
871
+
872
+ /* Search for aliasing table.clear. */
873
+ if (!fwd_aa_tab_clear(J, lim, tab))
874
+ return lj_ir_emit(J);
875
+
876
+ /* Try to find a matching load. Below the conflicting store, if any. */
877
+ return lj_opt_cselim(J, lim);
878
+ }
879
+
880
+ /* -- ASTORE/HSTORE previous type analysis -------------------------------- */
881
+
882
+ /* Check whether the previous value for a table store is non-nil.
883
+ ** This can be derived either from a previous store or from a previous
884
+ ** load (because all loads from tables perform a type check).
885
+ **
886
+ ** The result of the analysis can be used to avoid the metatable check
887
+ ** and the guard against HREF returning niltv. Both of these are cheap,
888
+ ** so let's not spend too much effort on the analysis.
889
+ **
890
+ ** A result of 1 is exact: previous value CANNOT be nil.
891
+ ** A result of 0 is inexact: previous value MAY be nil.
892
+ */
893
+ int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref)
894
+ {
895
+ /* First check stores. */
896
+ IRRef ref = J->chain[loadop+IRDELTA_L2S];
897
+ while (ref > xref) {
898
+ IRIns *store = IR(ref);
899
+ if (store->op1 == xref) { /* Same xREF. */
900
+ /* A nil store MAY alias, but a non-nil store MUST alias. */
901
+ return !irt_isnil(store->t);
902
+ } else if (irt_isnil(store->t)) { /* Must check any nil store. */
903
+ IRRef skref = IR(store->op1)->op2;
904
+ IRRef xkref = IR(xref)->op2;
905
+ /* Same key type MAY alias. Need ALOAD check due to multiple int types. */
906
+ if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) {
907
+ if (skref == xkref || !irref_isk(skref) || !irref_isk(xkref))
908
+ return 0; /* A nil store with same const key or var key MAY alias. */
909
+ /* Different const keys CANNOT alias. */
910
+ } /* Different key types CANNOT alias. */
911
+ } /* Other non-nil stores MAY alias. */
912
+ ref = store->prev;
913
+ }
914
+
915
+ /* Check loads since nothing could be derived from stores. */
916
+ ref = J->chain[loadop];
917
+ while (ref > xref) {
918
+ IRIns *load = IR(ref);
919
+ if (load->op1 == xref) { /* Same xREF. */
920
+ /* A nil load MAY alias, but a non-nil load MUST alias. */
921
+ return !irt_isnil(load->t);
922
+ } /* Other non-nil loads MAY alias. */
923
+ ref = load->prev;
924
+ }
925
+ return 0; /* Nothing derived at all, previous value MAY be nil. */
926
+ }
927
+
928
+ /* ------------------------------------------------------------------------ */
929
+
930
+ #undef IR
931
+ #undef fins
932
+ #undef fleft
933
+ #undef fright
934
+
935
+ #endif