diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -932,6 +932,9 @@ // convertFromStorage method to handle the case where the attribute is // not present. bit isOptional = 0; + + // Whether the getter/setter function of the attribute will be hidden. + bit isHidden = 0; // What is the base-level Attr instantiation that this Attr is built upon. // Unset means this is a base-level Attr. @@ -1010,6 +1013,19 @@ let baseAttr = attr; } +// Decorates an attribute as hidden. The hidden attribute will not have their +// getter/setter functions gererated. +class HiddenAttr : Attr { + // Rewrite the attribute to be hidden. + let storageType = attr.storageType; + let returnType = attr.returnType; + let convertFromStorage = attr.convertFromStorage; + let constBuilderCall = attr.constBuilderCall; + let isHidden = 1; + + let baseAttr = attr; +} + // Default-valued string-based attribute. Wraps the default value in escaped // quotes. class DefaultValuedStrAttr diff --git a/mlir/include/mlir/TableGen/Attribute.h b/mlir/include/mlir/TableGen/Attribute.h --- a/mlir/include/mlir/TableGen/Attribute.h +++ b/mlir/include/mlir/TableGen/Attribute.h @@ -86,6 +86,9 @@ // Returns whether this attribute is optional. bool isOptional() const; + // Returns whether this attribute is hidden. + bool isHidden() const; + // Returns true if this attribute is a derived attribute (i.e., a subclass // of `DerivedAttr`). bool isDerivedAttr() const; diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp --- a/mlir/lib/TableGen/Attribute.cpp +++ b/mlir/lib/TableGen/Attribute.cpp @@ -111,6 +111,8 @@ bool Attribute::isOptional() const { return def->getValueAsBit("isOptional"); } +bool Attribute::isHidden() const { return def->getValueAsBit("isHidden"); } + StringRef Attribute::getAttrDefName() const { if (def->isAnonymous()) { return getBaseAttr().def->getName(); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1015,6 +1015,9 @@ for (const NamedAttribute &namedAttr : op.getAttributes()) { for (StringRef name : op.getGetterNames(namedAttr.name)) { + if(namedAttr.attr.isHidden){ + continue; + } if (namedAttr.attr.isDerivedAttr()) { emitDerivedAttr(name, namedAttr.attr); } else { @@ -1163,7 +1166,7 @@ }; for (const NamedAttribute &namedAttr : op.getAttributes()) { - if (namedAttr.attr.isDerivedAttr()) + if (namedAttr.attr.isDerivedAttr() || namedAttr.attr.isHidden()) continue; for (auto [setterName, getterName] : llvm::zip(op.getSetterNames(namedAttr.name),