Skip to content

Commit 9ebab24

Browse files
Kshitijjkshtj
authored andcommitted
tmp
1 parent 7361395 commit 9ebab24

File tree

5 files changed

+170
-168
lines changed

5 files changed

+170
-168
lines changed

mlir/examples/toy/Ch2/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# For a better template to copy, see examples/standalone
22
add_subdirectory(include)
33

4+
add_embedded_lit_tests(EmbeddedLitTestsGen
5+
"include/toy/Ops.td"
6+
"${CMAKE_CURRENT_BINARY_DIR}"
7+
)
8+
49
set(LLVM_LINK_COMPONENTS
510
Support
611
)
@@ -13,8 +18,9 @@ add_toy_chapter(toyc-ch2
1318

1419
DEPENDS
1520
ToyCh2OpsIncGen
16-
21+
EmbeddedLitTestsGen
1722
)
23+
1824
include_directories(include/)
1925
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
2026
target_link_libraries(toyc-ch2

mlir/include/mlir/IR/Testable.td

Lines changed: 0 additions & 40 deletions
This file was deleted.

mlir/include/mlir/Pass/PassBase.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Statistic<string varName, string statName, string desc> {
6464
// Pass
6565
//===----------------------------------------------------------------------===//
6666

67-
class PassBase<string passArg, string base> : Testable {
67+
class PassBase<string passArg, string base> {
6868
// The command line argument of the pass.
6969
string argument = passArg;
7070

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,74 @@
1-
// RUN: mlir-tblgen -gen-lit-tests -I %S/../../include -dialect=test %s | FileCheck %s
1+
// RUN: mlir-tblgen -gen-lit-tests -I %S/../../include %s | FileCheck %s
22

3-
include "mlir/Pass/PassBase.td"
4-
include "mlir/IR/Testable.td"
3+
include "mlir/IR/OpBase.td"
54

6-
def TestPassWithEmbeddedLitTests : Pass<"test-pass-with-embedded-lit-tests"> {
7-
let summary = "pass summary";
5+
def Test_Dialect : Dialect {
6+
let name = "test";
7+
let cppNamespace = "test";
8+
}
9+
10+
def TestOp : Op<Test_Dialect, "test_op"> {
11+
let summary = "test op with mlir_example code blocks";
812
let description = [{
9-
Pass description
13+
This operation demonstrates the mlir_example feature for ops.
14+
15+
Basic usage:
16+
```mlir_example(mlir-opt)
17+
func.func @foo(%arg0: i32) -> i32 {
18+
%0 = test.test_op %arg0 : i32
19+
return %0 : i32
20+
}
21+
```
22+
23+
And some more back to back examples -
24+
25+
```mlir_example(some-other-tool)
26+
func.func @foo1(%arg1: i32) -> i32 {
27+
%0 = test.test_op %arg1 : i32
28+
return %0 : i32
29+
}
30+
```
31+
```mlir_example(yet-another-tool)
32+
func.func @foo2(%arg2: i32) -> i32 {
33+
%0 = test.test_op %arg2 : i32
34+
return %0 : i32
35+
}
36+
```
1037
}];
11-
12-
let tests = [
13-
LitTest<
14-
"lit_test_file_1.mlir",
15-
[{
16-
func.func @test1() {
17-
return 42;
18-
}
19-
}],
20-
[
21-
"// RUN: mlir-opt %s --verify-roundtrip | FileCheck %s",
22-
],
23-
[
24-
"// RANDOM-CHECK-LABEL: func.func @test1",
25-
]
26-
>,
27-
LitTest<
28-
"lit_test_file_2.mlir",
29-
[{
30-
func.func @test2() {
31-
return 42;
32-
}
33-
}],
34-
[
35-
"// RUN: mlir-opt %s --verify-roundtrip | FileCheck %s",
36-
],
37-
[
38-
"// RANDOM-CHECK-LABEL: func.func @test2",
39-
]
40-
>,
41-
];
38+
39+
let arguments = (ins I32:$input);
40+
let results = (outs I32:$output);
4241
}
4342

44-
// CHECK-LABEL: // Generated 2 LIT test files
45-
// CHECK: // Use the following files for LIT testing:
43+
// CHECK-LABEL: // Generated 3 LIT test files
44+
// CHECK: // Use the following files for LIT testing:
45+
46+
// CHECK: // File: generated_TestOp_example_0.mlir
47+
// CHECK: // --- BEGIN generated_TestOp_example_0.mlir ---
48+
// CHECK: mlir-opt %s --verify-roundtrip
49+
// CHECK: // Generated from TableGen definition: TestOp
50+
// CHECK: func.func @foo(%arg0: i32) -> i32 {
51+
// CHECK: %0 = test.test_op %arg0 : i32
52+
// CHECK: return %0 : i32
53+
// CHECK: }
54+
// CHECK: // --- END generated_TestOp_example_0.mlir ---
4655

47-
// CHECK: // File: generated_TestPassWithEmbeddedLitTests_lit_test_file_1.mlir
48-
// CHECK: // --- BEGIN generated_TestPassWithEmbeddedLitTests_lit_test_file_1.mlir ---
49-
// CHECK: // RUN: mlir-opt %s --verify-roundtrip | FileCheck %s
50-
// CHECK: // Generated from TableGen definition: TestPassWithEmbeddedLitTests
51-
// CHECK: func.func @test1() {
52-
// CHECK: return 42;
53-
// CHECK: }
54-
// CHECK: // RANDOM-CHECK-LABEL: func.func @test1
55-
// CHECK: --- END generated_TestPassWithEmbeddedLitTests_lit_test_file_1.mlir ---
56+
// CHECK: // File: generated_TestOp_example_1.mlir
57+
// CHECK: // --- BEGIN generated_TestOp_example_1.mlir ---
58+
// CHECK: some-other-tool %s --verify-roundtrip
59+
// CHECK: // Generated from TableGen definition: TestOp
60+
// CHECK: func.func @foo1(%arg1: i32) -> i32 {
61+
// CHECK: %0 = test.test_op %arg1 : i32
62+
// CHECK: return %0 : i32
63+
// CHECK: }
64+
// CHECK: // --- END generated_TestOp_example_1.mlir ---
5665

57-
// CHECK: // File: generated_TestPassWithEmbeddedLitTests_lit_test_file_2.mlir
58-
// CHECK: // --- BEGIN generated_TestPassWithEmbeddedLitTests_lit_test_file_2.mlir ---
59-
// CHECK: // RUN: mlir-opt %s --verify-roundtrip | FileCheck %s
60-
// CHECK: // Generated from TableGen definition: TestPassWithEmbeddedLitTests
61-
// CHECK: func.func @test2() {
62-
// CHECK: return 42;
63-
// CHECK: }
64-
// CHECK: // RANDOM-CHECK-LABEL: func.func @test2
65-
// CHECK: // --- END generated_TestPassWithEmbeddedLitTests_lit_test_file_2.mlir ---
66+
// CHECK: // File: generated_TestOp_example_2.mlir
67+
// CHECK: // --- BEGIN generated_TestOp_example_2.mlir ---
68+
// CHECK: yet-another-tool %s --verify-roundtrip
69+
// CHECK: // Generated from TableGen definition: TestOp
70+
// CHECK: func.func @foo2(%arg2: i32) -> i32 {
71+
// CHECK: %0 = test.test_op %arg2 : i32
72+
// CHECK: return %0 : i32
73+
// CHECK: }
74+
// CHECK: // --- END generated_TestOp_example_2.mlir ---

0 commit comments

Comments
 (0)