Stream: git-wasmtime

Topic: wasmtime / issue #9923 Cranelift as a backend for clang


view this post on Zulip Wasmtime GitHub notifications bot (Jan 06 2025 at 01:12):

michaeleisel opened issue #9923:

Feature

Since Cranelift is already experimentally working for rustc, I'd like to discuss if it could work for clang, and if so what would be involved. For instance, does rustc_codegen_cranelift turn miri into Cranelift IR, or does it turn LLVM IR into Cranelift IR? From benchmarking my own clang builds, I can see that the backend is a bottleneck and I'd love to see it get faster.

@bjorn3

view this post on Zulip Wasmtime GitHub notifications bot (Jan 06 2025 at 01:16):

cfallin commented on issue #9923:

rustc_codegen_cranelift turns miri into CLIF, so unfortunately it wouldn't offer any useful reusable pieces for this quest. In theory it should be possible-ish(*) to translate LLVM IR to CLIF -- it's just a very large project, is all.

(*) there are some bits of functionality we would have to implement that we don't support today, like: inline assembly (or reject), variadic signatures (or reject), probably other things. Note also that CLIF is at a lower semantic level than LLVM IR specifically wrt aggregate types -- we don't handle structs natively, we expect the producer to lower into primitives and pointers. How much each of these things matters depends on whether you need 100% coverage (e.g. compiling the world or a large project with Clang) or less (compiling your own small code tailor-written with restrictions in mind).

view this post on Zulip Wasmtime GitHub notifications bot (Jan 06 2025 at 01:21):

michaeleisel commented on issue #9923:

I wonder how hard it'd be to "reject" everything that's not currently supported, such as inline assembly, but in those cases just gracefully fall back to the LLVM backend. If, say, it works for 95% of the files of a large project (assuming all the stuff that's rejected, like inline assembly, is typically rare), and it just falls back to LLVM for the other 5%, then it's providing roughly 95% of the possible value without new additions to CLIF.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 06 2025 at 01:34):

cfallin commented on issue #9923:

rustc_codegen_cranelift has a fairly elegant solution to inline assembly -- as far as I understand, it builds the snippets as separate functions with LLVM then performs ordinary calls. In theory one could do the same for calls to variadic signatures, too (with a custom anonymous helper function generated per callsite or per argument count).

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2025 at 15:29):

michaeleisel edited issue #9923:

Feature

Since Cranelift is already experimentally working for rustc, I'd like to discuss if it could work for clang, and if so what would be involved. For instance, does rustc_codegen_cranelift turn miri into Cranelift IR, or does it turn LLVM IR into Cranelift IR? From benchmarking my own clang builds, I can see that the backend is a bottleneck and I'd love to see it get faster.

@bjorn3
```[tasklist]

Tasks

~~~

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2025 at 15:29):

michaeleisel edited issue #9923:

Feature

Since Cranelift is already experimentally working for rustc, I'd like to discuss if it could work for clang, and if so what would be involved. For instance, does rustc_codegen_cranelift turn miri into Cranelift IR, or does it turn LLVM IR into Cranelift IR? From benchmarking my own clang builds, I can see that the backend is a bottleneck and I'd love to see it get faster.

@bjorn3


Last updated: Jan 24 2025 at 00:11 UTC