forked from OSchip/llvm-project
[mlir] Switch create to use NamedAttrList&&
Avoids needing the two parallel functions as NamedAttrList already takes care of caching DictionaryAttr and implicitly can convert from either. Differential Revision: https://reviews.llvm.org/D129527
This commit is contained in:
parent
2a0aa98c8d
commit
0db084d4c7
|
@ -33,14 +33,7 @@ public:
|
||||||
/// Create a new Operation with the specific fields.
|
/// Create a new Operation with the specific fields.
|
||||||
static Operation *create(Location location, OperationName name,
|
static Operation *create(Location location, OperationName name,
|
||||||
TypeRange resultTypes, ValueRange operands,
|
TypeRange resultTypes, ValueRange operands,
|
||||||
ArrayRef<NamedAttribute> attributes,
|
NamedAttrList &&attributes, BlockRange successors,
|
||||||
BlockRange successors, unsigned numRegions);
|
|
||||||
|
|
||||||
/// Overload of create that takes an existing DictionaryAttr to avoid
|
|
||||||
/// unnecessarily uniquing a list of attributes.
|
|
||||||
static Operation *create(Location location, OperationName name,
|
|
||||||
TypeRange resultTypes, ValueRange operands,
|
|
||||||
DictionaryAttr attributes, BlockRange successors,
|
|
||||||
unsigned numRegions);
|
unsigned numRegions);
|
||||||
|
|
||||||
/// Create a new Operation from the fields stored in `state`.
|
/// Create a new Operation from the fields stored in `state`.
|
||||||
|
@ -49,7 +42,7 @@ public:
|
||||||
/// Create a new Operation with the specific fields.
|
/// Create a new Operation with the specific fields.
|
||||||
static Operation *create(Location location, OperationName name,
|
static Operation *create(Location location, OperationName name,
|
||||||
TypeRange resultTypes, ValueRange operands,
|
TypeRange resultTypes, ValueRange operands,
|
||||||
DictionaryAttr attributes,
|
NamedAttrList &&attributes,
|
||||||
BlockRange successors = {},
|
BlockRange successors = {},
|
||||||
RegionRange regions = {});
|
RegionRange regions = {});
|
||||||
|
|
||||||
|
|
|
@ -485,10 +485,15 @@ public:
|
||||||
using size_type = size_t;
|
using size_type = size_t;
|
||||||
|
|
||||||
NamedAttrList() : dictionarySorted({}, true) {}
|
NamedAttrList() : dictionarySorted({}, true) {}
|
||||||
|
NamedAttrList(llvm::NoneType none) : NamedAttrList() {}
|
||||||
NamedAttrList(ArrayRef<NamedAttribute> attributes);
|
NamedAttrList(ArrayRef<NamedAttribute> attributes);
|
||||||
NamedAttrList(DictionaryAttr attributes);
|
NamedAttrList(DictionaryAttr attributes);
|
||||||
NamedAttrList(const_iterator inStart, const_iterator inEnd);
|
NamedAttrList(const_iterator inStart, const_iterator inEnd);
|
||||||
|
|
||||||
|
template <typename Container>
|
||||||
|
NamedAttrList(const Container &vec)
|
||||||
|
: NamedAttrList(ArrayRef<NamedAttribute>(vec)) {}
|
||||||
|
|
||||||
bool operator!=(const NamedAttrList &other) const {
|
bool operator!=(const NamedAttrList &other) const {
|
||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,6 @@ using namespace mlir;
|
||||||
// Operation
|
// Operation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Create a new Operation with the specific fields.
|
|
||||||
Operation *Operation::create(Location location, OperationName name,
|
|
||||||
TypeRange resultTypes, ValueRange operands,
|
|
||||||
ArrayRef<NamedAttribute> attributes,
|
|
||||||
BlockRange successors, unsigned numRegions) {
|
|
||||||
return create(location, name, resultTypes, operands,
|
|
||||||
DictionaryAttr::get(location.getContext(), attributes),
|
|
||||||
successors, numRegions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new Operation from operation state.
|
/// Create a new Operation from operation state.
|
||||||
Operation *Operation::create(const OperationState &state) {
|
Operation *Operation::create(const OperationState &state) {
|
||||||
return create(state.location, state.name, state.types, state.operands,
|
return create(state.location, state.name, state.types, state.operands,
|
||||||
|
@ -43,11 +33,11 @@ Operation *Operation::create(const OperationState &state) {
|
||||||
/// Create a new Operation with the specific fields.
|
/// Create a new Operation with the specific fields.
|
||||||
Operation *Operation::create(Location location, OperationName name,
|
Operation *Operation::create(Location location, OperationName name,
|
||||||
TypeRange resultTypes, ValueRange operands,
|
TypeRange resultTypes, ValueRange operands,
|
||||||
DictionaryAttr attributes, BlockRange successors,
|
NamedAttrList &&attributes, BlockRange successors,
|
||||||
RegionRange regions) {
|
RegionRange regions) {
|
||||||
unsigned numRegions = regions.size();
|
unsigned numRegions = regions.size();
|
||||||
Operation *op = create(location, name, resultTypes, operands, attributes,
|
Operation *op = create(location, name, resultTypes, operands,
|
||||||
successors, numRegions);
|
std::move(attributes), successors, numRegions);
|
||||||
for (unsigned i = 0; i < numRegions; ++i)
|
for (unsigned i = 0; i < numRegions; ++i)
|
||||||
if (regions[i])
|
if (regions[i])
|
||||||
op->getRegion(i).takeBody(*regions[i]);
|
op->getRegion(i).takeBody(*regions[i]);
|
||||||
|
@ -58,7 +48,7 @@ Operation *Operation::create(Location location, OperationName name,
|
||||||
/// unnecessarily uniquing a list of attributes.
|
/// unnecessarily uniquing a list of attributes.
|
||||||
Operation *Operation::create(Location location, OperationName name,
|
Operation *Operation::create(Location location, OperationName name,
|
||||||
TypeRange resultTypes, ValueRange operands,
|
TypeRange resultTypes, ValueRange operands,
|
||||||
DictionaryAttr attributes, BlockRange successors,
|
NamedAttrList &&attributes, BlockRange successors,
|
||||||
unsigned numRegions) {
|
unsigned numRegions) {
|
||||||
assert(llvm::all_of(resultTypes, [](Type t) { return t; }) &&
|
assert(llvm::all_of(resultTypes, [](Type t) { return t; }) &&
|
||||||
"unexpected null result type");
|
"unexpected null result type");
|
||||||
|
@ -88,9 +78,9 @@ Operation *Operation::create(Location location, OperationName name,
|
||||||
void *rawMem = mallocMem + prefixByteSize;
|
void *rawMem = mallocMem + prefixByteSize;
|
||||||
|
|
||||||
// Create the new Operation.
|
// Create the new Operation.
|
||||||
Operation *op =
|
Operation *op = ::new (rawMem) Operation(
|
||||||
::new (rawMem) Operation(location, name, numResults, numSuccessors,
|
location, name, numResults, numSuccessors, numRegions,
|
||||||
numRegions, attributes, needsOperandStorage);
|
attributes.getDictionary(location.getContext()), needsOperandStorage);
|
||||||
|
|
||||||
assert((numSuccessors == 0 || op->mightHaveTrait<OpTrait::IsTerminator>()) &&
|
assert((numSuccessors == 0 || op->mightHaveTrait<OpTrait::IsTerminator>()) &&
|
||||||
"unexpected successors in a non-terminator operation");
|
"unexpected successors in a non-terminator operation");
|
||||||
|
|
Loading…
Reference in New Issue