14#ifndef MLIR_IR_DIALECTIMPLEMENTATION_H
15#define MLIR_IR_DIALECTIMPLEMENTATION_H
23template <
typename T,
typename =
void>
24struct HasStaticDialectName : std::false_type {};
27struct HasStaticDialectName<
28 T, typename std::enable_if<
29 std::is_same<::llvm::StringLiteral,
30 std::decay_t<decltype(T::dialectName)>>::value,
31 void>::type> : std::true_type {};
82template <
typename T,
typename = T>
86template <
typename AttributeT>
88 AttributeT, std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
91 if constexpr (HasStaticDialectName<AttributeT>::value) {
102template <
typename TypeT>
104 TypeT, std::enable_if_t<std::is_base_of<Type, TypeT>::value, TypeT>> {
114template <
typename IntT>
115struct FieldParser<IntT, std::enable_if_t<(std::is_integral<IntT>::value ||
116 std::is_same_v<IntT, llvm::APInt>),
138template <
typename AttributeT>
140 std::optional<AttributeT>,
141 std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
142 std::optional<AttributeT>>> {
146 if constexpr (HasStaticDialectName<AttributeT>::value) {
153 return {std::optional<AttributeT>(attr)};
156 return {std::nullopt};
161template <
typename IntT>
164 std::enable_if_t<std::is_integral<IntT>::value, std::optional<IntT>>> {
172 return {std::optional<IntT>(value)};
175 return {std::nullopt};
182 std::declval<typename T::value_type &&>()));
184template <
typename StorageType,
typename =
void>
187template <
typename StorageType>
189 std::void_t<decltype(sizeof(FieldParser<StorageType>)),
190 decltype(FieldParser<StorageType>::parse(
191 std::declval<OpAsmParser &>()))>>
194template <
typename ContainerT,
typename =
void>
197template <
typename ContainerT>
199 std::void_t<has_push_back_t<ContainerT>>>
202template <
typename Parser,
typename =
void>
205template <
typename Parser>
207 Parser, std::void_t<decltype(Parser::isKeyValueCompositional)>>
208 : std::bool_constant<Parser::isKeyValueCompositional> {};
214template <
typename StorageType>
216 : std::conjunction<HasFieldParser<StorageType>,
217 IsKeyValueCompositional<FieldParser<StorageType>>> {};
221template <
typename ContainerT>
224 std::enable_if_t<detail::HasFieldParserContainer<ContainerT>::value,
231 auto elementParser = [&]() {
235 elements.push_back(std::move(*element));
258template <
typename StorageType,
typename ConvertFromAttribute>
266 storage = std::move(*value);
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
MLIRContext * getContext() const
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseAffineMap(AffineMap &map)=0
Parse an affine map instance into 'map'.
virtual ParseResult parseCustomAttributeWithFallback(Attribute &result, Type type, function_ref< ParseResult(Attribute &result, Type type)> parseAttribute)=0
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
ParseResult parseString(std::string *string)
Parse a quoted string token.
virtual ParseResult parseCustomTypeWithFallback(Type &result, function_ref< ParseResult(Type &result)> parseType)=0
Parse a custom type with the provided callback, unless the next token is #, in which case the generic...
virtual OptionalParseResult parseOptionalAttribute(Attribute &result, Type type={})=0
Parse an arbitrary optional attribute of a given type and return it in result.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
Attributes are known-constant values of operations.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
virtual StringRef getFullSymbolSpec() const =0
Returns the full specification of the symbol being parsed.
~DialectAsmParser() override
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
~DialectAsmPrinter() override
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This class implements Optional functionality for ParseResult.
This class implement support for parsing global entities like attributes and types.
decltype(std::declval< T >().push_back( std::declval< typename T::value_type && >())) has_push_back_t
ParseResult parsePropertyWithFallback(OpAsmParser &parser, StorageType &storage, ConvertFromAttribute convertFromAttribute)
Parse a property with its FieldParser when one is available, otherwise fall back to the property's at...
Include the generated interface declarations.
LogicalResult convertFromAttribute(int64_t &storage, Attribute attr, function_ref< InFlightDiagnostic()> emitError)
Convert an IntegerAttr attribute to an int64_t, or return an error if the attribute isn't an IntegerA...
static FailureOr< AffineMap > parse(AsmParser &parser)
static FailureOr< AttributeT > parse(AsmParser &parser)
static FailureOr< ContainerT > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
typename ContainerT::value_type ElementT
static FailureOr< IntT > parse(AsmParser &parser)
static FailureOr< TypeT > parse(AsmParser &parser)
static FailureOr< std::optional< AttributeT > > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
static FailureOr< std::optional< IntT > > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
static FailureOr< std::string > parse(AsmParser &parser)
Provide a template class that can be specialized by users to dispatch to parsers.
Whether the selected FieldParser consumes exactly one value in a keyed property list.