You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The IRDL (*Intermediate Representation Definition Language*) dialect allows defining MLIR dialects as MLIR programs. Nested operations are used to represent dialect structure: dialects contain operations, types and attributes, themselves containing type parameters, operands, results, etc. Each of those concepts are mapped to MLIR operations in the IRDL dialect, as shown in the example below:
3
+
[TOC]
4
+
5
+
## Basics
6
+
7
+
The IRDL (*Intermediate Representation Definition Language*) dialect allows defining MLIR dialects as MLIR programs. Nested operations are used to represent dialect structure: dialects contain operations, types and attributes, themselves containing type parameters, operands, results, etc. Each of those concepts are mapped to MLIR operations in the IRDL dialect, as shown in the example dialect below:
4
8
5
9
```mlir
6
-
irdl.dialect @my_dialect {
7
-
irdl.type @my_type {
8
-
// This type has a single parameter that must be i32.
9
-
%constraint = irdl.is : i32
10
-
irdl.parameters(param1: %constraint)
11
-
}
12
-
13
-
irdl.operation @my_scale_op {
14
-
// This operation represents the scaling of a vector.
IRDL provides a declarative way to define verifiers using constraint operations (`irdl.is` in the example above). See [constraints and combinators](#constraints-and-combinators) for more details.
29
+
This program defines a `cmath` dialect that defines a `complex` type, and
30
+
a `mul` operation. Both express constraints over their parameters using
31
+
SSA constraint operations. Informally, one can see those SSA values as
32
+
constraint variables that evaluate to a single type at constraint
33
+
evaluation. For example, the result of the `irdl.any_of` stored in `%2`
34
+
in the `mul` operation will collapse into either `f32` or `f64` for the
35
+
entirety of this instance of `mul` constraint evaluation. As such,
36
+
both operands and the result of `mul` must be of equal type (and not just
37
+
satisfy the same constraint). For more information, see
38
+
[constraints and combinators](#constraints-and-combinators).
39
+
40
+
In order to simplify the dialect, IRDL variables are handles over
41
+
`mlir::Attribute`. In order to support manipulating `mlir::Type`,
42
+
IRDL wraps all types in an `mlir::TypeAttr` attribute.
43
+
44
+
## Principles
24
45
25
46
The core principles of IRDL are the following, in no particular order:
26
47
@@ -37,10 +58,10 @@ Attribute, type and operation verifiers are expressed in terms of constraint var
37
58
38
59
Constraint variables act as variables: as such, matching against the same constraint variable multiple times can only succeed if the matching type or attribute is the same as the one that previously matched. In the following example:
39
60
40
-
```
41
-
irdl.type foo {
42
-
%ty = irdl.any_type
43
-
irdl.parameters(param1: %ty, param2: %ty)
61
+
```mlir
62
+
irdl.type @foo {
63
+
%ty = irdl.any_type
64
+
irdl.parameters(param1: %ty, param2: %ty)
44
65
}
45
66
```
46
67
@@ -56,3 +77,7 @@ To illustrate the rationale behind IRDL, the following list describes examples o
56
77
-**Portable dialects between compiler infrastructures.** Some compiler infrastructures are independent from MLIR but are otherwise IR-compatible. Portable IRDL dialects allow to share the dialect definitions between MLIR and other compiler infrastructures without needing to maintain multiple potentially out-of-sync definitions.
57
78
-**Dialect simplification.** Because IRDL definitions can easily be mechanically modified, it is possible to simplify the definition of dialects based on which operations are actually used, leading to smaller compilers.
58
79
-**SMT analysis.** Because IRDL dialect definitions are declarative, their definition can be lowered to alternative representations like SMT, allowing analysis of the behavior of transforms taking verifiers into account.
0 commit comments