Make struct dialects have the same field name as everything else, 'dialect'.
authorFederico Lebrón <flebron@google.com>
Thu, 10 Sep 2020 19:00:49 +0000 (19:00 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Thu, 10 Sep 2020 19:13:42 +0000 (19:13 +0000)
Also make the behavior of getting a dialect more forgiving, in the case where
there isn't a dialect associated with an attribute.

Depends On D86807

Reviewed By: mehdi_amini

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

mlir/include/mlir/IR/OpBase.td
mlir/lib/TableGen/Attribute.cpp

index b0f08e9..29f139f 100644 (file)
@@ -1443,7 +1443,7 @@ class StructFieldAttr<string thisName, Attr thisType> {
 // Structured attribute that wraps a DictionaryAttr and provides both a
 // validation method and set of accessors for a fixed set of fields. This is
 // useful when representing data that would normally be in a structure.
-class StructAttr<string name, Dialect dialect,
+class StructAttr<string name, Dialect d,
                  list<StructFieldAttr> attributes> :
     DictionaryAttrBase<CPred<"$_self.isa<" # name # ">()">,
         "DictionaryAttr with field(s): " #
@@ -1459,7 +1459,7 @@ class StructAttr<string name, Dialect dialect,
   let storageType = name;
 
   // The dialect this StructAttr belongs to.
-  Dialect structDialect = dialect;
+  Dialect dialect = d;
 
   // List of fields that the StructAttr contains.
   list<StructFieldAttr> fields = attributes;
index e489174..f34d9c0 100644 (file)
@@ -126,7 +126,12 @@ StringRef Attribute::getDerivedCodeBody() const {
 }
 
 Dialect Attribute::getDialect() const {
-  return Dialect(def->getValueAsDef("dialect"));
+  const llvm::RecordVal *record = def->getValue("dialect");
+  if (record && record->getValue()) {
+    if (DefInit *init = dyn_cast<DefInit>(record->getValue()))
+      return Dialect(init->getDef());
+  }
+  return Dialect(nullptr);
 }
 
 ConstantAttr::ConstantAttr(const DefInit *init) : def(init->getDef()) {
@@ -255,7 +260,7 @@ StringRef StructAttr::getStructClassName() const {
 }
 
 StringRef StructAttr::getCppNamespace() const {
-  Dialect dialect(def->getValueAsDef("structDialect"));
+  Dialect dialect(def->getValueAsDef("dialect"));
   return dialect.getCppNamespace();
 }