Reputation: 137
How difficult would it be to add a generic code-gen
backend to Julia
in the vein of go
and chez-scheme
i.e. without the LLVM.
Would LLVM be a better way to do it - given that rust
and crystal
are also almost entirely self hosted and they can leverage the LLVM to emit binaries, even cross compile.
For a background, I've asked a question specifically about code-gen
in case of various LLVM front-ends here What are the issues faced while implementing a self-hosted language on LLVM?
Upvotes: 1
Views: 284
Reputation: 4366
rustc links and uses LLVM, both via the LLVM C API and via an extended wrapper in C++, exposed as a C ABI. I don't know about crystal, but some languages do target textual or bytecode LLVM IR directly, which has some potential advantages, but also performance and compatibility issues.
As far as "how difficult": NaN
, I guess? The most straightforward approach would be to start with Julia's type-inferred lowered form, which is already close to SSA. Someone with a good compiler background could probably write an un-optimized (spilling, no code motion, etc.), one-architecture template assembler in a short time (~months). Someone with no compiler background would probably need a fair amount of study to properly formulate the question.
Upvotes: 4
Reputation: 19162
Julia does have a form of code-gen which is its typed AST. You can see the typed AST using @code_typed
in front of any function call. Theoretically you can use that to emit to any IR, and Julia chooses LLVM IR for reasons stated elsewhere. Transpiler.jl is a package which does this to output things like OpenCL code from Julia functions.
You can use the LLVM IR to emit other bytecodes. CUDANative.jl uses LLVM's .ptx backend to emit CUDA kernels directly from Julia functions. The @polly
project is looking to do similar things whereby the macro would allow Julia to auto-accelerate some codes on the GPU (I admittedly have little knowledge of this, other than reading the post which suggested it and the followup. This was picked up as a GSoC project for LLVM).
Upvotes: 6