Skip to content

Add LLVM-targeting compiler backend and SIMD matrix support#287

Closed
cmontella wants to merge 2 commits intov0.3-betafrom
codex/add-llvm-compiler-support-for-simd-matrices
Closed

Add LLVM-targeting compiler backend and SIMD matrix support#287
cmontella wants to merge 2 commits intov0.3-betafrom
codex/add-llvm-compiler-support-for-simd-matrices

Conversation

@cmontella
Copy link
Copy Markdown
Member

Motivation

  • Provide a new compiler pipeline that parses Mech source, runs it through the existing bytecode interpreter, and lowers bytecode to LLVM IR text for downstream codegen or inspection.
  • Introduce a SIMD-friendly dense f32 matrix type to enable AVX-accelerated kernels for matrix operations when the target supports it.
  • Expose the compiler behind a compiler feature so the compiler surface is opt-in for consumers.

Description

  • Add src/compiler/mod.rs which implements LlvmCompiler, CompilerConfig, OptLevel, CompiledModule, and CompilerError, and a simple lowering from ParsedProgram bytecode to LLVM IR text via lower_bytecode_to_llvm_ir.
  • Integrate with the existing Mech pipeline by invoking mech_interpreter::Interpreter to interpret and compile a Program into bytecode and ParsedProgram before lowering.
  • Add src/compiler/simd.rs which defines MatrixF32 and an add implementation that dispatches to an AVX-optimized add_avx on x86_64 when avx is detected, with a portable fallback.
  • Update src/lib.rs to conditionally expose the compiler module with #[cfg(feature = "compiler")] and add unit tests for the compiler pipeline and matrix addition.

Testing

  • Ran the crate unit tests for the new compiler feature with cargo test --features compiler, which executed compile_source_uses_mech_pipeline and matrix_add_works and reported success.
  • Verified the new unit tests assert non-empty bytecode and LLVM IR patterns and correct matrix addition behavior, and they passed.

Codex Task

@cmontella cmontella closed this Apr 14, 2026
@cmontella cmontella deleted the codex/add-llvm-compiler-support-for-simd-matrices branch April 14, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant