Hi All,
I’m Anutosh, a core developer and contributor across clang/clang-repl and Project Jupyter—particularly JupyterLite and several Jupyter language kernels—and I currently work at QuantStack. Some of y’all might remember me from my talk at FOSDEM’s LLVM track on “Building Interactive C/C++ workflows in Jupyter through clang-repl” this Jan, 2026.
I would like to propose an upstream WebAssembly execution path for MLIR, together with the build support needed to use MLIR interactively from Python, C and C++ in a wasm32-unknown-emscripten process.
My prototypes run in JupyterLite, a distribution of JupyterLab that runs entirely in the browser, powered by WebAssembly. The language kernels, MLIR libraries, compiler pipeline, linker and generated programs all execute locally in the browser; no remote Python process or compiler service is involved.
I now have working prototypes in three JupyterLite kernels. From Python, C or C++23, users can construct or parse MLIR, run pass pipelines, inspect each lowering stage, compile an LLVM-dialect module into WebAssembly, dynamically load it and execute a resolved symbol.
The Python notebook is currently the most fully explored interface. It renders compiler graphs using an in-process WebAssembly build of Graphviz, a widely used graph-visualization toolkit, and passes the translated LLVM IR directly to llvmlite, the lightweight Python binding to LLVM used by Numba.
Here’s the demo for the same : https://youtu.be/ojzvWo7EgXI
(I had to upload it on Youtube because discourse won’t let me share a mp4
)
TL;DR
- MLIR can now run interactively inside the browser. MLIR has been built for
wasm32-unknown-emscripten, with the same packaged runtime exercised through Jupyter language kernels for Python, C and C++, all running entirely in the browser through JupyterLite. - The complete compilation and execution pipeline can run as WebAssembly. The execution engine translates MLIR to LLVM IR, emits a position-independent WebAssembly object, invokes an in-process WebAssembly build of LLD to link it into a shared WebAssembly module, loads that module with
dlopen, and resolves its exported C-interface symbols—all within the browser’s WebAssembly environment. - The execution engine is language-independent. The stable MLIR C API provides the boundary used by the C and C++ prototypes. The C++23 notebook adds RAII, exceptions and typed wrappers without depending on a fragile cross-module C++ ABI.
- The approach builds on established WebAssembly execution infrastructure. It extends the model previously developed by us (Vassil Vassilev, Anubhab Ghosh & Me) for Clang-Repl and closely related out-of-tree MLIR work by Maksim Levental in llvm/eudsl.
- The working implementation is ready to be divided into focused upstream patches. Feedback on the overall direction and API boundaries would be valuable during that process. Emscripten-based execution tests should also be feasible, following the existing approach used to build and run Clang-Repl’s interactive tests for WebAssembly.
Working notebook demoed above:
The same workflow has also been validated through C23 and C++23 Jupyter language kernels. Both prototypes load the packaged MLIR runtime, inspect the Linalg, Affine and LLVM-dialect stages, link the generated WebAssembly module using in-process LLD, and execute the compiled function—confirming that the execution path is not specific to Python. Shareable deployments of these notebooks remain packaging work in progress !
Here’s the demo for the C bindings : https://www.youtube.com/watch?v=FLrkBtuEr8s
Problem Statement
MLIR is particularly well suited to teaching and experimentation because an interesting compiler pipeline is not a single black-box invocation. A user may want to:
- construct or parse an operation;
- inspect the current dialect;
- apply one pass or a complete pass pipeline;
- inspect the transformed Intermediate Representation (IR);
- visualize control flow or operation structure;
- translate to LLVM IR;
- execute and validate the generated code.
Today, doing this generally requires a local LLVM/MLIR build or access to a server that owns one. MLIR offers C++, C and Python interfaces, but the native libraries and standard execution engine depend on facilities that are not directly available in an Emscripten browser process.
The goal is to make this complete learning and experimentation loop shareable as a notebook URL that runs locally in the reader’s browser—with no installation or remote compiler service required.
Motivation and prior work
From Clang-Repl to C++ in JupyterLite
This proposal follows a path that began in Clang-Repl.
Clang-Repl normally uses LLVM’s ORC JIT. For the browser, we added a different execution path: emit WebAssembly object files, link them into shared side modules and dynamically load each new module into the long-running process.
The initial support landed in llvm-project#86402, followed by fixes for shared Wasm binaries, browser execution, target creation, dynamic-library loading and temporary-file handling:
That work became the foundation for running xeus-cpp, Jupyter’s C & C++ kernels, completely inside JupyterLite. The browser can incrementally compile and execute C and C++ code and load libraries from the Emscripten ecosystem.
Examples:
- Basic C++ notebook
- Interactive ray tracing notebook
- FOSDEM 2026: Building Interactive C/C++ Workflows in Jupyter through
Clang-Repl
MLIR precedent in llvm/eudsl
Maksim Levental (@makslevental ) later applied the same model to MLIR in llvm/eudsl#248. That project lowers an MLIR LLVM-dialect module to a Wasm object, links a shared module and loads it in the browser, explicitly referencing Clang-Repl’s Wasm backend.
This is important prior art and I do not want to present the execution idea as new or independent of EUDSL. The opportunity here is to consolidate the common design and move the generally useful parts into upstream MLIR, while retaining runtime- or distribution-specific integration outside LLVM where appropriate.
Numba JIT & llvmlite
More recently, the Numba JIT compiler was brought to the browser and can now compile and execute Python and NumPy functions through a Jupyter Python kernel running entirely in JupyterLite. The implementation follows similar fundamental execution model explained above.
The complete story and technical background are described in my blog : Numba in the Browser: Unlocking a New Scientific Python Stack in JupyterLite.
Interactive demo : Numba and its downstream scientific Python ecosystem
This has already enabled browser-native experiments across a much broader scientific Python ecosystem: probabilistic programming and statistical modeling with PyTensor and PyMC, numerical interpolation with Interpolation․py, economic modeling with Dolo․py, and large-scale data visualization with Datashader. It demonstrates the broader opportunity: a reusable compiler foundation in JupyterLite can unlock entire scientific workflows rather than a single isolated demonstration. For eg : a DataShader example
The same runtime from Python, C and C++
The same packaged MLIR runtime has been exercised through Jupyter language kernels for Python, C and C++. In each case, users can parse MLIR, run lowering and optimization passes, inspect the intermediate representations, compile the LLVM-dialect result into WebAssembly, and execute the generated function inside the browser.
Python currently provides the most polished interface, but the underlying execution path is language-independent. The C and C++ notebooks access MLIR through its stable C API, avoiding dependence on a version-sensitive cross-module C++ ABI. This makes the reusable core an MLIR WebAssembly execution and dynamic-loading foundation rather than a Python-specific implementation
Proposal and current patch series
A working implementation is already available as a patch series in emscripten-forge. Think of emscripten-forge as Emscripten + conda-forge: a conda-forge-style ecosystem for building and distributing packages for the emscripten-wasm32 platform.
Emscripten-forge was created at QuantStack to support browser-native Jupyter environments. QuantStack originated JupyterLite and is deeply involved in the conda-forge ecosystem, but conda-forge does not currently target emscripten-wasm32. A separate package ecosystem was therefore needed for the compilers, runtimes and libraries used by JupyterLite.
Today, emscripten-forge powers browser-based Jupyter language kernels for Python, C, C++, R, OCaml, JavaScript, Fortran, Haskell among others. The C and C++ demonstrations above, for example, depend on WebAssembly builds of LLVM, Clang and LLD distributed through emscripten-forge. The same ecosystem now provides Graphviz, MLIR’s Python bindings, llvmlite, Numba and much of the scientific Python stack used in these demonstrations.
The current MLIR patches demonstrate a complete working workflow in this environment, while their final upstream APIs and boundaries remain open for discussion.
1. Building MLIR and its Python bindings for WebAssembly with Emscripten
The build system is adapted to cross-compile MLIR’s libraries, C API and composable Python bindings for wasm32-unknown-emscripten. This includes handling the target Python ABI, nanobind extension modules, WebAssembly shared libraries and symbol isolation between independently packaged LLVM-based modules.
Current patch: Emscripten and WebAssembly execution-engine CMake support
2. Providing a language-independent WebAssembly execution API
A public C API provides the core operations needed to compile an LLVM-dialect MLIR module, link the resulting WebAssembly object into a shared module, load it dynamically and resolve exported functions. This API is usable from C, C++ and Python bindings.
Current patches:
3. Exposing the execution engine to Python
A small nanobind module and Python wrapper expose compilation, dynamic loading and symbol lookup. The wrapper can also return translated LLVM IR, enabling inspection and composition with LLVM-based tools such as llvmlite.
Current patches:
4. Supporting target-sized MemRef descriptors
MLIR’s Python runtime helpers currently assume 64-bit fields for MemRef offsets, shapes and strides. Wasm32 lowering uses 32-bit index fields. The implementation makes the descriptor width explicit while preserving 64-bit behavior as the native default.
Current patch: Target-sized NumPy-to-MemRef descriptors
5. Visualizing MLIR pipelines in the browser
Interactive compiler environments benefit greatly from being able to inspect control-flow graphs and lowering pipelines. Helpers such as show_cfg and show_dot provide this workflow directly inside the notebook.
The standard Python Graphviz workflow launches the external dot executable through a subprocess. Browser-based Emscripten environments do not provide conventional process creation, so this approach cannot be used in JupyterLite. Instead, DOT rendering uses Graphviz compiled to WebAssembly and invoked in-process through its C API, without launching a subprocess.
One possible upstream direction is to expose DOT generated by MLIR’s existing operation-graph infrastructure and leave the choice of rendering mechanism to the frontend.
Current patch: MLIR graph and in-process Graphviz helpers
6. Loading packaged MLIR libraries in Emscripten
The Python package initializer preloads the MLIR shared libraries before importing extension modules. It accounts for how Emscripten’s dynamic loader resolves dependency names and ensures that the libraries are available through the global dynamic-symbol table.
This may ultimately remain a distribution-level concern rather than becoming part of upstream MLIR.
Current patch: Emscripten shared-library preloader
7. Testing the WebAssembly workflow
The upstream work should include focused tests for parsing and transforming MLIR, repeated in-process linking, scalar and MemRef execution, dynamic module loading and symbol resolution. Clang-Repl already builds and runs interactive tests under Emscripten, providing a useful precedent for testing this workflow.
The existing package tests exercise the composable Python bindings, WebAssembly execution engine, target-sized MemRef descriptors and in-process Graphviz integration.
Current tests: Emscripten MLIR package tests
NOTE : These patches should be treated as evidence of a working end-to-end implementation, not as a requirement that every downstream detail be upstreamed unchanged. The purpose of this RFC is to agree on the reusable boundaries and then submit the work as small, independently reviewable changes.
Discussion
i) Why not Compiler Explorer?
This proposal is complementary to Compiler Explorer, not a replacement for it.
Compiler Explorer offers broad access to many compilers, versions and targets through remote native processes. This proposal explores a narrower but deeper, entirely client-side workflow.
In JupyterLite, MLIR, its pass manager, the WebAssembly build of LLD and the generated code all run inside the browser. Users can modify lowering pipelines, inspect each intermediate representation, execute the result and share the complete experiment as a notebook URL.
The workflow goes all the way from high-level MLIR dialects to LLVM IR and finally to identifiable WebAssembly modules such as mlir_conv_bias_relu_o0.wasm, making every stage available for inspection. The screenshot below shows the generated module loaded by the browser after passing through the MLIR WebAssembly execution engine.
The trade-off is clear: Compiler Explorer supports far more toolchains; a JupyterLite MLIR environment offers a zero-install, executable compiler laboratory.
This direction was partly inspired by educational projects such as llvm-tutor and
MLIR’s Toy tutorial. I first shared the prototype with Andrzej Warzynski ( @banach-space ) because an “mlir-tutor in the browser” felt like a natural teaching use case. His initial questions about Compiler Explorer, lowering paths and performance helped shape this RFC.
ii) Performance: What the current result means
The combined demonstration implements a fixed Conv2D + bias + ReLU kernel, lowers it through MLIR and then optionally optimizes the translated LLVM IR with llvmlite.
In the recorded browser run, the target-aware O3 variant is approximately:
- about 60× faster than a pedagogical NumPy reference that performs the outer
traversal in Python and launches many tiny operations; and - about 1.8× faster than a vectorized NumPy reference based on sliding windows
andeinsum.
Both results are reported because the first number is largely about removing Python interpreter and dispatch overhead; it must not be read as a general claim that “MLIR is 60× faster than NumPy”. The exact result is specific to the kernel, shapes, browser, target features and pass pipeline. The notebook checks matching outputs and records both compile time and warm-kernel timing.
The educational notebook currently shows more than one lowering route. Its Affine route follows the progressive style of Stephen Diehl’s MLIR memory tutorial, but I do not propose it as the one canonical production pipeline. A browser notebook is useful precisely because users can compare Linalg-to-SCF/CF lowering, Affine-based teaching paths and, later, Transform dialect or vectorized paths.
iii) Relationship to Numba-MLIR
The 2023 MLIR Open Meeting presentation on Numba-MLIR described a pipeline that reused Numba’s frontend and type inference, lowered Numba IR through project-specific MLIR dialects, and targeted CPUs and GPUs.
That project is no longer actively maintained, but it remains useful prior art. Now that Numba itself runs in JupyterLite, a future experiment could connect Numba IR to an MLIR lowering path and make the intermediate dialects inspectable in the same browser notebook. This is not part of the first RFC; it is an example of what a maintained, upstream MLIR WebAssembly foundation could enable.
iv) Possible follow-up work
The initial proposal focuses on establishing a reusable MLIR WebAssembly compilation and execution foundation. Once that foundation is available, several useful directions become possible.
A natural next step would be to bring the complete MLIR Toy tutorial to JupyterLite. Each chapter could become an executable, zero-install notebook in which readers inspect the dialects, modify passes and run the resulting program directly in the browser.
GPU execution is another promising direction. Recent EUDSL WebGPU work demonstrates a path from MLIR through SPIR-V and WGSL to WebGPU. Integrating such a workflow with JupyterLite would require additional browser-runtime and buffer-management work, so it is better explored independently after the CPU execution path is established.
Upstream MLIR’s emerging WasmSSA dialect also creates a complementary browser-native use case: importing existing WebAssembly binaries, inspecting their structured representation and raising them into standard MLIR dialects interactively in JupyterLite.
Longer term, projects such as WAMI suggest that a direct MLIR-to-WebAssembly lowering path could complement the LLVM-based execution path described here.
Other follow-up experiments could include WebAssembly SIMD128 lowering, Transform-dialect workflows, richer upstream graph export and connections to compiler frontends that already use MLIR. These are possible applications of the proposed foundation rather than requirements for the initial upstream work.
Next steps
The implementation is working end to end, and the next step is to split it into small, independently reviewable upstream patches. The existing emscripten-forge patch series provides a concrete starting point, while leaving room to refine the API boundaries, native-platform compatibility and testing strategy during review.
I would be happy to drive this upstreaming effort and work with the relevant MLIR maintainers and contributors throughout the process. The immediate goal is not to prescribe every final API, but to establish a shared upstream foundation for compiling, inspecting and executing MLIR through WebAssembly.
cc @stellaraccident , @mehdi_amini , @ftynse , @makslevental , @rolfmorel — given your work on MLIR’s Python bindings, C API, execution infrastructure and compiler education, your feedback on the overall direction and guidance during upstreaming would be greatly appreciated.
Any comments, concerns or suggestions are welcome!
Thanks,
Anutosh Bhat.

