32 "variadic arguments must be in the end of the argument list");
43 argument,
true,
true);
44 if (argPresent.has_value()) {
45 if (failed(argPresent.value()))
49 if (!arguments.empty() && arguments.back().ssaName.name.empty())
51 "expected type instead of SSA identifier");
57 if (!arguments.empty() && !arguments.back().ssaName.name.empty())
59 "expected SSA identifier");
68 arguments.push_back(argument);
89 StringAttr argAttrsName, StringAttr resAttrsName) {
106 bool isVariadic =
false;
108 isVariadic, resultTypes, resultAttrs))
111 std::string errorMessage;
113 argTypes.reserve(entryArgs.size());
114 for (
auto &arg : entryArgs)
115 argTypes.push_back(arg.type);
116 Type type = funcTypeBuilder(builder, argTypes, resultTypes,
119 return parser.
emitError(signatureLocation)
120 <<
"failed to construct function type"
121 << (errorMessage.empty() ?
"" :
": ") << errorMessage;
123 result.addAttribute(typeAttrName, TypeAttr::get(type));
133 for (StringRef disallowed :
135 typeAttrName.getValue()}) {
136 if (parsedAttributes.
get(disallowed))
137 return parser.
emitError(attributeDictLocation,
"'")
139 <<
"' is an inferred attribute and should not be specified in the "
140 "explicit attribute dictionary";
142 result.attributes.append(parsedAttributes);
145 assert(resultAttrs.size() == resultTypes.size());
147 builder,
result, entryArgs, resultAttrs, argAttrsName, resAttrsName);
151 auto *body =
result.addRegion();
157 if (failed(*parseResult))
161 return parser.
emitError(loc,
"expected non-empty function body");
170 ignoredAttrs.append(elided.begin(), elided.end());
176 OpAsmPrinter &p, FunctionOpInterface op,
bool isVariadic,
177 StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName) {
185 if (
auto visibility = op->getAttrOfType<StringAttr>(visibilityAttrName))
186 p << visibility.getValue() <<
' ';
193 p, op, {visibilityAttrName, typeAttrName, argAttrsName, resAttrsName});
195 Region &body = op->getRegion(0);
static ParseResult parseFunctionArgumentList(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic)
ParseResult parseSymbolName(StringAttr &result)
Parse an -identifier and store it (without the '@' symbol) in a string attribute.
@ Paren
Parens surrounding zero or more operands.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
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 ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
virtual ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result)=0
Parse a named dictionary into 'result' if the attributes keyword is present.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalEllipsis()=0
Parse a ... token if present;.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
Attribute get(StringAttr name) const
Return the specified attribute if present, null otherwise.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
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.
virtual OptionalParseResult parseOptionalRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
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 printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
Operation is the basic unit of execution within MLIR.
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
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.
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
A named class for passing around the variadic flag.
ParseResult parseFunctionResultList(OpAsmParser &parser, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parse a function or call result list.
void addArgAndResultAttrs(Builder &builder, OperationState &result, ArrayRef< DictionaryAttr > argAttrs, ArrayRef< DictionaryAttr > resultAttrs, StringAttr argAttrsName, StringAttr resAttrsName)
Adds argument and result attributes, provided as argAttrs and resultAttrs arguments,...
function_ref< Type( Builder &, ArrayRef< Type >, ArrayRef< Type >, VariadicFlag, std::string &)> FuncTypeBuilder
Callback type for parseFunctionOp, the callback should produce the type that will be associated with ...
ParseResult parseFunctionSignatureWithArguments(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parses a function signature using parser.
void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName)
Printer implementation for function-like operations.
ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, StringAttr typeAttrName, FuncTypeBuilder funcTypeBuilder, StringAttr argAttrsName, StringAttr resAttrsName)
Parser implementation for function-like operations.
void printFunctionAttributes(OpAsmPrinter &p, Operation *op, ArrayRef< StringRef > elided={})
Prints the list of function prefixed with the "attributes" keyword.
void printFunctionSignature(OpAsmPrinter &p, FunctionOpInterface op, ArrayRef< Type > argTypes, bool isVariadic, ArrayRef< Type > resultTypes)
Prints the signature of the function-like operation op.
ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs)
Parse an optional visibility attribute keyword (i.e., public, private, or nested) without quotes in a...
Include the generated interface declarations.
UnresolvedOperand ssaName
std::optional< Location > sourceLoc
This represents an operation in an abstracted form, suitable for use with the builder APIs.