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())
50 return parser.emitError(argument.ssaName.location,
51 "expected type instead of SSA identifier");
54 argument.ssaName.location = parser.getCurrentLocation();
57 if (!arguments.empty() && !arguments.back().ssaName.name.empty())
58 return parser.emitError(argument.ssaName.location,
59 "expected SSA identifier");
62 if (parser.parseType(argument.type) ||
63 parser.parseOptionalAttrDict(attrs) ||
64 parser.parseOptionalLocationSpecifier(argument.sourceLoc))
66 argument.attrs = attrs.getDictionary(parser.getContext());
68 arguments.push_back(argument);
91 resultTypes.push_back(ty);
92 resultAttrs.emplace_back();
102 resultTypes.emplace_back();
103 resultAttrs.emplace_back();
105 if (parser.parseType(resultTypes.back()) ||
106 parser.parseOptionalAttrDict(attrs))
108 resultAttrs.back() = attrs.getDictionary(parser.getContext());
131 StringAttr resAttrsName) {
132 auto nonEmptyAttrsFn = [](DictionaryAttr attrs) {
133 return attrs && !attrs.empty();
139 for (
auto &dict : dictAttrs)
145 if (llvm::any_of(argAttrs, nonEmptyAttrsFn))
146 result.addAttribute(argAttrsName, getArrayAttr(argAttrs));
149 if (llvm::any_of(resultAttrs, nonEmptyAttrsFn))
150 result.addAttribute(resAttrsName, getArrayAttr(resultAttrs));
156 StringAttr argAttrsName, StringAttr resAttrsName) {
158 for (
const auto &arg : args)
159 argAttrs.push_back(arg.attrs);
167 StringAttr argAttrsName, StringAttr resAttrsName) {
184 bool isVariadic =
false;
186 resultTypes, resultAttrs))
189 std::string errorMessage;
191 argTypes.reserve(entryArgs.size());
192 for (
auto &arg : entryArgs)
193 argTypes.push_back(arg.type);
194 Type type = funcTypeBuilder(builder, argTypes, resultTypes,
197 return parser.
emitError(signatureLocation)
198 <<
"failed to construct function type"
199 << (errorMessage.empty() ?
"" :
": ") << errorMessage;
211 for (StringRef disallowed :
212 {SymbolTable::getVisibilityAttrName(), SymbolTable::getSymbolAttrName(),
213 typeAttrName.getValue()}) {
214 if (parsedAttributes.
get(disallowed))
215 return parser.
emitError(attributeDictLocation,
"'")
217 <<
"' is an inferred attribute and should not be specified in the "
218 "explicit attribute dictionary";
223 assert(resultAttrs.size() == resultTypes.size());
235 if (failed(*parseResult))
239 return parser.
emitError(loc,
"expected non-empty function body");
248 assert(!types.empty() &&
"Should not be called for empty result list.");
249 assert((!attrs || attrs.size() == types.size()) &&
250 "Invalid number of attributes.");
253 bool needsParens = types.size() > 1 || llvm::isa<FunctionType>(types[0]) ||
254 (attrs && !llvm::cast<DictionaryAttr>(attrs[0]).empty());
257 llvm::interleaveComma(llvm::seq<size_t>(0, types.size()), os, [&](
size_t i) {
258 p.printType(types[i]);
260 p.printOptionalAttrDict(llvm::cast<DictionaryAttr>(attrs[i]).getValue());
269 Region &body = op->getRegion(0);
270 bool isExternal = body.
empty();
273 ArrayAttr argAttrs = op.getArgAttrsAttr();
274 for (
unsigned i = 0, e = argTypes.size(); i < e; ++i) {
281 attrs = llvm::cast<DictionaryAttr>(argAttrs[i]).getValue();
287 llvm::cast<DictionaryAttr>(argAttrs[i]).getValue());
292 if (!argTypes.empty())
299 if (!resultTypes.empty()) {
301 auto resultAttrs = op.getResAttrsAttr();
310 ignoredAttrs.append(elided.begin(), elided.end());
316 OpAsmPrinter &p, FunctionOpInterface op,
bool isVariadic,
317 StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName) {
320 op->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName())
324 StringRef visibilityAttrName = SymbolTable::getVisibilityAttrName();
325 if (
auto visibility = op->getAttrOfType<StringAttr>(visibilityAttrName))
326 p << visibility.getValue() <<
' ';
333 p, op, {visibilityAttrName, typeAttrName, argAttrsName, resAttrsName});
335 Region &body = op->getRegion(0);
static void printFunctionResultList(OpAsmPrinter &p, ArrayRef< Type > types, ArrayAttr attrs)
Print a function result list.
static ParseResult parseFunctionArgumentList(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic)
static ParseResult parseFunctionResultList(OpAsmParser &parser, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parse a function result list.
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 ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
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 parseOptionalArrow()=0
Parse a '->' token if present.
virtual ParseResult parseOptionalRParen()=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 ParseResult parseOptionalLParen()=0
Parse a ( token if present.
virtual void printType(Type type)
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
This class is a general helper class for creating context-global objects like types,...
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
Attribute get(StringAttr name) const
Return the specified attribute if present, null otherwise.
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
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 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 printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
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...
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.
BlockArgument getArgument(unsigned i)
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.
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,...
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.
ParseResult parseFunctionSignature(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parses a function signature using parser.
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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This represents an operation in an abstracted form, suitable for use with the builder APIs.
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
Region * addRegion()
Create a region that should be attached to the operation.