13#ifndef MLIR_IR_DIALECT_H
14#define MLIR_IR_DIALECT_H
100 llvm_unreachable(
"dialect has no registered attribute printing hook");
108 llvm_unreachable(
"dialect has no registered type printing hook");
115 virtual std::optional<ParseOpHook>
133 unsigned regionIndex,
142 unsigned regionIndex,
143 unsigned resultIndex,
163 auto it = registeredInterfaces.find(interfaceID);
164 return it != registeredInterfaces.end() ? it->getSecond().get() :
nullptr;
166 template <
typename InterfaceT>
170 InterfaceT::getInterfaceID(),
171 llvm::getTypeName<InterfaceT>());
174 return static_cast<InterfaceT *
>(
184 template <
typename InterfaceT>
185 typename InterfaceT::Concept *
187 return static_cast<typename InterfaceT::Concept *
>(
192 void addInterface(std::unique_ptr<DialectInterface> interface);
195 template <
typename... Args>
199 template <
typename InterfaceT,
typename... Args>
201 InterfaceT *
interface = new InterfaceT(this, std::forward<Args>(args)...);
202 addInterface(std::unique_ptr<DialectInterface>(interface));
210 template <typename InterfaceT, typename ConcreteT>
212 unresolvedPromisedInterfaces.insert(
219 template <
typename InterfaceT,
typename... ConcreteT>
230 StringRef interfaceName =
"") {
231 if (unresolvedPromisedInterfaces.count(
232 {interfaceRequestorID, interfaceID})) {
233 llvm::report_fatal_error(
234 "checking for an interface (`" + interfaceName +
236 "' but never implemented. This is generally an indication "
237 "that the dialect extension implementing the interface was never "
247 unresolvedPromisedInterfaces.erase({interfaceRequestorID, interfaceID});
252 TypeID interfaceID)
const {
253 return unresolvedPromisedInterfaces.count(
254 {interfaceRequestorID, interfaceID});
258 template <
typename ConcreteT,
typename InterfaceT>
261 InterfaceT::getInterfaceID());
276 template <
typename... Args>
282 (
void)std::initializer_list<int>{
287 template <
typename... Args>
302 template <
typename... Args>
324 void operator=(
Dialect &) =
delete;
327 template <
typename T>
335 template <
typename T>
355 bool unknownOpsAllowed =
false;
360 bool unknownTypesAllowed =
false;
380 std::enable_if_t<std::is_base_of<::mlir::Dialect, T>::value>> {
381 static inline bool doit(const ::mlir::Dialect &dialect) {
388 std::enable_if_t<std::is_base_of<::mlir::DialectInterface, T>::value>> {
389 static inline bool doit(const ::mlir::Dialect &dialect) {
390 return const_cast<::
mlir::Dialect &
>(dialect).getRegisteredInterface<T>();
404 template <
typename To>
405 static std::enable_if_t<std::is_base_of<::mlir::Dialect, To>::value, To &>
407 return static_cast<To &
>(dialect);
409 template <
typename To>
410 static std::enable_if_t<std::is_base_of<::mlir::DialectInterface, To>::value,
421 return &cast_convert_val<T, ::mlir::Dialect, ::mlir::Dialect>::doit(
This class contains all of the static information common to all instances of a registered Attribute.
static AbstractAttribute get(Dialect &dialect)
This method is used by Dialect objects when they register the list of attributes they contain.
This class contains all of the static information common to all instances of a registered Type.
static AbstractType get(Dialect &dialect)
This method is used by Dialect objects when they register the list of types they contain.
Attributes are known-constant values of operations.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents an interface overridden for a single dialect.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
MLIRContext * getContext() const
void addAttributes()
Register a set of attribute classes with this dialect.
void addInterfaces()
Register a set of dialect interfaces with this dialect instance.
virtual Type parseType(DialectAsmParser &parser) const
Parse a type registered to this dialect.
virtual std::optional< ParseOpHook > getParseOperationHook(StringRef opName) const
Return the hook to parse an operation registered to this dialect, if any.
void handleUseOfUndefinedPromisedInterface(TypeID interfaceRequestorID, TypeID interfaceID, StringRef interfaceName="")
Checks if the given interface, which is attempting to be used, is a promised interface of this dialec...
StringRef getNamespace() const
static bool isValidNamespace(StringRef str)
Utility function that returns if the given string is a valid dialect namespace.
virtual LogicalResult verifyRegionResultAttribute(Operation *, unsigned regionIndex, unsigned resultIndex, NamedAttribute)
Verify an attribute from this dialect on the result at 'resultIndex' for the region at 'regionIndex' ...
function_ref< ParseResult(OpAsmParser &parser, OperationState &result)> ParseOpHook
Type for a callback provided by the dialect to parse a custom operation.
InterfaceT::Concept * getRegisteredInterfaceForOp(OperationName opName)
virtual LogicalResult verifyRegionArgAttribute(Operation *, unsigned regionIndex, unsigned argIndex, NamedAttribute)
Verify an attribute from this dialect on the argument at 'argIndex' for the region at 'regionIndex' o...
void addOperations()
This method is used by derived classes to add their operations to the set.
bool hasPromisedInterface() const
Checks if a promise has been made for the interface/requestor pair.
InterfaceT & addInterface(Args &&...args)
void declarePromisedInterface()
Declare that the given interface will be implemented, but has a delayed registration.
virtual llvm::unique_function< void(Operation *, OpAsmPrinter &printer)> getOperationPrinter(Operation *op) const
Print an operation registered to this dialect.
virtual void * getRegisteredInterfaceForOp(TypeID interfaceID, OperationName opName)
Lookup an op interface for the given ID if one is registered, otherwise nullptr.
void addType(TypeID typeID, AbstractType &&typeInfo)
Register a type instance with this dialect.
void handleAdditionOfUndefinedPromisedInterface(TypeID interfaceRequestorID, TypeID interfaceID)
Checks if the given interface, which is attempting to be attached to a construct owned by this dialec...
bool allowsUnknownTypes() const
Return true if this dialect allows for unregistered types, i.e., types prefixed with the dialect name...
virtual void printAttribute(Attribute, DialectAsmPrinter &) const
Print an attribute registered to this dialect.
void addTypes()
Register a set of type classes with this dialect.
virtual void printType(Type, DialectAsmPrinter &) const
Print a type registered to this dialect.
void allowUnknownTypes(bool allow=true)
Enable support for unregistered types.
virtual LogicalResult verifyOperationAttribute(Operation *, NamedAttribute)
Verify an attribute from this dialect on the given operation.
void allowUnknownOperations(bool allow=true)
Enable support for unregistered operations.
bool allowsUnknownOperations() const
Returns true if this dialect allows for unregistered operations, i.e.
virtual Attribute parseAttribute(DialectAsmParser &parser, Type type) const
Parse an attribute registered to this dialect.
void declarePromisedInterfaces()
InterfaceT * getRegisteredInterface()
virtual Operation * materializeConstant(OpBuilder &builder, Attribute value, Type type, Location loc)
Registered hook to materialize a single constant operation from a given attribute value with the desi...
void addInterface(std::unique_ptr< DialectInterface > interface)
Register a dialect interface with this dialect instance.
friend class DialectRegistry
TypeID getTypeID() const
Returns the unique identifier that corresponds to this dialect.
DialectInterface * getRegisteredInterface(TypeID interfaceID)
Lookup an interface for the given ID if one is registered, otherwise nullptr.
bool hasPromisedInterface(TypeID interfaceRequestorID, TypeID interfaceID) const
Checks if a promise has been made for the interface/requestor pair.
Dialect(StringRef name, MLIRContext *context, TypeID id)
The constructor takes a unique namespace for this dialect as well as the context to bind to.
void addAttribute(TypeID typeID, AbstractAttribute &&attrInfo)
Register an attribute instance with this dialect.
virtual void getCanonicalizationPatterns(RewritePatternSet &results) const
Register dialect-wide canonicalization patterns.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttribute represents a combination of a name and an Attribute value.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
static void insert(Dialect &dialect)
Register a new operation in a Dialect object.
This class provides an efficient unique identifier for a specific C++ type.
static TypeID get()
Construct a type info object for the given type T.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static void registerAttribute(MLIRContext *ctx)
Register an attribute instance T with the uniquer.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
llvm::function_ref< Fn > function_ref
static std::enable_if_t< std::is_base_of<::mlir::DialectInterface, To >::value, To & > doitImpl(::mlir::Dialect &dialect)
static auto & doit(::mlir::Dialect &dialect)
static std::enable_if_t< std::is_base_of<::mlir::Dialect, To >::value, To & > doitImpl(::mlir::Dialect &dialect)
static auto doit(::mlir::Dialect *dialect)
static bool doit(const ::mlir::Dialect &dialect)
static bool doit(const ::mlir::Dialect &dialect)
This represents an operation in an abstracted form, suitable for use with the builder APIs.
static void registerType(MLIRContext *ctx)
Register a type instance T with the uniquer.