The readme says that cretonne is supposed to be a code generator for WebAssembly, but it's a bit unclear what that means, seeing how there doesn't appear to be anything to actually do with wasm in the code.
Preferably, the readme or documentation should be able to answer these questions.
Cretonne is still in development, so big pieces are still missing.
Cretonne is meant to be a part of a larger compiler or JIT that prioritizes fast compilation times. In particular, it must be possible to parallelize compilation to make use of multiple cores. This is achieved by making a function in Cretonne IR an independent data structure without external references. When a Cretonne function refers to a global variable or calls another function, it uses the _name_ of the external object instead of a pointer.
A later linking phase depends on the framework embedding Cretonne to resolve these references. Cretonne won't have the global data structures needed to do that itself.
Inter-procedural optimizations necessarily need to work with multiple functions at once, and so they need a closer interaction with the larger compiler framework and how it does concurrency. I consider this out of scope for Cretonne, at least initially.
Cretonne could provide useful functions for an IPO framework, for example "inline this function at this call site".
This hasn't been built yet, by I expect there will be a lib/wasm crate which can translate binary WebAssembly to Cretonne IR. Again, since Cretonne is supposed to support concurrent compilation without imposing a way of managing threads, this crate should support translating wasm functions individually.
This is an interesting idea that I didn't consider initially, but I think it could work.
A subset of the Cretonne instruction set is equivalent to WebAssembly and can be translated easily. A larger subset of the instructions could be transformed into wasm-equivalent instructions using the legalizer framework.
Some instructions are too low-level to be translated to WebAssembly. This includes raw loads and stores (as opposed to heap_load and heap_store) and things like taking the address of a stack slot. When LLVM is translating C/C++ to WebAssembly, it deals with these things by sandboxing. It maps loads and stores to the wasm heap and moves stacks objects to a shadow stack in the heap if their address escapes.
I see three tiers on the AOT-JIT scale:
Cretonne is initially targeting 2. as a second-tier WebAssembly compiler for Firefox. I imagine its scope expanding in both directions.
Most helpful comment
Cretonne is still in development, so big pieces are still missing.
Inter-procedural optimizations
Cretonne is meant to be a part of a larger compiler or JIT that prioritizes fast compilation times. In particular, it must be possible to parallelize compilation to make use of multiple cores. This is achieved by making a function in Cretonne IR an independent data structure without external references. When a Cretonne function refers to a global variable or calls another function, it uses the _name_ of the external object instead of a pointer.
A later linking phase depends on the framework embedding Cretonne to resolve these references. Cretonne won't have the global data structures needed to do that itself.
Inter-procedural optimizations necessarily need to work with multiple functions at once, and so they need a closer interaction with the larger compiler framework and how it does concurrency. I consider this out of scope for Cretonne, at least initially.
Cretonne could provide useful functions for an IPO framework, for example "inline this function at this call site".
Translating WebAssembly to Cretonne IR
This hasn't been built yet, by I expect there will be a
lib/wasmcrate which can translate binary WebAssembly to Cretonne IR. Again, since Cretonne is supposed to support concurrent compilation without imposing a way of managing threads, this crate should support translating wasm functions individually.Translating Cretonne IR to WebAssembly
This is an interesting idea that I didn't consider initially, but I think it could work.
A subset of the Cretonne instruction set is equivalent to WebAssembly and can be translated easily. A larger subset of the instructions could be transformed into wasm-equivalent instructions using the legalizer framework.
Some instructions are too low-level to be translated to WebAssembly. This includes raw loads and stores (as opposed to
heap_loadandheap_store) and things like taking the address of a stack slot. When LLVM is translating C/C++ to WebAssembly, it deals with these things by sandboxing. It maps loads and stores to the wasm heap and moves stacks objects to a shadow stack in the heap if their address escapes.JIT vs AOT compilation
I see three tiers on the AOT-JIT scale:
Cretonne is initially targeting 2. as a second-tier WebAssembly compiler for Firefox. I imagine its scope expanding in both directions.