Follow

hm, i'm looking into compiling rust to jvm bytecode (why are you looking at me like that) and somewhat surprisingly converting from ssa form to java bytecode doesn't seem to at all be a solved problem? there's obviously a naive way that barely uses the operand stack, and i've found some papers that do that, but i'm not at all confident in hotspot handling that well....

· · Web · 4 · 0 · 3

all the approaches mentioned in this paper need an operation that can't be implemented in the jvm
so, I think the best approach might just be to treat it as a register machine (using locals) then apply peephole optimization to remove redundant store/load pairs

finally found a very directly relevant paper, they compared just removing redundant store/load pairs to a brute-force optimal solution and found that the difference was negligible link.springer.com/content/pdf/

@leo anyway take a look at maple IR
https://github.com/LLVM-but-worse/maple-ir

> lifts it to SSA IR [...] then recompiles back down to bytecode

@bun i don't 100% understand what that's doing but it seems like while it's more efficient than the naive method it's still treating bytecode as a register machine instead of a hybrid stack/register machine which isn't the most efficient thing to do (but getting rid of all the redundant loads/stores in the naive approach is definitely a plus)

@leo I don't think it matters a huge amount after JIT anyways

@bun bigger issue with the naive approach is that it uses a massive amount of locals and even if the jit is fine with it that could easily lead to stack overflows with the interpreter

@leo wait is this inspired by our discussion a few weeks ago
Sign in to participate in the conversation
Mastodon

personal server for leo60228 (@leo@60228.dev)