rustc_codegen_cranelift icon indicating copy to clipboard operation
rustc_codegen_cranelift copied to clipboard

Implement vendor intrinsics by pre-compiling using LLVM

Open bjorn3 opened this issue 10 months ago • 1 comments

Basically we would scrape all vendor intrinsics defined in the LLVM source code at llvm/include/llvm/IR/Intrinsics.td, generate some Rust or C code which exercises the vendor intrinsic, compile it using LLVM and then extract the raw instruction bytes for each function and generate Rust code to include in cg_clif itself that reproduces those raw instruction bytes whenever it needs to codegen the respective vendor intrinsic.

The disadvantage of this would be that we did need to either check in generated source code (which distros may not like) or somehow integrate the generation process with building cg_clif itself (which would make building cg_clif more complicated and require the LLVM backend to be present too). The big advantage however is that is saves a ton of work manually implementing every single vendor intrinsic of which there are many thousands. It also likely has better performance than the manual emulation of them. And for the intrinsics we currently implement using inline asm it would be non-trivial compile time boost (as inline asm is implemented by invoking rustc a second time to use the LLVM backend)

bjorn3 avatar Dec 11 '24 11:12 bjorn3