From 0db084d4c7010981e17db1bcaec134dab9d696e8 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Tue, 12 Jul 2022 13:24:09 -0700 Subject: [PATCH] [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 --- mlir/include/mlir/IR/Operation.h | 11 ++--------- mlir/include/mlir/IR/OperationSupport.h | 5 +++++ mlir/lib/IR/Operation.cpp | 24 +++++++----------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 70509bdb2c51..f785214cd8cb 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -33,14 +33,7 @@ public: /// Create a new Operation with the specific fields. static Operation *create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - ArrayRef attributes, - 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, + NamedAttrList &&attributes, BlockRange successors, unsigned numRegions); /// Create a new Operation from the fields stored in `state`. @@ -49,7 +42,7 @@ public: /// Create a new Operation with the specific fields. static Operation *create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - DictionaryAttr attributes, + NamedAttrList &&attributes, BlockRange successors = {}, RegionRange regions = {}); diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index 2c480d6ca52d..83dd9eab4964 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -485,10 +485,15 @@ public: using size_type = size_t; NamedAttrList() : dictionarySorted({}, true) {} + NamedAttrList(llvm::NoneType none) : NamedAttrList() {} NamedAttrList(ArrayRef attributes); NamedAttrList(DictionaryAttr attributes); NamedAttrList(const_iterator inStart, const_iterator inEnd); + template + NamedAttrList(const Container &vec) + : NamedAttrList(ArrayRef(vec)) {} + bool operator!=(const NamedAttrList &other) const { return !(*this == other); } diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index d529385c25e1..b255e80c0960 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -23,16 +23,6 @@ using namespace mlir; // Operation //===----------------------------------------------------------------------===// -/// Create a new Operation with the specific fields. -Operation *Operation::create(Location location, OperationName name, - TypeRange resultTypes, ValueRange operands, - ArrayRef 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. Operation *Operation::create(const OperationState &state) { 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. Operation *Operation::create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - DictionaryAttr attributes, BlockRange successors, + NamedAttrList &&attributes, BlockRange successors, RegionRange regions) { unsigned numRegions = regions.size(); - Operation *op = create(location, name, resultTypes, operands, attributes, - successors, numRegions); + Operation *op = create(location, name, resultTypes, operands, + std::move(attributes), successors, numRegions); for (unsigned i = 0; i < numRegions; ++i) if (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. Operation *Operation::create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - DictionaryAttr attributes, BlockRange successors, + NamedAttrList &&attributes, BlockRange successors, unsigned numRegions) { assert(llvm::all_of(resultTypes, [](Type t) { return t; }) && "unexpected null result type"); @@ -88,9 +78,9 @@ Operation *Operation::create(Location location, OperationName name, void *rawMem = mallocMem + prefixByteSize; // Create the new Operation. - Operation *op = - ::new (rawMem) Operation(location, name, numResults, numSuccessors, - numRegions, attributes, needsOperandStorage); + Operation *op = ::new (rawMem) Operation( + location, name, numResults, numSuccessors, numRegions, + attributes.getDictionary(location.getContext()), needsOperandStorage); assert((numSuccessors == 0 || op->mightHaveTrait()) && "unexpected successors in a non-terminator operation");