13#ifndef MLIR_IR_OPIMPLEMENTATION_H
14#define MLIR_IR_OPIMPLEMENTATION_H
19#include "llvm/ADT/Twine.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/SMLoc.h"
27template <
typename T,
typename =
void>
28struct HasStaticName : std::false_type {};
31struct HasStaticName<T,
32 typename std::enable_if<
33 std::is_same<::llvm::StringLiteral,
34 std::decay_t<decltype(T::name)>>::value,
35 void>::type> : std::true_type {};
52 : resource(resource), opaqueID(resourceID), dialect(dialect) {}
54 return resource == other.resource;
68 void *resource =
nullptr;
78template <
typename DerivedT,
typename ResourceT,
typename DialectT>
149 virtual void printFloat(
const APFloat &value);
153 template <
typename IntT,
154 typename = std::enable_if_t<std::is_integral_v<IntT>>>
157 if constexpr (std::is_same_v<IntT, int8_t> ||
158 std::is_same_v<IntT, uint8_t>) {
169 template <
typename AttrOrType>
171 decltype(std::declval<AttrOrType>().print(std::declval<AsmPrinter &>()));
172 template <
typename AttrOrType>
174 llvm::is_detected<has_print_method, AttrOrType>;
179 template <
typename AttrOrType,
180 std::enable_if_t<detect_has_print_method<AttrOrType>::value>
187 uint64_t posPrior = os.tell();
188 attrOrType.print(*
this);
189 if (posPrior != os.tell())
201 template <
typename AttrOrType,
202 std::enable_if_t<detect_has_print_method<AttrOrType>::value>
205 llvm::interleaveComma(
213 template <
typename AttrOrType,
214 std::enable_if_t<!detect_has_print_method<AttrOrType>::value>
231 llvm::interleaveComma(values,
getStream(), [
this](
char value) {
238 template <
typename IntT,
239 std::enable_if_t<std::is_integral_v<IntT> &&
240 !std::is_same_v<IntT, bool>> *sfinae =
nullptr>
280 template <
typename TypeRange>
282 if (types.begin() != types.end())
285 template <
typename TypeRange>
289 bool wrapped = !llvm::hasSingleElement(types) ||
290 llvm::isa<FunctionType>((*types.begin()));
293 llvm::interleaveComma(types, *
this);
299 template <
typename InputRangeT,
typename ResultRangeT>
303 llvm::interleaveComma(inputs, *
this);
317 printer->popCyclicPrinting();
325 : printer(std::exchange(rhs.printer,
nullptr)) {}
328 printer = std::exchange(rhs.printer,
nullptr);
345 template <
class AttrOrTypeT>
348 std::is_base_of_v<AttributeTrait::IsMutable<AttrOrTypeT>,
350 std::is_base_of_v<TypeTrait::IsMutable<AttrOrTypeT>, AttrOrTypeT>,
351 "Only mutable attributes or types can be cyclic");
381template <
typename AsmPrinterT,
383 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
389template <
typename AsmPrinterT,
391 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
393 p.printAttribute(attr);
397template <
typename AsmPrinterT,
399 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
400inline AsmPrinterT &
operator<<(AsmPrinterT &p,
const APFloat &value) {
404template <
typename AsmPrinterT,
406 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
408 return p << APFloat(value);
410template <
typename AsmPrinterT,
412 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
413inline AsmPrinterT &
operator<<(AsmPrinterT &p,
double value) {
414 return p << APFloat(value);
419template <
typename AsmPrinterT,
421 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
422inline AsmPrinterT &
operator<<(AsmPrinterT &p, int8_t value) {
423 p.printInteger(value);
426template <
typename AsmPrinterT,
428 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
429inline AsmPrinterT &
operator<<(AsmPrinterT &p, uint8_t value) {
430 p.printInteger(value);
437template <
typename AsmPrinterT,
typename T,
438 std::enable_if_t<!std::is_convertible<T &, Value &>::value &&
439 !std::is_convertible<T &, Type &>::value &&
440 !std::is_convertible<T &, Attribute &>::value &&
441 !std::is_convertible<T &, ValueRange>::value &&
442 !std::is_convertible<T &, APFloat &>::value &&
443 !llvm::is_one_of<T,
bool, float, double, int8_t,
447 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
448inline AsmPrinterT &
operator<<(AsmPrinterT &p,
const T &other) {
449 p.getStream() << other;
453template <
typename AsmPrinterT,
455 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
457 return p << (value ? StringRef(
"true") :
"false");
460template <
typename AsmPrinterT,
typename ValueRangeT,
462 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
465 llvm::interleaveComma(types, p);
469template <
typename AsmPrinterT,
471 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
473 llvm::interleaveComma(types, p);
483 typename AsmPrinterT,
typename T,
484 typename = std::enable_if_t<std::is_same<AsmPrinter, AsmPrinterT>::value &&
485 std::is_convertible<T &, ValueRange>::value>>
486inline AsmPrinterT &
operator<<(AsmPrinterT &p,
const T &other) =
delete;
488template <
typename AsmPrinterT,
typename ElementT,
490 std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value>>
492 llvm::interleaveComma(types, p);
517 bool omitType =
false) = 0;
531 template <
typename ContainerType>
537 template <
typename IteratorType>
539 llvm::interleaveComma(llvm::make_range(it, end),
getStream(),
583 bool printBlockTerminators =
true,
584 bool printEmptyBlock =
false) = 0;
629 std::enable_if_t<std::is_convertible<T &, ValueRange>::value &&
630 !std::is_convertible<T &, Value &>::value,
664 const Twine &message = {}) = 0;
775 return emitError(loc,
"expected string");
819 virtual ParseResult
parseFloat(
const llvm::fltSemantics &semantics,
823 template <
typename IntT>
828 return emitError(loc,
"expected integer value");
833 template <
typename IntT>
838 return emitError(loc,
"expected decimal integer value");
847 template <
typename IntT,
typename ParseFn>
853 if (!parseResult.
has_value() || failed(*parseResult))
860 (IntT)uintResult.sextOrTrunc(
sizeof(IntT) * CHAR_BIT).getLimitedValue();
861 if (APInt(uintResult.getBitWidth(),
result,
862 std::is_signed_v<IntT>,
864 return emitError(loc,
"integer value too large");
869 template <
typename IntT>
871 return parseOptionalIntegerAndCheck(
875 template <
typename IntT>
877 return parseOptionalIntegerAndCheck(
result, [&](APInt &
result) {
914 StringRef contextMessage = StringRef()) = 0;
932 template <
typename ResultT = ParseResult>
937 if (keyword && !keyword->empty())
938 this->keyword = *keyword;
939 else if (failed(parser.parseKeywordOrCompletion(&
this->keyword)))
944 return Case(str, [&](StringRef, SMLoc) {
return std::move(value); });
947 return Default([&](StringRef, SMLoc) {
return std::move(value); });
952 template <
typename FnT,
typename = std::enable_if_t<
953 !std::is_convertible<FnT, ResultT>::value>>
960 parser.codeCompleteExpectedTokens(str);
961 else if (keyword == str)
962 result.emplace(std::move(fn(keyword, loc)));
965 template <
typename FnT,
typename = std::enable_if_t<
966 !std::is_convertible<FnT, ResultT>::value>>
969 result.emplace(fn(keyword, loc));
974 bool hasValue()
const {
return result.has_value(); }
977 [[nodiscard]]
operator ResultT() {
979 return parser.emitError(loc,
"unexpected keyword: ") << keyword;
980 return std::move(*result);
994 std::optional<ResultT>
result;
1007 return emitError(loc,
"expected valid keyword");
1033 <<
"expected valid keyword or string";
1054 template <
typename T,
typename... ParamsT>
1056 return T::getChecked([&] {
return emitError(loc); },
1057 std::forward<ParamsT>(params)...);
1061 template <
typename T,
typename... ParamsT>
1064 std::forward<ParamsT>(params)...);
1082 template <
typename AttrType>
1092 if (!(
result = llvm::dyn_cast<AttrType>(attr)))
1093 return emitError(loc,
"invalid kind of attribute specified");
1106 template <
typename AttrType>
1115 template <
typename AttrType>
1126 result = llvm::dyn_cast<AttrType>(attr);
1128 return emitError(loc,
"invalid kind of attribute specified");
1135 template <
typename AttrType>
1137 std::declval<Type>()));
1138 template <
typename AttrType>
1145 template <
typename AttrType>
1146 std::enable_if_t<detect_has_parse_method<AttrType>::value, ParseResult>
1155 result = AttrType::parse(*
this, type);
1163 result = llvm::dyn_cast<AttrType>(attr);
1165 return emitError(loc,
"invalid kind of attribute specified");
1172 template <
typename AttrType>
1173 std::enable_if_t<!detect_has_parse_method<AttrType>::value, ParseResult>
1182 template <
typename AttrType>
1183 std::enable_if_t<detect_has_parse_method<AttrType>::value, ParseResult>
1191 result = AttrType::parse(*
this, type);
1197 result = llvm::dyn_cast<AttrType>(attr);
1199 return emitError(loc,
"invalid kind of attribute specified");
1204 template <
typename AttrType>
1205 std::enable_if_t<!detect_has_parse_method<AttrType>::value, ParseResult>
1213 Type type = {}) = 0;
1217 Type type = {}) = 0;
1221 Type type = {}) = 0;
1225 Type type = {}) = 0;
1233 typename = std::enable_if_t<!llvm::is_one_of<
1239 if (!parseResult.
has_value() || failed(*parseResult))
1241 result = dyn_cast<AttrType>(attr);
1244 emitError(loc,
"invalid kind of attribute specified");
1245 if constexpr (HasStaticName<AttrType>::value)
1246 diag <<
": expected " << AttrType::name <<
", but found " << attr;
1254 template <
typename AttrType>
1263 template <
typename AttrType>
1268 if (parseResult.
has_value() && succeeded(*parseResult))
1302 <<
"expected valid '@'-identifier for symbol name";
1336 template <
typename ResourceT>
1345 <<
"dialect '" << ResourceT::Dialect::getDialectNamespace()
1352 if (
auto *
result = dyn_cast<ResourceT>(&*handle))
1353 return std::move(*
result);
1354 return emitError(handleLoc) <<
"provided resource handle differs from the "
1355 "expected resource type";
1374 template <
typename TypeT>
1384 result = llvm::dyn_cast<TypeT>(type);
1387 emitError(loc,
"invalid kind of type specified");
1388 if constexpr (HasStaticName<TypeT>::value)
1389 diag <<
": expected " << TypeT::name <<
", but found " << type;
1397 template <
typename TypeT>
1399 decltype(TypeT::parse(std::declval<AsmParser &>()));
1400 template <
typename TypeT>
1402 llvm::is_detected<type_has_parse_method, TypeT>;
1407 template <
typename TypeT>
1408 std::enable_if_t<detect_type_has_parse_method<TypeT>::value, ParseResult>
1415 result = TypeT::parse(*
this);
1421 result = llvm::dyn_cast<TypeT>(type);
1424 emitError(loc,
"invalid kind of type specified");
1425 if constexpr (HasStaticName<TypeT>::value)
1426 diag <<
": expected " << TypeT::name <<
", but found " << type;
1433 template <
typename TypeT>
1434 std::enable_if_t<!detect_type_has_parse_method<TypeT>::value, ParseResult>
1453 template <
typename TypeType>
1463 result = llvm::dyn_cast<TypeType>(type);
1466 emitError(loc,
"invalid kind of type specified");
1467 if constexpr (HasStaticName<TypeType>::value)
1468 diag <<
": expected " << TypeType::name <<
", but found " << type;
1501 result.append(types.begin(), types.end());
1519 bool allowDynamic =
true,
1520 bool withTrailingX =
true) = 0;
1534 parser->popCyclicParsing();
1540 : parser(std::exchange(rhs.parser,
nullptr)) {}
1542 parser = std::exchange(rhs.parser,
nullptr);
1558 template <
class AttrOrTypeT>
1561 std::is_base_of_v<AttributeTrait::IsMutable<AttrOrTypeT>,
1563 std::is_base_of_v<TypeTrait::IsMutable<AttrOrTypeT>, AttrOrTypeT>,
1564 "Only mutable attributes or types can be cyclic");
1574 virtual FailureOr<AsmDialectResourceHandle>
1601 void operator=(
const AsmParser &) =
delete;
1646 virtual std::pair<StringRef, unsigned>
1690 std::optional<
MutableArrayRef<std::unique_ptr<Region>>> parsedRegions =
1693 std::optional<Attribute> parsedPropertiesAttribute = std::nullopt,
1694 std::optional<FunctionType> parsedFnType = std::nullopt) = 0;
1699 bool allowResultNumber =
true) = 0;
1704 bool allowResultNumber =
true) = 0;
1711 bool allowResultNumber =
true,
1712 int requiredOperandCount = -1) = 0;
1716 int requiredOperandCount,
1719 true, requiredOperandCount);
1742 template <
typename Operands = ArrayRef<UnresolvedOperand>>
1750 template <
typename Operands = ArrayRef<UnresolvedOperand>>
1762 typename = std::enable_if_t<!std::is_convertible<Types, Type>::value>>
1765 size_t operandSize = llvm::range_size(operands);
1766 size_t typeSize = llvm::range_size(types);
1767 if (operandSize != typeSize) {
1770 <<
"number of operands and types do not match: got " << operandSize
1771 <<
" operands and " << typeSize <<
" types";
1774 for (
auto [operand, type] : llvm::zip_equal(operands, types))
1815 bool allowAttrs =
false) = 0;
1820 bool allowAttrs =
false) = 0;
1825 bool allowType =
false,
1826 bool allowAttrs =
false) = 0;
1842 bool enableNameShadowing =
false) = 0;
1847 bool enableNameShadowing =
false) = 0;
1855 bool enableNameShadowing =
false) = 0;
1923 ArrayRef<int64_t> dimensions);
1934#include "mlir/IR/OpAsmOpInterface.h.inc"
1941#include "mlir/IR/OpAsmDialectInterface.h.inc"
1951 return lhs.getResource() == rhs.getResource();
return MutableOperandRange * this
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
AsmDialectResourceHandleBase(AsmDialectResourceHandle handle)
const ResourceT * getResource() const
static bool classof(const AsmDialectResourceHandle *handle)
Support llvm style casting.
AsmDialectResourceHandleBase(ResourceT *resource, DialectT *dialect)
Construct a handle from a pointer to the resource.
ResourceT * getResource()
Return the resource referenced by this handle.
DialectT * getDialect() const
Return the dialect that owns the resource.
This class represents an opaque handle to a dialect resource entry.
AsmDialectResourceHandle()=default
TypeID getTypeID() const
Return the type ID of the resource.
Dialect * getDialect() const
Return the dialect that owns the resource.
void * getResource() const
Return an opaque pointer to the referenced resource.
bool operator==(const AsmDialectResourceHandle &other) const
AsmDialectResourceHandle(void *resource, TypeID resourceID, Dialect *dialect)
This class represents a single parsed resource entry.
Class used to automatically end a cyclic region on destruction.
CyclicParseReset & operator=(CyclicParseReset &&rhs)
CyclicParseReset(const CyclicParseReset &)=delete
CyclicParseReset & operator=(const CyclicParseReset &)=delete
CyclicParseReset(AsmParser *parser)
CyclicParseReset(CyclicParseReset &&rhs)
bool hasValue() const
Returns true if this switch has a value yet.
KeywordSwitch & Default(FnT &&fn)
KeywordSwitch & Case(StringLiteral str, FnT &&fn)
Case that invokes the provided functor when true.
KeywordSwitch & Default(ResultT value)
KeywordSwitch & Case(StringLiteral str, ResultT value)
Case that uses the provided value when true.
KeywordSwitch(AsmParser &parser, StringRef *keyword=nullptr)
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual ParseResult parseMinus()=0
Parse a '-' token.
llvm::is_detected< has_parse_method, AttrType > detect_has_parse_method
ParseResult parseSymbolName(StringAttr &result)
Parse an -identifier and store it (without the '@' symbol) in a string attribute.
std::enable_if_t< detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result, Type type={})
Parse a custom attribute of a given type unless the next token is #, in which case the generic parser...
virtual ParseResult parseLBrace()=0
Parse a { token.
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
@ Paren
Parens surrounding zero or more operands.
@ None
Zero or more operands with no delimiters.
@ OptionalLessGreater
<> brackets supporting zero or more ops, or nothing.
@ Braces
{} brackets surrounding zero or more operands.
@ OptionalBraces
{} brackets surrounding zero or more operands, or nothing.
@ OptionalParen
Parens supporting zero or more operands, or nothing.
@ Square
Square brackets surrounding zero or more operands.
@ LessGreater
<> brackets surrounding zero or more operands.
@ OptionalSquare
Square brackets supporting zero or more ops, or nothing.
decltype(TypeT::parse(std::declval< AsmParser & >())) type_has_parse_method
Trait to check if TypeT provides a parse method.
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual ParseResult parseColonTypeList(SmallVectorImpl< Type > &result)=0
Parse a colon followed by a type list, which must have at least one type.
virtual ParseResult parseIntegerSet(IntegerSet &set)=0
Parse an integer set instance into 'set'.
virtual ParseResult parseOptionalKeywordOrString(std::string *result)=0
Parse an optional keyword or string.
virtual ParseResult parseOptionalSymbolName(StringAttr &result)=0
Parse an optional -identifier and store it (without the '@' symbol) in a string attribute.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseOptionalRBrace()=0
Parse a } token if present.
ParseResult parseDecimalInteger(IntT &result)
Parse a decimal integer value from the stream.
virtual ParseResult parseOptionalMinus()=0
Parse a '-' token if present.
virtual ParseResult parsePlus()=0
Parse a '+' token.
ParseResult parseKeyword(StringRef *keyword)
Parse a keyword into 'keyword'.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual void popCyclicParsing()=0
Removes the element that was last inserted with a successful call to pushCyclicParsing.
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseOptionalEqual()=0
Parse a = token if present.
decltype(AttrType::parse(std::declval< AsmParser & >(), std::declval< Type >())) has_parse_method
Trait to check if AttrType provides a parse method.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual OptionalParseResult parseOptionalType(Type &result)=0
Parse an optional type.
MLIRContext * getContext() const
virtual Location getEncodedSourceLoc(SMLoc loc)=0
Re-encode the given source location as an MLIR location and return it.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalColon()=0
Parse a : token if present.
virtual ParseResult parseLSquare()=0
Parse a [ token.
virtual ParseResult parseRSquare()=0
Parse a ] token.
virtual ParseResult parseOptionalColonTypeList(SmallVectorImpl< Type > &result)=0
Parse an optional colon followed by a type list, which if present must have at least one type.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName, NamedAttrList &attrs)
Parse an optional -identifier and store it (without the '@' symbol) in a string attribute named 'attr...
virtual OptionalParseResult parseOptionalDecimalInteger(APInt &result)=0
ParseResult parseAttribute(AttrType &result, Type type, StringRef attrName, NamedAttrList &attrs)
Parse an arbitrary attribute of a given type and populate it in result.
ParseResult parseAttribute(AttrType &result, Type type={})
Parse an attribute of a specific kind and type.
ParseResult parseKeywordOrString(std::string *result)
Parse a keyword or a quoted string.
virtual void codeCompleteExpectedTokens(ArrayRef< StringRef > tokens)=0
Signal the code completion of a set of expected tokens.
virtual ParseResult parseRBrace()=0
Parse a } token.
virtual ParseResult parseAffineMap(AffineMap &map)=0
Parse an affine map instance into 'map'.
ParseResult addTypeToList(Type type, SmallVectorImpl< Type > &result)
Add the specified type to the end of the specified type list and return success.
virtual ParseResult parseOptionalKeywordOrString(std::string *result, ArrayRef< StringRef > allowedValues)=0
Parse an optional keyword or string into result if it is present and one of the 'allowedValues'.
virtual ParseResult parseOptionalRParen()=0
Parse a ) token if present.
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...
OptionalParseResult parseOptionalAttribute(AttrType &result, Type type={})
Parse an optional attribute of a specific typed result.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseDimensionList(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)=0
Parse a dimension list of a tensor or memref type.
ParseResult parseString(std::string *string)
Parse a quoted string token.
virtual ParseResult parseOptionalPlus()=0
Parse a '+' token if present.
virtual ParseResult parseOptionalKeyword(StringRef *keyword, ArrayRef< StringRef > allowedValues)=0
Parse a keyword, if present, and if one of the 'allowedValues', into 'keyword'.
virtual ParseResult parseOptionalGreater()=0
Parse a '>' token if present.
std::enable_if_t<!detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result, Type type={})
SFINAE parsing method for Attribute that don't implement a parse method.
virtual ParseResult parseEqual()=0
Parse a = 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 ParseResult parseFloat(const llvm::fltSemantics &semantics, APFloat &result)=0
Parse a floating point value into APFloat from the stream.
virtual OptionalParseResult parseOptionalAttribute(ArrayAttr &result, Type type={})=0
Parse an optional array attribute and return it in result.
virtual ParseResult parseStar()=0
Parse a '*' token.
virtual ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result)=0
Parse a named dictionary into 'result' if the attributes keyword is present.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual OptionalParseResult parseOptionalAttribute(Attribute &result, Type type={})=0
Parse an arbitrary optional attribute of a given type and return it in result.
virtual ParseResult parseSlash()=0
Parse a '/' token.
ParseResult parseCommaSeparatedList(function_ref< ParseResult()> parseElementFn)
Parse a comma separated list of elements that must have at least one entry in it.
virtual ParseResult parseVerticalBar()=0
Parse a '|' token.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalComma()=0
Parse a , token if present.
std::enable_if_t<!detect_type_has_parse_method< TypeT >::value, ParseResult > parseCustomTypeWithFallback(TypeT &result)
SFINAE parsing method for Type that don't implement a parse method.
OptionalParseResult parseOptionalAttribute(AttrType &result, StringRef attrName, NamedAttrList &attrs)
Parse an optional attribute of a specific type and add it to the list with the specified name.
auto getChecked(SMLoc loc, ParamsT &&...params)
Invoke the getChecked method of the given Attribute or Type class, using the provided location to emi...
std::enable_if_t< detect_type_has_parse_method< TypeT >::value, ParseResult > parseCustomTypeWithFallback(TypeT &result)
Parse a custom Type of a given type unless the next token is #, in which case the generic parser is i...
virtual ParseResult parseColon()=0
Parse a : token.
ParseResult addTypesToList(ArrayRef< Type > types, SmallVectorImpl< Type > &result)
Add the specified types to the end of the specified type list and return success.
ParseResult parseAttribute(Attribute &result, StringRef attrName, NamedAttrList &attrs)
Parse an arbitrary attribute and return it in result.
FailureOr< ResourceT > parseResourceHandle()
Parse a handle to a resource within the assembly format.
virtual OptionalParseResult parseOptionalAttribute(StringAttr &result, Type type={})=0
Parse an optional string attribute and return it in result.
llvm::is_detected< type_has_parse_method, TypeT > detect_type_has_parse_method
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseOptionalString(std::string *string)=0
Parse a quoted string token if present.
std::enable_if_t< detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result, Type type, StringRef attrName, NamedAttrList &attrs)
Parse a custom attribute of a given type unless the next token is #, in which case the generic parser...
OptionalParseResult parseOptionalInteger(IntT &result)
ParseResult getCurrentLocation(SMLoc *loc)
virtual ParseResult parseOptionalLess()=0
Parse a '<' token if present.
virtual ParseResult parseOptionalStar()=0
Parse a '*' token if present.
OptionalParseResult parseOptionalAttribute(AttrType &result, Type type, StringRef attrName, NamedAttrList &attrs)
Parse an optional attribute of a specific type and add it to the list with the specified name.
virtual OptionalParseResult parseOptionalAttribute(SymbolRefAttr &result, Type type={})=0
Parse an optional symbol ref attribute and return it in result.
virtual ParseResult parseOptionalString(std::string *string, ArrayRef< StringRef > allowedValues)=0
Parse a string into 'string' if it is present and one of the 'allowedValues'.
virtual ParseResult parseQuestion()=0
Parse a '?' token.
virtual ParseResult parseOptionalSlash()=0
Parse a '/' token if present.
ParseResult parseType(TypeT &result)
Parse a type of a specific type.
FailureOr< CyclicParseReset > tryStartCyclicParse(AttrOrTypeT attrOrType)
Attempts to start a cyclic parsing region for attrOrType.
virtual ParseResult parseOptionalRSquare()=0
Parse a ] token if present.
virtual ParseResult parseArrow()=0
Parse a '->' token.
ParseResult parseColonType(TypeType &result)
Parse a colon followed by a type of a specific kind, e.g. a FunctionType.
virtual ParseResult parseGreater()=0
Parse a '>' token.
OptionalParseResult parseOptionalDecimalInteger(IntT &result)
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseOptionalEllipsis()=0
Parse a ... token if present;.
virtual ParseResult parseType(Type &result)=0
Parse a type.
ParseResult parseAttribute(AttrType &result, StringRef attrName, NamedAttrList &attrs)
Parse an attribute of a specific kind and type.
virtual FailureOr< AsmDialectResourceHandle > parseResourceHandle(Dialect *dialect)=0
Parse a handle to a resource within the assembly format for the given dialect.
virtual ParseResult parseEllipsis()=0
Parse a ... token.
auto getChecked(ParamsT &&...params)
A variant of getChecked that uses the result of getNameLoc to emit errors.
virtual ParseResult parseComma()=0
Parse a , token.
virtual ParseResult parseOptionalArrowTypeList(SmallVectorImpl< Type > &result)=0
Parse an optional arrow followed by a type list.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
ParseResult parseKeywordType(const char *keyword, Type &result)
Parse a keyword followed by a type.
virtual ParseResult parseArrowTypeList(SmallVectorImpl< Type > &result)=0
Parse an arrow followed by a type list.
virtual ParseResult parseOptionalVerticalBar()=0
Parse a '|' token if present.
ParseResult parseTypeList(SmallVectorImpl< Type > &result)
Parse a type list.
virtual ParseResult parseBase64Bytes(std::vector< char > *bytes)=0
Parses a Base64 encoded string of bytes.
virtual ParseResult parseAffineExpr(ArrayRef< std::pair< StringRef, AffineExpr > > symbolSet, AffineExpr &expr)=0
Parse an affine expr instance into 'expr' using the already computed mapping from symbols to affine e...
virtual ParseResult parseKeywordOrCompletion(StringRef *keyword)=0
Parse a keyword, or an empty string if the current location signals a code completion.
virtual ParseResult parseFloat(double &result)=0
Parse a floating point value from the stream.
ParseResult parseSymbolName(StringAttr &result, StringRef attrName, NamedAttrList &attrs)
Parse an -identifier and store it (without the '@' symbol) in a string attribute named 'attrName'.
virtual ParseResult parseOptionalKeyword(StringRef *keyword)=0
Parse a keyword, if present, into 'keyword'.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
virtual ParseResult parseOptionalLSquare()=0
Parse a [ token if present.
virtual LogicalResult pushCyclicParsing(const void *opaquePointer)=0
Pushes a new attribute or type in the form of a type erased pointer into an internal set.
std::enable_if_t<!detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result, Type type, StringRef attrName, NamedAttrList &attrs)
SFINAE parsing method for Attribute that don't implement a parse method.
virtual ParseResult parseOptionalQuestion()=0
Parse a '?' token if present.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
virtual ParseResult parseXInDimensionList()=0
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
virtual ParseResult parseOptionalLBrace()=0
Parse a { token if present.
virtual ParseResult parseKeyword(StringRef keyword, const Twine &msg)=0
Class used to automatically end a cyclic region on destruction.
CyclicPrintReset(AsmPrinter *printer)
CyclicPrintReset & operator=(CyclicPrintReset &&rhs)
CyclicPrintReset & operator=(const CyclicPrintReset &)=delete
CyclicPrintReset(const CyclicPrintReset &)=delete
CyclicPrintReset(CyclicPrintReset &&rhs)
void printStrippedAttrOrType(char value)
Print a plain char parameter as a bare keyword for identifier characters (e.g.
void printStrippedAttrOrType(ArrayRef< AttrOrType > attrOrTypes)
Print the provided array of attributes or types in the context of an operation custom printer/parser:...
virtual void decreaseIndent()
Decrease indentation.
decltype(std::declval< AttrOrType >().print(std::declval< AsmPrinter & >())) has_print_method
Trait to check if AttrType provides a print method.
virtual void printAttributeWithoutType(Attribute attr)
Print the given attribute without its type.
virtual LogicalResult printAlias(Attribute attr)
Print the alias for the given attribute, return failure if no alias could be printed.
virtual void popCyclicPrinting()
Removes the element that was last inserted with a successful call to pushCyclicPrinting.
AsmPrinter()=default
Initialize the printer with no internal implementation.
virtual void increaseIndent()
Increase indentation.
void printFunctionalType(InputRangeT &&inputs, ResultRangeT &&results)
Print the two given type ranges in a functional form.
void printStrippedAttrOrType(ArrayRef< char > values)
Print an array of plain char parameters element-wise with the char overload above,...
virtual LogicalResult pushCyclicPrinting(const void *opaquePointer)
Pushes a new attribute or type in the form of a type erased pointer into an internal set.
virtual void printType(Type type)
virtual void printKeywordOrString(StringRef keyword)
Print the given string as a keyword, or a quoted and escaped string if it has any special or non-prin...
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
virtual void printString(StringRef string)
Print the given string as a quoted string, escaping any special or non-printable characters in it.
FailureOr< CyclicPrintReset > tryStartCyclicPrint(AttrOrTypeT attrOrType)
Attempts to start a cyclic printing region for attrOrType.
void printOptionalArrowTypeList(TypeRange &&types)
Print an optional arrow followed by a type list.
llvm::is_detected< has_print_method, AttrOrType > detect_has_print_method
virtual void printAttribute(Attribute attr)
void printDimensionList(ArrayRef< int64_t > shape)
void printArrowTypeList(TypeRange &&types)
void printInteger(IntT value)
Print the given integer value.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
virtual void printResourceHandle(const AsmDialectResourceHandle &resource)
Print a handle to the given dialect resource.
virtual void printFloat(const APFloat &value)
Print the given floating point value in a stabilized form that can be roundtripped through the IR.
virtual void printNamedAttribute(NamedAttribute attr)
Print the given named attribute.
virtual void printNewline()
Print a newline and indent the printer to the start of the current operation/attribute/type.
void printStrippedAttrOrType(std::optional< IntT > value)
Print a present optional integer parameter through the overloads for its underlying type,...
void printStrippedAttrOrType(AttrOrType attrOrType)
Print the provided attribute in the context of an operation custom printer/parser: this will invoke d...
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
This class is used to build resource entries for use by the printer.
Attributes are known-constant values of operations.
This class represents an argument of a Block.
Block represents an ordered list of Operations.
OpListType::iterator iterator
This class is a general helper class for creating context-global objects like types,...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
This class represents a diagnostic that is inflight and set to be reported.
An integer set representing a conjunction of one or more affine equalities and inequalities.
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.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
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,...
virtual size_t getNumResults() const =0
Return the number of declared SSA results.
virtual OptionalParseResult parseOptionalAssignmentList(SmallVectorImpl< Argument > &lhs, SmallVectorImpl< UnresolvedOperand > &rhs)=0
virtual ParseResult parseRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region.
virtual ParseResult parseSuccessor(Block *&dest)=0
Parse a single operation successor.
virtual std::pair< StringRef, unsigned > getResultName(unsigned resultNo) const =0
Return the name of the specified result in the specified syntax, as well as the sub-element in the na...
virtual ParseResult parseArgument(Argument &result, bool allowType=false, bool allowAttrs=false)=0
Parse a single argument with the following syntax:
ParseResult parseTrailingOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None)
Parse zero or more trailing SSA comma-separated trailing operand references with a specified surround...
ParseResult resolveOperands(Operands &&operands, Type type, SMLoc loc, SmallVectorImpl< Value > &result)
virtual ParseResult parseArgumentList(SmallVectorImpl< Argument > &result, Delimiter delimiter=Delimiter::None, bool allowType=false, bool allowAttrs=false)=0
Parse zero or more arguments with a specified surrounding delimiter.
virtual ParseResult parseAffineMapOfSSAIds(SmallVectorImpl< UnresolvedOperand > &operands, Attribute &map, StringRef attrName, NamedAttrList &attrs, Delimiter delimiter=Delimiter::Square)=0
Parses an affine map attribute where dims and symbols are SSA operands.
ParseResult resolveOperands(Operands &&operands, Types &&types, SMLoc loc, SmallVectorImpl< Value > &result)
Resolve a list of operands and a list of operand types to SSA values, emitting an error and returning...
virtual OptionalParseResult parseOptionalArgument(Argument &result, bool allowType=false, bool allowAttrs=false)=0
Parse a single argument if present.
virtual ParseResult parseOptionalLocationSpecifier(std::optional< Location > &result)=0
Parse a loc(...) specifier if present, filling in result if so.
ParseResult parseAssignmentList(SmallVectorImpl< Argument > &lhs, SmallVectorImpl< UnresolvedOperand > &rhs)
Parse a list of assignments of the form (x1 = y1, x2 = y2, ...)
virtual ParseResult resolveOperand(const UnresolvedOperand &operand, Type type, SmallVectorImpl< Value > &result)=0
Resolve an operand to an SSA value, emitting an error on failure.
virtual OptionalParseResult parseOptionalOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single operand if present.
virtual FailureOr< OperationName > parseCustomOperationName()=0
Parse the name of an operation, in the custom form.
virtual ParseResult parseSuccessorAndUseList(Block *&dest, SmallVectorImpl< Value > &operands)=0
Parse a single operation successor and its operand list.
virtual OptionalParseResult parseOptionalRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
virtual Operation * parseGenericOperation(Block *insertBlock, Block::iterator insertPt)=0
Parse an operation in its generic form.
ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, int requiredOperandCount, Delimiter delimiter=Delimiter::None)
Parse a specified number of comma separated operands.
ParseResult resolveOperands(Operands &&operands, Type type, SmallVectorImpl< Value > &result)
Resolve a list of operands to SSA values, emitting an error on failure, or appending the results to t...
virtual ParseResult parseOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single SSA value operand name along with a result number if allowResultNumber is true.
virtual ParseResult parseAffineExprOfSSAIds(SmallVectorImpl< UnresolvedOperand > &dimOperands, SmallVectorImpl< UnresolvedOperand > &symbOperands, AffineExpr &expr)=0
Parses an affine expression where dims and symbols are SSA operands.
virtual OptionalParseResult parseOptionalSuccessor(Block *&dest)=0
Parse an optional operation successor.
virtual ParseResult parseGenericOperationAfterOpName(OperationState &result, std::optional< ArrayRef< UnresolvedOperand > > parsedOperandType=std::nullopt, std::optional< ArrayRef< Block * > > parsedSuccessors=std::nullopt, std::optional< MutableArrayRef< std::unique_ptr< Region > > > parsedRegions=std::nullopt, std::optional< ArrayRef< NamedAttribute > > parsedAttributes=std::nullopt, std::optional< Attribute > parsedPropertiesAttribute=std::nullopt, std::optional< FunctionType > parsedFnType=std::nullopt)=0
Parse different components, viz., use-info of operand(s), successor(s), region(s),...
virtual OptionalParseResult parseOptionalRegion(std::unique_ptr< Region > ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
virtual ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None, bool allowResultNumber=true, int requiredOperandCount=-1)=0
Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
void printOperands(IteratorType it, IteratorType end)
Print a comma separated list of operands.
virtual void shadowRegionArgs(Region ®ion, ValueRange namesToUse)=0
Renumber the arguments for the specified region to the same names as the SSA values in namesToUse.
virtual void printSuccessorAndUseList(Block *successor, ValueRange succOperands)=0
Print the successor and its operands.
void printOperands(const ContainerType &container)
Print a comma separated list of operands.
virtual void printOptionalAttrDictWithKeyword(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary prefixed with 'attribute...
void printOperands(OperandRange operands)
Print a comma separated range of operation operands out of line to avoid instantiating the range iter...
void printOptionalAttrDict(DictionaryAttr attrs, ArrayRef< StringRef > elidedAttrs={})
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
virtual void printOptionalLocationSpecifier(Location loc)=0
Print a loc(...) specifier if printing debug info is enabled.
virtual void printCustomOrGenericOp(Operation *op)=0
Prints the entire operation with the custom assembly form, if available, or the generic assembly form...
void printOperandTypes(ValueTypeRange< OperandRange > types)
Print the types of a comma separated range of operation operands.
virtual void printOperand(Value value, raw_ostream &os)=0
virtual void printSuccessor(Block *successor)=0
Print the given successor.
virtual void printAffineExprOfSSAIds(AffineExpr expr, ValueRange dimOperands, ValueRange symOperands)=0
Prints an affine expression of SSA ids with SSA id names used instead of dims and symbols.
void printFunctionalType(Operation *op)
Print the complete type of an operation in functional form.
virtual void printAffineMapOfSSAIds(AffineMapAttr mapAttr, ValueRange operands)=0
Prints an affine map of SSA ids, where SSA id names are used in place of dims/symbols.
virtual void printGenericOp(Operation *op, bool printOpName=true)=0
Print the entire operation with the default generic assembly form.
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
virtual void printRegionArgument(BlockArgument arg, ArrayRef< NamedAttribute > argAttrs={}, bool omitType=false)=0
Print a block argument in the usual format of: ssaName : type {attr1=42} loc("here") where location p...
virtual void printOperand(Value value)=0
Print implementations for various things an operation contains.
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
This class implements Optional functionality for ParseResult.
bool has_value() const
Returns true if we contain a valid ParseResult value.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
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.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
This class implements iteration on the types of a given range of values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
LLVM_ATTRIBUTE_NOINLINE OperandParserStorage()
Group & operator[](size_t index)
llvm::SmallVector< OpAsmParser::UnresolvedOperand, 4 > Group
LLVM_ATTRIBUTE_NOINLINE ~OperandParserStorage()
The OpAsmOpInterface, see OpAsmInterface.td for more details.
ParseResult parseOptionalTypeInto(AsmParser &parser, SmallVectorImpl< Type > &types)
ParseResult parseOptionalOperandInto(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands)
Parse an optional operand or type into a generated parser's storage.
Include the generated interface declarations.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
ParseResult parseDimensionList(OpAsmParser &parser, DenseI64ArrayAttr &dimensions)
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
void printDimensionList(OpAsmPrinter &printer, Operation *op, ArrayRef< int64_t > dimensions)
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
llvm::function_ref< Fn > function_ref
static unsigned getHashValue(const mlir::AsmDialectResourceHandle &handle)
static bool isEqual(const mlir::AsmDialectResourceHandle &lhs, const mlir::AsmDialectResourceHandle &rhs)
UnresolvedOperand ssaName
std::optional< Location > sourceLoc
This is the representation of an operand reference.
This represents an operation in an abstracted form, suitable for use with the builder APIs.