14 #ifndef MLIR_IR_FUNCTIONINTERFACES_H
15 #define MLIR_IR_FUNCTIONINTERFACES_H
23 #include "llvm/ADT/BitVector.h"
24 #include "llvm/ADT/SmallString.h"
27 class FunctionOpInterface;
29 namespace function_interface_impl {
34 DictionaryAttr
getArgAttrDict(FunctionOpInterface op,
unsigned index);
42 ArrayRef<NamedAttribute>
getArgAttrs(FunctionOpInterface op,
unsigned index);
45 ArrayRef<NamedAttribute>
getResultAttrs(FunctionOpInterface op,
unsigned index);
53 ArrayRef<DictionaryAttr> attrs);
58 ArrayRef<unsigned> argIndices, TypeRange argTypes,
59 ArrayRef<DictionaryAttr> argAttrs,
60 ArrayRef<Location> argLocs,
61 unsigned originalNumArgs, Type newType);
65 ArrayRef<unsigned> resultIndices,
66 TypeRange resultTypes,
67 ArrayRef<DictionaryAttr> resultAttrs,
68 unsigned originalNumResults, Type newType);
76 const BitVector &resultIndices, Type newType);
86 void setArgAttrs(FunctionOpInterface op,
unsigned index,
87 ArrayRef<NamedAttribute> attributes);
88 void setArgAttrs(FunctionOpInterface op,
unsigned index,
89 DictionaryAttr attributes);
93 template <
typename ConcreteType>
94 void setArgAttr(ConcreteType op,
unsigned index, StringAttr name,
100 if (value != oldValue)
106 template <
typename ConcreteType>
126 DictionaryAttr attributes);
130 template <
typename ConcreteType>
137 if (oldAttr != value)
142 template <
typename ConcreteType>
150 op.setResultAttrs(index,
157 template <
typename ConcreteOp>
159 if (failed(op.verifyType()))
162 if (ArrayAttr allArgAttrs = op.getAllArgAttrs()) {
163 unsigned numArgs = op.getNumArguments();
164 if (allArgAttrs.size() != numArgs) {
165 return op.emitOpError()
166 <<
"expects argument attribute array to have the same number of "
167 "elements as the number of function arguments, got "
168 << allArgAttrs.size() <<
", but expected " << numArgs;
170 for (
unsigned i = 0; i != numArgs; ++i) {
171 DictionaryAttr argAttrs =
172 llvm::dyn_cast_or_null<DictionaryAttr>(allArgAttrs[i]);
174 return op.emitOpError() <<
"expects argument attribute dictionary "
175 "to be a DictionaryAttr, but got `"
176 << allArgAttrs[i] <<
"`";
182 for (
auto attr : argAttrs) {
183 if (!attr.getName().strref().contains(
'.'))
184 return op.emitOpError(
"arguments may only have dialect attributes");
185 if (
Dialect *dialect = attr.getNameDialect()) {
186 if (failed(dialect->verifyRegionArgAttribute(op, 0,
193 if (ArrayAttr allResultAttrs = op.getAllResultAttrs()) {
194 unsigned numResults = op.getNumResults();
195 if (allResultAttrs.size() != numResults) {
196 return op.emitOpError()
197 <<
"expects result attribute array to have the same number of "
198 "elements as the number of function results, got "
199 << allResultAttrs.size() <<
", but expected " << numResults;
201 for (
unsigned i = 0; i != numResults; ++i) {
202 DictionaryAttr resultAttrs =
203 llvm::dyn_cast_or_null<DictionaryAttr>(allResultAttrs[i]);
205 return op.emitOpError() <<
"expects result attribute dictionary "
206 "to be a DictionaryAttr, but got `"
207 << allResultAttrs[i] <<
"`";
213 for (
auto attr : resultAttrs) {
214 if (!attr.getName().strref().contains(
'.'))
215 return op.emitOpError(
"results may only have dialect attributes");
216 if (
Dialect *dialect = attr.getNameDialect()) {
217 if (failed(dialect->verifyRegionResultAttribute(op, 0,
227 if (op->getNumRegions() != 1)
228 return op.emitOpError(
"expects one region");
230 return op.verifyBody();
239 #include "mlir/Interfaces/FunctionInterfaces.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.
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.
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.