Makes the relationship and function clearer. Accordingly rename getAttrList to getMutableAttrDict.
Differential Revision: https://reviews.llvm.org/D79125
OpBuilder<"OpBuilder &builder, OperationState &result, StringRef name, "
"LLVMType type, LLVM::Linkage linkage = LLVM::Linkage::External, "
"ArrayRef<NamedAttribute> attrs = {}, "
- "ArrayRef<NamedAttributeList> argAttrs = {}">
+ "ArrayRef<MutableDictionaryAttr> argAttrs = {}">
];
let extraClassDeclaration = [{
}
//===----------------------------------------------------------------------===//
-// NamedAttributeList
+// MutableDictionaryAttr
//===----------------------------------------------------------------------===//
-/// A NamedAttributeList is a mutable wrapper around a DictionaryAttr. It
+/// A MutableDictionaryAttr is a mutable wrapper around a DictionaryAttr. It
/// provides additional interfaces for adding, removing, replacing attributes
/// within a DictionaryAttr.
///
/// We assume there will be relatively few attributes on a given operation
/// (maybe a dozen or so, but not hundreds or thousands) so we use linear
/// searches for everything.
-class NamedAttributeList {
+class MutableDictionaryAttr {
public:
- NamedAttributeList(DictionaryAttr attrs = nullptr)
+ MutableDictionaryAttr(DictionaryAttr attrs = nullptr)
: attrs((attrs && !attrs.empty()) ? attrs : nullptr) {}
- NamedAttributeList(ArrayRef<NamedAttribute> attributes);
+ MutableDictionaryAttr(ArrayRef<NamedAttribute> attributes);
- bool operator!=(const NamedAttributeList &other) const {
+ bool operator!=(const MutableDictionaryAttr &other) const {
return !(*this == other);
}
- bool operator==(const NamedAttributeList &other) const {
+ bool operator==(const MutableDictionaryAttr &other) const {
return attrs == other.attrs;
}
iterator_range<dialect_attr_iterator> attrs);
static FuncOp create(Location location, StringRef name, FunctionType type,
ArrayRef<NamedAttribute> attrs,
- ArrayRef<NamedAttributeList> argAttrs);
+ ArrayRef<MutableDictionaryAttr> argAttrs);
static void build(OpBuilder &builder, OperationState &result, StringRef name,
FunctionType type, ArrayRef<NamedAttribute> attrs);
static void build(OpBuilder &builder, OperationState &result, StringRef name,
FunctionType type, ArrayRef<NamedAttribute> attrs,
- ArrayRef<NamedAttributeList> argAttrs);
+ ArrayRef<MutableDictionaryAttr> argAttrs);
/// Operation hooks.
static ParseResult parse(OpAsmParser &parser, OperationState &result);
}
/// Return all argument attributes of this function.
- void getAllArgAttrs(SmallVectorImpl<NamedAttributeList> &result) {
+ void getAllArgAttrs(SmallVectorImpl<MutableDictionaryAttr> &result) {
for (unsigned i = 0, e = getNumArguments(); i != e; ++i)
result.emplace_back(getArgAttrDict(i));
}
/// Set the attributes held by the argument at 'index'.
void setArgAttrs(unsigned index, ArrayRef<NamedAttribute> attributes);
- void setArgAttrs(unsigned index, NamedAttributeList attributes);
- void setAllArgAttrs(ArrayRef<NamedAttributeList> attributes) {
+ void setArgAttrs(unsigned index, MutableDictionaryAttr attributes);
+ void setAllArgAttrs(ArrayRef<MutableDictionaryAttr> attributes) {
assert(attributes.size() == getNumArguments());
for (unsigned i = 0, e = attributes.size(); i != e; ++i)
setArgAttrs(i, attributes[i]);
}
/// Remove the attribute 'name' from the argument at 'index'.
- NamedAttributeList::RemoveResult removeArgAttr(unsigned index,
- Identifier name);
+ MutableDictionaryAttr::RemoveResult removeArgAttr(unsigned index,
+ Identifier name);
//===--------------------------------------------------------------------===//
// Result Attributes
}
/// Return all result attributes of this function.
- void getAllResultAttrs(SmallVectorImpl<NamedAttributeList> &result) {
+ void getAllResultAttrs(SmallVectorImpl<MutableDictionaryAttr> &result) {
for (unsigned i = 0, e = getNumResults(); i != e; ++i)
result.emplace_back(getResultAttrDict(i));
}
/// Set the attributes held by the result at 'index'.
void setResultAttrs(unsigned index, ArrayRef<NamedAttribute> attributes);
- void setResultAttrs(unsigned index, NamedAttributeList attributes);
- void setAllResultAttrs(ArrayRef<NamedAttributeList> attributes) {
+ void setResultAttrs(unsigned index, MutableDictionaryAttr attributes);
+ void setAllResultAttrs(ArrayRef<MutableDictionaryAttr> attributes) {
assert(attributes.size() == getNumResults());
for (unsigned i = 0, e = attributes.size(); i != e; ++i)
setResultAttrs(i, attributes[i]);
}
/// Remove the attribute 'name' from the result at 'index'.
- NamedAttributeList::RemoveResult removeResultAttr(unsigned index,
- Identifier name);
+ MutableDictionaryAttr::RemoveResult removeResultAttr(unsigned index,
+ Identifier name);
protected:
/// Returns the attribute entry name for the set of argument attributes at
template <typename ConcreteType>
void FunctionLike<ConcreteType>::setArgAttrs(unsigned index,
- NamedAttributeList attributes) {
+ MutableDictionaryAttr attributes) {
assert(index < getNumArguments() && "invalid argument number");
SmallString<8> nameOut;
if (auto newAttr = attributes.getDictionary())
void FunctionLike<ConcreteType>::setArgAttr(unsigned index, Identifier name,
Attribute value) {
auto curAttr = getArgAttrDict(index);
- NamedAttributeList attrList(curAttr);
- attrList.set(name, value);
+ MutableDictionaryAttr attrDict(curAttr);
+ attrDict.set(name, value);
// If the attribute changed, then set the new arg attribute list.
- if (curAttr != attrList.getDictionary())
- setArgAttrs(index, attrList);
+ if (curAttr != attrDict.getDictionary())
+ setArgAttrs(index, attrDict);
}
/// Remove the attribute 'name' from the argument at 'index'.
template <typename ConcreteType>
-NamedAttributeList::RemoveResult
+MutableDictionaryAttr::RemoveResult
FunctionLike<ConcreteType>::removeArgAttr(unsigned index, Identifier name) {
// Build an attribute list and remove the attribute at 'name'.
- NamedAttributeList attrList(getArgAttrDict(index));
- auto result = attrList.remove(name);
+ MutableDictionaryAttr attrDict(getArgAttrDict(index));
+ auto result = attrDict.remove(name);
// If the attribute was removed, then update the argument dictionary.
- if (result == NamedAttributeList::RemoveResult::Removed)
- setArgAttrs(index, attrList);
+ if (result == MutableDictionaryAttr::RemoveResult::Removed)
+ setArgAttrs(index, attrDict);
return result;
}
}
template <typename ConcreteType>
-void FunctionLike<ConcreteType>::setResultAttrs(unsigned index,
- NamedAttributeList attributes) {
+void FunctionLike<ConcreteType>::setResultAttrs(
+ unsigned index, MutableDictionaryAttr attributes) {
assert(index < getNumResults() && "invalid result number");
SmallString<8> nameOut;
if (auto newAttr = attributes.getDictionary())
void FunctionLike<ConcreteType>::setResultAttr(unsigned index, Identifier name,
Attribute value) {
auto curAttr = getResultAttrDict(index);
- NamedAttributeList attrList(curAttr);
- attrList.set(name, value);
+ MutableDictionaryAttr attrDict(curAttr);
+ attrDict.set(name, value);
// If the attribute changed, then set the new arg attribute list.
- if (curAttr != attrList.getDictionary())
- setResultAttrs(index, attrList);
+ if (curAttr != attrDict.getDictionary())
+ setResultAttrs(index, attrDict);
}
/// Remove the attribute 'name' from the result at 'index'.
template <typename ConcreteType>
-NamedAttributeList::RemoveResult
+MutableDictionaryAttr::RemoveResult
FunctionLike<ConcreteType>::removeResultAttr(unsigned index, Identifier name) {
// Build an attribute list and remove the attribute at 'name'.
- NamedAttributeList attrList(getResultAttrDict(index));
- auto result = attrList.remove(name);
+ MutableDictionaryAttr attrDict(getResultAttrDict(index));
+ auto result = attrDict.remove(name);
// If the attribute was removed, then update the result dictionary.
- if (result == NamedAttributeList::RemoveResult::Removed)
- setResultAttrs(index, attrList);
+ if (result == MutableDictionaryAttr::RemoveResult::Removed)
+ setResultAttrs(index, attrDict);
return result;
}
void setAttrs(ArrayRef<NamedAttribute> attributes) {
state->setAttrs(attributes);
}
- void setAttrs(NamedAttributeList newAttrs) { state->setAttrs(newAttrs); }
+ void setAttrs(MutableDictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
/// Set the dialect attributes for this operation, and preserve all dependent.
template <typename DialectAttrs> void setDialectAttrs(DialectAttrs &&attrs) {
/// Remove the attribute with the specified name if it exists. The return
/// value indicates whether the attribute was present or not.
- NamedAttributeList::RemoveResult removeAttr(Identifier name) {
+ MutableDictionaryAttr::RemoveResult removeAttr(Identifier name) {
return state->removeAttr(name);
}
- NamedAttributeList::RemoveResult removeAttr(StringRef name) {
+ MutableDictionaryAttr::RemoveResult removeAttr(StringRef name) {
return state->removeAttr(Identifier::get(name, getContext()));
}
ArrayRef<NamedAttribute> attributes,
ArrayRef<Block *> successors, unsigned numRegions);
- /// Overload of create that takes an existing NamedAttributeList to avoid
+ /// Overload of create that takes an existing MutableDictionaryAttr to avoid
/// unnecessarily uniquing a list of attributes.
static Operation *create(Location location, OperationName name,
ArrayRef<Type> resultTypes, ArrayRef<Value> operands,
- NamedAttributeList attributes,
+ MutableDictionaryAttr attributes,
ArrayRef<Block *> successors, unsigned numRegions);
/// Create a new Operation from the fields stored in `state`.
/// Create a new Operation with the specific fields.
static Operation *create(Location location, OperationName name,
ArrayRef<Type> resultTypes, ArrayRef<Value> operands,
- NamedAttributeList attributes,
+ MutableDictionaryAttr attributes,
ArrayRef<Block *> successors = {},
RegionRange regions = {});
/// Return all of the attributes on this operation.
ArrayRef<NamedAttribute> getAttrs() { return attrs.getAttrs(); }
- /// Return the internal attribute list on this operation.
- NamedAttributeList &getAttrList() { return attrs; }
+ /// Return mutable container of all the attributes on this operation.
+ MutableDictionaryAttr &getMutableAttrDict() { return attrs; }
- /// Set the attribute list on this operation.
- /// Using a NamedAttributeList is more efficient as it does not require new
+ /// Set the attribute dictionary on this operation.
+ /// Using a MutableDictionaryAttr is more efficient as it does not require new
/// uniquing in the MLIRContext.
- void setAttrs(NamedAttributeList newAttrs) { attrs = newAttrs; }
+ void setAttrs(MutableDictionaryAttr newAttrs) { attrs = newAttrs; }
/// Return the specified attribute if present, null otherwise.
Attribute getAttr(Identifier name) { return attrs.get(name); }
/// Remove the attribute with the specified name if it exists. The return
/// value indicates whether the attribute was present or not.
- NamedAttributeList::RemoveResult removeAttr(Identifier name) {
+ MutableDictionaryAttr::RemoveResult removeAttr(Identifier name) {
return attrs.remove(name);
}
private:
Operation(Location location, OperationName name, ArrayRef<Type> resultTypes,
unsigned numSuccessors, unsigned numRegions,
- const NamedAttributeList &attributes, bool hasOperandStorage);
+ const MutableDictionaryAttr &attributes, bool hasOperandStorage);
// Operations are deleted through the destroy() member because they are
// allocated with malloc.
OperationName name;
/// This holds general named attributes for the operation.
- NamedAttributeList attrs;
+ MutableDictionaryAttr attrs;
// allow ilist_traits access to 'block' field.
friend struct llvm::ilist_traits<Operation>;
auto *parentOp = callableRegion->getParentOp();
os << "'" << callableRegion->getParentOp()->getName() << "' - Region #"
<< callableRegion->getRegionNumber();
- if (auto attrs = parentOp->getAttrList().getDictionary())
+ if (auto attrs = parentOp->getMutableAttrDict().getDictionary())
os << " : " << attrs;
};
void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
StringRef name, LLVMType type, LLVM::Linkage linkage,
ArrayRef<NamedAttribute> attrs,
- ArrayRef<NamedAttributeList> argAttrs) {
+ ArrayRef<MutableDictionaryAttr> argAttrs) {
result.addRegion();
result.addAttribute(SymbolTable::getSymbolAttrName(),
builder.getStringAttr(name));
}
bool isSameAttrList(spirv::StoreOp lhs, spirv::StoreOp rhs) const {
- return lhs.getOperation()->getAttrList().getDictionary() ==
- rhs.getOperation()->getAttrList().getDictionary();
+ return lhs.getOperation()->getMutableAttrDict().getDictionary() ==
+ rhs.getOperation()->getMutableAttrDict().getDictionary();
}
DenseMap<uint32_t, StringRef> nameMap;
// Result <id> to decorations mapping.
- DenseMap<uint32_t, NamedAttributeList> decorations;
+ DenseMap<uint32_t, MutableDictionaryAttr> decorations;
// Result <id> to type decorations.
DenseMap<uint32_t, uint32_t> typeDecorations;
}
//===----------------------------------------------------------------------===//
-// NamedAttributeList
+// MutableDictionaryAttr
//===----------------------------------------------------------------------===//
-NamedAttributeList::NamedAttributeList(ArrayRef<NamedAttribute> attributes) {
+MutableDictionaryAttr::MutableDictionaryAttr(
+ ArrayRef<NamedAttribute> attributes) {
setAttrs(attributes);
}
-ArrayRef<NamedAttribute> NamedAttributeList::getAttrs() const {
+ArrayRef<NamedAttribute> MutableDictionaryAttr::getAttrs() const {
return attrs ? attrs.getValue() : llvm::None;
}
/// Replace the held attributes with ones provided in 'newAttrs'.
-void NamedAttributeList::setAttrs(ArrayRef<NamedAttribute> attributes) {
+void MutableDictionaryAttr::setAttrs(ArrayRef<NamedAttribute> attributes) {
// Don't create an attribute list if there are no attributes.
if (attributes.empty())
attrs = nullptr;
}
/// Return the specified attribute if present, null otherwise.
-Attribute NamedAttributeList::get(StringRef name) const {
+Attribute MutableDictionaryAttr::get(StringRef name) const {
return attrs ? attrs.get(name) : nullptr;
}
/// Return the specified attribute if present, null otherwise.
-Attribute NamedAttributeList::get(Identifier name) const {
+Attribute MutableDictionaryAttr::get(Identifier name) const {
return attrs ? attrs.get(name) : nullptr;
}
/// 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.
-void NamedAttributeList::set(Identifier name, Attribute value) {
+void MutableDictionaryAttr::set(Identifier name, Attribute value) {
assert(value && "attributes may never be null");
// Look for an existing value for the given name, and set it in-place.
/// Remove the attribute with the specified name if it exists. The return
/// value indicates whether the attribute was present or not.
-auto NamedAttributeList::remove(Identifier name) -> RemoveResult {
+auto MutableDictionaryAttr::remove(Identifier name) -> RemoveResult {
auto origAttrs = getAttrs();
for (unsigned i = 0, e = origAttrs.size(); i != e; ++i) {
if (origAttrs[i].first == name) {
}
FuncOp FuncOp::create(Location location, StringRef name, FunctionType type,
ArrayRef<NamedAttribute> attrs,
- ArrayRef<NamedAttributeList> argAttrs) {
+ ArrayRef<MutableDictionaryAttr> argAttrs) {
FuncOp func = create(location, name, type, attrs);
func.setAllArgAttrs(argAttrs);
return func;
void FuncOp::build(OpBuilder &builder, OperationState &result, StringRef name,
FunctionType type, ArrayRef<NamedAttribute> attrs,
- ArrayRef<NamedAttributeList> argAttrs) {
+ ArrayRef<MutableDictionaryAttr> argAttrs) {
build(builder, result, name, type, attrs);
assert(type.getNumInputs() == argAttrs.size());
SmallString<8> argAttrName;
// Update the function type and arg attrs.
SmallVector<Type, 4> newInputTypes;
- SmallVector<NamedAttributeList, 4> newArgAttrs;
+ SmallVector<MutableDictionaryAttr, 4> newArgAttrs;
for (int i = 0; i < originalNumArgs; i++) {
if (shouldEraseArg(i))
continue;
// Check that none of the attributes are non-dialect attributes, except for
// the symbol related attributes.
- for (auto attr : getOperation()->getAttrList().getAttrs()) {
+ for (auto attr : getOperation()->getMutableAttrDict().getAttrs()) {
if (!attr.first.strref().contains('.') &&
!llvm::is_contained(
ArrayRef<StringRef>{mlir::SymbolTable::getSymbolAttrName(),
ArrayRef<Block *> successors,
unsigned numRegions) {
return create(location, name, resultTypes, operands,
- NamedAttributeList(attributes), successors, numRegions);
+ MutableDictionaryAttr(attributes), successors, numRegions);
}
/// Create a new Operation from operation state.
Operation *Operation::create(const OperationState &state) {
- return Operation::create(state.location, state.name, state.types,
- state.operands, NamedAttributeList(state.attributes),
- state.successors, state.regions);
+ return Operation::create(
+ state.location, state.name, state.types, state.operands,
+ MutableDictionaryAttr(state.attributes), state.successors, state.regions);
}
/// Create a new Operation with the specific fields.
Operation *Operation::create(Location location, OperationName name,
ArrayRef<Type> resultTypes,
ArrayRef<Value> operands,
- NamedAttributeList attributes,
+ MutableDictionaryAttr attributes,
ArrayRef<Block *> successors,
RegionRange regions) {
unsigned numRegions = regions.size();
return op;
}
-/// Overload of create that takes an existing NamedAttributeList to avoid
+/// Overload of create that takes an existing MutableDictionaryAttr to avoid
/// unnecessarily uniquing a list of attributes.
Operation *Operation::create(Location location, OperationName name,
ArrayRef<Type> resultTypes,
ArrayRef<Value> operands,
- NamedAttributeList attributes,
+ MutableDictionaryAttr attributes,
ArrayRef<Block *> successors,
unsigned numRegions) {
// We only need to allocate additional memory for a subset of results.
Operation::Operation(Location location, OperationName name,
ArrayRef<Type> resultTypes, unsigned numSuccessors,
- unsigned numRegions, const NamedAttributeList &attributes,
+ unsigned numRegions,
+ const MutableDictionaryAttr &attributes,
bool hasOperandStorage)
: location(location), numSuccs(numSuccessors), numRegions(numRegions),
hasOperandStorage(hasOperandStorage), hasSingleResult(false), name(name),
Operation *op,
function_ref<WalkResult(SymbolTable::SymbolUse, ArrayRef<int>)> callback) {
// Check to see if the operation has any attributes.
- DictionaryAttr attrDict = op->getAttrList().getDictionary();
+ DictionaryAttr attrDict = op->getMutableAttrDict().getDictionary();
if (!attrDict)
return WalkResult::advance();
// Generate a new attribute dictionary for the current operation by replacing
// references to the old symbol.
auto generateNewAttrDict = [&] {
- auto oldDict = curOp->getAttrList().getDictionary();
+ auto oldDict = curOp->getMutableAttrDict().getDictionary();
auto newDict = rebuildAttrAfterRAUW(oldDict, accessChains, /*depth=*/0);
return newDict.cast<DictionaryAttr>();
};
if (nested && std::next(operations.begin(), 2) == operations.end()) {
// Merge the data of the nested module operation into 'module'.
module.setLoc(nested.getLoc());
- module.setAttrs(nested.getOperation()->getAttrList());
+ module.setAttrs(nested.getOperation()->getMutableAttrDict());
bodyBlocks.splice(bodyBlocks.end(), nested.getBodyRegion().getBlocks());
// Erase the original module body.
// - Operation pointer
addDataToHash(hasher, op);
// - Attributes
- addDataToHash(hasher,
- op->getAttrList().getDictionary().getAsOpaquePointer());
+ addDataToHash(
+ hasher,
+ op->getMutableAttrDict().getDictionary().getAsOpaquePointer());
// - Blocks in Regions
for (Region ®ion : op->getRegions()) {
for (Block &block : region) {
// - Result Types
// - Operands
return llvm::hash_combine(
- op->getName(), op->getAttrList().getDictionary(), op->getResultTypes(),
+ op->getName(), op->getMutableAttrDict().getDictionary(),
+ op->getResultTypes(),
llvm::hash_combine_range(op->operand_begin(), op->operand_end()));
}
static bool isEqual(const Operation *lhsC, const Operation *rhsC) {
lhs->getNumResults() != rhs->getNumResults())
return false;
// Compare attributes.
- if (lhs->getAttrList() != rhs->getAttrList())
+ if (lhs->getMutableAttrDict() != rhs->getMutableAttrDict())
return false;
// Compare operands.
if (!std::equal(lhs->operand_begin(), lhs->operand_end(),
public:
OperationTransactionState() = default;
OperationTransactionState(Operation *op)
- : op(op), loc(op->getLoc()), attrs(op->getAttrList()),
+ : op(op), loc(op->getLoc()), attrs(op->getMutableAttrDict()),
operands(op->operand_begin(), op->operand_end()),
successors(op->successor_begin(), op->successor_end()) {}
private:
Operation *op;
LocationAttr loc;
- NamedAttributeList attrs;
+ MutableDictionaryAttr attrs;
SmallVector<Value, 8> operands;
SmallVector<Block *, 2> successors;
};
// in-place. The constant passed in may not correspond to the real runtime
// value, so in-place updates are not allowed.
SmallVector<Value, 8> originalOperands(op->getOperands());
- NamedAttributeList originalAttrs = op->getAttrList();
+ MutableDictionaryAttr originalAttrs = op->getMutableAttrDict();
// Simulate the result of folding this operation to a constant. If folding
// fails or was an in-place fold, mark the results as overdefined.