diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h --- a/mlir/include/mlir/IR/AttributeSupport.h +++ b/mlir/include/mlir/IR/AttributeSupport.h @@ -30,14 +30,18 @@ /// a registered Attribute. class AbstractAttribute { public: + using HasTraitFn = llvm::unique_function; + /// Look up the specified abstract attribute in the MLIRContext and return a /// reference to it. static const AbstractAttribute &lookup(TypeID typeID, MLIRContext *context); /// This method is used by Dialect objects when they register the list of /// attributes they contain. - template static AbstractAttribute get(Dialect &dialect) { - return AbstractAttribute(dialect, T::getInterfaceMap(), T::getTypeID()); + template + static AbstractAttribute get(Dialect &dialect) { + return AbstractAttribute(dialect, T::getInterfaceMap(), T::getHasTraitFn(), + T::getTypeID()); } /// Return the dialect this attribute was registered to. @@ -46,7 +50,8 @@ /// Returns an instance of the concept object for the given interface if it /// was registered to this attribute, null otherwise. This should not be used /// directly. - template typename T::Concept *getInterface() const { + template + typename T::Concept *getInterface() const { return interfaceMap.lookup(); } @@ -56,14 +61,23 @@ return interfaceMap.contains(interfaceID); } + /// Returns true if the attribute has a particular trait. + template