They are identified by a name – that must be unique within the dialect they belong to – and have optional operands, results, attributes and regions.
[11] The following code defines a function that takes two floating point matrices and performs the sum between the values at the same positions: Different dialects may be used to achieve the same result, and each of them may imply different levels of abstraction.
Its purpose is to provide a one-to-one map of LLVM-IR – the intermediate representation used by LLVM – in order to enable the reuse all of its middle-end and backend transformations, including machine code generation.
[14] The autogenerated code can include parsing and printing methods – which are based on a simple string mapping the structure of desired textual representation – together with all the boilerplate code for accessing fields and perform common actions such verification of the semantics of each operation, canonicalization or folding.
[15] The following example illustrates how to specify the assembly format of an operation expecting a variadic number of operands and producing zero results.
Each driver receives a set of objects named patterns, each of which has its own internal logic to match operations with certain properties.
Considering the example about the sum of matrices, a possible lowering strategy may be to generate for-loops belonging to the scf dialect, obtaining code to be executed on CPUs: Another possible strategy, however, could have been to use the gpu dialect to generate code for GPUs: The driver greedily applies the provided patterns according to their benefit, until a fixed point is reached or the maximum number of iterations is reached.
[16] MLIR allows to apply existing optimizations (e.g., common subexpression elimination, loop-invariant code motion) on custom dialects by means of traits and interfaces.
This includes traditional programming languages,[20] but also high-level synthesis,[21][22] quantum computing[23] and homomorphic encryption.
[24][25][26] Machine learning applications also take advantage of built-in polyhedral compilation techniques, together with dialects targeting accelerators and other heterogeneous systems.