[mlir] Introduce IRDL dialect
authorMathieu Fehr <mathieu.fehr@gmail.com>
Tue, 4 Apr 2023 19:16:45 +0000 (20:16 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Tue, 4 Apr 2023 19:19:49 +0000 (20:19 +0100)
commit0e0db0a4d7fd606ee58595f997142f7f2476cbe6
tree892714a128eb0c8ace7ce633b7bdbe6926945be2
parent1e36156ab1dc70f9f9b94a8d9820c819da4187be
[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