[Mlir-commits] [mlir] [mlir][tblgen] Adds support for embedded LIT tests in TableGen records (PR #158017)

Kshitij Jain llvmlistbot at llvm.org
Fri Sep 12 10:55:01 PDT 2025


================
@@ -0,0 +1,65 @@
+// RUN: mlir-tblgen -gen-lit-tests -I %S/../../include -dialect=test %s | FileCheck %s
+
+include "mlir/Pass/PassBase.td"
+include "mlir/IR/Testable.td"
+
+def TestPassWithEmbeddedLitTests : Pass<"test-pass-with-embedded-lit-tests"> {
+  let summary = "pass summary";
+  let description = [{
+    Pass description
+  }];
+  
+  let tests = [
+    LitTest<
+      "lit_test_file_1.mlir", 
+      [{
+          func.func @test1() {
----------------
jkshtj wrote:

Thank you for the suggestions. In general I agree with the ideas you guys mentioned. I have a few questions to get a better understanding of the desired end product.

**Do we always want to include the IR examples in the documentation** or **do we want to give the user an option to only generate LIT tests from them**?

1. If it's the former then we'd always need the user to also specify the full "after" version of the IR. This "after" version obviously can be used as the CHECK lines in the test. It does increase the onus on the user a bit, but should give high-quality before/after versions of the IR to go along with documentation, as well as precise LIT tests.

2. If it's the latter, we'd still need the user to specify CHECK lines, but It'd be quite complicated to generate the "after" versions of the IR for documentation.

3. It seemed to me, from the comments, that there may be a third option of just generating a `--verify-roundtrip` test. 
  
    > This can then be similarly extracted for round-trip test generation by default... 
  
    If so, I'm not sure what utility such IR can provide either for documentation or for testing.

I personally prefer option 1, and have the user always always specify IR examples in before/after pairs. 

Thoughts?



https://github.com/llvm/llvm-project/pull/158017


More information about the Mlir-commits mailing list