MENU

Mono mini JIT 引擎RISCV移植Wiki

September 25, 2022 • 实习

描述:

文章用于记录在Mono mini JIT 引擎的移植过程中使用到的文档等资源,以便后续的使用。

Mono中使用了两种JIT引擎,其一是Mono自己的JIT引擎,而另一种是基于LLVM实现的JIT引擎。目前Mono项目中使用的是LLVM 6.0版本。版本过老,所以如果想要使用LLVM参与Mono RISCV的JIT编译,可能需要升级LLVM先,但是不知道是否有LLVM API的变动。升级LLVM可能潜在的需要更新其他架构的代码以适配新版LLVM。

相关仓库:

相关文章:

相关issue

相关文档:

目前需求:

首先计划支持risc-v 64位架构的JIT支持(具体先支持那些扩展,还没计划,起码先I吧?),以下是通过阅读文档得知的基于Mono自己的JIT引擎实现RISCV支持所需要实现的函数:

  • mono_arch_output_basic_block: 用来以bb为单位发射native代码。
  • mono_arch_emit_prolog: 生成prolog
  • mono_arch_emit_epilog: 生成epilog
  • mono_arch_patch_code: 还没有理解作用,贴上原描述:When the epilog has been emitted, the upper level code arranges for the buffer of memory that contains the native code to be copied in an area of executable memory and at this point, instructions that use relative addressing need to be patched to have the right offsets.
  • mono_arch_allocate_vars: 为变量计算并分配堆栈大小(assigns to both arguments and local variables the offset relative to the frame register where they are stored, dead variables are simply discarded. The total amount of stack needed is calculated.)
  • mono_arch_call_opcode: 实现函数间调用/跳转(较多架构没有实现)。
  • mono_arch_local_regalloc: 为本地变量分配寄存器(没有架构实现,疑似被弃用)。
  • mono_arch_create_jit_trampoline: 处理汇编代码和字节码间的切换(没有架构实现,疑似被弃用)
  • mono_arch_get_throw_exception: 抛出异常。
  • mono_arch_handle_exception: 处理异常
  • ves_icall_get_frame_info: 返回有关特定框架的信息
  • mono_jit_walk_stack: 获得调用栈。
  • ves_icall_get_trace: 返回调用栈(目前不清楚和mono_jit_walk_stack的区别)
  • mono_arch_cpu_optimizations: 返回应为当前 CPU 启用和关闭的优化(目前不需要实现)
  • mono_arch_regname: 返回寄存器的名称
  • mono_arch_get_allocatable_int_vars: 返回可分配给当前架构中的整数寄存器的变量列表
  • mono_arch_get_global_int_regs: 返回可用于在当前方法中分配变量的caller保存寄存器列表
  • mono_arch_instrument_mem_needs: 未知,实现分析接口所需的函数
  • mono_arch_instrument_prolog: 未知,实现分析接口所需的函数
  • mono_arch_instrument_epilog: 未知,实现分析接口所需的函数

其他链接

Last Modified: March 13, 2023