14 #ifndef MLIR_IR_FUNCTIONINTERFACES_H
15 #define MLIR_IR_FUNCTIONINTERFACES_H
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/SmallString.h"
25 class FunctionOpInterface;
27 namespace function_interface_impl {
32 DictionaryAttr
getArgAttrDict(FunctionOpInterface op,
unsigned index);
40 ArrayRef<NamedAttribute>
getArgAttrs(FunctionOpInterface op,
unsigned index);
43 ArrayRef<NamedAttribute>
getResultAttrs(FunctionOpInterface op,
unsigned index);
51 ArrayRef<DictionaryAttr> attrs);
56 ArrayRef<unsigned> argIndices, TypeRange argTypes,
57 ArrayRef<DictionaryAttr> argAttrs,
58 ArrayRef<Location> argLocs,
59 unsigned originalNumArgs, Type newType);
63 ArrayRef<unsigned> resultIndices,
64 TypeRange resultTypes,
65 ArrayRef<DictionaryAttr> resultAttrs,
66 unsigned originalNumResults, Type newType);
74 const BitVector &resultIndices, Type newType);
82 TypeRange
insertTypesInto(TypeRange oldTypes, ArrayRef<unsigned> indices,
83 TypeRange newTypes, SmallVectorImpl<Type> &storage);
87 TypeRange
filterTypesOut(TypeRange types,
const BitVector &indices,
88 SmallVectorImpl<Type> &storage);
95 void setArgAttrs(FunctionOpInterface op,
unsigned index,
96 ArrayRef<NamedAttribute> attributes);
97 void setArgAttrs(FunctionOpInterface op,
unsigned index,
98 DictionaryAttr attributes);
102 template <
typename ConcreteType>
103 void setArgAttr(ConcreteType op,
unsigned index, StringAttr name,
109 if (value != oldValue)
115 template <
typename ConcreteType>
135 DictionaryAttr attributes);
139 template <
typename ConcreteType>
146 if (oldAttr != value)
151 template <
typename ConcreteType>
159 op.setResultAttrs(index,
166 template <
typename ConcreteOp>
168 if (
failed(op.verifyType()))
171 if (ArrayAttr allArgAttrs = op.getAllArgAttrs()) {
172 unsigned numArgs = op.getNumArguments();
173 if (allArgAttrs.size() != numArgs) {
174 return op.emitOpError()
175 <<
"expects argument attribute array to have the same number of "
176 "elements as the number of function arguments, got "
177 << allArgAttrs.size() <<
", but expected " << numArgs;
179 for (
unsigned i = 0; i != numArgs; ++i) {
180 DictionaryAttr argAttrs =
181 allArgAttrs[i].dyn_cast_or_null<DictionaryAttr>();
183 return op.emitOpError() <<
"expects argument attribute dictionary "
184 "to be a DictionaryAttr, but got `"
185 << allArgAttrs[i] <<
"`";
191 for (
auto attr : argAttrs) {
192 if (!attr.getName().strref().contains(
'.'))
193 return op.emitOpError(
"arguments may only have dialect attributes");
194 if (
Dialect *dialect = attr.getNameDialect()) {
195 if (
failed(dialect->verifyRegionArgAttribute(op, 0,
202 if (ArrayAttr allResultAttrs = op.getAllResultAttrs()) {
203 unsigned numResults = op.getNumResults();
204 if (allResultAttrs.size() != numResults) {
205 return op.emitOpError()
206 <<
"expects result attribute array to have the same number of "
207 "elements as the number of function results, got "
208 << allResultAttrs.size() <<
", but expected " << numResults;
210 for (
unsigned i = 0; i != numResults; ++i) {
211 DictionaryAttr resultAttrs =
212 allResultAttrs[i].dyn_cast_or_null<DictionaryAttr>();
214 return op.emitOpError() <<
"expects result attribute dictionary "
215 "to be a DictionaryAttr, but got `"
216 << allResultAttrs[i] <<
"`";
222 for (
auto attr : resultAttrs) {
223 if (!attr.getName().strref().contains(
'.'))
224 return op.emitOpError(
"results may only have dialect attributes");
225 if (
Dialect *dialect = attr.getNameDialect()) {
226 if (
failed(dialect->verifyRegionResultAttribute(op, 0,
236 if (op->getNumRegions() != 1)
237 return op.emitOpError(
"expects one region");
239 return op.verifyBody();
248 #include "mlir/IR/FunctionOpInterfaces.h.inc"
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
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.
Attribute erase(StringAttr name)
Erase the attribute with the given name from the list.
Attribute set(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
ArrayRef< NamedAttribute > getResultAttrs(FunctionOpInterface op, unsigned index)
Return all of the attributes for the result at 'index'.
void setAllResultAttrDicts(FunctionOpInterface op, ArrayRef< DictionaryAttr > 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.
LogicalResult verifyTrait(ConcreteOp op)
This function defines the internal implementation of the verifyTrait method on FunctionOpInterface::T...
void setResultAttrs(FunctionOpInterface op, unsigned index, ArrayRef< NamedAttribute > attributes)
Set the attributes held by the result at 'index'.
Attribute removeArgAttr(ConcreteType op, unsigned index, StringAttr name)
Remove the attribute 'name' from the argument at 'index'.
void eraseFunctionResults(FunctionOpInterface op, const BitVector &resultIndices, Type newType)
Erase the specified results and update the function type attribute.
void setArgAttrs(FunctionOpInterface op, unsigned index, ArrayRef< NamedAttribute > attributes)
Set the attributes held by the argument at 'index'.
ArrayRef< NamedAttribute > getArgAttrs(FunctionOpInterface op, unsigned index)
Return all of the attributes for the argument at 'index'.
void setAllArgAttrDicts(FunctionOpInterface op, ArrayRef< DictionaryAttr > attrs)
Set all of the argument or result attribute dictionaries for a function.
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.
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.
TypeRange insertTypesInto(TypeRange oldTypes, ArrayRef< unsigned > indices, TypeRange newTypes, SmallVectorImpl< Type > &storage)
Insert a set of newTypes into oldTypes at the given indices.
DictionaryAttr getResultAttrDict(FunctionOpInterface op, unsigned index)
Returns the dictionary attribute corresponding to the result at 'index'.
DictionaryAttr getArgAttrDict(FunctionOpInterface op, unsigned index)
Returns the dictionary attribute corresponding to the argument at 'index'.
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.
void eraseFunctionArguments(FunctionOpInterface op, const BitVector &argIndices, Type newType)
Erase the specified arguments and update the function type attribute.
TypeRange filterTypesOut(TypeRange types, const BitVector &indices, SmallVectorImpl< Type > &storage)
Filters out any elements referenced by indices.
void setFunctionType(FunctionOpInterface op, Type newType)
Set a FunctionOpInterface operation's type signature.
Attribute removeResultAttr(ConcreteType op, unsigned index, StringAttr name)
Remove the attribute 'name' from the result at 'index'.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.