[mlir] Introduce IRDL dialect
authorMathieu Fehr <mathieu.fehr@gmail.com>
Mon, 3 Apr 2023 16:42:53 +0000 (09:42 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 3 Apr 2023 17:08:21 +0000 (10:08 -0700)
commit31229d48bbfd394b64179d9be94f74ab70c84630
tree16d88209abecbeec32ce82785471c2c275c3c5c4
parente51f46705e2876fbbdb59d4f1ba43fa6ecf78611
[mlir] Introduce IRDL dialect

This patch introduces the IRDL dialect, which allow users to represent
dynamic dialect definitions as an MLIR program.

The IRDL dialect defines operations, attributes, and types, using
attribute constraints. For example:

```
module {
  irdl.dialect @cmath {
    irdl.type @complex {
      %0 = irdl.is f32
      %1 = irdl.is f64
      %2 = irdl.any_of(%0, %1)
      irdl.parameters(%2)
    }

    irdl.operation @norm {
      %0 = irdl.any
      %1 = irdl.parametric @complex<%0>
      irdl.operands(%1)
      irdl.results(%0)
    }
}
```

This program will define a new `cmath.complex` type, which expects a single
parameter, which is either an `f32` or an `f64`. It also defines an
`cmath.norm` operation, which expects a single `cmath.complex` type as operand,
and returns a value of the underlying type. Note that like PDL (which IRDL is
heavily inspired from), both uses of `%0` are expected to be of the same attribute.

IRDL handles attributes and types with the same operations, and does this by always
wrapping types in a `TypeAttr`. This is to simplify the language.

Depends on D144690

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D144692
15 files changed:
mlir/include/mlir/Dialect/CMakeLists.txt
mlir/include/mlir/Dialect/IRDL/CMakeLists.txt [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/CMakeLists.txt [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/IRDL.h [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/IRDL.td [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h [new file with mode: 0644]
mlir/include/mlir/Dialect/IRDL/IR/IRDLTypes.td [new file with mode: 0644]
mlir/include/mlir/InitAllDialects.h
mlir/lib/Dialect/CMakeLists.txt
mlir/lib/Dialect/IRDL/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Dialect/IRDL/IR/IRDL.cpp [new file with mode: 0644]
mlir/test/Dialect/IRDL/cmath.irdl.mlir [new file with mode: 0644]
mlir/test/Dialect/IRDL/testd.irdl.mlir [new file with mode: 0644]
mlir/test/mlir-opt/commandline.mlir