43 resultTypes.push_back(ty);
44 resultAttrs.emplace_back();
74 if (mustParseEmptyResult)
83 assert(!types.empty() &&
"Should not be called for empty result list.");
84 assert((!attrs || attrs.size() == types.size()) &&
85 "Invalid number of attributes.");
88 bool needsParens = types.size() > 1 || llvm::isa<FunctionType>(types[0]) ||
89 (attrs && !llvm::cast<DictionaryAttr>(attrs[0]).empty());
92 llvm::interleaveComma(llvm::seq<size_t>(0, types.size()), os, [&](
size_t i) {
93 p.printType(types[i]);
95 p.printOptionalAttrDict(llvm::cast<DictionaryAttr>(attrs[i]).getValue());
104 bool printEmptyResult) {
105 bool isExternal = !body || body->
empty();
106 if (!isExternal && !isVariadic && !argAttrs && !resultAttrs &&
113 for (
unsigned i = 0, e = argTypes.size(); i < e; ++i) {
120 attrs = llvm::cast<DictionaryAttr>(argAttrs[i]).getValue();
126 llvm::cast<DictionaryAttr>(argAttrs[i]).getValue());
131 if (!argTypes.empty())
138 if (!resultTypes.empty()) {
141 }
else if (printEmptyResult) {
149 StringAttr resAttrsName) {
150 auto nonEmptyAttrsFn = [](DictionaryAttr attrs) {
151 return attrs && !attrs.empty();
157 for (
auto &dict : dictAttrs)
163 if (llvm::any_of(argAttrs, nonEmptyAttrsFn))
164 result.addAttribute(argAttrsName, getArrayAttr(argAttrs));
167 if (llvm::any_of(resultAttrs, nonEmptyAttrsFn))
168 result.addAttribute(resAttrsName, getArrayAttr(resultAttrs));
174 StringAttr argAttrsName, StringAttr resAttrsName) {
176 for (
const auto &arg : args)
177 argAttrs.push_back(arg.attrs);
190 if (
auto symbolVal = dyn_cast<Value>(callable))
191 return symbolVal.getDefiningOp();
194 auto symbolRef = cast<SymbolRefAttr>(callable);
197 return SymbolTable::lookupNearestSymbolFrom(call.getOperation(), symbolRef);
204 #include "mlir/Interfaces/CallInterfaces.cpp.inc"
static void printFunctionResultList(OpAsmPrinter &p, TypeRange types, ArrayAttr attrs)
Print a function result list.
static ParseResult parseTypeAndAttrList(OpAsmParser &parser, SmallVectorImpl< Type > &types, SmallVectorImpl< DictionaryAttr > &attrs)
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 ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
virtual ParseResult parseOptionalRParen()=0
Parse a ) token if present.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
virtual void printType(Type type)
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...
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
void printFunctionalType(Operation *op)
Print the complete type of an operation in functional form.
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.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockArgument getArgument(unsigned i)
This class represents a collection of SymbolTables.
Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
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...
void printFunctionSignature(OpAsmPrinter &p, TypeRange argTypes, ArrayAttr argAttrs, bool isVariadic, TypeRange resultTypes, ArrayAttr resultAttrs, Region *body=nullptr, bool printEmptyResult=true)
Print a function signature for a call or callable operation.
Operation * resolveCallable(CallOpInterface call, SymbolTableCollection *symbolTable=nullptr)
Resolve the callable operation for given callee to a CallableOpInterface, or nullptr if a valid calla...
ParseResult parseFunctionResultList(OpAsmParser &parser, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parse a function or call result list.
ParseResult parseFunctionSignature(OpAsmParser &parser, SmallVectorImpl< Type > &argTypes, SmallVectorImpl< DictionaryAttr > &argAttrs, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs, bool mustParseEmptyResult=true)
Parses a function signature using parser.
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,...
Include the generated interface declarations.
A callable is either a symbol, or an SSA value, that is referenced by a call-like operation.
This represents an operation in an abstracted form, suitable for use with the builder APIs.