13 #ifndef MLIR_IR_OPIMPLEMENTATION_H
14 #define MLIR_IR_OPIMPLEMENTATION_H
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Support/SMLoc.h"
24 class AsmParsedResourceEntry;
25 class AsmResourceBuilder;
37 : resource(resource), opaqueID(resourceID), dialect(dialect) {}
39 return resource == other.resource;
53 void *resource =
nullptr;
63 template <
typename DerivedT,
typename ResourceT,
typename DialectT>
74 assert(handle.
getTypeID() == TypeID::get<DerivedT>());
92 return handle->
getTypeID() == TypeID::get<DerivedT>();
122 virtual void printFloat(
const APFloat &value);
128 template <
typename AttrOrType>
130 decltype(std::declval<AttrOrType>().
print(std::declval<AsmPrinter &>()));
131 template <
typename AttrOrType>
133 llvm::is_detected<has_print_method, AttrOrType>;
138 template <
typename AttrOrType,
139 std::enable_if_t<detect_has_print_method<AttrOrType>::value>
146 uint64_t posPrior = os.tell();
147 attrOrType.print(*
this);
148 if (posPrior != os.tell())
160 template <
typename AttrOrType,
161 std::enable_if_t<detect_has_print_method<AttrOrType>::value>
164 llvm::interleaveComma(
172 template <
typename AttrOrType,
173 std::enable_if_t<!detect_has_print_method<AttrOrType>::value>
197 template <
typename TypeRange>
199 if (types.begin() != types.end())
202 template <
typename TypeRange>
206 bool wrapped = !llvm::hasSingleElement(types) ||
207 (*types.begin()).
template isa<FunctionType>();
210 llvm::interleaveComma(types, *
this);
216 template <
typename InputRangeT,
typename ResultRangeT>
220 llvm::interleaveComma(inputs, *
this);
246 template <
typename AsmPr
interT>
247 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
254 template <
typename AsmPr
interT>
255 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
258 p.printAttribute(attr);
262 template <
typename AsmPr
interT>
263 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
265 operator<<(AsmPrinterT &p,
const APFloat &value) {
269 template <
typename AsmPr
interT>
270 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
273 return p << APFloat(value);
275 template <
typename AsmPr
interT>
276 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
279 return p << APFloat(value);
285 template <
typename AsmPrinterT,
typename T,
286 std::enable_if_t<!std::is_convertible<T &, Value &>::value &&
287 !std::is_convertible<T &, Type &>::value &&
288 !std::is_convertible<T &, Attribute &>::value &&
289 !std::is_convertible<T &, ValueRange>::value &&
290 !std::is_convertible<T &, APFloat &>::value &&
291 !llvm::is_one_of<T, bool, float, double>::value,
293 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
296 p.getStream() << other;
300 template <
typename AsmPr
interT>
301 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
304 return p << (value ? StringRef(
"true") :
"false");
307 template <
typename AsmPr
interT,
typename ValueRangeT>
308 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
310 operator<<(AsmPrinterT &p,
const ValueTypeRange<ValueRangeT> &types) {
311 llvm::interleaveComma(types, p);
315 template <
typename AsmPr
interT>
316 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
318 operator<<(AsmPrinterT &p,
const TypeRange &types) {
319 llvm::interleaveComma(types, p);
328 template <
typename AsmPr
interT,
typename T>
329 inline std::enable_if_t<std::is_same<AsmPrinter, AsmPrinterT>::value &&
330 std::is_convertible<T &, ValueRange>::value,
332 operator<<(AsmPrinterT &p,
const T &other) =
delete;
334 template <
typename AsmPr
interT,
typename ElementT>
335 inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
337 operator<<(AsmPrinterT &p, ArrayRef<ElementT> types) {
338 llvm::interleaveComma(types, p);
373 bool omitType =
false) = 0;
380 template <
typename ContainerType>
386 template <
typename IteratorType>
388 llvm::interleaveComma(llvm::make_range(it, end),
getStream(),
427 bool printBlockTerminators =
true,
428 bool printEmptyBlock =
false) = 0;
461 template <
typename T,
462 std::enable_if_t<std::is_convertible<T &, ValueRange>::value &&
463 !std::is_convertible<T &, Value &>::value,
497 const Twine &message = {}) = 0;
596 return emitError(loc,
"expected string");
640 template <
typename IntT>
645 return emitError(loc,
"expected integer value");
652 template <
typename IntT>
666 (IntT)uintResult.sextOrTrunc(
sizeof(IntT) * CHAR_BIT).getLimitedValue();
667 if (APInt(uintResult.getBitWidth(), result) != uintResult)
668 return emitError(loc,
"integer value too large");
704 StringRef contextMessage = StringRef()) = 0;
721 template <
typename ResultT = ParseResult>
732 return Case(str, [&](StringRef, SMLoc) {
return std::move(value); });
735 return Default([&](StringRef, SMLoc) {
return std::move(value); });
740 template <
typename FnT>
741 std::enable_if_t<!std::is_convertible<FnT, ResultT>::value,
KeywordSwitch &>
742 Case(StringLiteral str, FnT &&fn) {
749 else if (keyword == str)
750 result.emplace(std::move(fn(keyword, loc)));
753 template <
typename FnT>
754 std::enable_if_t<!std::is_convertible<FnT, ResultT>::value,
KeywordSwitch &>
757 result.emplace(fn(keyword, loc));
762 bool hasValue()
const {
return result.has_value(); }
765 [[nodiscard]]
operator ResultT() {
767 return parser.
emitError(loc,
"unexpected keyword: ") << keyword;
768 return std::move(*result);
782 std::optional<ResultT> result;
795 return emitError(loc,
"expected valid keyword");
815 <<
"expected valid keyword or string";
830 template <
typename T,
typename... ParamsT>
832 return T::getChecked([&] {
return emitError(loc); },
833 std::forward<ParamsT>(params)...);
837 template <
typename T,
typename... ParamsT>
840 std::forward<ParamsT>(params)...);
858 template <
typename AttrType>
868 if (!(result = attr.
dyn_cast<AttrType>()))
869 return emitError(loc,
"invalid kind of attribute specified");
882 template <
typename AttrType>
891 template <
typename AttrType>
904 return emitError(loc,
"invalid kind of attribute specified");
906 attrs.
append(attrName, result);
911 template <
typename AttrType>
913 std::declval<Type>()));
914 template <
typename AttrType>
921 template <
typename AttrType>
922 std::enable_if_t<detect_has_parse_method<AttrType>::value,
ParseResult>
931 result = AttrType::parse(*
this, type);
941 return emitError(loc,
"invalid kind of attribute specified");
943 attrs.
append(attrName, result);
948 template <
typename AttrType>
949 std::enable_if_t<!detect_has_parse_method<AttrType>::value,
ParseResult>
958 template <
typename AttrType>
959 std::enable_if_t<detect_has_parse_method<AttrType>::value,
ParseResult>
967 result = AttrType::parse(*
this, type);
975 return emitError(loc,
"invalid kind of attribute specified");
980 template <
typename AttrType>
981 std::enable_if_t<!detect_has_parse_method<AttrType>::value,
ParseResult>
1001 Type type = {}) = 0;
1005 template <
typename AttrType>
1014 template <
typename AttrType>
1020 attrs.
append(attrName, result);
1047 <<
"expected valid '@'-identifier for symbol name";
1057 attrs.
append(attrName, result);
1070 attrs.
append(attrName, result);
1081 template <
typename ResourceT>
1090 <<
"dialect '" << ResourceT::Dialect::getDialectNamespace()
1097 if (
auto *result = dyn_cast<ResourceT>(&*handle))
1098 return std::move(*result);
1099 return emitError(handleLoc) <<
"provided resource handle differs from the "
1100 "expected resource type";
1119 template <
typename TypeT>
1131 return emitError(loc,
"invalid kind of type specified");
1137 template <
typename TypeT>
1139 decltype(TypeT::parse(std::declval<AsmParser &>()));
1140 template <
typename TypeT>
1142 llvm::is_detected<type_has_parse_method, TypeT>;
1147 template <
typename TypeT>
1148 std::enable_if_t<detect_type_has_parse_method<TypeT>::value,
ParseResult>
1155 result = TypeT::parse(*
this);
1163 return emitError(loc,
"invalid kind of Type specified");
1168 template <
typename TypeT>
1169 std::enable_if_t<!detect_type_has_parse_method<TypeT>::value,
ParseResult>
1177 [&]() {
return parseType(result.emplace_back()); });
1191 template <
typename TypeType>
1201 result = type.
dyn_cast<TypeType>();
1203 return emitError(loc,
"invalid kind of type specified");
1225 result.push_back(type);
1234 result.append(types.begin(), types.end());
1252 bool allowDynamic =
true,
1253 bool withTrailingX =
true) = 0;
1279 void operator=(
const AsmParser &) =
delete;
1324 virtual std::pair<StringRef, unsigned>
1368 std::optional<
MutableArrayRef<std::unique_ptr<Region>>> parsedRegions =
1371 std::optional<FunctionType> parsedFnType = std::nullopt) = 0;
1376 bool allowResultNumber =
true) = 0;
1381 bool allowResultNumber =
true) = 0;
1388 bool allowResultNumber =
true,
1389 int requiredOperandCount = -1) = 0;
1393 int requiredOperandCount,
1396 true, requiredOperandCount);
1419 template <
typename Operands = ArrayRef<UnresolvedOperand>>
1427 template <
typename Operands = ArrayRef<UnresolvedOperand>>
1430 return resolveOperands(std::forward<Operands>(operands), type, result);
1436 template <
typename Operands = ArrayRef<UnresolvedOperand>,
1437 typename Types = ArrayRef<Type>>
1438 std::enable_if_t<!std::is_convertible<Types, Type>::value,
ParseResult>
1441 size_t operandSize = std::distance(operands.begin(), operands.end());
1442 size_t typeSize = std::distance(types.begin(), types.end());
1443 if (operandSize != typeSize)
1445 << operandSize <<
" operands present, but expected " << typeSize;
1447 for (
auto [operand, type] : llvm::zip(operands, types))
1488 bool allowAttrs =
false) = 0;
1493 bool allowAttrs =
false) = 0;
1498 bool allowType =
false,
1499 bool allowAttrs =
false) = 0;
1515 bool enableNameShadowing =
false) = 0;
1520 bool enableNameShadowing =
false) = 0;
1528 bool enableNameShadowing =
false) = 0;
1555 return result.
value();
1625 "Dialect must implement `getResourceKey` when defining resources");
1649 #include "mlir/IR/OpAsmInterface.h.inc"
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
This class represents a CRTP base class for dialect resource handles.
const ResourceT * getResource() const
AsmDialectResourceHandleBase(AsmDialectResourceHandle handle)
ResourceT * getResource()
Return the resource referenced by this handle.
static bool classof(const AsmDialectResourceHandle *handle)
Support llvm style casting.
AsmDialectResourceHandleBase(ResourceT *resource, DialectT *dialect)
Construct a handle from a pointer to the resource.
DialectT * getDialect() const
Return the dialect that owns the resource.
This class represents an opaque handle to a dialect resource entry.
AsmDialectResourceHandle()=default
Dialect * getDialect() const
Return the dialect that owns the resource.
TypeID getTypeID() const
Return the type ID of the resource.
bool operator==(const AsmDialectResourceHandle &other) const
AsmDialectResourceHandle(void *resource, TypeID resourceID, Dialect *dialect)
void * getResource() const
Return an opaque pointer to the referenced resource.
This class represents a single parsed resource entry.
This class represents a StringSwitch like class that is useful for parsing expected keywords.
std::enable_if_t<!std::is_convertible< FnT, ResultT >::value, KeywordSwitch & > Default(FnT &&fn)
KeywordSwitch & Case(StringLiteral str, ResultT value)
Case that uses the provided value when true.
bool hasValue() const
Returns true if this switch has a value yet.
std::enable_if_t<!std::is_convertible< FnT, ResultT >::value, KeywordSwitch & > Case(StringLiteral str, FnT &&fn)
Case that invokes the provided functor when true.
KeywordSwitch(AsmParser &parser)
KeywordSwitch & Default(ResultT value)
This base class exposes generic asm parser hooks, usable across the various derived parsers.
llvm::is_detected< has_parse_method, AttrType > detect_has_parse_method
virtual ParseResult printIntegerSet(IntegerSet &set)=0
Parse an integer set instance into 'set'.
ParseResult parseSymbolName(StringAttr &result)
Parse an -identifier and store it (without the '@' symbol) in a string attribute.
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.
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 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 ParseResult parseOptionalRBrace()=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.
decltype(AttrType::parse(std::declval< AsmParser & >(), std::declval< Type >())) has_parse_method
Trait to check if AttrType provides a parse method.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
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.
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.
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.
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...
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 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...
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.
virtual ParseResult parseEqual()=0
Parse a = token.
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 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(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.
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.
ParseResult parseTypeList(SmallVectorImpl< Type > &result)
Parse a type list.
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.
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...
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.
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...
ParseResult parseAttribute(Attribute &result, StringRef attrName, NamedAttrList &attrs)
Parse an arbitrary attribute and return it in result.
virtual OptionalParseResult parseOptionalAttribute(StringAttr &result, Type type={})=0
Parse an optional string attribute and return it in result.
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.
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 parseQuestion()=0
Parse a '?' token.
std::enable_if_t< detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result)
Parse a custom attribute of a given type unless the next token is #, in which case the generic parser...
ParseResult parseType(TypeT &result)
Parse a type of a specific type.
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.
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 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.
std::enable_if_t<!detect_has_parse_method< AttrType >::value, ParseResult > parseCustomAttributeWithFallback(AttrType &result)
SFINAE parsing method for Attribute that don't implement a parse method.
virtual ParseResult parseArrowTypeList(SmallVectorImpl< Type > &result)=0
Parse an arrow followed by a type list.
virtual ParseResult parseOptionalVerticalBar()=0
Parse a '|' token if present.
virtual ParseResult parseBase64Bytes(std::vector< char > *bytes)=0
Parses a Base64 encoded string of bytes.
llvm::is_detected< type_has_parse_method, TypeT > detect_type_has_parse_method
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'.
decltype(TypeT::parse(std::declval< AsmParser & >())) type_has_parse_method
Trait to check if TypeT provides a parse method.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
virtual ParseResult parseOptionalLSquare()=0
Parse a [ token if present.
virtual FailureOr< AsmDialectResourceHandle > parseResourceHandle(Dialect *dialect)=0
Parse a handle to a resource within the assembly format for the given dialect.
virtual ParseResult parseOptionalQuestion()=0
Parse a '?' 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...
FailureOr< ResourceT > parseResourceHandle()
Parse a handle to a resource within the assembly format.
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
This base class exposes generic asm printer hooks, usable across the various derived printers.
void printStrippedAttrOrType(ArrayRef< AttrOrType > attrOrTypes)
Print the provided array of attributes or types in the context of an operation custom printer/parser:...
virtual void printAttributeWithoutType(Attribute attr)
Print the given attribute without its type.
AsmPrinter()=default
Initialize the printer with no internal implementation.
void printFunctionalType(InputRangeT &&inputs, ResultRangeT &&results)
Print the two given type ranges in a functional form.
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...
llvm::is_detected< has_print_method, AttrOrType > detect_has_print_method
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
void printOptionalArrowTypeList(TypeRange &&types)
Print an optional arrow followed by a type list.
virtual void printAttribute(Attribute attr)
void printArrowTypeList(TypeRange &&types)
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.
decltype(std::declval< AttrOrType >().print(std::declval< AsmPrinter & >())) has_print_method
Trait to check if AttrType provides a print method.
virtual void printFloat(const APFloat &value)
Print the given floating point value in a stabilized form that can be roundtripped through the IR.
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 provides support for representing a failure result, or a valid value of type T.
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.
virtual void buildResources(Operation *op, const SetVector< AsmDialectResourceHandle > &referencedResources, AsmResourceBuilder &builder) const
Hook for building resources to use during printing.
virtual AliasResult getAlias(Attribute attr, raw_ostream &os) const
Hooks for getting an alias identifier alias for a given symbol, that is not necessarily a part of thi...
OpAsmDialectInterface(Dialect *dialect)
virtual AliasResult getAlias(Type type, raw_ostream &os) const
virtual std::string getResourceKey(const AsmDialectResourceHandle &handle) const
Return a key to use for the given resource.
virtual FailureOr< AsmDialectResourceHandle > declareResource(StringRef key) const
Declare a resource with the given key, returning a handle to use for any references of this resource ...
virtual LogicalResult parseResource(AsmParsedResourceEntry &entry) const
Hook for parsing resource entries.
AliasResult
Holds the result of getAlias hook call.
@ FinalAlias
An alias was provided and it should be used (no other hooks will be checked).
@ NoAlias
The object (type or attribute) is not supported by the hook and an alias was not provided.
@ OverridableAlias
An alias was provided, but it might be overriden by other hook.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
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 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 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.
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 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 FailureOr< OperationName > parseCustomOperationName()=0
Parse the name of an operation, in the custom 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 Operation * parseGenericOperation(Block *insertBlock, Block::iterator insertPt)=0
Parse an operation in its generic form.
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< FunctionType > parsedFnType=std::nullopt)=0
Parse different components, viz., use-info of operand(s), successor(s), region(s),...
std::enable_if_t<!std::is_convertible< Types, Type >::value, 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 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 printNewline()=0
Print a newline and indent the printer to the start of the current operation.
virtual void increaseIndent()=0
Increase indentation.
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...
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...
virtual void decreaseIndent()=0
Decrease indentation.
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.
Operation is the basic unit of execution within MLIR.
This class implements Optional functionality for ParseResult.
ParseResult value() const
Access the internal ParseResult value.
bool has_value() const
Returns true if we contain a valid ParseResult value.
This class represents success/failure for parsing-like operations that find it important to chain tog...
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.
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 represents an instance of an SSA value in the MLIR system, representing a computable value...
The base class used for all derived interface types.
Include the generated interface declarations.
This header declares functions that assit transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
llvm::hash_code hash_value(const AsmDialectResourceHandle ¶m)
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static mlir::AsmDialectResourceHandle getTombstoneKey()
static unsigned getHashValue(const mlir::AsmDialectResourceHandle &handle)
static mlir::AsmDialectResourceHandle getEmptyKey()
static bool isEqual(const mlir::AsmDialectResourceHandle &lhs, const mlir::AsmDialectResourceHandle &rhs)
This class represents an efficient way to signal success or failure.
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.