Skip to main content

Crate nova_codegen_llvm

Crate nova_codegen_llvm 

Source
Expand description

LLVM codegen backend for Nova — the optimizing release backend.

Rather than link against llvm-sys/inkwell (which would require a matching LLVM installed at build time), this backend emits textual LLVM IR (.ll) from monomorphized MIR. nova build --release writes the IR and hands it to a discovered LLVM toolchain (clang/llc) for optimizing compilation, reusing the existing native linker path for the final executable. The IR requires LLVM >= 15 (opaque pointers).

The emitted code mirrors the Cranelift backend’s semantics exactly — the same 8-byte-slot heap layouts (sum { tag, fields… }, record { fields… }, array { len, elems… }, closure fat pointer { code, env }), the same env-first indirect-call ABI, and the same nova_rt_* runtime — so a program behaves identically under nova run, debug nova build, and nova build --release.

MIR temps are not SSA (they are reassigned across blocks, e.g. loop counters), so each temp becomes an entry-block alloca with load/store at every use/def. LLVM’s mem2reg promotes these to SSA registers with phis during optimization, keeping this emitter simple and obviously correct.

Constants§

NOVA_ENTRY_SYMBOL
The symbol the MIR main is emitted under, leaving the conventional main name for the exported C entry wrapper (matching the Cranelift object path).

Functions§

compile_ir
Compile a monomorphized MIR module to a textual LLVM IR module.