[mlir] Add a new "Pattern Descriptor Language" (PDL) dialect.
authorRiver Riddle <riddleriver@gmail.com>
Wed, 19 Aug 2020 19:57:45 +0000 (12:57 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Wed, 19 Aug 2020 20:13:06 +0000 (13:13 -0700)
commit3fb3927bd333cded1f51025161a4ee7e7ca722c1
tree03dcf7725fdcbdc233bc5254cd002588f4fc1104
parentef8992b9f0189005e0d9e09bd0967301bd7a7cc6
[mlir] Add a new "Pattern Descriptor Language" (PDL) dialect.

PDL presents a high level abstraction for the rewrite pattern infrastructure available in MLIR. This abstraction allows for representing patterns transforming MLIR, as MLIR. This allows for applying all of the benefits that the general MLIR infrastructure provides, to the infrastructure itself. This means that pattern matching can be more easily verified for correctness, targeted by frontends, and optimized.

PDL abstracts over various different aspects of patterns and core MLIR data structures. Patterns are specified via a `pdl.pattern` operation. These operations contain a region body for the "matcher" code, and terminate with a `pdl.rewrite` that either dispatches to an external rewriter or contains a region for the rewrite specified via `pdl`. The types of values in `pdl` are handle types to MLIR C++ types, with `!pdl.attribute`, `!pdl.operation`, and `!pdl.type` directly mapping to `mlir::Attribute`, `mlir::Operation*`, and `mlir::Value` respectively.

An example pattern is shown below:

```mlir
// pdl.pattern contains metadata similarly to a `RewritePattern`.
pdl.pattern : benefit(1) {
  // External input operand values are specified via `pdl.input` operations.
  // Result types are constrainted via `pdl.type` operations.

  %resultType = pdl.type
  %inputOperand = pdl.input
  %root, %results = pdl.operation "foo.op"(%inputOperand) -> %resultType
  pdl.rewrite(%root) {
    pdl.replace %root with (%inputOperand)
  }
}
```

This is a culmination of the work originally discussed here: https://groups.google.com/a/tensorflow.org/g/mlir/c/j_bn74ByxlQ

Differential Revision: https://reviews.llvm.org/D84578
17 files changed:
mlir/include/mlir/Dialect/CMakeLists.txt
mlir/include/mlir/Dialect/PDL/CMakeLists.txt [new file with mode: 0644]
mlir/include/mlir/Dialect/PDL/IR/CMakeLists.txt [new file with mode: 0644]
mlir/include/mlir/Dialect/PDL/IR/PDL.h [new file with mode: 0644]
mlir/include/mlir/Dialect/PDL/IR/PDLBase.td [new file with mode: 0644]
mlir/include/mlir/Dialect/PDL/IR/PDLOps.td [new file with mode: 0644]
mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h [new file with mode: 0644]
mlir/include/mlir/IR/OpImplementation.h
mlir/include/mlir/InitAllDialects.h
mlir/lib/Dialect/CMakeLists.txt
mlir/lib/Dialect/PDL/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Dialect/PDL/IR/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Dialect/PDL/IR/PDL.cpp [new file with mode: 0644]
mlir/lib/Parser/Parser.cpp
mlir/test/Dialect/PDL/invalid.mlir [new file with mode: 0644]
mlir/test/Dialect/PDL/ops.mlir [new file with mode: 0644]
mlir/tools/mlir-tblgen/OpFormatGen.cpp