Skip to content

Commit 1931e14

Browse files
committed
move rationale to dialect docs
1 parent 07e925f commit 1931e14

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed
Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1-
# IRDL Rationale
1+
# 'irdl' Dialect
22

3-
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:
48

59
```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.
15-
%vec_constraint = irdl.is : vector<i64>
16-
%scalar_constraint = irdl.is : i64
17-
irdl.operands(vector: %vec_constraint, scalar: %scalar_constraint)
18-
irdl.results(result: %vec_constraint)
19-
}
10+
irdl.dialect @cmath {
11+
irdl.type @complex {
12+
%0 = irdl.is f32
13+
%1 = irdl.is f64
14+
%2 = irdl.any_of(%0, %1)
15+
irdl.parameters(%2)
16+
}
17+
18+
irdl.operation @mul {
19+
%0 = irdl.is f32
20+
%1 = irdl.is f64
21+
%2 = irdl.any_of(%0, %1)
22+
%3 = irdl.parametric @cmath::@complex<%2>
23+
irdl.operands(%3, %3)
24+
irdl.results(%3)
25+
}
2026
}
2127
```
2228

23-
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
2445

2546
The core principles of IRDL are the following, in no particular order:
2647

@@ -37,10 +58,10 @@ Attribute, type and operation verifiers are expressed in terms of constraint var
3758

3859
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:
3960

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)
4465
}
4566
```
4667

@@ -56,3 +77,7 @@ To illustrate the rationale behind IRDL, the following list describes examples o
5677
- **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.
5778
- **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.
5879
- **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.
80+
81+
## Operations
82+
83+
[include "Dialects/IRDLOps.md"]

mlir/include/mlir/Dialect/IRDL/IR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_mlir_dialect(IRDL irdl)
2-
add_mlir_doc(IRDLOps IRDL Dialects/ -gen-dialect-doc -dialect=irdl)
2+
add_mlir_doc(IRDLOps IRDLOps Dialects/ -gen-op-doc -dialect=irdl)
33

44
# Add IRDL interfaces
55
set(LLVM_TARGET_DEFINITIONS IRDLInterfaces.td)

0 commit comments

Comments
 (0)