14#ifndef MLIR_IR_FUNCTIONINTERFACES_H
15#define MLIR_IR_FUNCTIONINTERFACES_H
20#include "llvm/ADT/BitVector.h"
21#include "llvm/ADT/SmallString.h"
24class FunctionOpInterface;
31DictionaryAttr
getArgAttrDict(FunctionOpInterface op,
unsigned index);
39ArrayRef<NamedAttribute>
getArgAttrs(FunctionOpInterface op,
unsigned index);
42ArrayRef<NamedAttribute>
getResultAttrs(FunctionOpInterface op,
unsigned index);
50 ArrayRef<DictionaryAttr> attrs);
55 ArrayRef<unsigned> argIndices,
TypeRange argTypes,
56 ArrayRef<DictionaryAttr> argAttrs,
57 ArrayRef<Location> argLocs,
58 unsigned originalNumArgs, Type newType);
62 ArrayRef<unsigned> resultIndices,
64 ArrayRef<DictionaryAttr> resultAttrs,
65 unsigned originalNumResults, Type newType);
73 const BitVector &resultIndices, Type newType);
83void setArgAttrs(FunctionOpInterface op,
unsigned index,
84 ArrayRef<NamedAttribute> attributes);
85void setArgAttrs(FunctionOpInterface op,
unsigned index,
86 DictionaryAttr attributes);
90template <
typename ConcreteType>
97 if (value != oldValue)
103template <
typename ConcreteType>
123 DictionaryAttr attributes);
127template <
typename ConcreteType>
134 if (oldAttr != value)
139template <
typename ConcreteType>
147 op.setResultAttrs(
index,
154template <
typename ConcreteOp>
156 if (failed(op.verifyType()))
159 if (
ArrayAttr allArgAttrs = op.getAllArgAttrs()) {
160 unsigned numArgs = op.getNumArguments();
161 if (allArgAttrs.size() != numArgs) {
162 return op.emitOpError()
163 <<
"expects argument attribute array to have the same number of "
164 "elements as the number of function arguments, got "
165 << allArgAttrs.size() <<
", but expected " << numArgs;
167 for (
unsigned i = 0; i != numArgs; ++i) {
168 DictionaryAttr argAttrs =
169 llvm::dyn_cast_or_null<DictionaryAttr>(allArgAttrs[i]);
171 return op.emitOpError() <<
"expects argument attribute dictionary "
172 "to be a DictionaryAttr, but got `"
173 << allArgAttrs[i] <<
"`";
179 for (
auto attr : argAttrs) {
180 if (!attr.getName().strref().contains(
'.'))
181 return op.emitOpError(
"arguments may only have dialect attributes");
182 if (
Dialect *dialect = attr.getNameDialect()) {
183 if (failed(dialect->verifyRegionArgAttribute(op, 0,
190 if (
ArrayAttr allResultAttrs = op.getAllResultAttrs()) {
191 unsigned numResults = op.getNumResults();
192 if (allResultAttrs.size() != numResults) {
193 return op.emitOpError()
194 <<
"expects result attribute array to have the same number of "
195 "elements as the number of function results, got "
196 << allResultAttrs.size() <<
", but expected " << numResults;
198 for (
unsigned i = 0; i != numResults; ++i) {
199 DictionaryAttr resultAttrs =
200 llvm::dyn_cast_or_null<DictionaryAttr>(allResultAttrs[i]);
202 return op.emitOpError() <<
"expects result attribute dictionary "
203 "to be a DictionaryAttr, but got `"
204 << allResultAttrs[i] <<
"`";
210 for (
auto attr : resultAttrs) {
211 if (!attr.getName().strref().contains(
'.'))
212 return op.emitOpError(
"results may only have dialect attributes");
213 if (
Dialect *dialect = attr.getNameDialect()) {
214 if (failed(dialect->verifyRegionResultAttribute(op, 0,
224 if (op->getNumRegions() != 1)
225 return op.emitOpError(
"expects one region");
227 return op.verifyBody();
236#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.