RISC-V code generator (assembly-text emitter, not JIT machine-code path) — worth pursuing this direction?#169
Conversation
…loat params/return)
…runc, if/else; 29 tests pass
… from pool; matmul verified
|
interesting step, but it's not very suitable.
Generating assembler text doesn't make a lot of sense for the JIT related project.
Of course, I would prefer the real back-end. And as I told, I think about getting rid of DynAsm. |
|
That makes sense — agreed the assembly-text route isn't the right fit for a JIT framework, and thanks for confirming the direction. Is there anything about the ir_match_insn/rules interface (currently living inside the .dasc files) that you'd want done differently for a hand-written encoder, given you're also rethinking the DynAsm situation? I don't want to build against an interface you're about to change. No urgency on my end — happy to just work on this quietly and check back in once there's something concrete to look at, if that's easier for you. |
You may try to be close to the X86/ARM back-end design.
Ideally this should be rewritten using declarative DSL. The more compact and clean the better. Something like the following... I don't have the final picture yet. Some ideas might be found in BEG, TWIG, iburg, lburg, ...
It should pass simple IR tests in "tests/run" (not necessary all). You may add tests to cover simple instruction (ADD, SUB, MUL, ...). [Now I'm creating similar tests for SIMD using RCC]
Yeah, sorry. I'm deep inside x86 SIMD back-end development... crying because of SSE*/AVX* design :( |
Hi Dmitry,
Following up on the RISC-V thread — I put together a working RISC-V backend, but want to flag upfront that it's architecturally different from the x86/aarch64 backends: it emits RISC-V assembly text (via fprintf, in the same spirit as ir_emit_c.c/ir_emit_llvm.c) rather than machine code through ir_match()/ir_ra.c into an in-memory code buffer. It needs an external assembler afterward, so it isn't a drop-in for the PHP-JIT in-memory codegen path — more suited to the standalone ir tool / AOT use cases.
I did this partly to sidestep the missing RISC-V DynAsm backend you mentioned, without waiting on the DynAsm replacement work.
Known limitations I haven't addressed yet: the loop-carried PHI register pool is capped at 6 int + 6 FP registers (breaks down for functions with more concurrently-live loop variables), and basic-block/if-else pairing is done by scanning forward through the instruction stream rather than using the CFG the framework already builds.
Before I put more time into this, wanted your take: is a text-emission backend like this worth having in the tree at all (given the emit_c/emit_llvm precedent), or would you rather RISC-V support eventually be a "real" backend integrated into ir_match/ir_ra.c once the DynAsm situation is sorted? Happy to go either direction.