Restructure the Test dialect ODS to include the AttrDef in TestOps.td (NFC)
authorMehdi Amini <joker.eph@gmail.com>
Sat, 6 Nov 2021 07:14:02 +0000 (07:14 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Wed, 10 Nov 2021 00:38:19 +0000 (00:38 +0000)
This structure is necessary to be able to use AttrDef as arguments on operations.

Differential Revision: https://reviews.llvm.org/D113327

mlir/test/lib/Dialect/Test/CMakeLists.txt
mlir/test/lib/Dialect/Test/TestDialect.h
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/op-format.mlir
utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel

index 52d1cac..06fd280 100644 (file)
@@ -13,7 +13,7 @@ mlir_tablegen(TestOpInterfaces.h.inc -gen-op-interface-decls)
 mlir_tablegen(TestOpInterfaces.cpp.inc -gen-op-interface-defs)
 add_public_tablegen_target(MLIRTestInterfaceIncGen)
 
-set(LLVM_TARGET_DEFINITIONS TestAttrDefs.td)
+set(LLVM_TARGET_DEFINITIONS TestOps.td)
 mlir_tablegen(TestAttrDefs.h.inc -gen-attrdef-decls)
 mlir_tablegen(TestAttrDefs.cpp.inc -gen-attrdef-defs)
 add_public_tablegen_target(MLIRTestAttrDefIncGen)
index b887ff7..cd77d62 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef MLIR_TESTDIALECT_H
 #define MLIR_TESTDIALECT_H
 
+#include "TestAttributes.h"
 #include "TestInterfaces.h"
 #include "mlir/Dialect/DLTI/DLTI.h"
 #include "mlir/Dialect/DLTI/Traits.h"
index 098937d..90eb1d8 100644 (file)
@@ -40,11 +40,6 @@ def Test_Dialect : Dialect {
     void registerAttributes();
     void registerTypes();
 
-    ::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser,
-                                     ::mlir::Type type) const override;
-    void printAttribute(::mlir::Attribute attr,
-                        ::mlir::DialectAsmPrinter &printer) const override;
-
     // Provides a custom printing/parsing for some operations.
     ::llvm::Optional<ParseOpHook>
       getParseOperationHook(::llvm::StringRef opName) const override;
@@ -59,6 +54,10 @@ def Test_Dialect : Dialect {
   }];
 }
 
+// Include the attribute definitions.
+include "TestAttrDefs.td"
+
+
 class TEST_Op<string mnemonic, list<OpTrait> traits = []> :
     Op<Test_Dialect, mnemonic, traits>;
 
@@ -1897,6 +1896,11 @@ def FormatOptionalWithElse : TEST_Op<"format_optional_else"> {
   let assemblyFormat = "(`then` $isFirstBranchPresent^):(`else`)? attr-dict";
 }
 
+def FormatCompoundAttr : TEST_Op<"format_compound_attr"> {
+  let arguments = (ins CompoundAttrA:$compound);
+  let assemblyFormat = "$compound attr-dict-with-keyword";
+}
+
 //===----------------------------------------------------------------------===//
 // Custom Directives
 
index 5108af3..3d9de2e 100644 (file)
@@ -253,6 +253,13 @@ test.format_optional_else then
 test.format_optional_else else
 
 //===----------------------------------------------------------------------===//
+// Format a custom attribute
+//===----------------------------------------------------------------------===//
+
+// CHECK: test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]>
+test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]>
+
+//===----------------------------------------------------------------------===//
 // Format custom directives
 //===----------------------------------------------------------------------===//
 
index eb19a15..31c0a73 100644 (file)
@@ -155,7 +155,7 @@ gentbl_cc_library(
         ),
     ],
     tblgen = "//mlir:mlir-tblgen",
-    td_file = "lib/Dialect/Test/TestAttrDefs.td",
+    td_file = "lib/Dialect/Test/TestOps.td",
     test = True,
     deps = [
         ":TestOpTdFiles",