17 #include "mlir/IR/FunctionOpInterfaces.cpp.inc" 24 return attr.
cast<DictionaryAttr>().empty();
30 DictionaryAttr argAttrs =
31 attrs ? attrs[index].cast<DictionaryAttr>() : DictionaryAttr();
39 DictionaryAttr resAttrs =
40 attrs ? attrs[index].cast<DictionaryAttr>() : DictionaryAttr();
45 Operation *op, StringRef attrName,
unsigned numTotalIndices,
unsigned index,
46 DictionaryAttr attrs) {
55 newAttrs[index] = attrs;
60 if (allAttrs[index] == attrs)
75 newAttrs[index] = attrs;
95 return !attr ? DictionaryAttr::get(op->
getContext()) : attr;
98 llvm::to_vector<8>(wrappedAttrs));
108 return !attr ? DictionaryAttr::get(op->
getContext()) : attr;
111 llvm::to_vector<8>(wrappedAttrs));
117 unsigned originalNumArgs,
Type newType) {
118 assert(argIndices.size() == argTypes.size());
119 assert(argIndices.size() == argAttrs.size() || argAttrs.empty());
120 assert(argIndices.size() == argLocs.size());
121 if (argIndices.empty())
132 if (oldArgAttrs || !argAttrs.empty()) {
134 newArgAttrs.reserve(originalNumArgs + argIndices.size());
136 auto migrate = [&](
unsigned untilIdx) {
138 newArgAttrs.resize(newArgAttrs.size() + untilIdx - oldIdx);
140 auto oldArgAttrRange = oldArgAttrs.getAsRange<DictionaryAttr>();
141 newArgAttrs.append(oldArgAttrRange.begin() + oldIdx,
142 oldArgAttrRange.begin() + untilIdx);
146 for (
unsigned i = 0, e = argIndices.size(); i < e; ++i) {
147 migrate(argIndices[i]);
148 newArgAttrs.push_back(argAttrs.empty() ? DictionaryAttr{} : argAttrs[i]);
150 migrate(originalNumArgs);
156 for (
unsigned i = 0, e = argIndices.size(); i < e; ++i)
164 assert(resultIndices.size() == resultTypes.size());
165 assert(resultIndices.size() == resultAttrs.size() || resultAttrs.empty());
166 if (resultIndices.empty())
175 if (oldResultAttrs || !resultAttrs.empty()) {
177 newResultAttrs.reserve(originalNumResults + resultIndices.size());
179 auto migrate = [&](
unsigned untilIdx) {
180 if (!oldResultAttrs) {
181 newResultAttrs.resize(newResultAttrs.size() + untilIdx - oldIdx);
183 auto oldResultAttrsRange = oldResultAttrs.getAsRange<DictionaryAttr>();
184 newResultAttrs.append(oldResultAttrsRange.begin() + oldIdx,
185 oldResultAttrsRange.begin() + untilIdx);
189 for (
unsigned i = 0, e = resultIndices.size(); i < e; ++i) {
190 migrate(resultIndices[i]);
191 newResultAttrs.push_back(resultAttrs.empty() ? DictionaryAttr{}
194 migrate(originalNumResults);
213 newArgAttrs.reserve(argAttrs.size());
214 for (
unsigned i = 0, e = argIndices.size(); i < e; ++i)
216 newArgAttrs.emplace_back(argAttrs[i].cast<DictionaryAttr>());
226 Operation *op,
const BitVector &resultIndices,
Type newType) {
234 newResultAttrs.reserve(resAttrs.size());
235 for (
unsigned i = 0, e = resultIndices.size(); i < e; ++i)
236 if (!resultIndices[i])
237 newResultAttrs.emplace_back(resAttrs[i].cast<DictionaryAttr>());
248 assert(indices.size() == newTypes.size() &&
249 "mismatch between indice and type count");
253 auto fromIt = oldTypes.begin();
254 for (
auto it : llvm::zip(indices, newTypes)) {
255 const auto toIt = oldTypes.begin() + std::get<0>(it);
256 storage.append(fromIt, toIt);
257 storage.push_back(std::get<1>(it));
260 storage.append(fromIt, oldTypes.end());
269 for (
unsigned i = 0, e = types.size(); i < e; ++i)
271 storage.emplace_back(types[i]);
281 FunctionOpInterface funcOp = cast<FunctionOpInterface>(op);
282 unsigned oldNumArgs = funcOp.getNumArguments();
283 unsigned oldNumResults = funcOp.getNumResults();
285 unsigned newNumArgs = funcOp.getNumArguments();
286 unsigned newNumResults = funcOp.getNumResults();
289 auto updateAttrFn = [&](StringRef attrName,
unsigned oldCount,
290 unsigned newCount,
auto setAttrFn) {
291 if (oldCount == newCount)
303 if (newCount < oldCount)
304 return setAttrFn(op, attrs.getValue().take_front(newCount));
309 newAttrs.resize(newCount);
310 setAttrFn(op, newAttrs);
Include the generated interface declarations.
StringRef getResultDictAttrName()
Return the name of the attribute used for function argument attributes.
DictionaryAttr getResultAttrDict(Operation *op, unsigned index)
Returns the dictionary attribute corresponding to the result at 'index'.
Operation is a basic unit of execution within MLIR.
StringRef getArgDictAttrName()
Return the name of the attribute used for function argument attributes.
Block represents an ordered list of Operations.
AttrClass getAttrOfType(StringAttr name)
BlockArgument insertArgument(args_iterator it, Type type, Location loc)
Insert one value to the position in the argument list indicated by the given iterator.
void setAllArgAttrDicts(Operation *op, ArrayRef< DictionaryAttr > attrs)
Set all of the argument or result attribute dictionaries for a function.
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.
TypeRange filterTypesOut(TypeRange types, const BitVector &indices, SmallVectorImpl< Type > &storage)
Filters out any elements referenced by indices.
void eraseFunctionResults(Operation *op, const BitVector &resultIndices, Type newType)
Erase the specified results and update the function type attribute.
StringRef getTypeAttrName()
Return the name of the attribute used for function types.
DictionaryAttr getArgAttrDict(Operation *op, unsigned index)
Returns the dictionary attribute corresponding to the argument at 'index'.
MLIRContext * getContext()
Return the context this operation is associated with.
void eraseArguments(ArrayRef< unsigned > argIndices)
Erases the arguments listed in argIndices and removes them from the argument list.
void setArgResAttrDict(Operation *op, StringRef attrName, unsigned numTotalIndices, unsigned index, DictionaryAttr attrs)
Update the given index into an argument or result attribute dictionary.
Attributes are known-constant values of operations.
Attribute removeAttr(StringAttr name)
Remove the attribute with the specified name if it exists.
This class provides an abstraction over the various different ranges of value types.
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.
void setFunctionType(Operation *op, Type newType)
Set a FunctionOpInterface operation's type signature.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
void eraseFunctionArguments(Operation *op, const BitVector &argIndices, Type newType)
Erase the specified arguments and update the function type attribute.
void setAllResultAttrDicts(Operation *op, ArrayRef< DictionaryAttr > attrs)
static bool isEmptyAttrDict(Attribute attr)
static void setAllArgResAttrDicts(Operation *op, StringRef attrName, ArrayRef< Attribute > attrs)
Set all of the argument or result attribute dictionaries for a function.
TypeRange insertTypesInto(TypeRange oldTypes, ArrayRef< unsigned > indices, TypeRange newTypes, SmallVectorImpl< Type > &storage)
Insert a set of newTypes into oldTypes at the given indices.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.