MLIR  19.0.0git
Classes | Typedefs | Functions
mlir::function_interface_impl Namespace Reference

Classes

class  VariadicFlag
 A named class for passing around the variadic flag. More...
 

Typedefs

using FuncTypeBuilder = function_ref< Type(Builder &, ArrayRef< Type >, ArrayRef< Type >, VariadicFlag, std::string &)>
 Callback type for parseFunctionOp, the callback should produce the type that will be associated with a function-like operation from lists of function arguments and results, VariadicFlag indicates whether the function should have variadic arguments; in case of error, it may populate the last argument with a message. More...
 

Functions

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, to the list of operation attributes in result. More...
 
void addArgAndResultAttrs (Builder &builder, OperationState &result, ArrayRef< OpAsmParser::Argument > args, ArrayRef< DictionaryAttr > resultAttrs, StringAttr argAttrsName, StringAttr resAttrsName)
 
ParseResult parseFunctionSignature (OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
 Parses a function signature using parser. More...
 
ParseResult parseFunctionOp (OpAsmParser &parser, OperationState &result, bool allowVariadic, StringAttr typeAttrName, FuncTypeBuilder funcTypeBuilder, StringAttr argAttrsName, StringAttr resAttrsName)
 Parser implementation for function-like operations. More...
 
void printFunctionOp (OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName)
 Printer implementation for function-like operations. More...
 
void printFunctionSignature (OpAsmPrinter &p, FunctionOpInterface op, ArrayRef< Type > argTypes, bool isVariadic, ArrayRef< Type > resultTypes)
 Prints the signature of the function-like operation op. More...
 
void printFunctionAttributes (OpAsmPrinter &p, Operation *op, ArrayRef< StringRef > elided={})
 Prints the list of function prefixed with the "attributes" keyword. More...
 
DictionaryAttr getArgAttrDict (FunctionOpInterface op, unsigned index)
 Returns the dictionary attribute corresponding to the argument at 'index'. More...
 
DictionaryAttr getResultAttrDict (FunctionOpInterface op, unsigned index)
 Returns the dictionary attribute corresponding to the result at 'index'. More...
 
ArrayRef< NamedAttributegetArgAttrs (FunctionOpInterface op, unsigned index)
 Return all of the attributes for the argument at 'index'. More...
 
ArrayRef< NamedAttributegetResultAttrs (FunctionOpInterface op, unsigned index)
 Return all of the attributes for the result at 'index'. More...
 
void setAllArgAttrDicts (FunctionOpInterface op, ArrayRef< DictionaryAttr > attrs)
 Set all of the argument or result attribute dictionaries for a function. More...
 
void setAllArgAttrDicts (FunctionOpInterface op, ArrayRef< Attribute > attrs)
 
void setAllResultAttrDicts (FunctionOpInterface op, ArrayRef< DictionaryAttr > attrs)
 
void setAllResultAttrDicts (FunctionOpInterface op, ArrayRef< Attribute > attrs)
 
void insertFunctionArguments (FunctionOpInterface op, ArrayRef< unsigned > argIndices, TypeRange argTypes, ArrayRef< DictionaryAttr > argAttrs, ArrayRef< Location > argLocs, unsigned originalNumArgs, Type newType)
 Insert the specified arguments and update the function type attribute. More...
 
void insertFunctionResults (FunctionOpInterface op, ArrayRef< unsigned > resultIndices, TypeRange resultTypes, ArrayRef< DictionaryAttr > resultAttrs, unsigned originalNumResults, Type newType)
 Insert the specified results and update the function type attribute. More...
 
void eraseFunctionArguments (FunctionOpInterface op, const BitVector &argIndices, Type newType)
 Erase the specified arguments and update the function type attribute. More...
 
void eraseFunctionResults (FunctionOpInterface op, const BitVector &resultIndices, Type newType)
 Erase the specified results and update the function type attribute. More...
 
void setFunctionType (FunctionOpInterface op, Type newType)
 Set a FunctionOpInterface operation's type signature. More...
 
void setArgAttrs (FunctionOpInterface op, unsigned index, ArrayRef< NamedAttribute > attributes)
 Set the attributes held by the argument at 'index'. More...
 
void setArgAttrs (FunctionOpInterface op, unsigned index, DictionaryAttr attributes)
 
template<typename ConcreteType >
void setArgAttr (ConcreteType op, unsigned index, StringAttr name, Attribute value)
 If the an attribute exists with the specified name, change it to the new value. More...
 
template<typename ConcreteType >
Attribute removeArgAttr (ConcreteType op, unsigned index, StringAttr name)
 Remove the attribute 'name' from the argument at 'index'. More...
 
void setResultAttrs (FunctionOpInterface op, unsigned index, ArrayRef< NamedAttribute > attributes)
 Set the attributes held by the result at 'index'. More...
 
void setResultAttrs (FunctionOpInterface op, unsigned index, DictionaryAttr attributes)
 
template<typename ConcreteType >
void setResultAttr (ConcreteType op, unsigned index, StringAttr name, Attribute value)
 If the an attribute exists with the specified name, change it to the new value. More...
 
template<typename ConcreteType >
Attribute removeResultAttr (ConcreteType op, unsigned index, StringAttr name)
 Remove the attribute 'name' from the result at 'index'. More...
 
template<typename ConcreteOp >
LogicalResult verifyTrait (ConcreteOp op)
 This function defines the internal implementation of the verifyTrait method on FunctionOpInterface::Trait. More...
 

Typedef Documentation

◆ FuncTypeBuilder

Callback type for parseFunctionOp, the callback should produce the type that will be associated with a function-like operation from lists of function arguments and results, VariadicFlag indicates whether the function should have variadic arguments; in case of error, it may populate the last argument with a message.

Definition at line 54 of file FunctionImplementation.h.

Function Documentation

◆ addArgAndResultAttrs() [1/2]

void mlir::function_interface_impl::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, to the list of operation attributes in result.

Internally, argument and result attributes are stored as dict attributes with special names given by getResultAttrName, getArgumentAttrName.

Definition at line 128 of file FunctionImplementation.cpp.

References mlir::Builder::getArrayAttr(), and mlir::Builder::getDictionaryAttr().

Referenced by addArgAndResultAttrs(), and parseFunctionOp().

◆ addArgAndResultAttrs() [2/2]

void mlir::function_interface_impl::addArgAndResultAttrs ( Builder builder,
OperationState result,
ArrayRef< OpAsmParser::Argument args,
ArrayRef< DictionaryAttr >  resultAttrs,
StringAttr  argAttrsName,
StringAttr  resAttrsName 
)

Definition at line 153 of file FunctionImplementation.cpp.

References addArgAndResultAttrs().

◆ eraseFunctionArguments()

void mlir::function_interface_impl::eraseFunctionArguments ( FunctionOpInterface  op,
const BitVector &  argIndices,
Type  newType 
)

Erase the specified arguments and update the function type attribute.

Definition at line 277 of file FunctionInterfaces.cpp.

◆ eraseFunctionResults()

void mlir::function_interface_impl::eraseFunctionResults ( FunctionOpInterface  op,
const BitVector &  resultIndices,
Type  newType 
)

Erase the specified results and update the function type attribute.

Definition at line 300 of file FunctionInterfaces.cpp.

◆ getArgAttrDict()

DictionaryAttr mlir::function_interface_impl::getArgAttrDict ( FunctionOpInterface  op,
unsigned  index 
)

Returns the dictionary attribute corresponding to the argument at 'index'.

If there are no argument attributes at 'index', a null attribute is returned.

Definition at line 27 of file FunctionInterfaces.cpp.

◆ getArgAttrs()

ArrayRef< NamedAttribute > mlir::function_interface_impl::getArgAttrs ( FunctionOpInterface  op,
unsigned  index 
)

Return all of the attributes for the argument at 'index'.

Definition at line 45 of file FunctionInterfaces.cpp.

◆ getResultAttrDict()

DictionaryAttr mlir::function_interface_impl::getResultAttrDict ( FunctionOpInterface  op,
unsigned  index 
)

Returns the dictionary attribute corresponding to the result at 'index'.

If there are no result attributes at 'index', a null attribute is returned.

Definition at line 36 of file FunctionInterfaces.cpp.

◆ getResultAttrs()

ArrayRef< NamedAttribute > mlir::function_interface_impl::getResultAttrs ( FunctionOpInterface  op,
unsigned  index 
)

Return all of the attributes for the result at 'index'.

Definition at line 51 of file FunctionInterfaces.cpp.

◆ insertFunctionArguments()

void mlir::function_interface_impl::insertFunctionArguments ( FunctionOpInterface  op,
ArrayRef< unsigned >  argIndices,
TypeRange  argTypes,
ArrayRef< DictionaryAttr >  argAttrs,
ArrayRef< Location argLocs,
unsigned  originalNumArgs,
Type  newType 
)

Insert the specified arguments and update the function type attribute.

Definition at line 189 of file FunctionInterfaces.cpp.

◆ insertFunctionResults()

void mlir::function_interface_impl::insertFunctionResults ( FunctionOpInterface  op,
ArrayRef< unsigned >  resultIndices,
TypeRange  resultTypes,
ArrayRef< DictionaryAttr >  resultAttrs,
unsigned  originalNumResults,
Type  newType 
)

Insert the specified results and update the function type attribute.

Definition at line 235 of file FunctionInterfaces.cpp.

◆ parseFunctionOp()

ParseResult mlir::function_interface_impl::parseFunctionOp ( OpAsmParser parser,
OperationState result,
bool  allowVariadic,
StringAttr  typeAttrName,
FuncTypeBuilder  funcTypeBuilder,
StringAttr  argAttrsName,
StringAttr  resAttrsName 
)

Parser implementation for function-like operations.

Uses funcTypeBuilder to construct the custom function type given lists of input and output types. The parser sets the typeAttrName attribute to the resulting function type. If allowVariadic is set, the parser will accept trailing ellipsis in the function signature and indicate to the builder whether the function is variadic. If the builder returns a null type, result will not contain the type attribute. The caller can then add a type, report the error or delegate the reporting to the op's verifier.

Definition at line 164 of file FunctionImplementation.cpp.

References addArgAndResultAttrs(), mlir::OperationState::addAttribute(), mlir::OperationState::addRegion(), mlir::NamedAttrList::append(), mlir::OperationState::attributes, mlir::AsmParser::emitError(), mlir::failed(), mlir::failure(), mlir::get(), mlir::NamedAttrList::get(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getCurrentLocation(), mlir::OptionalParseResult::has_value(), parseFunctionSignature(), mlir::AsmParser::parseOptionalAttrDictWithKeyword(), mlir::OpAsmParser::parseOptionalRegion(), mlir::impl::parseOptionalVisibilityKeyword(), mlir::AsmParser::parseSymbolName(), and mlir::success().

◆ parseFunctionSignature()

ParseResult mlir::function_interface_impl::parseFunctionSignature ( OpAsmParser parser,
bool  allowVariadic,
SmallVectorImpl< OpAsmParser::Argument > &  arguments,
bool &  isVariadic,
SmallVectorImpl< Type > &  resultTypes,
SmallVectorImpl< DictionaryAttr > &  resultAttrs 
)

Parses a function signature using parser.

The allowVariadic argument indicates whether functions with variadic arguments are supported. The trailing arguments are populated by this function with names, types, attributes and locations of the arguments and those of the results.

Definition at line 116 of file FunctionImplementation.cpp.

References mlir::failure(), parseFunctionArgumentList(), parseFunctionResultList(), mlir::AsmParser::parseOptionalArrow(), mlir::succeeded(), and mlir::success().

Referenced by parseFunctionOp().

◆ printFunctionAttributes()

void mlir::function_interface_impl::printFunctionAttributes ( OpAsmPrinter p,
Operation op,
ArrayRef< StringRef >  elided = {} 
)

Prints the list of function prefixed with the "attributes" keyword.

The attributes with names listed in "elided" as well as those used by the function-like operation internally are not printed. Nothing is printed if all attributes are elided. Assumes op is a FunctionOpInterface and has passed verification.

Definition at line 306 of file FunctionImplementation.cpp.

◆ printFunctionOp()

void mlir::function_interface_impl::printFunctionOp ( OpAsmPrinter p,
FunctionOpInterface  op,
bool  isVariadic,
StringRef  typeAttrName,
StringAttr  argAttrsName,
StringAttr  resAttrsName 
)

Printer implementation for function-like operations.

Definition at line 315 of file FunctionImplementation.cpp.

◆ printFunctionSignature()

void mlir::function_interface_impl::printFunctionSignature ( OpAsmPrinter p,
FunctionOpInterface  op,
ArrayRef< Type argTypes,
bool  isVariadic,
ArrayRef< Type resultTypes 
)

Prints the signature of the function-like operation op.

Assumes op has is a FunctionOpInterface and has passed verification.

Definition at line 266 of file FunctionImplementation.cpp.

◆ removeArgAttr()

template<typename ConcreteType >
Attribute mlir::function_interface_impl::removeArgAttr ( ConcreteType  op,
unsigned  index,
StringAttr  name 
)

Remove the attribute 'name' from the argument at 'index'.

Returns the removed attribute, or nullptr if name was not a valid attribute.

Definition at line 107 of file FunctionInterfaces.h.

◆ removeResultAttr()

template<typename ConcreteType >
Attribute mlir::function_interface_impl::removeResultAttr ( ConcreteType  op,
unsigned  index,
StringAttr  name 
)

Remove the attribute 'name' from the result at 'index'.

Definition at line 143 of file FunctionInterfaces.h.

◆ setAllArgAttrDicts() [1/2]

void mlir::function_interface_impl::setAllArgAttrDicts ( FunctionOpInterface  op,
ArrayRef< Attribute attrs 
)

Definition at line 99 of file FunctionInterfaces.cpp.

◆ setAllArgAttrDicts() [2/2]

void mlir::function_interface_impl::setAllArgAttrDicts ( FunctionOpInterface  op,
ArrayRef< DictionaryAttr >  attrs 
)

Set all of the argument or result attribute dictionaries for a function.

The size of attrs is expected to match the number of arguments/results of the given op.

Definition at line 94 of file FunctionInterfaces.cpp.

◆ setAllResultAttrDicts() [1/2]

void mlir::function_interface_impl::setAllResultAttrDicts ( FunctionOpInterface  op,
ArrayRef< Attribute attrs 
)

Definition at line 112 of file FunctionInterfaces.cpp.

◆ setAllResultAttrDicts() [2/2]

void mlir::function_interface_impl::setAllResultAttrDicts ( FunctionOpInterface  op,
ArrayRef< DictionaryAttr >  attrs 
)

Definition at line 107 of file FunctionInterfaces.cpp.

◆ setArgAttr()

template<typename ConcreteType >
void mlir::function_interface_impl::setArgAttr ( ConcreteType  op,
unsigned  index,
StringAttr  name,
Attribute  value 
)

If the an attribute exists with the specified name, change it to the new value.

Otherwise, add a new attribute with the specified name/value.

Definition at line 94 of file FunctionInterfaces.h.

◆ setArgAttrs() [1/2]

void mlir::function_interface_impl::setArgAttrs ( FunctionOpInterface  op,
unsigned  index,
ArrayRef< NamedAttribute attributes 
)

Set the attributes held by the argument at 'index'.

Definition at line 154 of file FunctionInterfaces.cpp.

◆ setArgAttrs() [2/2]

void mlir::function_interface_impl::setArgAttrs ( FunctionOpInterface  op,
unsigned  index,
DictionaryAttr  attributes 
)

Definition at line 163 of file FunctionInterfaces.cpp.

◆ setFunctionType()

void mlir::function_interface_impl::setFunctionType ( FunctionOpInterface  op,
Type  newType 
)

Set a FunctionOpInterface operation's type signature.

Definition at line 324 of file FunctionInterfaces.cpp.

◆ setResultAttr()

template<typename ConcreteType >
void mlir::function_interface_impl::setResultAttr ( ConcreteType  op,
unsigned  index,
StringAttr  name,
Attribute  value 
)

If the an attribute exists with the specified name, change it to the new value.

Otherwise, add a new attribute with the specified name/value.

Definition at line 131 of file FunctionInterfaces.h.

◆ setResultAttrs() [1/2]

void mlir::function_interface_impl::setResultAttrs ( FunctionOpInterface  op,
unsigned  index,
ArrayRef< NamedAttribute attributes 
)

Set the attributes held by the result at 'index'.

Definition at line 171 of file FunctionInterfaces.cpp.

◆ setResultAttrs() [2/2]

void mlir::function_interface_impl::setResultAttrs ( FunctionOpInterface  op,
unsigned  index,
DictionaryAttr  attributes 
)

Definition at line 180 of file FunctionInterfaces.cpp.

◆ verifyTrait()

template<typename ConcreteOp >
LogicalResult mlir::function_interface_impl::verifyTrait ( ConcreteOp  op)

This function defines the internal implementation of the verifyTrait method on FunctionOpInterface::Trait.

Definition at line 158 of file FunctionInterfaces.h.