6  Dialect

A dialect is a named extension of MLIR’s vocabulary. It owns operations, types, attributes, parsing, verification, and a coherent abstraction such as structured linear algebra, GPU execution, hardware circuits, or target code.

6.1 A Dialect Is A Semantic Contract

Prefixes such as arith, tensor, and scf are not cosmetic namespaces. They identify different semantic models and implementation owners. Dialects can coexist in one function because they share core operation/value/region infrastructure, not because their operations are interchangeable.

A dialect registers generated operation classes, custom types and attributes, interfaces, parsers, and optional hooks with an MLIRContext. Its operation definitions normally use ODS/TableGen to declare structural fields; dialect C++ code supplies semantics that cannot be expressed declaratively.

6.2 Registration Is A Tool Dependency

Textual IR is understood only when the consuming tool has registered the dialect. A DialectRegistry is applied to an MLIRContext, while passes declare the dialects they construct or depend on. An unregistered-dialect error often means the tool lacks a linked registration, not that the IR spelling is wrong.

Generic passes can traverse all operations and query shared interfaces, but they must not assume identical behavior. A tensor extract reads a value-like tensor; a memref load reads mutable storage. Their printed shape may look similar, but aliasing and effects make their transformation rules different.

6.3 Dialects Form A Pipeline Vocabulary

A compiler often moves from source or model dialects through tensors and structured computation, then loops, memory, vectors, and control flow, then a target dialect. This is not a fixed ladder. The right lowering boundary is where the current vocabulary no longer carries information a later optimization needs, or where the next consumer requires a different representation.

6.4 Designing Extensions

Create a dialect when operations share a genuine semantic model, need common types or attributes, or require a clear conversion boundary. Specify effects, invariants, and intended lowering before adding patterns. A dialect that hides essential facts in opaque strings forces every pass to guess; one with precise verification and interfaces can participate safely in generic infrastructure.