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
Copy file name to clipboardExpand all lines: mlir/docs/Dialects/IRDL.md
+57-17Lines changed: 57 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,12 @@
4
4
5
5
## Basics
6
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:
7
+
The IRDL (*Intermediate Representation Definition Language*) dialect allows
8
+
defining MLIR dialects as MLIR programs. Nested operations are used to
9
+
represent dialect structure: dialects contain operations, types and
10
+
attributes, themselves containing type parameters, operands, results, etc.
11
+
Each of those concepts are mapped to MLIR operations in the IRDL dialect, as
12
+
shown in the example dialect below:
8
13
9
14
```mlir
10
15
irdl.dialect @cmath {
@@ -45,18 +50,34 @@ IRDL wraps all types in an `mlir::TypeAttr` attribute.
45
50
46
51
The core principles of IRDL are the following, in no particular order:
47
52
48
-
-**Portability.** IRDL dialects should be self-contained, such that dialects can be easily distributed with minimal assumptions on which compiler infrastructure (or which commit of MLIR) is used.
49
-
-**Introspection.** The IRDL dialect definition mechanism should strive towards offering as much introspection abilities as possible. Dialects should be as easy to manipulate, generate, and analyze as possible.
50
-
-**Runtime declaration support**. The specification of IRDL dialects should offer the ability to have them be loaded at runtime, via dynamic registration or JIT compilation. Compatibility with dynamic workflows should not hinder the ability to compile IRDL dialects into ahead-of-time declarations.
51
-
-**Reliability.** Concepts in IRDL should be consistent and predictable, with as much focus on high-level simplicity as possible. Consequently, IRDL definitions that verify should work out of the box, and those that do not verify should provide clear and understandable errors in all circumstances.
52
-
53
-
While IRDL simplifies IR definition, it remains an IR itself and thus does not require to be comfortably user-writeable.
53
+
-**Portability.** IRDL dialects should be self-contained, such that dialects
54
+
can be easily distributed with minimal assumptions on which compiler
55
+
infrastructure (or which commit of MLIR) is used.
56
+
-**Introspection.** The IRDL dialect definition mechanism should strive
57
+
towards offering as much introspection abilities as possible. Dialects
58
+
should be as easy to manipulate, generate, and analyze as possible.
59
+
-**Runtime declaration support**. The specification of IRDL dialects should
60
+
offer the ability to have them be loaded at runtime, via dynamic registration
61
+
or JIT compilation. Compatibility with dynamic workflows should not hinder
62
+
the ability to compile IRDL dialects into ahead-of-time declarations.
63
+
-**Reliability.** Concepts in IRDL should be consistent and predictable, with
64
+
as much focus on high-level simplicity as possible. Consequently, IRDL
65
+
definitions that verify should work out of the box, and those that do not
66
+
verify should provide clear and understandable errors in all circumstances.
67
+
68
+
While IRDL simplifies IR definition, it remains an IR itself and thus does not
69
+
require to be comfortably user-writeable.
54
70
55
71
## Constraints and combinators
56
72
57
-
Attribute, type and operation verifiers are expressed in terms of constraint variables. Constraint variables are defined as the results of constraint operations (like `irdl.is` or constraint combinators).
73
+
Attribute, type and operation verifiers are expressed in terms of constraint
74
+
variables. Constraint variables are defined as the results of constraint
75
+
operations (like `irdl.is` or constraint combinators).
58
76
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:
77
+
Constraint variables act as variables: as such, matching against the same
78
+
constraint variable multiple times can only succeed if the matching type or
79
+
attribute is the same as the one that previously matched. In the following
80
+
example:
60
81
61
82
```mlir
62
83
irdl.type @foo {
@@ -65,18 +86,37 @@ irdl.type @foo {
65
86
}
66
87
```
67
88
68
-
only types with two equal parameters will successfully match (`foo<i32, i32>` would match while `foo<i32, i64>` would fail, even though both i32 and i64 individually satisfy the `irdl.any_type` constraint). This constraint variable mechanism allows to easily express a requirement on type or attribute equality.
89
+
only types with two equal parameters will successfully match (`foo<i32, i32>`
90
+
would match while `foo<i32, i64>` would fail, even though both i32 and i64
91
+
individually satisfy the `irdl.any_type` constraint). This constraint variable
92
+
mechanism allows to easily express a requirement on type or attribute equality.
69
93
70
-
To declare more complex verifiers, IRDL provides constraint-combinator operations such as `irdl.any_of`, `irdl.all_of` or `irdl.parametric`. These combinators can be used to combine constraint variables into new constraint variables. Like all uses of constraint variables, their constraint variable operands enforce equality of matched types of attributes as explained in the previous paragraph.
94
+
To declare more complex verifiers, IRDL provides constraint-combinator
95
+
operations such as `irdl.any_of`, `irdl.all_of` or `irdl.parametric`. These
96
+
combinators can be used to combine constraint variables into new constraint
97
+
variables. Like all uses of constraint variables, their constraint variable
98
+
operands enforce equality of matched types of attributes as explained in the
99
+
previous paragraph.
71
100
72
101
## Motivating use cases
73
102
74
-
To illustrate the rationale behind IRDL, the following list describes examples of intended use cases for IRDL, in no particular order:
75
-
76
-
-**Fuzzer generation.** With declarative verifier definitions, it is possible to compile IRDL dialects into compiler fuzzers that generate only programs passing verifiers.
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.
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.
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.
103
+
To illustrate the rationale behind IRDL, the following list describes examples
104
+
of intended use cases for IRDL, in no particular order:
105
+
106
+
-**Fuzzer generation.** With declarative verifier definitions, it is possible
107
+
to compile IRDL dialects into compiler fuzzers that generate only programs
108
+
passing verifiers.
109
+
-**Portable dialects between compiler infrastructures.** Some compiler
110
+
infrastructures are independent from MLIR but are otherwise IR-compatible.
111
+
Portable IRDL dialects allow to share the dialect definitions between MLIR
112
+
and other compiler infrastructures without needing to maintain multiple
113
+
potentially out-of-sync definitions.
114
+
-**Dialect simplification.** Because IRDL definitions can easily be
115
+
mechanically modified, it is possible to simplify the definition of dialects
116
+
based on which operations are actually used, leading to smaller compilers.
117
+
-**SMT analysis.** Because IRDL dialect definitions are declarative, their
118
+
definition can be lowered to alternative representations like SMT, allowing
119
+
analysis of the behavior of transforms taking verifiers into account.
0 commit comments