Skip to main content
v2026.11,858 entries · CC-BY 4.0

MLIR (Multi-Level Intermediate Representation): What It Is and How to Build It

MLIR is LLVM’s Multi-Level Intermediate Representation framework: what it is, how it differs from LLVM, and how to build and test it.

Written and maintained by CASRAI Editorial Board

Last updated

MLIR stands for Multi-Level Intermediate Representation. It is an open-source compiler infrastructure inside the LLVM Project, not a programming language: it gives compiler authors a common way to define their own intermediate representations (called dialects) and to transform code between them. This page is for researchers and research-software engineers who meet MLIR in a machine-learning, high-performance-computing or domain-specific-language project and need to know what it is, how it differs from LLVM, and how to build it from source. Facts below come from the MLIR and LLVM project sites and the original paper, read 2026-11-07.

What does MLIR stand for?

The MLIR rationale document says its authors prefer Multi-Level IR, and it lists other readings people have offered: Multi-dimensional Loop IR, Machine Learning IR and Mid Level IR. The project site’s tagline is “Multi-Level IR Compiler Framework”. The first published description is the 2020 paper MLIR: A Compiler Infrastructure for the End of Moore’s Law (arXiv:2002.11054).

Is MLIR a language?

No. MLIR is an intermediate representation (IR) and compiler framework. Programs written in a source language are lowered into MLIR, optimised there, and then lowered further, for example towards LLVM IR. MLIR has a textual form that people read and write when testing compilers, but it is not what researchers normally write their application code in. The Toy tutorial on the MLIR site shows the full path: a small tensor-based language is compiled through MLIR step by step.

What is LLVM and what is it used for?

The LLVM Project describes itself as “a collection of modular and reusable compiler and toolchain technologies”. Subprojects include the Clang C/C++ compiler, the LLDB debugger, the libc++ standard library and the LLD linker. The name is historical: LLVM states that, despite it, the project has little to do with traditional virtual machines. LLVM began at the University of Illinois and is licensed under Apache 2.0 with LLVM exceptions. Research groups use it as a back end for building compilers, static-analysis tools and code generators. MLIR is one of the projects in the LLVM repository, which is why its build starts from the LLVM source tree.

What is the difference between LLVM and MLIR?

LLVM is the whole compiler-technology project; LLVM IR is its single, fixed intermediate representation. MLIR is a framework, inside that project, for defining many representations. The MLIR rationale says MLIR is “an open system” designed to support modular and pluggable dialects, and that its IR has similarities to the three-address static-single-assignment (SSA) form used by LLVM IR.

Aspect LLVM IR MLIR
Extensibility One fixed instruction set Modular, pluggable dialects
SSA form Three-address SSA Similar to three-address SSA
Control-flow merging PHI instructions Block arguments instead of PHI
Loop concepts Lowered form Polyhedral loop concepts are first-class

Source: MLIR Rationale document, mlir.llvm.org/docs/Rationale/Rationale, read 2026-11-07.

What it is used for in research

The paper’s stated aims are to reduce software fragmentation, improve compilation for heterogeneous hardware, cut the cost of building domain-specific compilers, and help connect existing compilers. In practice a research group builds a dialect for its domain, such as tensor operations, and reuses shared infrastructure for parsing, transformation and lowering instead of writing a compiler from scratch. The dialects listed in the official Toy tutorial sidebar include arith, linalg and tensor. Results that depend on compiled code are easier to reproduce when the exact compiler version is recorded; see computational reproducibility and reproducibility infrastructure. Groups that maintain such tooling often rely on research software engineers, and MLIR is open-source software. For a machine-learning framework in the same space, see what TensorFlow is.

Install or access (official source only)

MLIR is built from the LLVM source repository at github.com/llvm/llvm-project; the official Getting Started page at mlir.llvm.org/getting_started is the reference. It assumes git, Ninja and a working C++ toolchain, and recommends installing clang and lld because they speed up the build (on Ubuntu, sudo apt-get install clang lld).

Step-by-step: build MLIR and run its tests

These are the Unix commands from the Getting Started page, read 2026-11-07. Run them in a shell.

  1. Clone the repository: git clone https://github.com/llvm/llvm-project.git
  2. Create and enter a build directory: mkdir llvm-project/build then cd llvm-project/build
  3. Configure with CMake and Ninja: cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_BUILD_EXAMPLES=ON -DLLVM_TARGETS_TO_BUILD="Native;NVPTX;AMDGPU" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON
  4. Optionally speed up the build by adding the documented clang and lld flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON
  5. Build and run the test suite: cmake --build . --target check-mlir

On Windows the same page gives a Visual Studio generator command and uses the target tools/mlir/test/check-mlir; copy it from the page, since generator names change between Visual Studio versions.

Output and how to read it

The check-mlir target builds what the tests need and then runs the MLIR test suite. A run in which every test passes confirms that your build works; any failing test is reported by name in the build output, and that name is what to include in a bug report. The LLVM_BUILD_EXAMPLES=ON option additionally builds the project’s example programs. LLVM_TARGETS_TO_BUILD selects code-generation back ends: “Native” is your own machine, NVPTX targets NVIDIA GPUs and AMDGPU targets AMD GPUs.

Troubleshooting

  • The build is very slow. The documentation recommends clang and lld for faster builds; use the flags in step 4.
  • You need to debug MLIR itself. The page says to use -DCMAKE_BUILD_TYPE=Debug or -DCMAKE_BUILD_TYPE=RelWithDebInfo if you need debug info.
  • CMake cannot find a toolchain. The documented prerequisites are git, Ninja and a working C++ toolchain; install those before configuring.

Free alternatives

Option What it is Licence
MLIR Framework for defining and transforming multiple IRs, part of LLVM Apache 2.0 with LLVM exceptions (LLVM Project licence)
LLVM IR directly The single fixed IR of the LLVM Project, without dialects Apache 2.0 with LLVM exceptions

If your project only needs a conventional low-level IR, LLVM IR alone is enough; MLIR becomes relevant when you need higher-level, domain-specific representations before reaching LLVM IR.

Frequently asked questions

What does MLIR stand for?

Multi-Level Intermediate Representation, the reading preferred by its authors in the project’s rationale document.

What is the difference between LLVM and MLIR?

LLVM is the umbrella compiler project with one fixed IR; MLIR is a framework within it for pluggable, multi-level dialects.

Is MLIR a language?

No, it is an intermediate representation and compiler framework.

What is LLVM and what is it used for?

A collection of modular, reusable compiler and toolchain technologies, including Clang, LLDB, libc++ and LLD.

Sources (official docs)

  • MLIR Getting Started, mlir.llvm.org/getting_started, read 2026-11-07
  • MLIR Rationale, mlir.llvm.org/docs/Rationale/Rationale, read 2026-11-07
  • MLIR Toy tutorial, Chapter 1, mlir.llvm.org/docs/Tutorials/Toy/Ch-1, read 2026-11-07
  • The LLVM Project, llvm.org, read 2026-11-07
  • Lattner et al., MLIR: A Compiler Infrastructure for the End of Moore’s Law, arXiv:2002.11054 (2020)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about MLIR (Multi-Level Intermediate Representation): What It Is and How to Build It

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →