[Mlir-commits] [mlir] 9d506ae - Restructure the Test dialect ODS to include the AttrDef in TestOps.td (NFC)
Mehdi Amini
llvmlistbot at llvm.org
Tue Nov 9 16:39:10 PST 2021
Author: Mehdi Amini
Date: 2021-11-10T00:38:19Z
New Revision: 9d506ae0f607db876e8bfcd1169d24c92156ae48
URL: https://github.com/llvm/llvm-project/commit/9d506ae0f607db876e8bfcd1169d24c92156ae48
DIFF: https://github.com/llvm/llvm-project/commit/9d506ae0f607db876e8bfcd1169d24c92156ae48.diff
LOG: Restructure the Test dialect ODS to include the AttrDef in TestOps.td (NFC)
This structure is necessary to be able to use AttrDef as arguments on operations.
Differential Revision: https://reviews.llvm.org/D113327
Added:
Modified:
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
Removed:
################################################################################
diff --git a/mlir/test/lib/Dialect/Test/CMakeLists.txt b/mlir/test/lib/Dialect/Test/CMakeLists.txt
index 52d1cac3b310d..06fd28032e8dc 100644
--- a/mlir/test/lib/Dialect/Test/CMakeLists.txt
+++ b/mlir/test/lib/Dialect/Test/CMakeLists.txt
@@ -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)
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h
index b887ff77c2dc4..cd77d62c89cb2 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.h
+++ b/mlir/test/lib/Dialect/Test/TestDialect.h
@@ -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"
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 098937d1d74cc..90eb1d833c76c 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -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
diff --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir
index 5108af345e86d..3d9de2e247d4f 100644
--- a/mlir/test/mlir-tblgen/op-format.mlir
+++ b/mlir/test/mlir-tblgen/op-format.mlir
@@ -252,6 +252,13 @@ test.format_optional_else then
// CHECK: test.format_optional_else else
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
//===----------------------------------------------------------------------===//
diff --git a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
index eb19a15cabc85..31c0a7303f2fb 100644
--- a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
@@ -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",
More information about the Mlir-commits
mailing list