From a007d4395a36adf3aad0f4b9914dcb8756a37c7d Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 14 Nov 2019 04:25:56 -0800 Subject: [PATCH] [doc] Add debugging tips in ODS and DRR doc regarding mlir-tblgen PiperOrigin-RevId: 280398956 --- mlir/g3doc/DeclarativeRewrites.md | 18 ++++++++++++++++++ mlir/g3doc/OpDefinitions.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/mlir/g3doc/DeclarativeRewrites.md b/mlir/g3doc/DeclarativeRewrites.md index 65fe450..94eb841 100644 --- a/mlir/g3doc/DeclarativeRewrites.md +++ b/mlir/g3doc/DeclarativeRewrites.md @@ -640,5 +640,23 @@ pattern's benefit. Just supply `(addBenefit N)` to add `N` to the benefit value. [TODO] +## Debugging Tips + +### Run `mlir-tblgen` to see the generated content + +TableGen syntax sometimes can be obscure; reading the generated content can be +a very helpful way to understand and debug issues. To build `mlir-tblgen`, run +`cmake --build . --target mlir-tblgen` in your build directory and find the +`mlir-tblgen` binary in the `bin/` subdirectory. All the supported generators +can be found via `mlir-tblgen --help`. + +To see the generated code, invoke `mlir-tblgen` with a specific generator by +providing include paths via `-I`. For example, + +```sh +# To see all the C++ pattern rewrite classes +mlir-tblgen --gen-rewriters -I /path/to/mlir/include /path/to/input/td/file +``` + [TableGen]: https://llvm.org/docs/TableGen/index.html [OpBase]: https://github.com/tensorflow/mlir/blob/master/include/mlir/IR/OpBase.td diff --git a/mlir/g3doc/OpDefinitions.md b/mlir/g3doc/OpDefinitions.md index 9967f65..2a18982 100644 --- a/mlir/g3doc/OpDefinitions.md +++ b/mlir/g3doc/OpDefinitions.md @@ -939,6 +939,37 @@ between the internal storage and the helper method. Derived attributes are a special class of attributes that do not have storage but are instead calculated based on the operation and its attributes. +## Debugging Tips + +### Run `mlir-tblgen` to see the generated content + +TableGen syntax sometimes can be obscure; reading the generated content can be +a very helpful way to understand and debug issues. To build `mlir-tblgen`, run +`cmake --build . --target mlir-tblgen` in your build directory and find the +`mlir-tblgen` binary in the `bin/` subdirectory. All the supported generators +can be found via `mlir-tblgen --help`. For example, `--gen-op-decls` and +`--gen-op-defs` as explained in [Generated C++ code](#generated-c++-code). + +To see the generated code, invoke `mlir-tblgen` with a specific generator by +providing include paths via `-I`. For example, + +```sh +# To see op C++ class declaration +mlir-tblgen --gen-op-decls -I /path/to/mlir/include /path/to/input/td/file +# To see op C++ class definition +mlir-tblgen --gen-op-defs -I /path/to/mlir/include /path/to/input/td/file +# To see op documentation +mlir-tblgen --gen-op-doc -I /path/to/mlir/include /path/to/input/td/file + +# To see op interface C++ class declaration +mlir-tblgen --gen-op-interface-decls -I /path/to/mlir/include /path/to/input/td/file +# To see op interface C++ class definition +mlir-tblgen --gen-op-interface-defs -I /path/to/mlir/include /path/to/input/td/file +# To see op interface documentation +mlir-tblgen --gen-op-interface-doc -I /path/to/mlir/include /path/to/input/td/file +``` + + ## Appendix ### Requirements and existing mechanisms analysis -- 2.7.4