Hi, I’m looking for a way to emit the entire Mojo source file as LLVM IR.
Currently, compile_info() only exposes the LLVM IR for individual Mojo functions, but this is not sufficient for performing full optimization when linking with LLVM IR generated from other languages (e.g., C/C++, Rust, etc.).
For complete, whole-program optimization, having access to the full IR is essential.
As far as I understand, under the current implementation, even the main function cannot be compiled into LLVM IR as a whole. Because of this, it’s currently not possible to call external functions (already compiled into LLVM IR) from Mojo code in a unified LLVM-level optimization context.
Is there any method or workaround at this stage to generate a full .ll or .bc output from a Mojo module and enable integration with external LLVM-compiled code?
I’d appreciate any guidance or suggestions.
Thank you!
Hey everyone, I’m Rob Parolin, an Engineering Manager at Modular working on the Tools team. I wanted to share that we’ve added a new argument to the mojo build command: --emit-llvm. This argument does two things—it dumps the LLVM IR of the specified mojo file to stdout, and it writes the LLVM IR to an .ll file in the same directory with the same filename as the mojo file.
This feature is expected to be included in the next nightly release. Please reach out if you have any questions or comments. Enjoy!
> mojo build --help
mojo-build — Builds an executable from a Mojo file.
SYNOPSIS
mojo build [options] <path>
<snipped>
--emit-llvm
Whether to emit LLVM IR. Defaults to false.
Thank you so much, Rob!
This is exactly the feature I was hoping for—and it’s a fantastic improvement for LLVM-based workflows.
I really appreciate the amazing work your team is doing on this project. Looking forward to trying it out in the next nightly!