diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -193,6 +193,11 @@ (void)std::initializer_list{0, (addType(), 0)...}; } + /// Register a type instance with this dialect. + /// The use of this method is in general discouraged in favor of + /// 'addTypes()'. + void addType(TypeID typeID, AbstractType &&typeInfo); + /// Register a set of attribute classes with this dialect. template void addAttributes() { (void)std::initializer_list{0, (addAttribute(), 0)...}; @@ -231,7 +236,6 @@ addType(T::getTypeID(), AbstractType::get(*this)); detail::TypeUniquer::registerType(context); } - void addType(TypeID typeID, AbstractType &&typeInfo); /// The namespace of this dialect. StringRef name; diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -172,7 +172,9 @@ T::getHasTraitFn()); } -private: + /// Register a new operation in a Dialect object. + /// The use of this method is in general discouraged in favor of + /// 'insert(dialect)'. static void insert(StringRef name, Dialect &dialect, TypeID typeID, ParseAssemblyFn parseAssembly, PrintAssemblyFn printAssembly, @@ -180,6 +182,7 @@ GetCanonicalizationPatternsFn getCanonicalizationPatterns, detail::InterfaceMap &&interfaceMap, HasTraitFn hasTrait); +private: AbstractOperation(StringRef name, Dialect &dialect, TypeID typeID, ParseAssemblyFn parseAssembly, PrintAssemblyFn printAssembly, diff --git a/mlir/include/mlir/IR/TypeSupport.h b/mlir/include/mlir/IR/TypeSupport.h --- a/mlir/include/mlir/IR/TypeSupport.h +++ b/mlir/include/mlir/IR/TypeSupport.h @@ -39,6 +39,15 @@ return AbstractType(dialect, T::getInterfaceMap(), T::getTypeID()); } + /// This method is used by Dialect objects to register types with + /// custom TypeIDs. + /// The use of this method is in general discouraged in favor of + /// 'get(dialect)'; + static AbstractType get(Dialect &dialect, detail::InterfaceMap &&interfaceMap, + TypeID typeID) { + return AbstractType(dialect, std::move(interfaceMap), typeID); + } + /// Return the dialect this type was registered to. Dialect &getDialect() const { return const_cast(dialect); } diff --git a/mlir/include/mlir/Support/InterfaceSupport.h b/mlir/include/mlir/Support/InterfaceSupport.h --- a/mlir/include/mlir/Support/InterfaceSupport.h +++ b/mlir/include/mlir/Support/InterfaceSupport.h @@ -188,6 +188,16 @@ /// Returns true if the interface map contains an interface for the given id. bool contains(TypeID interfaceID) const { return lookup(interfaceID); } + /// Create an InterfaceMap given with the implementation of the interfaces. + /// The use of this constructor is in general discouraged in favor of + /// 'InterfaceMap::get()'. + InterfaceMap(MutableArrayRef> elements) + : interfaces(elements.begin(), elements.end()) { + llvm::sort(interfaces, [](const auto &lhs, const auto &rhs) { + return compare(lhs.first, rhs.first); + }); + } + private: /// Compare two TypeID instances by comparing the underlying pointer. static bool compare(TypeID lhs, TypeID rhs) { @@ -195,12 +205,6 @@ } InterfaceMap() = default; - InterfaceMap(MutableArrayRef> elements) - : interfaces(elements.begin(), elements.end()) { - llvm::sort(interfaces, [](const auto &lhs, const auto &rhs) { - return compare(lhs.first, rhs.first); - }); - } template static InterfaceMap getImpl(std::tuple *) {