A compiler is a series of translations, and each translation throws information away. The art of compiler design is deciding what to keep until the last possible moment. Two frameworks approach that decision differently, and the gap shows up most clearly when the input is a machine learning model rather than an ordinary program.
LLVM IR represents a program at one carefully chosen level of abstraction, while MLIR lets a compiler hold many levels at once and lower them gradually, so high-level intent survives longer.
Part One: One level versus many
LLVM IR is a single, well-defined intermediate representation. It is close enough to machine code to be optimised aggressively, yet abstract enough to be shared by many source languages. A front end lowers source code into LLVM IR, a long list of passes improves it, and a back end emits machine code. The strength of this design is its clarity: one representation, one set of passes, one target.
MLIR grows out of a different observation. A modern compiler often needs several intermediate forms: one for a tensor computation, one for a loop nest, one for a vector operation, and finally one close to machine code. Keeping all of them in a single flat representation forces early decisions. MLIR lets each level be a dialect, a set of operations with its own semantics, and provides a standard way to convert one dialect into another.
Part Two: What information survives
A tensor operation lowered too early into scalar loops loses the fact that it was a matrix multiply, and with it the chance to use a specialised accelerator instruction that would have made the whole operation far cheaper.
That loss is the problem MLIR is built to solve. A compiler can keep a computation as a tensor operation through several optimisation passes, apply transformations that are only meaningful at that level, and only then lower it into loops. By contrast, a traditional LLVM pipeline receives code already lowered, so any optimisation that needs the original structure must have happened earlier, often in a front end with limited visibility.
Both systems share ideas. MLIR uses LLVM's infrastructure in many places and can lower into LLVM IR as a final step, which means the two are often collaborators rather than rivals. The distinction is about where the compiler chooses to preserve meaning and how easily a new level can be added without redesigning everything around it.
Part Three: A concrete example
Consider a program that multiplies a large matrix on a laptop with both a CPU and a graphics processor. In a single-level pipeline, the front end must decide early which device to use, and that decision is hard to reverse. In a multi-level pipeline, the compiler can reason about the tensor operation, tile it for the chosen device, vectorise the inner loops, and only at the end emit code. Each stage keeps the options that still matter.
This is why hardware teams adopted MLIR quickly. A new accelerator needs its own dialect and a set of conversions, but it does not require rewriting the front end or abandoning existing optimisations. The cost is a steeper learning curve: a compiler built from many dialects has more moving parts, and a conversion path that is incomplete will fail in ways that are hard to diagnose.
Part Four: Choosing a level of abstraction
For a language with a straightforward mapping to machine code, a single mature intermediate representation is efficient and well understood. The tooling is stable, the pass infrastructure is rich, and most engineers can reason about the whole pipeline. Adding abstraction layers without a concrete need mostly adds complexity.
For workloads with several legitimate target levels, such as machine learning, scientific computing or custom hardware, preserving structure pays off. The optimisation opportunities that live between a high-level operation and a loop nest are too valuable to discard early. That is the space MLIR was designed for, and it explains its rapid adoption there.
A useful everyday analogy is a recipe. A cook who translates a dish into a list of individual muscle movements at the start cannot later decide to change the pan; keeping the instruction at the level of steps preserves choices. Compilers are now following the same principle, holding ideas in their richest form until the machine makes the decision unavoidable.
The real difference is not which framework produces faster code today, but how long a compiler can afford to keep its options open before the target forces its hand.
Teams often find that the two coexist: a front end lowers into MLIR dialects where structure matters, then hands the remaining work to LLVM IR where the back end is strongest. That division plays to each system's strength and keeps the pipeline understandable.
As hardware grows more specialised, the number of useful abstraction levels keeps increasing. A compiler that can hold several at once is not a luxury in that world; it is the only practical way to reach all of them without rewriting the stack for every new device.
SOL: HCqPmPJM3NVtS6YrmVaTZYnuP8XZ2PFgQZKT94VK1LkS
Creating this takes real effort — thank you for the support.
Top comments (0)