13a799deeSJacques Pienaar# Toy Tutorial 23a799deeSJacques Pienaar 33a799deeSJacques PienaarThis tutorial runs through the implementation of a basic toy language on top of 43a799deeSJacques PienaarMLIR. The goal of this tutorial is to introduce the concepts of MLIR; in 5*31d1ae79SMarkus Böckparticular, how [dialects](../../LangRef.md/#dialects) can help easily support 63a799deeSJacques Pienaarlanguage specific constructs and transformations while still offering an easy 73a799deeSJacques Pienaarpath to lower to LLVM or other codegen infrastructure. This tutorial is based on 83a799deeSJacques Pienaarthe model of the 93a799deeSJacques Pienaar[LLVM Kaleidoscope Tutorial](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index.html). 103a799deeSJacques Pienaar 110453d2ddSMehdi AminiAnother good source of introduction is the online [recording](https://www.youtube.com/watch?v=Y4SvqTtOIDk) 120453d2ddSMehdi Aminifrom the 2020 LLVM Dev Conference ([slides](https://llvm.org/devmtg/2020-09/slides/MLIR_Tutorial.pdf)). 130453d2ddSMehdi Amini 143a799deeSJacques PienaarThis tutorial assumes you have cloned and built MLIR; if you have not yet done 153a799deeSJacques Pienaarso, see 16*31d1ae79SMarkus Böck[Getting started with MLIR](../../../getting_started/). 173a799deeSJacques Pienaar 183a799deeSJacques PienaarThis tutorial is divided in the following chapters: 193a799deeSJacques Pienaar 203a799deeSJacques Pienaar- [Chapter #1](Ch-1.md): Introduction to the Toy language and the definition 213a799deeSJacques Pienaar of its AST. 223a799deeSJacques Pienaar- [Chapter #2](Ch-2.md): Traversing the AST to emit a dialect in MLIR, 233a799deeSJacques Pienaar introducing base MLIR concepts. Here we show how to start attaching 243a799deeSJacques Pienaar semantics to our custom operations in MLIR. 253a799deeSJacques Pienaar- [Chapter #3](Ch-3.md): High-level language-specific optimization using 263a799deeSJacques Pienaar pattern rewriting system. 273a799deeSJacques Pienaar- [Chapter #4](Ch-4.md): Writing generic dialect-independent transformations 283a799deeSJacques Pienaar with Interfaces. Here we will show how to plug dialect specific information 293a799deeSJacques Pienaar into generic transformations like shape inference and inlining. 303a799deeSJacques Pienaar- [Chapter #5](Ch-5.md): Partially lowering to lower-level dialects. We'll 313a799deeSJacques Pienaar convert some of our high level language specific semantics towards a generic 323a799deeSJacques Pienaar affine oriented dialect for optimization. 333a799deeSJacques Pienaar- [Chapter #6](Ch-6.md): Lowering to LLVM and code generation. Here we'll 343a799deeSJacques Pienaar target LLVM IR for code generation, and detail more of the lowering 353a799deeSJacques Pienaar framework. 363a799deeSJacques Pienaar- [Chapter #7](Ch-7.md): Extending Toy: Adding support for a composite type. 373a799deeSJacques Pienaar We'll demonstrate how to add a custom type to MLIR, and how it fits in the 383a799deeSJacques Pienaar existing pipeline. 393a799deeSJacques Pienaar 403a799deeSJacques PienaarThe [first chapter](Ch-1.md) will introduce the Toy language and AST. 41