Skip to content

Commit 619ee20

Browse files
authored
[mlir] add an example of using transform dialect standalone (#82623)
Transform dialect interpreter is designed to be usable outside of the pass pipeline, as the main program transformation driver, e.g., for languages with explicit schedules. Provide an example of such usage with a couple of tests.
1 parent a4fff36 commit 619ee20

12 files changed

+541
-0
lines changed

mlir/examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(toy)
22
add_subdirectory(transform)
3+
add_subdirectory(transform-opt)
34
add_subdirectory(minimal-opt)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
2+
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
3+
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
4+
5+
set(LIBS
6+
MLIRAnalysis
7+
MLIRIR
8+
MLIRParser
9+
MLIRSupport
10+
MLIRTransformDialect
11+
MLIRTransformDialectTransforms
12+
MLIRTransforms
13+
${dialect_libs}
14+
${conversion_libs}
15+
${extension_libs}
16+
)
17+
18+
add_mlir_tool(mlir-transform-opt
19+
mlir-transform-opt.cpp
20+
21+
DEPENDS
22+
${LIBS}
23+
)
24+
target_link_libraries(mlir-transform-opt PRIVATE ${LIBS})
25+
llvm_update_compile_flags(mlir-transform-opt)
26+
mlir_check_all_link_libraries(mlir-transform-opt)

mlir/examples/transform-opt/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Standalone Transform Dialect Interpreter
2+
3+
This is an example of using the Transform dialect interpreter functionality standalone, that is, outside of the regular pass pipeline. The example is a
4+
binary capable of processing MLIR source files similar to `mlir-opt` and other
5+
optimizer drivers, with the entire transformation process driven by a Transform
6+
dialect script. This script can be embedded into the source file or provided in
7+
a separate MLIR source file.
8+
9+
Either the input module or the transform module must contain a top-level symbol
10+
named `__transform_main`, which is used as the entry point to the transformation
11+
script.
12+
13+
```sh
14+
mlir-transform-opt payload_with_embedded_transform.mlir
15+
mlir-transform-opt payload.mlir -transform=transform.mlir
16+
```
17+
18+
The name of the entry point can be overridden using command-line options.
19+
20+
```sh
21+
mlir-transform-opt payload-mlir -transform-entry-point=another_entry_point
22+
```
23+
24+
Transform scripts can reference symbols defined in other source files, called
25+
libraries, which can be supplied to the binary through command-line options.
26+
Libraries will be embedded into the main transformation module by the tool and
27+
the interpreter will process everything as a single module. A debug option is
28+
available to see the contents of the transform module before it goes into the interpreter.
29+
30+
```sh
31+
mlir-transform-opt payload.mlir -transform=transform.mlir \
32+
-transform-library=external_definitions_1.mlir \
33+
-transform-library=external_definitions_2.mlir \
34+
-dump-library-module
35+
```
36+
37+
Check out the [Transform dialect
38+
tutorial](https://mlir.llvm.org/docs/Tutorials/transform/) as well as
39+
[documentation](https://mlir.llvm.org/docs/Dialects/Transform/) to learn more
40+
about the dialect.

0 commit comments

Comments
 (0)