[mlir] Add opt-in default property bytecode read and write implementation
authorMarkus Böck <markus.boeck02@gmail.com>
Fri, 21 Jul 2023 05:40:10 +0000 (07:40 +0200)
committerMarkus Böck <markus.boeck02@gmail.com>
Fri, 21 Jul 2023 06:03:26 +0000 (08:03 +0200)
commitf117bbca041c9b0c59002835d939e1bc9e76cf39
treefbee358caaa748d2ea16e891c71c753961195f0c
parentede20c1e690b8cb1f708c01c5267404a8fccd410
[mlir] Add opt-in default property bytecode read and write implementation

Using properties currently requires at the very least implementing four methods/code snippets:
* `convertToAttribute`
* `convertFromAttribute`
* `writeToMlirBytecode`
* `readFromMlirBytecode`

This makes replacing attributes with properties harder than it has to be: Attributes by default do not require immediately defining custom bytecode encoding.

This patch therefore adds opt-in implementations of `writeToMlirBytecode` and `readFromMlirBytecode` that work with the default implementations of `convertToAttribute` and `convertFromAttribute`. They are provided by `defvar`s in `OpBase.td` and can be used by adding:
```
let writeToMlirBytecode = writeMlirBytecodeWithConvertToAttribute;
let readFromMlirBytecode = readMlirBytecodeUsingConvertFromAttribute;
```
to ones TableGen definition.

While this bytecode encoding is almost certainly not ideal for a given property, it allows more incremental use of properties and getting something sane working before optimizing the bytecode format.

Differential Revision: https://reviews.llvm.org/D155286
mlir/include/mlir/IR/OpBase.td
mlir/test/IR/properties-bytecode-roundtrip.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Test/TestOps.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp