@@ -26,27 +26,66 @@ to the tree traversal strategy. The different strategies may lead to different
2626results and different time complexity. You can run as
2727` -reduction-tree='traversal-mode=0' ` to select the mode for example.
2828
29+ ### Example MLIR input
30+
31+ ``` mlir
32+ // query-test.mlir
33+ func.func @func1() {
34+ // A func can be pruned if it's not relevant to the error.
35+ return
36+ }
37+
38+ func.func @func2() -> i32 {
39+ %0 = arith.constant 1 : i32
40+ %1 = arith.constant 2 : i32
41+ %2 = arith.constant 2.2 : f32
42+ %3 = arith.constant 5.3 : f32
43+ %4 = arith.addi %0, %1 : i32
44+ %5 = arith.addf %2, %3 : f32
45+ %6 = arith.muli %4, %4 : i32
46+ %7 = arith.subi %6, %4 : i32
47+ %8 = arith.fptosi %5 : f32 to i32
48+ %9 = arith.addi %7, %8 : i32
49+ return %9 : i32
50+ }
51+ ```
52+
2953### Write the script for testing interestingness
3054
31- As mentioned, you need to provide a command to ` mlir-reduce ` which identifies
32- cases you're interested in. For each intermediate output generated during
33- reduction, ` mlir-reduce ` will run the command over the it, the script should
34- returns 1 for interesting case, 0 otherwise. The sample script,
55+ You need to provide a command to ` mlir-reduce ` which identifies cases you're
56+ interested in. For each intermediate output generated during reduction,
57+ ` mlir-reduce ` will run the command over the it, the script should returns 1 for
58+ interesting case, 0 otherwise. For the IR above, a sample script might simply
59+ look for the presence of the ` arith.fptosi ` operation. A more realistic script
60+ would check for the presence of a particular kind of error message in stderr.
3561
3662``` shell
37- mlir-opt -convert-vector-to-spirv $1 | grep " failed to materialize"
38- if [[ $? -eq 1 ]]; then
63+ # query-test.sh
64+ # `2>&1` redirects stderr (where errors and diagnostics are printed) to stdout
65+ # so it can be piped to grep.
66+ mlir-opt $1 2>&1 | grep " arith.fptosi"
67+
68+ # grep's exit code is 0 if the queried string is found
69+ if [[ $? -eq 0 ]]; then
3970 exit 1
4071else
4172 exit 0
4273fi
4374```
4475
45- The sample usage will be like, note that the ` test ` argument is part of the mode
46- argument.
76+ ### Running the example
77+
78+ The sample usage will be as follows, noting that the ` test ` argument is part of
79+ the mode argument.
4780
4881``` shell
49- mlir-reduce $INPUT -reduction-tree=' traversal-mode=0 test=$TEST_SCRIPT'
82+ mlir-reduce query-test.mlir -reduction-tree=' traversal-mode=0 test=query-test.sh'
83+ ```
84+
85+ The output:
86+
87+ ```
88+ TODO: the usage above produces a stack trace
5089```
5190
5291## Available reduction strategies
0 commit comments