Add a short TableGen HowTo to tutorial chapter 2.

Add a note to chapter 2 of the Toy tutorial stating how to invoke
mlir-tblgen to check the generated C++ code. IMHO this is incredibly
useful when getting acquainted with TableGen/ODS.

Closes tensorflow/mlir#228

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/228 from ombre5733:toy-ch2-howto-mlir-tblgen a051a3734ca8bbf4f12027fe737aca07c64ca59d
PiperOrigin-RevId: 279518989
This commit is contained in:
Manuel Freiberger 2019-11-09 12:14:39 -08:00 committed by A. Unique TensorFlower
parent 9fbf52e330
commit 1328f93e91
1 changed files with 14 additions and 1 deletions

View File

@ -330,6 +330,18 @@ def ConstantOp : Toy_Op<"constant", [NoSideEffect]> {
}
```
At this point you probably might want to know what the C++ code generated by
TableGen looks like. Simply run the `mlir-tblgen` command with the
`gen-op-decls` or the `gen-op-defs` action like so:
```
${build_root}/bin/mlir-tblgen -gen-op-defs ${mlir_src_root}/examples/toy/Ch2/include/toy/Ops.td -I ${mlir_src_root}/include/
```
Depending on the selected action, this will print either the `ConstantOp` class
declaration or its implementation. Comparing this output to the hand-crafted
implementation is incredibly useful when getting started with TableGen.
#### Defining Arguments and Results
With the shell of the operation defined, we can now provide the
@ -539,7 +551,8 @@ module {
You can build `toyc-ch2` and try yourself: `toyc-ch2 test/codegen.toy -emit=mlir
-mlir-print-debuginfo`. We can also check our RoundTrip: `toyc-ch2
test/codegen.toy -emit=mlir -mlir-print-debuginfo 2> codegen.mlir` followed by
`toyc-ch2 codegen.mlir -emit=mlir`.
`toyc-ch2 codegen.mlir -emit=mlir`. You should also use `mlir-tblgen` on the
final definition file and study the generated C++ code.
At this point MLIR knows about our Toy dialect and operations. In the
[next chapter](Ch-3.md) we will leverage our new dialect to implement some