From f27ceb726188d0b16c979fddf644e33886139006 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Tue, 26 Nov 2019 15:30:04 -0800 Subject: [PATCH] Add create method that takes equivalent of OperationState with NamedAttributeList This method is close to creating an OperationState first and then unpacking it but avoids creating the OperationState and takes a NamedAttributeList for attributes rather than array of NamedAttribute (to enable reusing an already created NamedAttributeList). Reuse this new method via create that takes OperationState. I'll update inferReturnTypes in follow up to also take NamedAttributeList and so a build method that uses both inferReturnTypes and create can reuse the same list. PiperOrigin-RevId: 282651642 --- mlir/include/mlir/IR/Operation.h | 9 +++++++++ mlir/lib/IR/Operation.cpp | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index ab14e66..8a7bad1 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -70,6 +70,15 @@ public: /// Create a new Operation from the fields stored in `state`. static Operation *create(const OperationState &state); + /// Create a new Operation with the specific fields. + static Operation *create(Location location, OperationName name, + ArrayRef resultTypes, + ArrayRef operands, + const NamedAttributeList &attributes, + ArrayRef successors = {}, + ArrayRef> regions = {}, + bool resizableOperandList = false); + /// The name of an operation is the key identifier for it. OperationName getName() { return name; } diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 973b833..e5ec43c 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -125,13 +125,26 @@ Operation *Operation::create(Location location, OperationName name, /// Create a new Operation from operation state. Operation *Operation::create(const OperationState &state) { - unsigned numRegions = state.regions.size(); - Operation *op = create(state.location, state.name, state.types, - state.operands, state.attributes, state.successors, - numRegions, state.resizableOperandList); + return Operation::create( + state.location, state.name, state.types, state.operands, + NamedAttributeList(state.attributes).getDictionary(), state.successors, + state.regions, state.resizableOperandList); +} + +/// Create a new Operation with the specific fields. +Operation *Operation::create(Location location, OperationName name, + ArrayRef resultTypes, + ArrayRef operands, + const NamedAttributeList &attributes, + ArrayRef successors, + ArrayRef> regions, + bool resizableOperandList) { + unsigned numRegions = regions.size(); + Operation *op = create(location, name, resultTypes, operands, attributes, + successors, numRegions, resizableOperandList); for (unsigned i = 0; i < numRegions; ++i) - if (state.regions[i]) - op->getRegion(i).takeBody(*state.regions[i]); + if (regions[i]) + op->getRegion(i).takeBody(*regions[i]); return op; } -- 2.7.4