[Mlir-commits] [mlir] f5f11e6 - Add a cppType string in AttrDef to make it possible to use them as parameters in other attributes

Mehdi Amini llvmlistbot at llvm.org
Thu Nov 11 23:30:56 PST 2021


Author: Mehdi Amini
Date: 2021-11-12T07:26:06Z
New Revision: f5f11e6b168fd00a62c7d881703281ff11f1a6d8

URL: https://github.com/llvm/llvm-project/commit/f5f11e6b168fd00a62c7d881703281ff11f1a6d8
DIFF: https://github.com/llvm/llvm-project/commit/f5f11e6b168fd00a62c7d881703281ff11f1a6d8.diff

LOG: Add a cppType string in AttrDef to make it possible to use them as parameters in other attributes

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpBase.td
    mlir/test/lib/Dialect/Test/TestAttrDefs.td
    mlir/test/lib/Dialect/Test/TestOps.td
    mlir/test/mlir-tblgen/op-format.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index d0469142f8550..47eb2311da0dc 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -2938,6 +2938,9 @@ class AttrDef<Dialect dialect, string name, list<Trait> traits = [],
   // The underlying C++ value type
   let returnType = dialect.cppNamespace # "::" # cppClassName;
 
+  // Make it possible to use such attributes as parameters for other attributes.
+  string cppType = dialect.cppNamespace # "::" # cppClassName;
+
   // The call expression to convert from the storage type to the return
   // type. For example, an enum can be stored as an int but returned as an
   // enum class.

diff  --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
index 06e2599def7df..af56d3cae8ddb 100644
--- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
@@ -43,6 +43,11 @@ def CompoundAttrA : Test_Attr<"CompoundA"> {
       >: $arrayOfInts
   );
 }
+def CompoundAttrNested : Test_Attr<"CompoundAttrNested"> {
+  let mnemonic = "cmpnd_nested";
+  let parameters = (ins CompoundAttrA : $nested );
+  let assemblyFormat = "`<` `nested` `=` $nested `>`";
+}
 
 // An attribute testing AttributeSelfTypeParameter.
 def AttrWithSelfTypeParam : Test_Attr<"AttrWithSelfTypeParam"> {

diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index c5fcc5c55b64a..6a06596838db0 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -1902,6 +1902,11 @@ def FormatCompoundAttr : TEST_Op<"format_compound_attr"> {
   let assemblyFormat = "$compound attr-dict-with-keyword";
 }
 
+def FormatNestedAttr : TEST_Op<"format_nested_attr"> {
+  let arguments = (ins CompoundAttrNested:$nested);
+  let assemblyFormat = "$nested 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 3d9de2e247d4f..dd996b8acc6bc 100644
--- a/mlir/test/mlir-tblgen/op-format.mlir
+++ b/mlir/test/mlir-tblgen/op-format.mlir
@@ -259,6 +259,14 @@ test.format_optional_else else
 // 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]>
 
+// CHECK:  module attributes {test.nested = #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>} {
+module attributes {test.nested = #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>} {
+}
+
+// CHECK: test.format_nested_attr #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>
+test.format_nested_attr #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>
+
+
 //===----------------------------------------------------------------------===//
 // Format custom directives
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list