From: Mathieu Fehr Date: Mon, 13 Sep 2021 06:22:19 +0000 (+0000) Subject: [mlir] Allows to query traits from types and attributes X-Git-Tag: upstream/15.0.7~31641 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=802bf02a738e091d5bf22c03e83204a38d2c7950;p=platform%2Fupstream%2Fllvm.git [mlir] Allows to query traits from types and attributes Types and attributes now have a `hasTrait` function that allow users to check if a type defines a trait. Also, AbstractType and AbstractAttribute has now a `hasTraitFn` field to carry the implementation of the `hasTrait` function of the concrete type or attribute. This patch also adds the remaining functions to access type and attribute traits in TableGen. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D105202 --- diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h index c84be62..d18f0ab 100644 --- a/mlir/include/mlir/IR/AttributeSupport.h +++ b/mlir/include/mlir/IR/AttributeSupport.h @@ -30,14 +30,18 @@ class Type; /// 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 @@ public: /// 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 @@ public: return interfaceMap.contains(interfaceID); } + /// Returns true if the attribute has a particular trait. + template