Design compilers and DSLs that reach real hardware with predictable performance and readable IR.
Many projects need more than library level tuning, they need control over kernels, memory, and code generation. This book shows how to use MLIR and Mojo to express intent clearly, verify it with tests and invariants, and lower it to LLVM, NVPTX, and AMDGPU without guesswork.
Across focused chapters you build a practical workflow, write and test IR, author patterns and passes, design types and attributes, plan bufferization to avoid copies, and integrate with Mojo through clean C ABI hooks and sys.ffi. You finish with end to end projects that prove results on real devices.
Adopt a working MLIR mental model, SSA values, regions, blocks, types, attributes, dialect boundaries, and canonicalization.Use mlir opt pipelines, FileCheck and lit tests, dumpers and translators to inspect IR at each stage and catch regressions early.Express control and math with scf, affine, and linalg, then lower through the vector dialect with transfers, contracts, rank reduction, and mask strategies that preserve speed.Apply one shot bufferize, allocation placement, alias analysis, and in place updates to avoid unnecessary copies.Target GPUs with the gpu dialect, nvgpu and NVVM for tensor core fragments, and the SPIR V path for portable device code.Encode schedules with the transform dialect, keep them resilient across compiler versions, and attach metrics and checks in CI.Author patterns with PDLL and ODS in TableGen, add mixed declarative and C plus plus rewrites, and assemble reliable pass pipelines.Engineer memory layouts, tiling and blocking for cache locality, vector friendly strides, and shared memory without bank conflicts.Generate code for real targets, LLVM triples, NVPTX with PTX versioning and flags, and AMDGPU code objects with correct linking and loader notes.Integrate with Mojo, export C ABI bridges, call C or C plus plus through sys.ffi, and map Mojo parameters and generics to specialization in IR.Validate correctness with a reference interpreter, differential testing against a baseline, and IR verification with well stated invariants.Complete projects, a custom attention op lowered to tensor cores and profiled, a time series feature DSL with vectorized lowering, and a MAX custom op packaged from MLIR generated Mojo code with a release kit for benchmarks and profiler captures.This is a code heavy guide. You get working MLIR files, pass pipelines, PDLL patterns, TableGen definitions, C and C plus plus hooks, and Mojo snippets that connect the pieces so you can build real systems.
Start building the compilers and DSLs you need, buy this book today.