32 "variadic arguments must be in the end of the argument list");
43 argument,
true,
true);
44 if (argPresent.hasValue()) {
45 if (
failed(argPresent.getValue()))
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);
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 auto nonEmptyAttrsFn = [](DictionaryAttr attrs) {
132 return attrs && !attrs.empty();
138 for (
auto &dict : dictAttrs)
144 if (llvm::any_of(argAttrs, nonEmptyAttrsFn))
146 getArrayAttr(argAttrs));
149 if (llvm::any_of(resultAttrs, nonEmptyAttrsFn))
151 getArrayAttr(resultAttrs));
159 for (
const auto &arg : args)
160 argAttrs.push_back(arg.attrs);
183 bool isVariadic =
false;
185 resultTypes, resultAttrs))
188 std::string errorMessage;
190 argTypes.reserve(entryArgs.size());
191 for (
auto &arg : entryArgs)
192 argTypes.push_back(arg.type);
193 Type type = funcTypeBuilder(builder, argTypes, resultTypes,
196 return parser.
emitError(signatureLocation)
197 <<
"failed to construct function type" 198 << (errorMessage.empty() ?
"" :
": ") << errorMessage;
210 for (StringRef disallowed :
213 if (parsedAttributes.
get(disallowed))
214 return parser.
emitError(attributeDictLocation,
"'")
216 <<
"' is an inferred attribute and should not be specified in the " 217 "explicit attribute dictionary";
222 assert(resultAttrs.size() == resultTypes.size());
237 return parser.
emitError(loc,
"expected non-empty function body");
246 assert(!types.empty() &&
"Should not be called for empty result list.");
247 assert((!attrs || attrs.size() == types.size()) &&
248 "Invalid number of attributes.");
251 bool needsParens = types.size() > 1 || types[0].isa<FunctionType>() ||
252 (attrs && !attrs[0].cast<DictionaryAttr>().empty());
255 llvm::interleaveComma(llvm::seq<size_t>(0, types.size()), os, [&](
size_t i) {
268 bool isExternal = body.
empty();
272 for (
unsigned i = 0, e = argTypes.size(); i < e; ++i) {
279 attrs = argAttrs[i].cast<DictionaryAttr>().getValue();
289 if (!argTypes.empty())
296 if (!resultTypes.empty()) {
310 ignoredAttrs.append(elided.begin(), elided.end());
316 FunctionOpInterface op,
325 if (
auto visibility = op->getAttrOfType<StringAttr>(visibilityAttrName))
326 p << visibility.getValue() <<
' ';
333 {visibilityAttrName});
335 Region &body = op->getRegion(0);
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
void printFunctionSignature(OpAsmPrinter &p, Operation *op, ArrayRef< Type > argTypes, bool isVariadic, ArrayRef< Type > resultTypes)
Prints the signature of the function-like operation op.
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
StringRef getResultDictAttrName()
Return the name of the attribute used for function argument attributes.
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.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
Operation is a basic unit of execution within MLIR.
StringRef getArgDictAttrName()
Return the name of the attribute used for function argument attributes.
virtual void printType(Type type)
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
AttrClass getAttrOfType(StringAttr name)
void addArgAndResultAttrs(Builder &builder, OperationState &result, ArrayRef< DictionaryAttr > argAttrs, ArrayRef< DictionaryAttr > resultAttrs)
Adds argument and result attributes, provided as argAttrs and resultAttrs arguments, to the list of operation attributes in result.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value...
StringRef getTypeAttrName()
Return the name of the attribute used for function types.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it...
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
A named class for passing around the variadic flag.
static void printFunctionResultList(OpAsmPrinter &p, ArrayRef< Type > types, ArrayAttr attrs)
Print a function result list.
UnresolvedOperand ssaName
ParseResult parseSymbolName(StringAttr &result, StringRef attrName, NamedAttrList &attrs)
Parse an -identifier and store it (without the '@' symbol) in a string attribute named 'attrName'...
void printFunctionAttributes(OpAsmPrinter &p, Operation *op, unsigned numInputs, unsigned numResults, ArrayRef< StringRef > elided={})
Prints the list of function prefixed with the "attributes" keyword.
BlockArgument getArgument(unsigned i)
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
Attribute get(StringAttr name) const
Return the specified attribute if present, null otherwise.
virtual OptionalParseResult parseOptionalRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
virtual ParseResult parseRParen()=0
Parse a ) token.
void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic)
Printer implementation for function-like operations.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This represents an operation in an abstracted form, suitable for use with the builder APIs...
Parens surrounding zero or more operands.
static ParseResult parseFunctionResultList(OpAsmParser &parser, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parse a function result list.
Optional< Location > sourceLoc
ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs)
Parse an optional visibility attribute keyword (i.e., public, private, or nested) without quotes in a...
virtual ParseResult parseOptionalLocationSpecifier(Optional< Location > &result)=0
Parse a loc(...) specifier if present, filling in result if so.
virtual ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result)=0
Parse a named dictionary into 'result' if the attributes keyword is present.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
virtual ParseResult parseOptionalRParen()=0
Parse a ) token if present.
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
This class implements Optional functionality for ParseResult.
static ParseResult parseFunctionArgumentList(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic)
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
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...
ParseResult parseFunctionSignature(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parses a function signature using parser.
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values...
Region * addRegion()
Create a region that should be attached to the operation.
virtual OptionalParseResult parseOptionalArgument(Argument &result, bool allowType=false, bool allowAttrs=false)=0
Parse a single argument if present.
This class is a general helper class for creating context-global objects like types, attributes, and affine expressions.
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual void printOptionalAttrDictWithKeyword(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary prefixed with 'attribute...
ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, FuncTypeBuilder funcTypeBuilder)
Parser implementation for function-like operations.
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
bool hasValue() const
Returns true if we contain a valid ParseResult value.
virtual ParseResult parseOptionalEllipsis()=0
Parse a ... token if present;.
MLIRContext * getContext() const
This class represents success/failure for parsing-like operations that find it important to chain tog...
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.