描述:
文章用于记录在 Mono mini JIT 引擎的移植过程中使用到的文档等资源,以便后续的使用。
Mono 中使用了两种 JIT 引擎,其一是 Mono 自己的 JIT 引擎,而另一种是基于 LLVM 实现的 JIT 引擎。目前 Mono 项目中使用的是 LLVM 6.0 版本。版本过老,所以如果想要使用 LLVM 参与 Mono RISCV 的 JIT 编译,可能需要升级 LLVM 先,但是不知道是否有 LLVM API 的变动。升级 LLVM 可能潜在的需要更新其他架构的代码以适配新版 LLVM。
相关仓库:
相关文章:
- Understanding RISC-V Calling Convention
- RISC-V from scratch 4: Creating a function prologue
- A Brief History of Just-In-Time
- Hello, JIT World: The Joy of Simple JITs
- RISC-V 架构移植
- RISC-V fence 指令
- RISC-V 内存一致性模型
- riscv asm cmpxchg 实现解析
- [RFC] RISC-V 内存一致性模型
相关 issue
相关文档:
- Mini JIT 引擎最初的设计文档(仅供参考,文档中涉及到的部分 API 已经删除 / 弃用)
- Mini JIT 添加新架构的相关流程介绍
- Mono JIT 交叉编译的文档
- Mono 的 API 文档
- Mono IR 文档
目前需求:
首先计划支持 risc-v 64 位架构的 JIT 支持(具体先支持那些扩展,还没计划,起码先 I 吧?),以下是通过阅读文档得知的基于 Mono 自己的 JIT 引擎实现 RISCV 支持所需要实现的函数:
mono_arch_output_basic_block
: 用来以 bb 为单位发射 native 代码。mono_arch_emit_prolog
: 生成 prologmono_arch_emit_epilog
: 生成 epilogmono_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
: 未知,实现分析接口所需的函数