MLIR  16.0.0git
Namespaces | Classes | Typedefs | Functions
mlir::function_interface_impl Namespace Reference

Namespaces

 detail
 

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)
 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 > argAttrs, ArrayRef< DictionaryAttr > resultAttrs)
 
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...
 
Type getFunctionType (Builder &builder, ArrayRef< OpAsmParser::Argument > argAttrs, ArrayRef< Type > resultTypes)
 Get a function type corresponding to an array of arguments (which have types) and a set of result types. More...
 
ParseResult parseFunctionOp (OpAsmParser &parser, OperationState &result, bool allowVariadic, FuncTypeBuilder funcTypeBuilder)
 Parser implementation for function-like operations. More...
 
void printFunctionOp (OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic)
 Printer implementation for function-like operations. More...
 
void printFunctionSignature (OpAsmPrinter &p, Operation *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, unsigned numInputs, unsigned numResults, ArrayRef< StringRef > elided={})
 Prints the list of function prefixed with the "attributes" keyword. More...
 
StringRef getTypeAttrName ()
 Return the name of the attribute used for function types. More...
 
StringRef getArgDictAttrName ()
 Return the name of the attribute used for function argument attributes. More...
 
StringRef getResultDictAttrName ()
 Return the name of the attribute used for function argument attributes. More...
 
DictionaryAttr getArgAttrDict (Operation *op, unsigned index)
 Returns the dictionary attribute corresponding to the argument at 'index'. More...
 
DictionaryAttr getResultAttrDict (Operation *op, unsigned index)
 Returns the dictionary attribute corresponding to the result at 'index'. More...
 
void setAllArgAttrDicts (Operation *op, ArrayRef< DictionaryAttr > attrs)
 Set all of the argument or result attribute dictionaries for a function. More...
 
void setAllArgAttrDicts (Operation *op, ArrayRef< Attribute > attrs)
 
void setAllResultAttrDicts (Operation *op, ArrayRef< DictionaryAttr > attrs)
 
void setAllResultAttrDicts (Operation *op, ArrayRef< Attribute > attrs)
 
ArrayRef< NamedAttributegetArgAttrs (Operation *op, unsigned index)
 Return all of the attributes for the argument at 'index'. More...
 
ArrayRef< NamedAttributegetResultAttrs (Operation *op, unsigned index)
 Return all of the attributes for the result at 'index'. More...
 
void insertFunctionArguments (Operation *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 (Operation *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 (Operation *op, const BitVector &argIndices, Type newType)
 Erase the specified arguments and update the function type attribute. More...
 
void eraseFunctionResults (Operation *op, const BitVector &resultIndices, Type newType)
 Erase the specified results and update the function type attribute. More...
 
void setFunctionType (Operation *op, Type newType)
 Set a FunctionOpInterface operation's type signature. More...
 
TypeRange insertTypesInto (TypeRange oldTypes, ArrayRef< unsigned > indices, TypeRange newTypes, SmallVectorImpl< Type > &storage)
 Insert a set of newTypes into oldTypes at the given indices. More...
 
TypeRange filterTypesOut (TypeRange types, const BitVector &indices, SmallVectorImpl< Type > &storage)
 Filters out any elements referenced by indices. More...
 
template<typename ConcreteType >
void setArgAttrs (ConcreteType op, unsigned index, ArrayRef< NamedAttribute > attributes)
 Set the attributes held by the argument at 'index'. More...
 
template<typename ConcreteType >
void setArgAttrs (ConcreteType 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...
 
template<typename ConcreteType >
void setResultAttrs (ConcreteType op, unsigned index, ArrayRef< NamedAttribute > attributes)
 Set the attributes held by the result at 'index'. More...
 
template<typename ConcreteType >
void setResultAttrs (ConcreteType 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 53 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 
)

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::OperationState::addAttribute(), getArgDictAttrName(), mlir::Builder::getArrayAttr(), mlir::Builder::getDictionaryAttr(), and getResultDictAttrName().

Referenced by addArgAndResultAttrs(), buildLLVMFunctionType(), mlir::function_interface_impl::VariadicFlag::isVariadic(), parseAttributions(), parseFunctionOp(), printShuffleType(), and verifyConstantType().

◆ addArgAndResultAttrs() [2/2]

void mlir::function_interface_impl::addArgAndResultAttrs ( Builder builder,
OperationState result,
ArrayRef< OpAsmParser::Argument argAttrs,
ArrayRef< DictionaryAttr >  resultAttrs 
)

Definition at line 154 of file FunctionImplementation.cpp.

References addArgAndResultAttrs().

◆ eraseFunctionArguments()

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

◆ eraseFunctionResults()

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

Erase the specified results and update the function type attribute.

Definition at line 225 of file FunctionInterfaces.cpp.

References mlir::Operation::getAttrOfType(), getResultDictAttrName(), getTypeAttrName(), setAllResultAttrDicts(), and mlir::Operation::setAttr().

Referenced by getResultAttrs().

◆ filterTypesOut()

TypeRange mlir::function_interface_impl::filterTypesOut ( TypeRange  types,
const BitVector &  indices,
SmallVectorImpl< Type > &  storage 
)

Filters out any elements referenced by indices.

If any types are removed, storage is used to hold the new type list. Returns the new type list.

Definition at line 264 of file FunctionInterfaces.cpp.

Referenced by mlir::FloatType::getFPMantissaWidth(), and getResultAttrs().

◆ getArgAttrDict()

DictionaryAttr mlir::function_interface_impl::getArgAttrDict ( Operation 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.

References getArgDictAttrName(), and mlir::Operation::getAttrOfType().

Referenced by getArgAttrs(), and getResultDictAttrName().

◆ getArgAttrs()

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

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

Definition at line 63 of file FunctionInterfaces.h.

References getArgAttrDict().

◆ getArgDictAttrName()

StringRef mlir::function_interface_impl::getArgDictAttrName ( )
inline

◆ getFunctionType()

Type mlir::function_interface_impl::getFunctionType ( Builder builder,
ArrayRef< OpAsmParser::Argument argAttrs,
ArrayRef< Type resultTypes 
)

Get a function type corresponding to an array of arguments (which have types) and a set of result types.

Referenced by buildLLVMFunctionType(), constructResultVector(), forwardPassthroughAttributes(), printAttributions(), printLaunchFuncOperands(), printShuffleType(), verifyAttributions(), and verifyConstantType().

◆ getResultAttrDict()

DictionaryAttr mlir::function_interface_impl::getResultAttrDict ( Operation 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.

References mlir::Operation::getAttrOfType(), and getResultDictAttrName().

Referenced by getResultAttrs(), and getResultDictAttrName().

◆ getResultAttrs()

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

◆ getResultDictAttrName()

StringRef mlir::function_interface_impl::getResultDictAttrName ( )
inline

◆ getTypeAttrName()

StringRef mlir::function_interface_impl::getTypeAttrName ( )
inline

◆ insertFunctionArguments()

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

◆ insertFunctionResults()

void mlir::function_interface_impl::insertFunctionResults ( Operation 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 160 of file FunctionInterfaces.cpp.

References mlir::Operation::getAttrOfType(), getResultDictAttrName(), getTypeAttrName(), setAllResultAttrDicts(), and mlir::Operation::setAttr().

Referenced by getResultAttrs().

◆ insertTypesInto()

TypeRange mlir::function_interface_impl::insertTypesInto ( TypeRange  oldTypes,
ArrayRef< unsigned indices,
TypeRange  newTypes,
SmallVectorImpl< Type > &  storage 
)

Insert a set of newTypes into oldTypes at the given indices.

If any types are inserted, storage is used to hold the new type list. The new type list is returned. indices must be sorted by increasing index.

Definition at line 245 of file FunctionInterfaces.cpp.

Referenced by mlir::FloatType::getFPMantissaWidth(), and getResultAttrs().

◆ parseFunctionOp()

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

Parser implementation for function-like operations.

Uses funcTypeBuilder to construct the custom function type given lists of input and output types. 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::NamedAttrList::get(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getCurrentLocation(), mlir::SymbolTable::getSymbolAttrName(), getTypeAttrName(), mlir::SymbolTable::getVisibilityAttrName(), mlir::OptionalParseResult::has_value(), parseFunctionSignature(), mlir::AsmParser::parseOptionalAttrDictWithKeyword(), mlir::OpAsmParser::parseOptionalRegion(), mlir::impl::parseOptionalVisibilityKeyword(), mlir::AsmParser::parseSymbolName(), and mlir::success().

Referenced by printCreateOperationOpResults().

◆ 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 buildLLVMFunctionType(), parseAttributions(), parseFunctionOp(), and verifyConstantType().

◆ printFunctionAttributes()

void mlir::function_interface_impl::printFunctionAttributes ( OpAsmPrinter p,
Operation op,
unsigned  numInputs,
unsigned  numResults,
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 303 of file FunctionImplementation.cpp.

References getArgDictAttrName(), mlir::Operation::getAttrs(), getResultDictAttrName(), mlir::SymbolTable::getSymbolAttrName(), getTypeAttrName(), and mlir::OpAsmPrinter::printOptionalAttrDictWithKeyword().

Referenced by buildLLVMFunctionType(), printAttributions(), printFunctionOp(), and verifyConstantType().

◆ printFunctionOp()

void mlir::function_interface_impl::printFunctionOp ( OpAsmPrinter p,
FunctionOpInterface  op,
bool  isVariadic 
)

◆ printFunctionSignature()

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

◆ 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 145 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 194 of file FunctionInterfaces.h.

◆ setAllArgAttrDicts() [1/2]

void mlir::function_interface_impl::setAllArgAttrDicts ( Operation 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 88 of file FunctionInterfaces.cpp.

Referenced by eraseFunctionArguments(), insertFunctionArguments(), and setFunctionType().

◆ setAllArgAttrDicts() [2/2]

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

◆ setAllResultAttrDicts() [1/2]

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

◆ setAllResultAttrDicts() [2/2]

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

◆ 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 132 of file FunctionInterfaces.h.

References mlir::Attribute::getContext().

◆ setArgAttrs() [1/2]

template<typename ConcreteType >
void mlir::function_interface_impl::setArgAttrs ( ConcreteType  op,
unsigned  index,
ArrayRef< NamedAttribute attributes 
)

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

Definition at line 115 of file FunctionInterfaces.h.

References getArgDictAttrName(), and mlir::function_interface_impl::detail::setArgResAttrDict().

◆ setArgAttrs() [2/2]

template<typename ConcreteType >
void mlir::function_interface_impl::setArgAttrs ( ConcreteType  op,
unsigned  index,
DictionaryAttr  attributes 
)

◆ setFunctionType()

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

◆ 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 182 of file FunctionInterfaces.h.

References mlir::Attribute::getContext().

◆ setResultAttrs() [1/2]

template<typename ConcreteType >
void mlir::function_interface_impl::setResultAttrs ( ConcreteType  op,
unsigned  index,
ArrayRef< NamedAttribute attributes 
)

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

Definition at line 162 of file FunctionInterfaces.h.

References getResultDictAttrName(), and mlir::function_interface_impl::detail::setArgResAttrDict().

◆ setResultAttrs() [2/2]

template<typename ConcreteType >
void mlir::function_interface_impl::setResultAttrs ( ConcreteType  op,
unsigned  index,
DictionaryAttr  attributes 
)

◆ 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 209 of file FunctionInterfaces.h.

References mlir::failed(), mlir::failure(), getArgDictAttrName(), getResultDictAttrName(), and getTypeAttrName().