A comprehensive tutorial series for learning MLIR (Multi-Level Intermediate Representation), with first-class support for Windows, Linux, and macOS.
Based on: Jeremy Kun's MLIR tutorial series
This fork simplifies the original tutorial by:
- Removing the or-tools dependency (2100+ build targets eliminated!)
- Fast Windows setup using MSYS2 prebuilt MLIR libraries
- Under 30 minutes from install to working build
- Beginner-friendly documentation with clear setup instructions
# Using winget (recommended)
winget install --id MSYS2.MSYS2
# Or download from: https://www.msys2.org/Open MSYS2 MSYS terminal and run:
# Update package database
pacman -Syu
# Install CLANG64 toolchain and MLIR (prebuilt)
pacman -S --needed \
mingw-w64-clang-x86_64-toolchain \
mingw-w64-clang-x86_64-cmake \
mingw-w64-clang-x86_64-ninja \
mingw-w64-clang-x86_64-mlir \
mingw-w64-clang-x86_64-llvmOpen MSYS2 CLANG64 terminal (find it in Start menu), then:
# Clone the repository
git clone https://github.com/j2kun/mlir-tutorial.git
cd mlir-tutorial
# Build (takes 2-5 minutes)
./scripts/build-windows.ps1
# Test it works
./cmake-build/tools/tutorial-opt.exe --helpThat's it! You're ready to start learning MLIR.
π Detailed Windows setup: See Windows Build Guide
# Install dependencies (Ubuntu/Debian)
sudo apt install build-essential cmake ninja-build llvm-dev mlir-tools libmlir-dev
# Clone and build
git clone https://github.com/speakeztech/mlir-tutorial.git
cd mlir-tutorial
mkdir build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
ninja
# Test it works
./tools/tutorial-opt --help# Install dependencies
brew install llvm cmake ninja
# Clone and build
git clone https://github.com/j2kun/mlir-tutorial.git
cd mlir-tutorial
mkdir build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DLLVM_DIR=$(brew --prefix llvm)/lib/cmake/llvm \
-DMLIR_DIR=$(brew --prefix llvm)/lib/cmake/mlir \
..
ninja
# Test it works
./tools/tutorial-opt --helpThis repository includes 13 complete tutorials that progressively teach MLIR concepts, from basics to advanced compiler features.
- Getting Started - Setup, building, first MLIR program
- Running and Testing a Lowering - lit/FileCheck testing, dialects, progressive lowering
- Writing Your First Pass - Pattern rewriting, IR walking, debugging passes
- Using Tablegen for Passes - TableGen basics,
.tdfiles, build integration
- Defining a New Dialect - Dialect architecture, types, operations, TableGen definitions
- Using Traits - Operation traits, optimization enablement, memory effects
- Folders and Constant Propagation - Constant folding, materializers, SCCP pass
- Verifiers - Verification architecture, custom verifiers, error messages
- Canonicalizers and Declarative Rewrite Patterns - DRR patterns, constraints, pattern benefits
- Dialect Conversion - Systematic conversion, type converters, materialization
- Lowering through LLVM - Complete lowering pipeline, JIT compilation, code generation
- Dataflow Analysis - Analysis framework, lattices, custom analyses
- Defining Patterns with PDLL - Pattern Description Language, advanced pattern features
β Start Learning: Tutorial 01: Getting Started
Time to Complete: ~20-30 hours for all tutorials (2-3 hours each)
Original tutorial: Used or-tools library for integer linear programming in Tutorial 12
- Added 2100+ build targets
- Required complex dependencies (SCIP, HiGHS, glpk, etc.)
- Long compilation times
This fork: Replaced with simple greedy algorithm
- Teaches the same MLIR concepts (dataflow analysis, lattices)
- Eliminates dependency complexity
- Much faster builds
- Uses MSYS2 CLANG64 with prebuilt MLIR libraries
- No multi-hour LLVM compilation required
- Fast setup: under 30 minutes from install to working build
- Windows Build Guide - Complete Windows setup with MSYS2 CLANG64
- Tutorial Completion Summary - Overview of all completed tutorials
# Build
.\scripts\build-windows.ps1
# Clean build
.\scripts\build-windows.ps1 -Clean
# Release build
.\scripts\build-windows.ps1 -BuildType Release
# Run tutorial-opt
.\cmake-build\tools\tutorial-opt.exe --help
.\cmake-build\tools\tutorial-opt.exe .\tests\poly_syntax.mlir --canonicalize# Build
cd build && ninja
# Clean build
rm -rf build && mkdir build && cd build && cmake -G Ninja .. && ninja
# Run tutorial-opt
./tools/tutorial-opt --help
./tools/tutorial-opt ../tests/poly_syntax.mlir --canonicalize-
Install extensions:
- C/C++ by Microsoft
- CMake Tools by Microsoft
- MLIR by LLVM Foundation
-
Open the repository folder in VS Code
-
Configure CMake (Ctrl+Shift+P β "CMake: Configure")
- Open the repository as a CMake project
- CLion will automatically detect CMakeLists.txt
- Select build configuration and build
mlir-tutorial/
βββ docs/
β βββ tutorials/ # 13 complete MLIR tutorials
β βββ WINDOWS_BUILD_GUIDE.md
βββ lib/
β βββ Dialect/ # Custom dialects (Poly, Noisy)
β βββ Transform/ # Custom transformation passes
β βββ Conversion/ # Dialect conversion passes
β βββ Analysis/ # Dataflow analyses
βββ tools/
β βββ tutorial-opt.cpp # Main compiler driver
βββ tests/ # lit/FileCheck tests
βββ scripts/
β βββ build-windows.ps1 # Windows build script
βββ CMakeLists.txt # CMake configuration
This fork focuses on simplifying the learning experience. Contributions welcome for:
- Tutorial improvements
- Documentation clarity
- Build system enhancements
- Cross-platform compatibility
Apache 2.0 with LLVM Exceptions (same as upstream LLVM/MLIR)
- Jeremy Kun for the original MLIR tutorial series
- LLVM Foundation for MLIR and documentation
- All contributors to the original repository
- Windows build issues: See Windows Build Guide
- MLIR questions: MLIR Discourse
- Project issues: GitHub Issues
Happy hacking with MLIR! π