Hasty Briefsbeta

Bilingual

A multi-entry CFG design conundrum

2 days ago
  • ZJIT compiles Ruby YARV bytecode to machine code using a high-level SSA intermediate representation (HIR) with control-flow graphs and block parameters instead of phi nodes.
  • Ruby's default positional parameters are evaluated at call time, leading to multiple entry points in the bytecode depending on the number of arguments passed; the JIT must handle these separate entry blocks.
  • HIR supports multiple function entrypoints (interpreter, JIT, and default parameter stubs), each with block parameters mirroring function arguments.
  • Multiple entrypoints complicate dominator analysis: no single start block, so reverse post-order traversal and dominator computation require special handling.
  • Three approaches considered: (1) special-case entry blocks in dominator algorithm, (2) synthesize a super-entry block (with fake or real block and LoadArg instructions), (3) duplicate the CFG per entrypoint.
  • The chosen approach is 2.b: synthesizing a super-entry block with LoadArg instructions, which provides flexibility for future specialization without mandatory code duplication.
  • The problem is analogous to handling multiple return instructions in postdominator analysis, where a common solution is to branch to a single return.