MLIR (Multi-Level Intermediate Representation) is a modular compiler infrastructure developed within the LLVM project.
It allows representing and transforming programs at multiple abstraction levels, using an extensible architecture made of dialects.
In many projects, it is necessary to define custom operations, types, and transformation rules. This is done by creating a custom MLIR dialect.
There are two main ways to develop an MLIR dialect:
arith
, math
, or linalg
dialects).The out-of-tree approach is the most flexible for independent projects.
It allows:
This tutorial will guide you step by step through:
arith
, math
).lit
and mlir-opt
.This tutorial is up to date for LLVM 22.